From torriem at gmail.com Sun Mar 1 00:05:16 2015 From: torriem at gmail.com (Michael Torrie) Date: Sat, 28 Feb 2015 22:05:16 -0700 Subject: suggestions for functional style (singleton pattern?) In-Reply-To: References: <13v4falb4odnhtvss4qdatnn16sgiv5pgd@4ax.com> Message-ID: <54F29E0C.7090107@gmail.com> On 02/28/2015 09:29 PM, yves at zioup.com wrote: >> Problem 4: >> You speak of a singleton. But you haven't implemented one. It is not >> clear from your code if this class should be a singleton. I'm guessing >> not. Singletons are in fact rare. Well, let me put it another way: >> Good reasons to code a singleton are rare. > > Thanks. I hadn't realise "singleton" meant a class built such that it could > not be instanciated more than once, I thought it corresponded to a pattern > where only one object is ever created from a given class. Is not "only one object is ever created from a given class" the same as "could not be [instantiated] more than once?" To be clear, singletons are commonly used in Python every time you import a module. A module *is* a singleton pattern, particularly one that maintains state. I use sometimes use this feature for sharing config and other data between other modules (global state when it's required). "import module" essentially does the one-time instantiation if it's a new import; top-level code in the module is run once on first import, where it acts like a constructor. So it functions as a singleton. As near as I can tell there's very little reason to make a class-based singleton in Python, since a module has the same effect and is cleaner. From torriem at gmail.com Sun Mar 1 00:14:11 2015 From: torriem at gmail.com (Michael Torrie) Date: Sat, 28 Feb 2015 22:14:11 -0700 Subject: suggestions for functional style (singleton pattern?) In-Reply-To: References: Message-ID: <54F2A023.5050506@gmail.com> On 02/28/2015 09:11 PM, yves at zioup.com wrote: > On 2015-02-28 19:19, Michael Torrie wrote: >> You say you are trying to use a singleton pattern, but your code does >> not appear to implement a singleton. From what I can read of your code, > > I call it a singletone because I only every create one object. > > I am not trying to use a singleton, I'm trying to avoid issues created by the > alternative ways of doing this (not having access to the variables in the repl > etc...). > > There are type of problems where I don't want to bind functions to data. > > By the way, I have just added some more explanation in the code, > trying to clarify the problem. I suppose it's just a matter of style but I'd just have my utility function return a dict of all the calculated values, rather than store them in a utility class instance. Then you wouldn't need an intermediate object to hold state temporarily. The idea behind functional programming in part is you can chain things together easily should you need to, which your intermediate object cannot do. But I do see kind of the pattern you are trying to employ here; I just don't understand why it's required or what you'd use it for, given that a function could just do all the calculations and return a list or dict of all calculated the values. From greg.ewing at canterbury.ac.nz Sun Mar 1 01:00:48 2015 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 01 Mar 2015 19:00:48 +1300 Subject: suggestions for functional style (singleton pattern?) In-Reply-To: References: <13v4falb4odnhtvss4qdatnn16sgiv5pgd@4ax.com> Message-ID: yves at zioup.com wrote: > Thanks. I hadn't realise "singleton" meant a class built such that it could > not be instanciated more than once, It doesn't have to be, it could just be a class that you refrain from instantiating more than once. But as Michael Torrie said, it's rare to need to to that in Python. Most of the time you're better off using a module. -- Greg From no.email at nospam.invalid Sun Mar 1 01:23:02 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 28 Feb 2015 22:23:02 -0800 Subject: suggestions for functional style (singleton pattern?) References: Message-ID: <874mq58ce1.fsf@jester.gateway.pace.com> yves at zioup.com writes: > Are there better ways to address this? Any suggestion on this style? I guess I don't completely understand the question. But one way to do a singleton in python is put the initialization code into a separate module. Then the first time you import the module, the code runs, but it doesn't re-run on subsequent imports. From steve+comp.lang.python at pearwood.info Sun Mar 1 03:11:49 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 01 Mar 2015 19:11:49 +1100 Subject: Python Worst Practices References: <87ioem8ftg.fsf@elektro.pacujo.net> Message-ID: <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> Marko Rauhamaa wrote: > The language of science and technology is American English. Not so. Despite claims that "99% of science publishing is done in English", there are still significant amounts of science and technology published in non-English languages. And the majority which is published in English doesn't necessarily use American English. E.g. I searched for article titles containing "colour" in The Lancet, the world's premier medical journal, and found 328 results, versus 8 for "color". http://www.thelancet.com/action/doSearch?searchType=quick&searchText=colour&occurrences=articleTitle&journalCode=&searchScope=fullSite Likewise Nature uses Oxford spelling: http://en.wikipedia.org/wiki/Oxford_spelling Not surprisingly, the use of English varies by field and nationality. According to this study: http://www.researchtrends.com/issue-31-november-2012/the-language-of-future-scientific-communication/ Dutch scientists publish in English forty times as much as they publish in their native language, while Chinese scientists do so only twice as often. According to astronaut Chris Hadfield's autobiography, being able to speak and read fluent Russian is essential for astronauts on the ISS, especially if they want to fly a Soyuz. I would expect that robotics is mostly written in Japanese. It is not a given that science and technology should be (1) monlingual, and (2) using the language of the dominant political superpower. As this article points out, monoglot science is neither historically inevitable, nor necessarily a good thing: http://aeon.co/magazine/science/how-did-science-come-to-speak-only-english/ Don't imagine for one second that the entire world is willing to meekly follow the path to American cultural hegemony: http://www.goethe.de/lhr/prj/diw/dos/enindex.htm (The irony of Germans publish pro-German articles in English has not escaped me, but if they had published them in German I wouldn't have found them.) As Russia flexes its muscles and tries to reclaim it's co-superpower role, I'm sure that there will be more hard sciences and mathematics published in Russian. Chinese is already one of the world's major diplomatic and trade linga francas, and somewhere between 1/3 and 1/2 of Chinese science and technology journals already publish in Chinese. If you want to specialise in solar power engineering, I suggest you learn German and Chinese. In IT, we have this: http://blog.stackoverflow.com/2014/02/cant-we-all-be-reasonable-and-speak-english/ I suspect that we're probably close to peak Anglophone science, and that in the next decade or so the trend will reverse. My prediction is that over the next half century, we'll return to a polyglot situation. > Learn it like everybody else has to. Stockholm Syndrome :-) "I learned English, and so everyone else should too." I often get the impression that many coders have an attitude that suffering is good for their art. "If it was hard for me to write, it should be hard for you to maintain" is part of it. Far too many coders love languages that make good programming *hard* (but not too hard, of course), and resist languages with garbage collection, compiler enforced safety, etc. It's not a universal thing, of course, otherwise Python, Java, etc. would be tiny niche languages, but the myth of the heroic genius programmer dies hard. I think that inside every hacker there is tiny bit of admiration for Mel the Real Programmer: https://www.cs.utah.edu/~elb/folklore/mel.html even if he didn't use a magnetised needle and a steady hand. http://xkcd.com/378/ -- Steven From gerrit.muller at gmail.com Sun Mar 1 04:28:07 2015 From: gerrit.muller at gmail.com (GerritM) Date: Sun, 1 Mar 2015 01:28:07 -0800 (PST) Subject: PIL installation fails; registration problem In-Reply-To: <2627328d-f9cb-48ba-bbfb-dfb94d24e001@googlegroups.com> References: <2627328d-f9cb-48ba-bbfb-dfb94d24e001@googlegroups.com> Message-ID: <0c93ac6e-6397-40be-ae5d-d7c0c7ec20b8@googlegroups.com> Some more searching brought me to Pillow. That seems to work! No answer needed anymore on previous question. On Saturday, February 28, 2015 at 9:51:53 PM UTC+1, GerritM wrote: > I am reinstalling everything on my new Windows 7 laptop. I run into a problem when installing PIL 1.1.7, in combination with my Activestate Python 2.7.8. > > The PIL installer complains that no Python is registered. I did run Joakim L?w's script to register Python. This results in the message "*** You probably have another Python installation!". Adding some code to this script reveals that my Python is registered with the following values (deviating from the values in the script): > installkey: C:\Python27\ > pythonkey C:\Python27\Lib;C:\Python27\DLLs;C:\Python27\Lib\lib-tk > > The script proposes for pythonkey: C:\Python27;C:\Python27\Lib\;C:\Python27\DLLs\ > > Can I change the pythonkey to the value proposed by Joakim L?w's script? From garabik-news-2005-05 at kassiopeia.juls.savba.sk Sun Mar 1 06:38:30 2015 From: garabik-news-2005-05 at kassiopeia.juls.savba.sk (garabik-news-2005-05 at kassiopeia.juls.savba.sk) Date: Sun, 1 Mar 2015 11:38:30 +0000 (UTC) Subject: ANN: grc 1.7 released Message-ID: This is generic colouriser, version 1.7. grc is a colouriser configured by regular expressions, including a simple command line wrapper for some commonly used unix commands. Notable changes in this version: - add the possibility to replace text in addition to colouring - add several configuration files License: GPL (any version) URL: http://kassiopeia.juls.savba.sk/~garabik/software/grc.html -- ----------------------------------------------------------- | Radovan Garab?k http://kassiopeia.juls.savba.sk/~garabik/ | | __..--^^^--..__ garabik @ kassiopeia.juls.savba.sk | ----------------------------------------------------------- Antivirus alert: file .signature infected by signature virus. Hi! I'm a signature virus! Copy me into your signature file to help me spread! From ginellobadellu at mail.com Sun Mar 1 06:41:51 2015 From: ginellobadellu at mail.com (MEMOCHE UNO) Date: Sun, 1 Mar 2015 03:41:51 -0800 (PST) Subject: -- redacted -- Message-ID: <360baff8-8111-49df-bde7-97df7e53ed17@googlegroups.com> -- redacted -- From bc at freeuk.com Sun Mar 1 07:47:17 2015 From: bc at freeuk.com (BartC) Date: Sun, 01 Mar 2015 12:47:17 +0000 Subject: Python Worst Practices In-Reply-To: <54f274bb$0$13011$c3e8da3$5496439d@news.astraweb.com> References: <7053A277-9687-49B0-9FDB-CB4DB3E76DEC@gmail.com> <54F0E38D.40006@davea.name> <54f274bb$0$13011$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 01/03/2015 02:08, Steven D'Aprano wrote: > BartC wrote: > >> On 28/02/2015 15:33, Mark Lawrence wrote: >> >>> It also makes me wonder what idiot decided to use C as the language for >>> the first Python implementation? Or was it written in something else and >>> then ported? >> >> Python was already slow enough even written in C. > > > Tell that to the IronPython developers. This was about the first implementation of Python. Wikipedia tells me that Python first appeared in 1991, while IronPython dates from 2006, and is apparently written in C# which came out in 2000. > Of course, benchmarks are very variable, depending on what you wish to do, > and a few things (like exceptions) are very much slower in IronPython: > > http://ironpython.codeplex.com/wikipage?title=IP27A1VsCPy27Perf&referringTitle=IronPython%20Performance And Hello World seems to be about 15 times slower. (Actually how can any Hello World program take more than a second to run?) -- Bartc From steve+comp.lang.python at pearwood.info Sun Mar 1 10:04:40 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 02 Mar 2015 02:04:40 +1100 Subject: suggestions for functional style (singleton pattern?) References: <13v4falb4odnhtvss4qdatnn16sgiv5pgd@4ax.com> Message-ID: <54f32a89$0$13007$c3e8da3$5496439d@news.astraweb.com> Mario Figueiredo wrote: > (warning: Didn't bother prove-reading and spell chocking. Sorry...) Warning: didn't bother reading. Not sorry at all. -- Steven From steve+comp.lang.python at pearwood.info Sun Mar 1 10:55:45 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 02 Mar 2015 02:55:45 +1100 Subject: suggestions for functional style (singleton pattern?) References: <13v4falb4odnhtvss4qdatnn16sgiv5pgd@4ax.com> Message-ID: <54f33682$0$13008$c3e8da3$5496439d@news.astraweb.com> Michael Torrie wrote: > Is not "only one object is ever created from a given class" the same as > "could not be [instantiated] more than once?" Not really. A class which you merely happen to only instantiate once is not a singleton class. It's just a class that you instantiate N times, where so far N has only equalled 1. A singleton class on the other hand is a class where N *must* equal 1, because the class itself enforces that rule. More generally, N may equal some small value, e.g. a Boolean class might have a fixed set of exactly 2 instances. Sometimes people try to invent names like "doubleton" for these, but none of those names have really taken off. Python modules are an interesting case. Although we often call them singletons, they're actually nothing like a singleton. Modules are instances of ModuleType, and there is no upper limit to the number of instances that can be created. It's not even true that Python enforces only a single instance per module, there are ways to get around that (albeit normally you don't want to get around it!). Here is just once way: # Don't do this at home! py> import sys py> mysys = sys py> del sys.modules['sys'], sys py> import sys py> sys is mysys False Nevertheless, modules can be used to implement similar semantics to those of singleton classes, and in particular they provide the most important features of singleton classes for free. But calling them singletons just because they quack like singletons is a little weird. Next we'll be calling the Borg pattern "singletons". -- Steven From marko at pacujo.net Sun Mar 1 11:16:05 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 01 Mar 2015 18:16:05 +0200 Subject: Python Worst Practices References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8761ak7kxm.fsf@elektro.pacujo.net> Steven D'Aprano : > Marko Rauhamaa wrote: >> Learn it like everybody else has to. > > Stockholm Syndrome :-) > > "I learned English, and so everyone else should too." No, the point is that if everybody else has taken the trouble of learning American English, it shouldn't be too much to ask for the British to make an effort as well. You can watch TV programmes at home, but in the office, you should be writing Python programs. (Spelling deviations are actually minor nuisances. A bigger problem is when a Brit thinks they can use their home accent in international contexts.) Marko From rosuav at gmail.com Sun Mar 1 11:32:23 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 Mar 2015 03:32:23 +1100 Subject: Python Worst Practices In-Reply-To: <8761ak7kxm.fsf@elektro.pacujo.net> References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> Message-ID: On Mon, Mar 2, 2015 at 3:16 AM, Marko Rauhamaa wrote: > No, the point is that if everybody else has taken the trouble of > learning American English, it shouldn't be too much to ask for the > British to make an effort as well. > > You can watch TV programmes at home, but in the office, you should be > writing Python programs. A programme is what you sell for five bucks in the theatre lobby. A program is something you execute to figure out how much money you lost on the show. Different words. > (Spelling deviations are actually minor nuisances. A bigger problem is > when a Brit thinks they can use their home accent in international > contexts.) Of course, because there's one "international accent" that everyone except the Brits use, isn't there? ChrisA From breamoreboy at yahoo.co.uk Sun Mar 1 11:38:57 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 01 Mar 2015 16:38:57 +0000 Subject: Python Worst Practices In-Reply-To: <8761ak7kxm.fsf@elektro.pacujo.net> References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> Message-ID: On 01/03/2015 16:16, Marko Rauhamaa wrote: > Steven D'Aprano : > >> Marko Rauhamaa wrote: >>> Learn it like everybody else has to. >> >> Stockholm Syndrome :-) >> >> "I learned English, and so everyone else should too." > > No, the point is that if everybody else has taken the trouble of > learning American English, it shouldn't be too much to ask for the > British to make an effort as well. > > You can watch TV programmes at home, but in the office, you should be > writing Python programs. > > (Spelling deviations are actually minor nuisances. A bigger problem is > when a Brit thinks they can use their home accent in international > contexts.) > > > Marko > Are you suggesting that we Brits have a single "home accent"? If you are, you need to stand up as your voice is rather muffled. That by the way is a British expression that may or may not be used around the Commonwealth. Should we unlearn it to fit in with American English? Two chances, zero or none. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rosuav at gmail.com Sun Mar 1 11:42:43 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 Mar 2015 03:42:43 +1100 Subject: Python Worst Practices In-Reply-To: References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> Message-ID: On Mon, Mar 2, 2015 at 3:38 AM, Mark Lawrence wrote: > Are you suggesting that we Brits have a single "home accent"? If you are, > you need to stand up as your voice is rather muffled. That by the way is a > British expression that may or may not be used around the Commonwealth. > Should we unlearn it to fit in with American English? Two chances, zero or > none. It's not one that we use out here in the Antipodes... probably a British peculiarity. Or perhaps an English peculiarity, but I would guess more likely British. ChrisA From breamoreboy at yahoo.co.uk Sun Mar 1 11:52:44 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 01 Mar 2015 16:52:44 +0000 Subject: Python Worst Practices In-Reply-To: References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> Message-ID: On 01/03/2015 16:42, Chris Angelico wrote: > On Mon, Mar 2, 2015 at 3:38 AM, Mark Lawrence wrote: >> Are you suggesting that we Brits have a single "home accent"? If you are, >> you need to stand up as your voice is rather muffled. That by the way is a >> British expression that may or may not be used around the Commonwealth. >> Should we unlearn it to fit in with American English? Two chances, zero or >> none. > > It's not one that we use out here in the Antipodes... probably a > British peculiarity. Or perhaps an English peculiarity, but I would > guess more likely British. > > ChrisA > British. Never call me English, my mum was Welsh and would come back from the grave to haunt you :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From marko at pacujo.net Sun Mar 1 11:58:19 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 01 Mar 2015 18:58:19 +0200 Subject: Python Worst Practices References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> Message-ID: <87wq3064es.fsf@elektro.pacujo.net> Chris Angelico : > On Mon, Mar 2, 2015 at 3:16 AM, Marko Rauhamaa wrote: >> (Spelling deviations are actually minor nuisances. A bigger problem >> is when a Brit thinks they can use their home accent in international >> contexts.) > > Of course, because there's one "international accent" that everyone > except the Brits use, isn't there? Well, every nonnative strives for the standard Hollywoodese and does a decent job at that. But when I hear a Brit speak their native tongue, I just "smile and wave, smile and wave" because I usually have little idea what they are trying to explain. Marko From marko at pacujo.net Sun Mar 1 12:01:46 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 01 Mar 2015 19:01:46 +0200 Subject: Python Worst Practices References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> Message-ID: <87sido6491.fsf@elektro.pacujo.net> Mark Lawrence : > Are you suggesting that we Brits have a single "home accent"? If you > are, you need to stand up as your voice is rather muffled. That by the > way is a British expression that may or may not be used around the > Commonwealth. Should we unlearn it to fit in with American English? Two > chances, zero or none. What you (or I) speak in our native surroundings is up to you (and me). However, when I exhange software engineering ideas with you, I wish both of us could stick to American English. Marko From breamoreboy at yahoo.co.uk Sun Mar 1 12:34:07 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 01 Mar 2015 17:34:07 +0000 Subject: Python Worst Practices In-Reply-To: <87sido6491.fsf@elektro.pacujo.net> References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> Message-ID: On 01/03/2015 17:01, Marko Rauhamaa wrote: > Mark Lawrence : > >> Are you suggesting that we Brits have a single "home accent"? If you >> are, you need to stand up as your voice is rather muffled. That by the >> way is a British expression that may or may not be used around the >> Commonwealth. Should we unlearn it to fit in with American English? Two >> chances, zero or none. > > What you (or I) speak in our native surroundings is up to you (and me). > > However, when I exhange software engineering ideas with you, I wish both > of us could stick to American English. > > > Marko > Well I'm not going to, so tough, or is that togh? Colour, harbour, tyre, antogonise are the way I spell words, and I'm not changing the habits of a lifetime simply because I'm on a technical site. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From torriem at gmail.com Sun Mar 1 12:42:36 2015 From: torriem at gmail.com (Michael Torrie) Date: Sun, 01 Mar 2015 10:42:36 -0700 Subject: Python Worst Practices In-Reply-To: <87wq3064es.fsf@elektro.pacujo.net> References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <87wq3064es.fsf@elektro.pacujo.net> Message-ID: <54F34F8C.5090906@gmail.com> On 03/01/2015 09:58 AM, Marko Rauhamaa wrote: > Well, every nonnative strives for the standard Hollywoodese and does a > decent job at that. But when I hear a Brit speak their native tongue, I > just "smile and wave, smile and wave" because I usually have little idea > what they are trying to explain. Ahh, I see. Your reaction, then, is similar to what most international English speakers do when they hear American politicians trying to speak in folksy southern accents. Seriously, though, it's interesting to note that in the previous generations of Americans and Canadians, many people, including a Hollywood actors, were taught elocution in schools, and a pseudo-posh English (as in the country) sort of accent. Completely fake of course much like the Queen's accent. My grandparents, for example had hints of such an accent, particularly in certain words. Christopher Plummer is a great example of this half-posh accent. Born and raised in Canada, he certainly sounds nothing like common broad north American, and certainly not common Canadian. Just listening to recordings of radio personalities and politicians from before 1950, and it's really interesting to hear the differences between modern speaking, both in accents and intonations. Language changes. If you want a bit of fun, listen to Patrick Stewart reciting a poem in his native northern accent. In school they drilled it out of him, I guess. From marko at pacujo.net Sun Mar 1 12:52:32 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 01 Mar 2015 19:52:32 +0200 Subject: Python Worst Practices References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> Message-ID: <87oaoc61wf.fsf@elektro.pacujo.net> Mark Lawrence : > On 01/03/2015 17:01, Marko Rauhamaa wrote: >> What you (or I) speak in our native surroundings is up to you (and >> me). >> >> However, when I exhange software engineering ideas with you, I wish >> both of us could stick to American English. > > Well I'm not going to, so tough, or is that togh? Colour, harbour, > tyre, antogonise are the way I spell words, and I'm not changing the > habits of a lifetime simply because I'm on a technical site. Wow, a somewhat Chauvinistic attitude, wouldn't you say? The French will learn it. The Germans will learn it. Us Finns will learn it. Only you won't learn it because you won't change the habits of a lifetime. I mean, nobody's taking away your native language. It's just that everybody's got to learn a foreign language. The learning curve shouldn't be too steep for a native Brit. Marko From breamoreboy at yahoo.co.uk Sun Mar 1 13:16:28 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 01 Mar 2015 18:16:28 +0000 Subject: Python Worst Practices In-Reply-To: <87oaoc61wf.fsf@elektro.pacujo.net> References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <87oaoc61wf.fsf@elektro.pacujo.net> Message-ID: On 01/03/2015 17:52, Marko Rauhamaa wrote: > Mark Lawrence : > >> On 01/03/2015 17:01, Marko Rauhamaa wrote: >>> What you (or I) speak in our native surroundings is up to you (and >>> me). >>> >>> However, when I exhange software engineering ideas with you, I wish >>> both of us could stick to American English. >> >> Well I'm not going to, so tough, or is that togh? Colour, harbour, >> tyre, antogonise are the way I spell words, and I'm not changing the >> habits of a lifetime simply because I'm on a technical site. > > Wow, a somewhat Chauvinistic attitude, wouldn't you say? The French will > learn it. The Germans will learn it. Us Finns will learn it. Only you > won't learn it because you won't change the habits of a lifetime. > > I mean, nobody's taking away your native language. It's just that > everybody's got to learn a foreign language. The learning curve > shouldn't be too steep for a native Brit. > > > Marko > I have German and Spanish 'O' levels taken 40 years ago. I've no intention of going back to school to learn a dialect of my own language. Why did those dumbos have to change it anyway, it's perfectly simple? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From marfig at gmail.com Sun Mar 1 13:20:56 2015 From: marfig at gmail.com (Mario Figueiredo) Date: Sun, 01 Mar 2015 19:20:56 +0100 Subject: suggestions for functional style (singleton pattern?) References: <13v4falb4odnhtvss4qdatnn16sgiv5pgd@4ax.com> <54f32a89$0$13007$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, 02 Mar 2015 02:04:40 +1100, Steven D'Aprano wrote: >Mario Figueiredo wrote: > >> (warning: Didn't bother prove-reading and spell chocking. Sorry...) > >Warning: didn't bother reading. Not sorry at all. Ohh.. how hurtful of you. It was 4:45 am when I posted that, after long hours trying to make some code work on Erlang that needs to be ready by Monday. And only because I wasn't seeing anyone replying to the OP request for help, that was sitting there for quite a few hours while everyone else was entertained discussing how many keywords are in a programming language. After I replied, I went to bed. Exhausted and sleepy. I'm not sorry you didn't read either, you pretentious prick. But I find it funny you replied to say that. From breamoreboy at yahoo.co.uk Sun Mar 1 13:24:51 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 01 Mar 2015 18:24:51 +0000 Subject: iPython 3 released Message-ID: This seemed to be a low key affair, at least from my perspective, but I'm fairly certain that people here will be interested. http://ipython.org/ipython-doc/3/whatsnew/version3.html http://ipython.org/install.html -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From marfig at gmail.com Sun Mar 1 13:32:13 2015 From: marfig at gmail.com (Mario Figueiredo) Date: Sun, 01 Mar 2015 19:32:13 +0100 Subject: Python Worst Practices References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <87oaoc61wf.fsf@elektro.pacujo.net> Message-ID: <7fm6fat9nrt1rj4520883hpuputfve6lem@4ax.com> On Sun, 01 Mar 2015 19:52:32 +0200, Marko Rauhamaa wrote: > >I mean, nobody's taking away your native language. It's just that >everybody's got to learn a foreign language. The learning curve >shouldn't be too steep for a native Brit. That's fine. But could you please point us to the ISO that details the international standard for variable names? Or failing that, to the public discussion that took place and decided American-English is the de-facto language for variable names? It would help seal your argumentation for american-english naming conventions on a positive note. From fabien.maussion at gmail.com Sun Mar 1 13:39:17 2015 From: fabien.maussion at gmail.com (Fabien) Date: Sun, 01 Mar 2015 19:39:17 +0100 Subject: iPython 3 released References: Message-ID: On 01.03.2015 19:24, Mark Lawrence wrote: > This seemed to be a low key affair, at least from my perspective True, no messages yet on the scientific python mailing lists either. I am wondering if avoiding a massive switch to a *.0 release was the reason for this (relative) silence. Fabien From wxjmfauth at gmail.com Sun Mar 1 14:13:28 2015 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sun, 1 Mar 2015 11:13:28 -0800 (PST) Subject: Python Worst Practices In-Reply-To: References: <85fv9t5zen.fsf@benfinney.id.au> <54EE88B2.1020008@gmail.com> <85d24x48na.fsf@benfinney.id.au> Message-ID: Le jeudi 26 f?vrier 2015 05:17:35 UTC+1, Chris Angelico a ?crit?: > On Thu, Feb 26, 2015 at 3:08 PM, Ben Finney wrote: > > Both of which have no technical justification; a PDF presentation > > document would do just as well and avoid those problems. > > Probably doesn't even need PDF. The slides are approximately as > complex as those in Ned Batchelder's "Pragmatic Unicode" presentation, > which is represented entirely in text. Maybe there's some slight > additional complications, but not many. > > I'd really like to see a lot more presentations done in pure text. > Scrap the graphics, scrap the fancy transitions, they aren't helping > you make your case anyway. Just give me the content. Tell me what > you're saying. I don't care about the fluff. > ======== For serious Unicode presentations, PDF or XPS are more or less the only valid candidates. For the simple reason, these file formats embed the "fonts" (in "quotes", because it's a litte bit more complicate). Examples: unicode.org: the Unicode Character Code Charts. jmf From marko at pacujo.net Sun Mar 1 14:21:35 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 01 Mar 2015 21:21:35 +0200 Subject: Python Worst Practices References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <87wq3064es.fsf@elektro.pacujo.net> Message-ID: <87ioek5xs0.fsf@elektro.pacujo.net> Michael Torrie : > On 03/01/2015 09:58 AM, Marko Rauhamaa wrote: >> Well, every nonnative strives for the standard Hollywoodese and does >> a decent job at that. But when I hear a Brit speak their native >> tongue, I just "smile and wave, smile and wave" because I usually >> have little idea what they are trying to explain. > > Ahh, I see. Your reaction, then, is similar to what most international > English speakers do when they hear American politicians trying to > speak in folksy southern accents. Yes. Note that the Atlanta-based CNN has standardized on a Hollywood accent(*). Only occasionally do the anchors slip and the Georgia accent shines through. Marko (*) With some fake artefacts. For example, "negotiate" is pronounced hypercorrectly [n?'go?s?e?t] instead of the standard [n?'go???e?t]. From rosuav at gmail.com Sun Mar 1 14:45:00 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 Mar 2015 06:45:00 +1100 Subject: Python Worst Practices In-Reply-To: References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> Message-ID: On Mon, Mar 2, 2015 at 3:52 AM, Mark Lawrence wrote: >> It's not one that we use out here in the Antipodes... probably a >> British peculiarity. Or perhaps an English peculiarity, but I would >> guess more likely British. >> >> ChrisA >> > > British. Never call me English, my mum was Welsh and would come back from > the grave to haunt you :) Ah, I didn't know you were part Welsh. The name Lawrence is a good English one, and Breamore is itself in England. But I shall strive to remember :) ChrisA From marfig at gmail.com Sun Mar 1 14:59:51 2015 From: marfig at gmail.com (Mario Figueiredo) Date: Sun, 01 Mar 2015 20:59:51 +0100 Subject: Python Worst Practices References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <87oaoc61wf.fsf@elektro.pacujo.net> <7fm6fat9nrt1rj4520883hpuputfve6lem@4ax.com> <28c6cac0-bd4b-4b6c-8b01-fe2170361051@googlegroups.com> Message-ID: <57r6fal04svtqf7meoujqv4rbb74e3d6in@4ax.com> On Sun, 1 Mar 2015 11:23:51 -0800 (PST), wxjmfauth at gmail.com wrote: > >http://www.unicode.org/reports/tr31/ > >Python is doing very on that sile. > >jmf > I'm glad Annex 31 agrees that I can name identifiers even in hebrew if I really want to. For a moment there I was shaking when I opened the link. Must be some other document then. This one didn't help. From alister.nospam.ware at ntlworld.com Sun Mar 1 15:16:26 2015 From: alister.nospam.ware at ntlworld.com (alister) Date: Sun, 1 Mar 2015 20:16:26 +0000 (UTC) Subject: Python Worst Practices References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> Message-ID: On Sun, 01 Mar 2015 18:16:05 +0200, Marko Rauhamaa wrote: > Steven D'Aprano : > >> Marko Rauhamaa wrote: >>> Learn it like everybody else has to. >> >> Stockholm Syndrome :-) >> >> "I learned English, and so everyone else should too." > > No, the point is that if everybody else has taken the trouble of > learning American English, it shouldn't be too much to ask for the > British to make an effort as well. > The language is called English, the clue is in the name. interestingly most 'Brits' can switch between American English & English without too much trouble (I still have a problem with Chips) > > You can watch TV programmes at home, but in the office, you should be > writing Python programs. > > (Spelling deviations are actually minor nuisances. A bigger problem is > when a Brit thinks they can use their home accent in international > contexts.) The bigger problem is that the USian does not know there even is an international context. I know that us British/English are poor at learning other languages but we do at least acknowledge that we should do better. Last time I was is the USA I had a local ask me which state London was in! (heck I know they only bother with their own history but I though we played quite an important role in that) > > > Marko -- You know it's going to be a long day when you get up, shave and shower, start to get dressed and your shoes are still warm. -- Dean Webber From rosuav at gmail.com Sun Mar 1 15:26:22 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 Mar 2015 07:26:22 +1100 Subject: Python Worst Practices In-Reply-To: References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> Message-ID: On Mon, Mar 2, 2015 at 7:16 AM, alister wrote: > Last time I was is the USA I had a local ask me which state London was > in! (heck I know they only bother with their own history but I though we > played quite an important role in that) See, that wasn't a geographic question, it was one of security alert level. He wanted to know if London was presently in a state of alarm. ChrisA From rxjwg98 at gmail.com Sun Mar 1 15:32:34 2015 From: rxjwg98 at gmail.com (fl) Date: Sun, 1 Mar 2015 12:32:34 -0800 (PST) Subject: Question about python package numpy Message-ID: Hi, It is difficult to install numpy package for my PC Windows 7, 64-bit OS. In the end, I install Enthought Canopy, which is recommended on line because it does install numpy automatically. Now, I can test it with import numpy it succeeds. On http://wiki.scipy.org/Cookbook, it shows some interesting code example snippet, such as Cookbook / ParticleFilter, Markov chain etc. I don't know how I can access these code examples, because I don't know where Enthought Canopy installs these package. Could you help me on using numpy examples? Thanks, From marko at pacujo.net Sun Mar 1 15:45:12 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 01 Mar 2015 22:45:12 +0200 Subject: Python Worst Practices References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> Message-ID: <87d24s5twn.fsf@elektro.pacujo.net> alister : > The language is called English, the clue is in the name. I don't care what you call it as long as you use the Hollywoodese accent and spelling. > interestingly most 'Brits' can switch between American English & > English without too much trouble I wish they actually did. Not to pick on the British. All native English-speakers seem to suffer from the same problem.(*) Fact remains I can easily understand what Chinese, Mexican, Italian, Russian or Malay colleagues say in English. For some reason, Australian and Indian speakers don't give me trouble, either. The Irish accent is borderline, but the British, sad to say, are hopeless. Marko (*) Why, I speak Finnish in the local dialect; however, I *don't* try my vernacular on any foreigner. The other day, a Russian colleague bravely initiated a dialogue in Finnish. I was careful to speak slowly using the standard dialect. From marfig at gmail.com Sun Mar 1 16:01:48 2015 From: marfig at gmail.com (Mario Figueiredo) Date: Sun, 01 Mar 2015 22:01:48 +0100 Subject: Python Worst Practices References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <87d24s5twn.fsf@elektro.pacujo.net> Message-ID: On Sun, 01 Mar 2015 22:45:12 +0200, Marko Rauhamaa wrote: > >Fact remains I can easily understand what Chinese, Mexican, Italian, >Russian or Malay colleagues say in English. For some reason, Australian >and Indian speakers don't give me trouble, either. The Irish accent is >borderline, but the British, sad to say, are hopeless. > You should listen to African English speakers... This is probably common among many languages. Not that I have a common understanding of the phenomena, but I can easily draw a parallel to Portuguese. The European Portuguese is harder to understand to folks learning the language than the non Portuguese dialects in Brazil, African countries and even Macau in Asia. This is also an issue among speakers of the language. European Portuguese don't have any trouble understanding dialect speakers in Angola, Brazil, Cape Verde, etc. But the those dialect speakers have an hard time understanding the European Portuguese. From alister.nospam.ware at ntlworld.com Sun Mar 1 16:07:52 2015 From: alister.nospam.ware at ntlworld.com (alister) Date: Sun, 1 Mar 2015 21:07:52 +0000 (UTC) Subject: Python Worst Practices References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> Message-ID: On Mon, 02 Mar 2015 07:26:22 +1100, Chris Angelico wrote: > On Mon, Mar 2, 2015 at 7:16 AM, alister > wrote: >> Last time I was is the USA I had a local ask me which state London was >> in! (heck I know they only bother with their own history but I though >> we played quite an important role in that) > > See, that wasn't a geographic question, it was one of security alert > level. He wanted to know if London was presently in a state of alarm. > > ChrisA unfortunately no, she didn't and was completely clueless. if fact she made the stereotypical air head in slasher movies look like a genius. -- Some scholars are like donkeys, they merely carry a lot of books. -- Folk saying From anddam+NOSPAM at brapi.net Sun Mar 1 16:25:31 2015 From: anddam+NOSPAM at brapi.net (Andrea D'Amore) Date: Sun, 1 Mar 2015 22:25:31 +0100 Subject: Question about python package numpy References: Message-ID: On 2015-03-01 20:32:34 +0000, fl said: > import numpy > it succeeds. On http://wiki.scipy.org/Cookbook, it shows some interesting > code example snippet, such as Cookbook / ParticleFilter, Markov chain etc. > I don't know how I can access these code examples, because I don't know where > Enthought Canopy installs these package. Did you check Canopy's documentation? Are you sure the examples in cookbook are installed with the package? You can print numpy.__file__ to know where the package is installed. At [1] I see "You can get the source code for this tutorial here: tandemqueue.py" with link to the file, why don't you get the source files for the example from their pages? [1] http://wiki.scipy.org/Cookbook/Solving_Large_Markov_Chains -- Andrea From greg.ewing at canterbury.ac.nz Sun Mar 1 16:40:04 2015 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 02 Mar 2015 10:40:04 +1300 Subject: Python Worst Practices In-Reply-To: <7fm6fat9nrt1rj4520883hpuputfve6lem@4ax.com> References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <87oaoc61wf.fsf@elektro.pacujo.net> <7fm6fat9nrt1rj4520883hpuputfve6lem@4ax.com> Message-ID: Mario Figueiredo wrote: > But could you please point us to the ISO that details the > international standard for variable names? Or failing that, to the > public discussion that took place and decided American-English is the > de-facto language for variable names? American became the standard for variable names the same way most de-facto standards come into being -- by historical accident and network effects. Many of the commonly-used libraries happen to be written by Americans, and programming languages being the way they are, anyone who uses them has to follow suit. When I'm programming I always spell it "color", even when I don't strictly have to, because having two spellings in the same body of code would be too confusing for everyone, myself included. But in documentation, in contexts where it's not critical, I'm more likely to use the spelling I'm most familiar with, which is "colour". I can't imagine any English speaker, native or otherwise, being unable to cope with that. -- Greg From roy at panix.com Sun Mar 1 16:47:04 2015 From: roy at panix.com (Roy Smith) Date: Sun, 01 Mar 2015 16:47:04 -0500 Subject: Python Worst Practices References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <87oaoc61wf.fsf@elektro.pacujo.net> <7fm6fat9nrt1rj4520883hpuputfve6lem@4ax.com> Message-ID: In article , Gregory Ewing wrote: > But in documentation, in contexts where it's not critical, > I'm more likely to use the spelling I'm most familiar > with, which is "colour". I can't imagine any English > speaker, native or otherwise, being unable to cope with > that. What abut people who can't pronounce the letter "B"? From breamoreboy at yahoo.co.uk Sun Mar 1 17:10:54 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 01 Mar 2015 22:10:54 +0000 Subject: Python Worst Practices In-Reply-To: References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <87oaoc61wf.fsf@elektro.pacujo.net> <7fm6fat9nrt1rj4520883hpuputfve6lem@4ax.com> Message-ID: On 01/03/2015 21:47, Roy Smith wrote: > In article , > Gregory Ewing wrote: > >> But in documentation, in contexts where it's not critical, >> I'm more likely to use the spelling I'm most familiar >> with, which is "colour". I can't imagine any English >> speaker, native or otherwise, being unable to cope with >> that. > > What abut people who can't pronounce the letter "B"? > It's people who can't pronounce "C" who are the problem, leading to troubles such as Kings Bollege Bambridge. Americans also drop the "u" so it should be "abot" not "abut". -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From bc at freeuk.com Sun Mar 1 17:14:05 2015 From: bc at freeuk.com (BartC) Date: Sun, 01 Mar 2015 22:14:05 +0000 Subject: Python Worst Practices In-Reply-To: <8761ak7kxm.fsf@elektro.pacujo.net> References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> Message-ID: On 01/03/2015 16:16, Marko Rauhamaa wrote: > Steven D'Aprano : > >> Marko Rauhamaa wrote: >>> Learn it like everybody else has to. >> >> Stockholm Syndrome :-) >> >> "I learned English, and so everyone else should too." > > No, the point is that if everybody else has taken the trouble of > learning American English, it shouldn't be too much to ask for the > British to make an effort as well. Actually it is the Brits who are bilingual; we can watch British /or/ American TV shows and movies without needing subtitles. It's not always the case the other way around. You have a point that American-English spellings have some domination internationally simply by sheer numbers (in the same way that C-style syntax has unfortunately permeated a great number of languages). But I think there are still a few places which have had a British influence which might still spell colour as "colour" (such as India with a population a mere 4 times as large as the USA). But programming in the UK I'm going to spell variables that include the word "colour" with a "u". I'm sure that any Americans will be able to guess what it means, if they were ever to see my source codes. (BTW "color" gets underlined in red by my spell-checker, another reason to avoid it.) While with any external interfaces that use "color", I often create an alias that uses "colour" (saves time later by not constantly misspelling it). -- Bartc From rxjwg98 at gmail.com Sun Mar 1 17:23:25 2015 From: rxjwg98 at gmail.com (fl) Date: Sun, 1 Mar 2015 14:23:25 -0800 (PST) Subject: Question about python package numpy In-Reply-To: References: Message-ID: On Sunday, March 1, 2015 at 1:25:59 PM UTC-8, Andrea D'Amore wrote: > On 2015-03-01 20:32:34 +0000, fl said: > > > import numpy > > it succeeds. On http://wiki.scipy.org/Cookbook, it shows some interesting > > code example snippet, such as Cookbook / ParticleFilter, Markov chain etc. > > > I don't know how I can access these code examples, because I don't know where > > Enthought Canopy installs these package. > > Did you check Canopy's documentation? > > Are you sure the examples in cookbook are installed with the package? > You can print numpy.__file__ to know where the package is installed. > > At [1] I see "You can get the source code for this tutorial here: > tandemqueue.py" with link to the file, why don't you get the source > files for the example from their pages? > > > [1] http://wiki.scipy.org/Cookbook/Solving_Large_Markov_Chains > > -- > Andrea Thanks for your reply. I learned Python for about one week ago. The link in your reply does look like executable. But the second snippet about particle filter, see below please, looks award. i.e. I do not see the connection between the first and the second code snippet. I should save them to one .py file? Or save to two files? What name should be for the second file? Thanks again. ............... http://wiki.scipy.org/Cookbook/ParticleFilter The following code shows the tracker operating on a test sequence featuring a moving square against a uniform background. Toggle line numbers 1 if __name__ == "__main__": 2 from pylab import * 3 from itertools import izip 4 import time 5 ion() From steve+comp.lang.python at pearwood.info Sun Mar 1 17:43:09 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 02 Mar 2015 09:43:09 +1100 Subject: OT Accents [was Re: Python Worst Practices] References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <87wq3064es.fsf@elektro.pacujo.net> Message-ID: <54f395fe$0$13012$c3e8da3$5496439d@news.astraweb.com> Michael Torrie wrote: > If you want a bit of fun, listen to Patrick Stewart reciting a poem in > his native northern accent. ?In school they drilled it out of him, I > guess. And then you have people like Alexis Denisof, husband to Alyson Hannigan, best known for playing Wesley Wyndam-Pryce in Buffy and Angel, and for a three second clip in The Avengers movie where he is in such heavy makeup and prosthetics that he is almost unrecognisable. As Wesley, he has such a sexy upper-crust British accent that he could could almost make straight men turn. In real life, he sounds like Kermit the Frog on helium. -- Steven From ben+python at benfinney.id.au Sun Mar 1 19:03:16 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 02 Mar 2015 11:03:16 +1100 Subject: An injury when I was a sbhoolboy; I was bitten by a bat. (was: Python Worst Practices) References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <87oaoc61wf.fsf@elektro.pacujo.net> <7fm6fat9nrt1rj4520883hpuputfve6lem@4ax.com> Message-ID: <851tl82rln.fsf_-_@benfinney.id.au> Roy Smith writes: > In article , > Gregory Ewing wrote: > > > But in documentation, in contexts where it's not critical, I'm more > > likely to use the spelling I'm most familiar with, which is > > "colour". I can't imagine any English speaker, native or otherwise, > > being unable to cope with that. > > What abut people who can't pronounce the letter "B"? You mean the letter ?C?? Yes, I thought so. Well why not pronounce the letter ?C? as though it were the letter ?K?? (See if you have no idea what this is all about.) Alternatively, I could ask you to pronounce ?busy? as though it was spelled with an ?i?; or pronounce ?friend? as though it *doesn't* have an ?i?. But that would be asking for sense in English orthography . -- \ ?Any sufficiently advanced bug is indistinguishable from a | `\ feature.? ?Rich Kulawiec | _o__) | Ben Finney From ben+python at benfinney.id.au Sun Mar 1 19:07:15 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 02 Mar 2015 11:07:15 +1100 Subject: An injury when I was a sbhoolboy; I was bitten by a bat. References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <87oaoc61wf.fsf@elektro.pacujo.net> <7fm6fat9nrt1rj4520883hpuputfve6lem@4ax.com> <851tl82rln.fsf_-_@benfinney.id.au> Message-ID: <85wq301cuk.fsf@benfinney.id.au> Ben Finney writes: > (See if you have no > idea what this is all about.) I was sloppy with my pronouns there. I'm pretty sure Roy knows what he's referring to; that ?you? was directed to anyone who is not aware. -- \ ?Some people have a problem, and they think ?I know, I'll use | `\ Perl!?. Now they have some number of problems but they're not | _o__) sure whether it's a string or an integer.? ?Benno Rice, 2011 | Ben Finney From python at mrabarnett.plus.com Sun Mar 1 20:59:27 2015 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 02 Mar 2015 01:59:27 +0000 Subject: Python Worst Practices In-Reply-To: References: <7053A277-9687-49B0-9FDB-CB4DB3E76DEC@gmail.com> <54F0E38D.40006@davea.name> <54f274bb$0$13011$c3e8da3$5496439d@news.astraweb.com> Message-ID: <54F3C3FF.3040608@mrabarnett.plus.com> On 2015-03-02 01:37, Dennis Lee Bieber wrote: > On Sun, 1 Mar 2015 13:43:50 +1100, Chris Angelico > declaimed the following: > >>losing performance. Conversely, I'm sure Python could also have been >>implemented on top of BASIC if someone felt like it, though what the >>advantages might be I have no idea. But performance is not (or should > > You'd be able to run it on a TI99/4 (in which the BASIC interpreter, > itself, was run on an interpreter... nothing like taking the first "16-bit" > home computer and shackling it with an interpreted language that was run on > an interpreted language) > The "16-bit" CPU had a 16-bit address bus (64K address space). If you were going to switch from an 8-bit processor to a 16-bit processor, one of the pluses you'd be looking for would the ability to directly address more than 64K. From steve+comp.lang.python at pearwood.info Sun Mar 1 21:35:50 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 02 Mar 2015 13:35:50 +1100 Subject: (Still OT) It's not the size of the vocabulary that matters, but what you do with it [was Re: Python Worst Practices] References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> Message-ID: <54f3cc87$0$11124$c3e8da3@news.astraweb.com> Dennis Lee Bieber wrote: > Well... when we've got states bigger than some countries... A Texan farmer goes to Australia on vacation. There he meets an Aussie farmer and gets to talking. They walk around the farm a little, and the Aussie shows off his herd of cattle. The Texan immediately replies, ?Our Texan longhorns are at least twice as large as your cows.? The Aussie shows off his big wheat field and the Texan says, ?In Texas, our wheat fields are ten times as big as that!? Just then a herd of kangaroos hop through the field. The Texan does a double-take and says "What in San Quentin are those?? The Aussie replies ?Don?t you have any grasshoppers in Texas?? The Texan recovers quickly and says ?Of course we do, I?ve just never seen them that color before. You?ve got a nice farm, but it?s a bit small. Back home, when I drive around the ranch checking the fences, I get in my SUV at 4 in the morning, and don?t get back home until 11 the next night.? The Aussie replies ?Ah yes, I had a car like that once. American-made, is it?? -- Steve From no.email at nospam.invalid Sun Mar 1 22:18:20 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 01 Mar 2015 19:18:20 -0800 Subject: (Still OT) It's not the size of the vocabulary that matters, but what you do with it [was Re: Python Worst Practices] References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <54f3cc87$0$11124$c3e8da3@news.astraweb.com> Message-ID: <87mw3w6q9v.fsf@jester.gateway.pace.com> Steven D'Aprano writes: > The Aussie replies ?Ah yes, I had a car like that once. American-made, is > it?? Is it true that in Australia, the number of the beast is 999? From rosuav at gmail.com Sun Mar 1 22:42:35 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 Mar 2015 14:42:35 +1100 Subject: (Still OT) It's not the size of the vocabulary that matters, but what you do with it [was Re: Python Worst Practices] In-Reply-To: <87mw3w6q9v.fsf@jester.gateway.pace.com> References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <54f3cc87$0$11124$c3e8da3@news.astraweb.com> <87mw3w6q9v.fsf@jester.gateway.pace.com> Message-ID: On Mon, Mar 2, 2015 at 2:18 PM, Paul Rubin wrote: > Steven D'Aprano writes: >> The Aussie replies ?Ah yes, I had a car like that once. American-made, is >> it?? > > Is it true that in Australia, the number of the beast is 999? Wouldn't know. Out here, we're not afraid of the beast - why should we be? We have spiders, and snakes, and kangaroos, and weather, and desert, and ants, and spiders, and drop bears, and spiders, and "jelly" (gelignite), and I nearly forgot to mention that we have spiders. If you feel like disposing of an unwanted Beast, you could do worse than deposit him somewhere in the Western Australian desert. It's kinda like sending him to hell, only the postage is cheaper. ChrisA From rustompmody at gmail.com Sun Mar 1 23:14:13 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 1 Mar 2015 20:14:13 -0800 (PST) Subject: Python Worst Practices In-Reply-To: <87sido6491.fsf@elektro.pacujo.net> References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> Message-ID: <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> On Sunday, March 1, 2015 at 10:32:00 PM UTC+5:30, Marko Rauhamaa wrote: > Mark Lawrence : > > > Are you suggesting that we Brits have a single "home accent"? If you > > are, you need to stand up as your voice is rather muffled. That by the > > way is a British expression that may or may not be used around the > > Commonwealth. Should we unlearn it to fit in with American English? Two > > chances, zero or none. > > What you (or I) speak in our native surroundings is up to you (and me). > > However, when I exhange software engineering ideas with you, I wish both > of us could stick to American English. When I was in college, there was this course called ?Accounting and Bookkeeping? It was a disaster since I always accounted on the wrong side of the ledger. I guess I only passed because the teacher occasionally also accounted on the wrong side of the ledger!! With due respect Marko, are you accounting on the wrong side of the ledger? If some non-native of English expresses him/herself poorly we still try to understand ? its even in the code of conduct or somethin And yet you insist that a Brit (or English or whatever) should change his ways?? I would say it is wrong side of the ledger because the amount of 'culture' invested into a Brit is more than into someone who just poorly learned the language yesterday. In school my most memorable encounters were with Shakespeare, Blake, Wordsworth [I did not like Keats]. Until he died at 102 my gpa would recite Longfellow's "Lives of great men" almost as a daily prayer. If all that gets erased for some tasteless colourless (ok colorless) internationalese, its a bloody shame. ========= ?Reminds of the modern mania for 'rights' Yeah some groups ? women, races, skin-colors etc etc etc ? have been traditionally have-nots. If the attempt at equalizing is not done in balance instead of equalization we get a swing in the opposite direction and the haves become the have-nots. From marko at pacujo.net Sun Mar 1 23:40:51 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 02 Mar 2015 06:40:51 +0200 Subject: Python Worst Practices References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> Message-ID: <87zj7w3tbg.fsf@elektro.pacujo.net> Rustom Mody : >> However, when I exhange software engineering ideas with you, I wish >> both of us could stick to American English. > > [...] > > I would say it is wrong side of the ledger because the amount of > culture' invested into a Brit is more than into someone who just > poorly learned the language yesterday. > > In school my most memorable encounters were with Shakespeare, Blake, > Wordsworth [I did not like Keats]. Until he died at 102 my gpa would > recite Longfellow's "Lives of great men" almost as a daily prayer. If > all that gets erased for some tasteless colourless (ok colorless) > internationalese, its a bloody shame. We are not talking about culture here but Python coding, conference keynote addresses at the most "cultured" end of it. Marko From davea at davea.name Sun Mar 1 23:49:57 2015 From: davea at davea.name (Dave Angel) Date: Sun, 01 Mar 2015 23:49:57 -0500 Subject: Python Worst Practices In-Reply-To: <54F3C3FF.3040608@mrabarnett.plus.com> References: <7053A277-9687-49B0-9FDB-CB4DB3E76DEC@gmail.com> <54F0E38D.40006@davea.name> <54f274bb$0$13011$c3e8da3$5496439d@news.astraweb.com> <54F3C3FF.3040608@mrabarnett.plus.com> Message-ID: <54F3EBF5.3030701@davea.name> On 03/01/2015 08:59 PM, MRAB wrote: > On 2015-03-02 01:37, Dennis Lee Bieber wrote >> >> You'd be able to run it on a TI99/4 (in which the BASIC interpreter, >> itself, was run on an interpreter... nothing like taking the first >> "16-bit" >> home computer and shackling it with an interpreted language that was >> run on >> an interpreted language) >> > The "16-bit" CPU had a 16-bit address bus (64K address space). If you > were going to switch from an 8-bit processor to a 16-bit processor, one > of the pluses you'd be looking for would the ability to directly > address more than 64K. > The 16 bit address bus permitted addressing of 64k words. On most processors, that was 64k bytes, though I know one Harris had no bytes, but every memory access was 16 bits. It therefore had the equivalent of 128k bytes. Likewise I believe some of the DEC and DG minis had 128k bytes of addressability. Usually, the term 8bit processor was referring to the size of the register(s), not the address bus. All the 8 bit micro-processors had 16 bit address buses. In fact, 4 bit processors generally had 12 to 16 bit address buses as well. So a 4 bit processor with a 16 bit address bus could address 32k bytes, a half byte (a nybble) at a time). The IBM PC's 8088 had an 8 bit data-bus and 20 address lines. But they called it a 16bit processor, to try to distinguish it from 8 bit processors like the 8080. Anyway, it was code compatible with the 8086, which really did have a 16bit data bus and 20 bit address bus. -- DaveA From sarvagya.pant at gmail.com Mon Mar 2 01:00:00 2015 From: sarvagya.pant at gmail.com (Sarvagya Pant) Date: Mon, 2 Mar 2015 11:45:00 +0545 Subject: Python27.dll could not be found Message-ID: I have been writing a c++ program that is supposed to call the python function. The code is a snippet from python.org itself. #include #include #include int main() { Py_SetProgramName("Learning"); Py_Initialize(); PyRun_SimpleString("import hashlib\nprint hashlib.md5('sarvagya pant').hexdigest()"); Py_Finalize(); return 0; } I have used Visual Studio 2010. I have linked the include directories and lib files correctly. It gets correctly built. Dependency walker shows the file depends upon Python27.dll. I have looked into the folder Dlls of python. It is not there. Also I have checked both System and System32 folder. It is not present in there too. Python version is 2.7. How can I get Python27.dll to deploy my app for customers? Please help. -- *sarvagya* -------------- next part -------------- An HTML attachment was scrubbed... URL: From sarvagya.pant at gmail.com Mon Mar 2 01:19:46 2015 From: sarvagya.pant at gmail.com (Sarvagya Pant) Date: Mon, 2 Mar 2015 12:04:46 +0545 Subject: Md5 is different in Windows and Linux Message-ID: Hello, I am amazed that the md5 of a file given by python in windows is different than that of linux. Consider the following code: import hashlib def md5_for_file(f, block_size=2**20): md5 = hashlib.md5() while True: data = f.read(block_size) if not data: break md5.update(data) return md5.hexdigest() f = open("somefile.txt") print md5_for_file(f) When I run the program I get the checksum value: 2f9cc8da53ee89762a34702f745d2956 But on this site http://onlinemd5.com/ and on linux it has value E10D4E3847713472F51BC606852712F1. Why is there difference in value of Checksum computed by python in windows and other system.? -- *sarvagya* -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- Hello Check the MD5 of this file From al.basili at gmail.com Mon Mar 2 02:59:03 2015 From: al.basili at gmail.com (alb) Date: 2 Mar 2015 07:59:03 GMT Subject: rst and pypandoc Message-ID: Hi everyone, I'm writing a document in restructured text and I'd like to convert it to latex for printing. To accomplish this I've used semi-successfully pandoc and the wrapper pypandoc. My biggest issue is with figures and references to them. We've our macro to allocate figures so I'm forced to bypass the rst directive /.. figure/, moreover I haven't happened to find how you can reference to a figure in the rst docs. For all the above reasons I'm writing snippets of pure latex in my rst doc, but I'm having issues with the escape characters: i = '\ref{fig:abc}' print pypandoc.convert(i, 'latex', format='rst') ef\{fig:abc\} because of the \r that is interpreted by python as special character. If I try to escape with '\' I don't seem to find a way out... Any idea/pointer/suggestion? Al -- A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing on usenet and in e-mail? From taleinat at gmail.com Mon Mar 2 03:08:14 2015 From: taleinat at gmail.com (Tal Einat) Date: Mon, 2 Mar 2015 10:08:14 +0200 Subject: reload a module imported with importlib.machinery.SourceFileLoader Message-ID: Hi everyone, I'm trying to import a module with tests, run the tests, then patch some things with mock.patch, reload the tests module and re-run the tests. This is part of an interactive course in which the tests module is written by the user. Therefore I'm using importlib.machinery.SourceFileLoader to import the tests module, like so: importlib.machinery.SourceFileLoader("tmp", path).load_module("tmp") This works just fine. However, when trying to reload the module, importlib.reload(module) is raising the following exception: Traceback (most recent call last): File ".../tests.py", line 28, in reload_module(module) File ".../custom_test_helpers.py", line 18, in reload_module importlib.reload(module) File ".../lib/python3.4/importlib/__init__.py", line 149, in reload methods.exec(module) File "", line 1134, in exec AttributeError: 'NoneType' object has no attribute 'name' Am I going about this the wrong way? Is this a bug in importlib? If it is a bug, and suggestions for a workaround? I'm running Python 3.4.2, installed via pyenv on OSX 10.8. - Tal Einat From robert.kern at gmail.com Mon Mar 2 03:48:00 2015 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 02 Mar 2015 08:48:00 +0000 Subject: Question about python package numpy In-Reply-To: References: Message-ID: On 2015-03-01 20:32, fl wrote: > Hi, > > It is difficult to install numpy package for my PC Windows 7, 64-bit OS. In > the end, I install Enthought Canopy, which is recommended on line because it > does install numpy automatically. Now, I can test it with > > import numpy > > it succeeds. On http://wiki.scipy.org/Cookbook, it shows some interesting > code example snippet, such as Cookbook / ParticleFilter, Markov chain etc. > > I don't know how I can access these code examples, because I don't know where > Enthought Canopy installs these package. > > Could you help me on using numpy examples? None of these examples come prepackaged in any distribution I am aware of. You are intended to copy-and-paste them from the wiki if you want to use them. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From mail at timgolden.me.uk Mon Mar 2 03:50:38 2015 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 02 Mar 2015 08:50:38 +0000 Subject: Md5 is different in Windows and Linux In-Reply-To: References: Message-ID: <54F4245E.6070909@timgolden.me.uk> On 02/03/2015 06:19, Sarvagya Pant wrote: > Hello, I am amazed that the md5 of a file given by python in windows is > different than that of linux. Consider the following code: > > import hashlib > def md5_for_file(f, block_size=2**20): > md5 = hashlib.md5() > while True: > data = f.read(block_size) > if not data: > break > md5.update(data) > return md5.hexdigest() > > f = open("somefile.txt") > print md5_for_file(f) > > When I run the program I get the checksum value: > 2f9cc8da53ee89762a34702f745d2956 > > But on this site http://onlinemd5.com/ and on linux it has value > E10D4E3847713472F51BC606852712F1. > > Why is there difference in value of Checksum computed by python in > windows and other system.? Because you're opening the file in text mode (implicitly; that's the default) which silently converts certain characters. If you open it in binary mode: f = open("somefile.txt", "rb") then you should see the same result TJG From __peter__ at web.de Mon Mar 2 03:54:13 2015 From: __peter__ at web.de (Peter Otten) Date: Mon, 02 Mar 2015 09:54:13 +0100 Subject: Md5 is different in Windows and Linux References: Message-ID: Sarvagya Pant wrote: > Hello, I am amazed that the md5 of a file given by python in windows is > different than that of linux. Consider the following code: > > import hashlib > def md5_for_file(f, block_size=2**20): > md5 = hashlib.md5() > while True: > data = f.read(block_size) > if not data: > break > md5.update(data) > return md5.hexdigest() > > f = open("somefile.txt") > print md5_for_file(f) > > When I run the program I get the checksum value: > 2f9cc8da53ee89762a34702f745d2956 > > But on this site http://onlinemd5.com/ and on linux it has value > E10D4E3847713472F51BC606852712F1. > > Why is there difference in value of Checksum computed by python in windows > and other system.? You have to open the file in binary mode f = open("somefile.txt", "rb") Otherwise on Windows "\r\n" will be translated to "\n" while Linux passes the bytes unchanged -- and thus md5.update() will see different data and produce a different checksum. From giordani.leonardo at gmail.com Mon Mar 2 03:58:13 2015 From: giordani.leonardo at gmail.com (Leonardo Giordani) Date: Mon, 2 Mar 2015 09:58:13 +0100 Subject: PyPI, reStructuredText and readthedocs problems Message-ID: Hi all, Some time ago I open sourced a package named postage ( https://pypi.python.org/pypi/postage/). I am experiencing issues with documentation. The project is hosted on GitHub (https://github.com/lgiordani/postage), where the README.md is perfectly rendered. My issues are: 1. I use pandoc to convert README.md to README.rst. This latter is rendered by GitHUb as well, but when I upload the package to PyPI I get a messy result (look at the package page). 2. When I import the project into readthedocs.org the build fails with no output. This is the only information I get ----------------------------- 8< ----------------------------- Build for postage Built: Feb. 27, 2015. 10:41 a.m. State: Finished Outcome: Failed (Status Code: 0) Version: latest Type: html Build Standard Output ----------------------------- 8< ----------------------------- May someone help me figuring out what's wrong in my code? Thanks! Leo Leonardo Giordani @tw_lgiordani - lgiordani.com My profile on About.me - My GitHub page -------------- next part -------------- An HTML attachment was scrubbed... URL: From alister.nospam.ware at ntlworld.com Mon Mar 2 03:59:31 2015 From: alister.nospam.ware at ntlworld.com (alister) Date: Mon, 2 Mar 2015 08:59:31 +0000 (UTC) Subject: Python Worst Practices References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> Message-ID: On Sun, 01 Mar 2015 20:14:13 -0800, Rustom Mody wrote: > On Sunday, March 1, 2015 at 10:32:00 PM UTC+5:30, Marko Rauhamaa wrote: >> Mark Lawrence : >> >> > Are you suggesting that we Brits have a single "home accent"? If you >> > are, you need to stand up as your voice is rather muffled. That by >> > the way is a British expression that may or may not be used around >> > the Commonwealth. Should we unlearn it to fit in with American >> > English? Two chances, zero or none. >> >> What you (or I) speak in our native surroundings is up to you (and me). >> >> However, when I exhange software engineering ideas with you, I wish >> both of us could stick to American English. > > When I was in college, there was this course called ?Accounting and > Bookkeeping? > It was a disaster since I always accounted on the wrong side of the > ledger. > I guess I only passed because the teacher occasionally also accounted on > the wrong side of the ledger!! > > With due respect Marko, are you accounting on the wrong side of the > ledger? > > If some non-native of English expresses him/herself poorly we still try > to understand ? its even in the code of conduct or somethin > > And yet you insist that a Brit (or English or whatever) should change > his ways?? or as another analogy why don't you (Marco) try telling a Barber in Seville that he should be speaking Latin Spanish not that strange variation he uses? I suspect the reaction you get will be far more severe than the one you are getting from we English (& Brits) -- system has been recalled From fabien.maussion at gmail.com Mon Mar 2 05:19:06 2015 From: fabien.maussion at gmail.com (Fabien) Date: Mon, 02 Mar 2015 11:19:06 +0100 Subject: suggestions for functional style (singleton pattern?) References: <13v4falb4odnhtvss4qdatnn16sgiv5pgd@4ax.com> Message-ID: On 01.03.2015 06:05, Michael Torrie wrote: > A module*is* a singleton pattern, particularly one > that maintains state. I use sometimes use this feature for sharing > config and other data between other modules (global state when it's > required). I do this too, after some helping recommendations I got from this discussion group. I find it neat to use a module for sharing config states, but I always wondered: does this pattern fall into the "globals are devil" category? Cheers, Fabien From denismfmcmahon at gmail.com Mon Mar 2 05:24:17 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Mon, 2 Mar 2015 10:24:17 +0000 (UTC) Subject: Md5 is different in Windows and Linux References: Message-ID: On Mon, 02 Mar 2015 12:04:46 +0545, Sarvagya Pant wrote: > When I run the program I get the checksum value: > 2f9cc8da53ee89762a34702f745d2956 > > But on this site http://onlinemd5.com/ and on linux it has value > E10D4E3847713472F51BC606852712F1. > > Why is there difference in value of Checksum computed by python in > windows and other system.? Perhaps windows file io is padding the file to the block size? Or maybe the windows version has different end of lines. -- Denis McMahon, denismfmcmahon at gmail.com From marfig at gmail.com Mon Mar 2 05:31:12 2015 From: marfig at gmail.com (Mario Figueiredo) Date: Mon, 02 Mar 2015 11:31:12 +0100 Subject: suggestions for functional style (singleton pattern?) References: <13v4falb4odnhtvss4qdatnn16sgiv5pgd@4ax.com> Message-ID: On Mon, 02 Mar 2015 11:19:06 +0100, Fabien wrote: >On 01.03.2015 06:05, Michael Torrie wrote: >> A module*is* a singleton pattern, particularly one >> that maintains state. I use sometimes use this feature for sharing >> config and other data between other modules (global state when it's >> required). > >I do this too, after some helping recommendations I got from this >discussion group. I find it neat to use a module for sharing config >states, but I always wondered: does this pattern fall into the "globals >are devil" category? > Global constants are conceptually different than global variables. It is just that in Python there is no semantic diference between the two. The former are OK and a useful pattern, whereas the latter are the ones we call evil. From songofacandy at gmail.com Mon Mar 2 05:33:59 2015 From: songofacandy at gmail.com (INADA Naoki) Date: Mon, 02 Mar 2015 10:33:59 +0000 Subject: PyPI, reStructuredText and readthedocs problems References: Message-ID: PyPI parses your README strictly. $ rst2html.py --strict README.rst README.rst:700: (INFO/1) Duplicate implicit target name: "fingerprint". Exiting due to level-1 (INFO) system message. But I don't know how to avoid this error when converting from markdown. On Mon, Mar 2, 2015 at 6:35 PM Leonardo Giordani < giordani.leonardo at gmail.com> wrote: > Hi all, > > Some time ago I open sourced a package named postage ( > https://pypi.python.org/pypi/postage/). > > I am experiencing issues with documentation. The project is hosted on > GitHub (https://github.com/lgiordani/postage), where the README.md is > perfectly rendered. My issues are: > > 1. I use pandoc to convert README.md to README.rst. This latter is > rendered by GitHUb as well, but when I upload the package to PyPI I get a > messy result (look at the package page). > > 2. When I import the project into readthedocs.org the build fails with no > output. This is the only information I get > > ----------------------------- 8< ----------------------------- > > Build for postage > > Built: Feb. 27, 2015. 10:41 a.m. > > State: Finished > > Outcome: Failed (Status Code: 0) > > Version: latest > > Type: html > > Build Standard Output > > ----------------------------- 8< ----------------------------- > > May someone help me figuring out what's wrong in my code? > Thanks! > > Leo > > > Leonardo Giordani > @tw_lgiordani - lgiordani.com > My profile on About.me - My GitHub > page > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From wolfgang.maier at biologie.uni-freiburg.de Mon Mar 2 05:54:06 2015 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Mon, 02 Mar 2015 11:54:06 +0100 Subject: PyPI, reStructuredText and readthedocs problems In-Reply-To: References: Message-ID: On 03/02/2015 11:33 AM, INADA Naoki wrote: > PyPI parses your README strictly. > > $ rst2html.py --strict README.rst > README.rst:700: (INFO/1) Duplicate implicit target name: "fingerprint". > Exiting due to level-1 (INFO) system message. > > But I don't know how to avoid this error when converting from markdown. > The other occurence of a title Fingerprint is at line 436. I guess you will have to change one of the two titles (maybe Fingerprints ?) to make things work. > On Mon, Mar 2, 2015 at 6:35 PM Leonardo Giordani > > wrote: > > Hi all, > > Some time ago I open sourced a package named postage > (https://pypi.python.org/pypi/postage/). > > I am experiencing issues with documentation. The project is hosted > on GitHub (https://github.com/lgiordani/postage), where the > README.md is perfectly rendered. My issues are: > > 1. I use pandoc to convert README.md to README.rst. This latter is > rendered by GitHUb as well, but when I upload the package to PyPI I > get a messy result (look at the package page). > > 2. When I import the project into readthedocs.org > the build fails with no output. This is the > only information I get > > ----------------------------- 8< ----------------------------- > > Build for postage > > Built: Feb. 27, 2015. 10:41 a.m. > > State: Finished > > Outcome: Failed (Status Code: 0) > > Version: latest > > Type: html > > Build Standard Output > > ----------------------------- 8< ----------------------------- > > May someone help me figuring out what's wrong in my code? > Thanks! > > Leo From jonas at wielicki.name Mon Mar 2 05:54:40 2015 From: jonas at wielicki.name (Jonas Wielicki) Date: Mon, 02 Mar 2015 11:54:40 +0100 Subject: Uncanny valley of languages In-Reply-To: References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> Message-ID: <54F44170.2020507@wielicki.name> On 01.03.2015 18:34, Mark Lawrence wrote: > On 01/03/2015 17:01, Marko Rauhamaa wrote: >> Mark Lawrence : >> >>> Are you suggesting that we Brits have a single "home accent"? If you >>> are, you need to stand up as your voice is rather muffled. That by the >>> way is a British expression that may or may not be used around the >>> Commonwealth. Should we unlearn it to fit in with American English? Two >>> chances, zero or none. >> >> What you (or I) speak in our native surroundings is up to you (and me). >> >> However, when I exhange software engineering ideas with you, I wish both >> of us could stick to American English. >> >> >> Marko >> > > Well I'm not going to, so tough, or is that togh? Colour, harbour, > tyre, antogonise are the way I spell words, and I'm not changing the > habits of a lifetime simply because I'm on a technical site. > I wonder whether this discussion has anything to do with the Uncanny Valley [1]. Anyone who is not native to some dialect of English just has to learn that language it if they want to be taken serious in the SE world. That?s kind of a law. On the other hand, there are some British refuse to learn a few minor adaptions to their native tongue, while others have to trade their native tongue completely. This leads me to believe that due to the fact that there are so many similarities between en_US and en_GB (they are even closer than C and C++, which are already taken as being the same language with dialects by some), it feels as if en_US was dictating them how to live their own language, while in fact, they are distinct and noone tries to dictate anything about en_GB. That said, I also prefer the British spelling. But that is just, like, my opinion, man. regards, jwi [1]: https://en.wikipedia.org/wiki/Uncanny_valley -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: OpenPGP digital signature URL: From wolfgang.maier at biologie.uni-freiburg.de Mon Mar 2 06:03:23 2015 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Mon, 02 Mar 2015 12:03:23 +0100 Subject: rst and pypandoc In-Reply-To: References: Message-ID: On 03/02/2015 08:59 AM, alb wrote: > Hi everyone, > > I'm writing a document in restructured text and I'd like to convert it > to latex for printing. To accomplish this I've used semi-successfully > pandoc and the wrapper pypandoc. > > My biggest issue is with figures and references to them. We've our macro > to allocate figures so I'm forced to bypass the rst directive /.. > figure/, moreover I haven't happened to find how you can reference to a > figure in the rst docs. > > For all the above reasons I'm writing snippets of pure latex in my rst > doc, but I'm having issues with the escape characters: > > i = '\ref{fig:abc}' > print pypandoc.convert(i, 'latex', format='rst') > ef\{fig:abc\} > > because of the \r that is interpreted by python as special character. > > If I try to escape with '\' I don't seem to find a way out... > what exactly do you mean by not finding a way out ? Escaping with a '\' should work. Of course, that backslash will print for clarity, but I suppose you want to write this to a file ? What happens if you do so ? From cfkaran2 at gmail.com Mon Mar 2 06:04:33 2015 From: cfkaran2 at gmail.com (Cem Karan) Date: Mon, 2 Mar 2015 06:04:33 -0500 Subject: Design thought for callbacks In-Reply-To: References: <33677AE8-B2FA-49F9-9304-C8D93784255D@gmail.com> Message-ID: <8A3659BC-9100-4A3A-9117-47227B3D290B@gmail.com> On Feb 26, 2015, at 2:54 PM, Ian Kelly wrote: > On Feb 26, 2015 4:00 AM, "Cem Karan" wrote: > > > > > > On Feb 26, 2015, at 12:36 AM, Gregory Ewing wrote: > > > > > Cem Karan wrote: > > >> I think I see what you're talking about now. Does WeakMethod > > >> (https://docs.python.org/3/library/weakref.html#weakref.WeakMethod) solve > > >> this problem? > > > > > > Yes, that looks like it would work. > > > > > > Cool! > > Sometimes I wonder whether anybody reads my posts. I suggested a solution involving WeakMethod four days ago that additionally extends the concept to non-method callbacks (requiring a small amount of extra effort from the client in those cases, but I think that is unavoidable. There is no way that the framework can determine the appropriate lifetime for a closure-based callback.) I apologize about taking so long to reply to everyone's posts, but I've been busy at home. Ian, it took me a while to do some research to understand WHY what you were suggesting was important; you're right about storing the object as well as the method/function separately, but I think that WeakMethod might solve that completely, correct? Are there any cases where WeakMethod wouldn't work? Thanks, Cem Karan From cfkaran2 at gmail.com Mon Mar 2 06:06:19 2015 From: cfkaran2 at gmail.com (Cem Karan) Date: Mon, 2 Mar 2015 06:06:19 -0500 Subject: Design thought for callbacks In-Reply-To: <54EF7B63.3050009@stoneleaf.us> References: <33677AE8-B2FA-49F9-9304-C8D93784255D@gmail.com> <54EF7B63.3050009@stoneleaf.us> Message-ID: <9245AA5F-99DB-4C64-B261-C68AD26F2180@gmail.com> On Feb 26, 2015, at 3:00 PM, Ethan Furman wrote: > On 02/26/2015 11:54 AM, Ian Kelly wrote: > >> Sometimes I wonder whether anybody reads my posts. > > It's entirely possible the OP wasn't ready to understand your solution four days ago, but two days later the OP was. Thank you Ethan, that was precisely my problem. Thanks, Cem Karan From cfkaran2 at gmail.com Mon Mar 2 06:11:59 2015 From: cfkaran2 at gmail.com (Cem Karan) Date: Mon, 2 Mar 2015 06:11:59 -0500 Subject: Design thought for callbacks In-Reply-To: References: <33677AE8-B2FA-49F9-9304-C8D93784255D@gmail.com> <575FE33B-D1AD-4391-B816-7440D5849C41@gmail.com> Message-ID: <95B97C92-5B57-4B66-A782-70CEAA37BE24@gmail.com> On Feb 26, 2015, at 7:04 PM, Fabio Zadrozny wrote: > > On Wed, Feb 25, 2015 at 9:46 AM, Cem Karan wrote: > > On Feb 24, 2015, at 8:23 AM, Fabio Zadrozny wrote: > > > Hi Cem, > > > > I didn't read the whole long thread, but I thought I'd point you to what I'm using in PyVmMonitor (http://www.pyvmmonitor.com/) -- which may already cover your use-case. > > > > Take a look at the callback.py at https://github.com/fabioz/pyvmmonitor-core/blob/master/pyvmmonitor_core/callback.py > > > > And its related test (where you can see how to use it): https://github.com/fabioz/pyvmmonitor-core/blob/master/_pyvmmonitor_core_tests/test_callback.py (note that it falls back to a strong reference on simple functions -- i.e.: usually top-level methods or methods created inside a scope -- but otherwise uses weak references). > > That looks like a better version of what I was thinking about originally. However, various people on the list have convinced me to stick with strong references everywhere. I'm working out a possible API right now, once I have some code that I can use to illustrate what I'm thinking to everyone, I'll post it to the list. > > Thank you for showing me your code though, it is clever! > > Thanks, > Cem Karan > > ?Hi Cem, > > Well, I decided to elaborate a bit on the use-case I have and how I use it (on a higher level): http://pydev.blogspot.com.br/2015/02/design-for-client-side-applications-in.html > > So, you can see if it may be worth for you or not (I agree that sometimes you should keep strong references, but for my use-cases, weak references usually work better -- with the only exception being closures, which is handled different anyways but with the gotcha of having to manually unregister it). As I mentioned in an earlier post, I've been quite busy at home, and expect to be for a few days to come, so I apologize both for being so late posting, and for not posting my own API plans. Your blog post has given me quite a bit to think about, thank you! Do you mind if I work up an API similar to yours? I'm planning on using a different license (not LGPL), which is why I ask. Thanks, Cem Karan From fomcl at yahoo.com Mon Mar 2 06:42:49 2015 From: fomcl at yahoo.com (Albert-Jan Roskam) Date: Mon, 2 Mar 2015 03:42:49 -0800 Subject: Pythonic locale Message-ID: <1425296569.88419.YahooMailBasic@web163802.mail.gq1.yahoo.com> Hi, The Python locale standard libraries has some oddities and (long-standing) bugs. Example oddity: SETlocale *returns* a locale; getlocale output cannot always be consumed by setlocale. Example bug: resetlocale fails in Windows. What is your opinion about the work-around code below? import sys import os import locale as locale_ locale_.setlocale(locale_.LC_ALL, "") class PythonicLocale(object): LC_ALL = locale_.LC_ALL LC_CTYPE = locale_.LC_CTYPE def __init__(self, failsafe=False): self.failsafe = failsafe @property def locale(self): """Partial wrapper for locale in standard library""" # LANG and LC_ALL sometimes not set if not sys.platform.startswith("win"): if locale_.getlocale()[0] is None and self.failsafe: os.environ["LANG"] = "en_US" os.environ["LC_ALL"] = "en_US.UTF-8" # getlocale output cannot be consumed by setlocale return locale_.setlocale(locale_.LC_ALL) @locale.setter def locale(self, category_and_locale_tuple): locale_.setlocale(*category_and_locale_tuple) @locale.deleter def locale(self): if sys.platform.startswith("win"): # resetlocale() is broken in Windows locale_.setlocale(locale_.LC_ALL, "") else: locale_.resetlocale() def getdefaultlocale(self): return locale_.getdefaultlocale() if __name__ == "__main__": locale = PythonicLocale() # getter print locale.locale # setter locale.locale = (locale.LC_ALL, "german") print locale.locale # deleter del locale.locale # check if deleter worked print locale.locale Thanks! Regards, Albert-Jan ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From giordani.leonardo at gmail.com Mon Mar 2 06:43:58 2015 From: giordani.leonardo at gmail.com (Leonardo Giordani) Date: Mon, 2 Mar 2015 12:43:58 +0100 Subject: PyPI, reStructuredText and readthedocs problems In-Reply-To: References: Message-ID: Sorry, seems that GMail cannot understand I'm on a ML, and just answered the single persons. [Thread with INADA] Thank you. Seems that rst2html.py uses the header of a section as the id of the corresponding HTML anchor. Since I had two headers with the same title there was a name clash. I just changed one of the headers and the problem is gone. [Thread with Wolfgang] On 03/02/2015 12:11 PM, Leonardo Giordani wrote: > Thanks, spotted! > > Now readthedocs fails with this message > > Traceback (most recent call last): > File "/home/docs/checkouts/ > readthedocs.org/user_builds/postage/envs/feature-docs/local/lib/python2.7/site-packages/sphinx/cmdline.py > < > http://readthedocs.org/user_builds/postage/envs/feature-docs/local/lib/python2.7/site-packages/sphinx/cmdline.py>", > line 253, in main > warningiserror, tags, verbosity, parallel) > File "/home/docs/checkouts/ > readthedocs.org/user_builds/postage/envs/feature-docs/local/lib/python2.7/site-packages/sphinx/application.py > < > http://readthedocs.org/user_builds/postage/envs/feature-docs/local/lib/python2.7/site-packages/sphinx/application.py>", > line 107, in __init__ > confoverrides or {}, self.tags) > File "/home/docs/checkouts/ > readthedocs.org/user_builds/postage/envs/feature-docs/local/lib/python2.7/site-packages/sphinx/config.py > < > http://readthedocs.org/user_builds/postage/envs/feature-docs/local/lib/python2.7/site-packages/sphinx/config.py>", > line 229, in __init__ > execfile_(filename, config) > File "/home/docs/checkouts/ > readthedocs.org/user_builds/postage/envs/feature-docs/local/lib/python2.7/site-packages/sphinx/util/pycompat.py > < > http://readthedocs.org/user_builds/postage/envs/feature-docs/local/lib/python2.7/site-packages/sphinx/util/pycompat.py>", > line 105, in execfile_ > exec code in _globals > File "conf.py", line 31, in > import postage > File "/home/docs/checkouts/ > readthedocs.org/user_builds/postage/checkouts/feature-docs/postage/__init__.py > < > http://readthedocs.org/user_builds/postage/checkouts/feature-docs/postage/__init__.py>", > line 10, in > from postage import messaging > File "/home/docs/checkouts/ > readthedocs.org/user_builds/postage/checkouts/feature-docs/postage/messaging.py > < > http://readthedocs.org/user_builds/postage/checkouts/feature-docs/postage/messaging.py>", > line 4, in > import pika > ImportError: No module named pika > > Exception occurred: > File "/home/docs/checkouts/ > readthedocs.org/user_builds/postage/checkouts/feature-docs/postage/messaging.py > < > http://readthedocs.org/user_builds/postage/checkouts/feature-docs/postage/messaging.py>", > line 4, in > import pika > ImportError: No module named pika > The full traceback has been saved in /tmp/sphinx-err-R4ZC2D.log, if you > want to report the issue to the developers. > Please also report this if it was a user error, so that a better error > message can be provided next time. > A bug report can be filed in the tracker at < > https://bitbucket.org/birkenfeld/sphinx/issues/>. Thanks! > > I however configured the build to use a virtualenv and specified 'pika' in > my requirements.txt file. > > Look at the complete output from readthedocs: Setup Output checkout ----- venv ----- Using real prefix '/usr' New python executable in /home/docs/checkouts/ readthedocs.org/user_builds/postage/envs/latest/bin/python Installing setuptools, pip...done. Running virtualenv with interpreter /home/docs/bin/python doc_builder ----- Requirement already up-to-date: sphinx==1.2.2 in /var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages Requirement already up-to-date: virtualenv==1.10.1 in /var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages Requirement already up-to-date: setuptools==1.1 in /var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages Requirement already up-to-date: docutils==0.11 in /var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages Requirement already up-to-date: mkdocs==0.11.1 in /var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages Requirement already up-to-date: mock==1.0.1 in /var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages Requirement already up-to-date: pillow==2.6.1 in /var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages Requirement already up-to-date: readthedocs-sphinx-ext==0.4.4 in /var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages Requirement already up-to-date: Jinja2>=2.7.1 in /var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages (from mkdocs==0.11.1) Requirement already up-to-date: Markdown>=2.3.1,<2.5 in /var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages (from mkdocs==0.11.1) Requirement already up-to-date: PyYAML>=3.10 in /var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages (from mkdocs==0.11.1) Requirement already up-to-date: watchdog>=0.7.0 in /var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages (from mkdocs==0.11.1) Requirement already up-to-date: ghp-import>=0.4.1 in /var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages (from mkdocs==0.11.1) Requirement already up-to-date: argh>=0.24.1 in /var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages (from watchdog>=0.7.0->mkdocs==0.11.1) Requirement already up-to-date: pathtools>=0.1.1 in /var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages (from watchdog>=0.7.0->mkdocs==0.11.1) Cleaning up... requirements ----- Requirement already satisfied (use --upgrade to upgrade): mock in /var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages (from -r requirements.txt (line 1)) Downloading/unpacking pika (from -r requirements.txt (line 2)) Running setup.py (path:/var/build/user_builds/postage/envs/latest/build/pika/setup.py) egg_info for package pika Downloading/unpacking tornado (from pika->-r requirements.txt (line 2)) Running setup.py (path:/var/build/user_builds/postage/envs/latest/build/tornado/setup.py) egg_info for package tornado Downloading/unpacking twisted (from pika->-r requirements.txt (line 2)) Running setup.py (path:/var/build/user_builds/postage/envs/latest/build/twisted/setup.py) egg_info for package twisted Downloading/unpacking pyev (from pika->-r requirements.txt (line 2)) Running setup.py (path:/var/build/user_builds/postage/envs/latest/build/pyev/setup.py) egg_info for package pyev Aborted: pyev-0.9.0 requires libev >= 4.15 Complete output from command python setup.py egg_info: Aborted: pyev-0.9.0 requires libev >= 4.15 There it is! readthedocs already failed to install pika because it, in turn, requires libev >= 4.15 . Leonardo Giordani @tw_lgiordani - lgiordani.com My profile on About.me - My GitHub page 2015-03-02 11:33 GMT+01:00 INADA Naoki : > PyPI parses your README strictly. > > $ rst2html.py --strict README.rst > README.rst:700: (INFO/1) Duplicate implicit target name: "fingerprint". > Exiting due to level-1 (INFO) system message. > > But I don't know how to avoid this error when converting from markdown. > > On Mon, Mar 2, 2015 at 6:35 PM Leonardo Giordani < > giordani.leonardo at gmail.com> wrote: > >> Hi all, >> >> Some time ago I open sourced a package named postage ( >> https://pypi.python.org/pypi/postage/). >> >> I am experiencing issues with documentation. The project is hosted on >> GitHub (https://github.com/lgiordani/postage), where the README.md is >> perfectly rendered. My issues are: >> >> 1. I use pandoc to convert README.md to README.rst. This latter is >> rendered by GitHUb as well, but when I upload the package to PyPI I get a >> messy result (look at the package page). >> >> 2. When I import the project into readthedocs.org the build fails with >> no output. This is the only information I get >> >> ----------------------------- 8< ----------------------------- >> >> Build for postage >> >> Built: Feb. 27, 2015. 10:41 a.m. >> >> State: Finished >> >> Outcome: Failed (Status Code: 0) >> >> Version: latest >> >> Type: html >> >> Build Standard Output >> >> ----------------------------- 8< ----------------------------- >> >> May someone help me figuring out what's wrong in my code? >> Thanks! >> >> Leo >> >> >> Leonardo Giordani >> @tw_lgiordani - lgiordani.com >> My profile on About.me - My GitHub >> page >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From giordani.leonardo at gmail.com Mon Mar 2 06:47:07 2015 From: giordani.leonardo at gmail.com (Leonardo Giordani) Date: Mon, 2 Mar 2015 12:47:07 +0100 Subject: PyPI, reStructuredText and readthedocs problems In-Reply-To: References: Message-ID: The libev problem happens on my local Ubuntu 14.10 too. It is not a pike requirement however (not installed by 'pip install pika'). Seems that pika forces some requirements when on readthedocs through this code on_rtd = os.environ.get('READTHEDOCS', None) == 'True' requirements = list() if on_rtd: requirements.append('tornado') requirements.append('twisted') requirements.append('pyev') I contacted Gavin Roy, the pika maintainer, to check this with him. Thanks Leonardo Giordani @tw_lgiordani - lgiordani.com My profile on About.me - My GitHub page 2015-03-02 12:43 GMT+01:00 Leonardo Giordani : > Sorry, seems that GMail cannot understand I'm on a ML, and just answered > the single persons. > > [Thread with INADA] > Thank you. > > Seems that rst2html.py uses the header of a section as the id of the > corresponding HTML anchor. > Since I had two headers with the same title there was a name clash. > I just changed one of the headers and the problem is gone. > > > [Thread with Wolfgang] > On 03/02/2015 12:11 PM, Leonardo Giordani wrote: > >> Thanks, spotted! >> >> Now readthedocs fails with this message >> >> Traceback (most recent call last): >> File "/home/docs/checkouts/ >> readthedocs.org/user_builds/postage/envs/feature-docs/local/lib/python2.7/site-packages/sphinx/cmdline.py >> < >> http://readthedocs.org/user_builds/postage/envs/feature-docs/local/lib/python2.7/site-packages/sphinx/cmdline.py>", >> line 253, in main >> warningiserror, tags, verbosity, parallel) >> File "/home/docs/checkouts/ >> readthedocs.org/user_builds/postage/envs/feature-docs/local/lib/python2.7/site-packages/sphinx/application.py >> < >> http://readthedocs.org/user_builds/postage/envs/feature-docs/local/lib/python2.7/site-packages/sphinx/application.py>", >> line 107, in __init__ >> confoverrides or {}, self.tags) >> File "/home/docs/checkouts/ >> readthedocs.org/user_builds/postage/envs/feature-docs/local/lib/python2.7/site-packages/sphinx/config.py >> < >> http://readthedocs.org/user_builds/postage/envs/feature-docs/local/lib/python2.7/site-packages/sphinx/config.py>", >> line 229, in __init__ >> execfile_(filename, config) >> File "/home/docs/checkouts/ >> readthedocs.org/user_builds/postage/envs/feature-docs/local/lib/python2.7/site-packages/sphinx/util/pycompat.py >> < >> http://readthedocs.org/user_builds/postage/envs/feature-docs/local/lib/python2.7/site-packages/sphinx/util/pycompat.py>", >> line 105, in execfile_ >> exec code in _globals >> File "conf.py", line 31, in >> import postage >> File "/home/docs/checkouts/ >> readthedocs.org/user_builds/postage/checkouts/feature-docs/postage/__init__.py >> < >> http://readthedocs.org/user_builds/postage/checkouts/feature-docs/postage/__init__.py>", >> line 10, in >> from postage import messaging >> File "/home/docs/checkouts/ >> readthedocs.org/user_builds/postage/checkouts/feature-docs/postage/messaging.py >> < >> http://readthedocs.org/user_builds/postage/checkouts/feature-docs/postage/messaging.py>", >> line 4, in >> import pika >> ImportError: No module named pika >> >> Exception occurred: >> File "/home/docs/checkouts/ >> readthedocs.org/user_builds/postage/checkouts/feature-docs/postage/messaging.py >> < >> http://readthedocs.org/user_builds/postage/checkouts/feature-docs/postage/messaging.py>", >> line 4, in >> import pika >> ImportError: No module named pika >> The full traceback has been saved in /tmp/sphinx-err-R4ZC2D.log, if you >> want to report the issue to the developers. >> Please also report this if it was a user error, so that a better error >> message can be provided next time. >> A bug report can be filed in the tracker at < >> https://bitbucket.org/birkenfeld/sphinx/issues/>. Thanks! >> >> I however configured the build to use a virtualenv and specified 'pika' >> in my requirements.txt file. >> >> > Look at the complete output from readthedocs: > > Setup Output > > > > checkout > ----- > > > > venv > ----- > > Using real prefix '/usr' > New python executable in /home/docs/checkouts/ > readthedocs.org/user_builds/postage/envs/latest/bin/python > Installing setuptools, pip...done. > Running virtualenv with interpreter /home/docs/bin/python > > > doc_builder > ----- > > Requirement already up-to-date: sphinx==1.2.2 in > /var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages > Requirement already up-to-date: virtualenv==1.10.1 in > /var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages > Requirement already up-to-date: setuptools==1.1 in > /var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages > Requirement already up-to-date: docutils==0.11 in > /var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages > Requirement already up-to-date: mkdocs==0.11.1 in > /var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages > Requirement already up-to-date: mock==1.0.1 in > /var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages > Requirement already up-to-date: pillow==2.6.1 in > /var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages > Requirement already up-to-date: readthedocs-sphinx-ext==0.4.4 in > /var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages > Requirement already up-to-date: Jinja2>=2.7.1 in > /var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages > (from mkdocs==0.11.1) > Requirement already up-to-date: Markdown>=2.3.1,<2.5 in > /var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages > (from mkdocs==0.11.1) > Requirement already up-to-date: PyYAML>=3.10 in > /var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages > (from mkdocs==0.11.1) > Requirement already up-to-date: watchdog>=0.7.0 in > /var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages > (from mkdocs==0.11.1) > Requirement already up-to-date: ghp-import>=0.4.1 in > /var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages > (from mkdocs==0.11.1) > Requirement already up-to-date: argh>=0.24.1 in > /var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages > (from watchdog>=0.7.0->mkdocs==0.11.1) > Requirement already up-to-date: pathtools>=0.1.1 in > /var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages > (from watchdog>=0.7.0->mkdocs==0.11.1) > Cleaning up... > > > requirements > ----- > > Requirement already satisfied (use --upgrade to upgrade): mock in > /var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages > (from -r requirements.txt (line 1)) > Downloading/unpacking pika (from -r requirements.txt (line 2)) > Running setup.py > (path:/var/build/user_builds/postage/envs/latest/build/pika/setup.py) > egg_info for package pika > > Downloading/unpacking tornado (from pika->-r requirements.txt (line 2)) > Running setup.py > (path:/var/build/user_builds/postage/envs/latest/build/tornado/setup.py) > egg_info for package tornado > > Downloading/unpacking twisted (from pika->-r requirements.txt (line 2)) > Running setup.py > (path:/var/build/user_builds/postage/envs/latest/build/twisted/setup.py) > egg_info for package twisted > > Downloading/unpacking pyev (from pika->-r requirements.txt (line 2)) > Running setup.py > (path:/var/build/user_builds/postage/envs/latest/build/pyev/setup.py) > egg_info for package pyev > Aborted: pyev-0.9.0 requires libev >= 4.15 > Complete output from command python setup.py egg_info: > Aborted: pyev-0.9.0 requires libev >= 4.15 > > There it is! readthedocs already failed to install pika because it, in > turn, requires libev >= 4.15 . > > > > > Leonardo Giordani > @tw_lgiordani - lgiordani.com > My profile on About.me - My GitHub > page > > 2015-03-02 11:33 GMT+01:00 INADA Naoki : > >> PyPI parses your README strictly. >> >> $ rst2html.py --strict README.rst >> README.rst:700: (INFO/1) Duplicate implicit target name: "fingerprint". >> Exiting due to level-1 (INFO) system message. >> >> But I don't know how to avoid this error when converting from markdown. >> >> On Mon, Mar 2, 2015 at 6:35 PM Leonardo Giordani < >> giordani.leonardo at gmail.com> wrote: >> >>> Hi all, >>> >>> Some time ago I open sourced a package named postage ( >>> https://pypi.python.org/pypi/postage/). >>> >>> I am experiencing issues with documentation. The project is hosted on >>> GitHub (https://github.com/lgiordani/postage), where the README.md is >>> perfectly rendered. My issues are: >>> >>> 1. I use pandoc to convert README.md to README.rst. This latter is >>> rendered by GitHUb as well, but when I upload the package to PyPI I get a >>> messy result (look at the package page). >>> >>> 2. When I import the project into readthedocs.org the build fails with >>> no output. This is the only information I get >>> >>> ----------------------------- 8< ----------------------------- >>> >>> Build for postage >>> >>> Built: Feb. 27, 2015. 10:41 a.m. >>> >>> State: Finished >>> >>> Outcome: Failed (Status Code: 0) >>> >>> Version: latest >>> >>> Type: html >>> >>> Build Standard Output >>> >>> ----------------------------- 8< ----------------------------- >>> >>> May someone help me figuring out what's wrong in my code? >>> Thanks! >>> >>> Leo >>> >>> >>> Leonardo Giordani >>> @tw_lgiordani - lgiordani.com >>> My profile on About.me - My GitHub >>> page >>> -- >>> https://mail.python.org/mailman/listinfo/python-list >>> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From maus at mail.com Mon Mar 2 06:55:37 2015 From: maus at mail.com (greymausg) Date: 2 Mar 2015 11:55:37 GMT Subject: date Message-ID: I have a csv file, the first item on a line is the date in the format 2015-03-02 I try to get that as a date by date(row[0]), but it barfs, replying "Expecting an integer". (I am really trying to get the offset in weeks from that date to today()) -- greymaus . . ... From manolo at austrohungaro.com Mon Mar 2 07:00:20 2015 From: manolo at austrohungaro.com (Manolo =?iso-8859-1?Q?Mart=EDnez?=) Date: Mon, 2 Mar 2015 13:00:20 +0100 Subject: Python Worst Practices In-Reply-To: References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> Message-ID: <20150302120020.GB5042@beagle> On 03/02/15 at 08:59am, alister wrote: > or as another analogy why don't you (Marco) try telling a Barber in > Seville that he should be speaking Latin Spanish not that strange > variation he uses? > > I suspect the reaction you get will be far more severe than the one you > are getting from we English (& Brits) > In fact, you would find that most Spaniards, in an international Spanish-speaking context, will tune down their dialectal idiosyncracies and aim for a 'neutral Spanish' of sorts. Manolo From davea at davea.name Mon Mar 2 07:03:52 2015 From: davea at davea.name (Dave Angel) Date: Mon, 02 Mar 2015 07:03:52 -0500 Subject: rst and pypandoc In-Reply-To: References: Message-ID: <54F451A8.2010305@davea.name> On 03/02/2015 02:59 AM, alb wrote: > Hi everyone, > > I'm writing a document in restructured text and I'd like to convert it > to latex for printing. To accomplish this I've used semi-successfully > pandoc and the wrapper pypandoc. I don't see other responses yet, so I'll respond even though i don't know pyandoc. > > My biggest issue is with figures and references to them. We've our macro > to allocate figures so I'm forced to bypass the rst directive /.. > figure/, moreover I haven't happened to find how you can reference to a > figure in the rst docs. > > For all the above reasons I'm writing snippets of pure latex in my rst > doc, but I'm having issues with the escape characters: > > i = '\ref{fig:abc}' > print pypandoc.convert(i, 'latex', format='rst') > ef\{fig:abc\} > > because of the \r that is interpreted by python as special character. I don't know whether your problem is understanding what Python does with literals, or what pyandoc wants. I can only help with the former. You could try printing the i to see what it looks like, if you don't understand Python literal escaping. Perhaps something like: print "++" + i + "++" Those pluses tend to help figure out what happens when you have control codes mixed in the line. For example as it stands, the 0x0d character will have the effect of overwriting those first two "++" A second method is to look at the string in hex: print i.encode("hex") > > If I try to escape with '\' I don't seem to find a way out... You should be a lot more explicit with all three parts of that statement. Try: I'm trying to get a string of When I try to escape with '\' i = '\\ref{fig:abc}' I get the following exception: -- DaveA From marko at pacujo.net Mon Mar 2 07:19:45 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 02 Mar 2015 14:19:45 +0200 Subject: Python Worst Practices References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> Message-ID: <87d24regm6.fsf@elektro.pacujo.net> alister : > or as another analogy why don't you (Marco) try telling a Barber in > Seville that he should be speaking Latin Spanish not that strange > variation he uses? If the barber conference language were Latin, and some Spaniard insisted on speaking Western Andalusian, I sure would consider that obnoxious. Similarly, I've heard some Finnish representatives in the Nordic Council complain how the Danish insist on speaking Danish. The official language there is Swedish. > I suspect the reaction you get will be far more severe than the one > you are getting from we English (& Brits) I don't understand your reaction. The rest of us are willing to walk a mile (say, Finnish -----> American English) and you are up in arms about having to shift a foot (say, Scouse -> American English). Marko From fabien.maussion at gmail.com Mon Mar 2 07:25:47 2015 From: fabien.maussion at gmail.com (Fabien) Date: Mon, 02 Mar 2015 13:25:47 +0100 Subject: date References: Message-ID: On 02.03.2015 12:55, greymausg wrote: > I have a csv file, the first item on a line is the date in the format > 2015-03-02 I try to get that as a date by date(row[0]), but it barfs, > replying "Expecting an integer". (I am really trying to get the offset > in weeks from that date to today()) Have you tried Pandas? http://pandas.pydata.org/ If your csv file has no other problems, the following should do the trick: import pandas as pd df = pd.read_csv('file.csv', index_col=0, parse_dates= {"time" : [0]}) Cheers, Fabien From davea at davea.name Mon Mar 2 07:26:41 2015 From: davea at davea.name (Dave Angel) Date: Mon, 02 Mar 2015 07:26:41 -0500 Subject: Python27.dll could not be found In-Reply-To: References: Message-ID: <54F45701.6030006@davea.name> On 03/02/2015 01:00 AM, Sarvagya Pant wrote: > I have been writing a c++ program that is supposed to call the python > function. The code is a snippet from python.org itself. > #include > #include > #include > > int main() > { > Py_SetProgramName("Learning"); > Py_Initialize(); > PyRun_SimpleString("import hashlib\nprint hashlib.md5('sarvagya > pant').hexdigest()"); > Py_Finalize(); > return 0; > } > Please be more explicit about what you know and what you guess. > I have used Visual Studio 2010. I have linked the include directories and > lib files correctly. It gets correctly built. Do you just mean that there are no errors displayed during the build? > Dependency walkerPlease be more explicit about what you know and what you guess. shows the > file depends upon Python27.dll. > I have looked into the folder Dlls of python. It is not there. What is not there? Your executable, or Python27.dll ? And exactly what folder(s) are you looking? > Also I have > checked both System and System32 folder. It is not present in there too. > Python version is 2.7. How can I get Python27.dll to deploy my app for > customers? Please help. > Python27.dll does not deploy your app. Your app loads Python27.dll. You can search for a file in Windows by doing something like: dir /s c:\somefile.dll at a cmd prompt. Does that find whatever file you're seeking? When I ran Windows, I had written a simple utility that searched the PATH for a specified file. I called it which.bat to match the Linux equivalent. I don't run Windows very often, but on my wife's machine I see python27.dll in c:\windows\syswow64 That's on a Windows7 machine running 64bit version. Location will be different on various versions of Windows. You can look to see where the system thinks the Python executable is located by doing ftype .py and seeing what it shows. Mine shows Python.File Then do assoc Python.File to see an actual path. -- DaveA From steve+comp.lang.python at pearwood.info Mon Mar 2 07:33:40 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 02 Mar 2015 23:33:40 +1100 Subject: rst and pypandoc References: Message-ID: <54f458a5$0$13003$c3e8da3$5496439d@news.astraweb.com> alb wrote: [...] > For all the above reasons I'm writing snippets of pure latex in my rst > doc, but I'm having issues with the escape characters: > > i = '\ref{fig:abc}' Since \r is an escape character, that will give you carriage return followed by "ef{fig:abc". The solution to that is to either escape the backslash: i = '\\ref{fig:abc}' or use a raw string: i = r'\\ref{fig:abc}' Oh, by the way, "i" is normally a terrible variable name for a string. Not only doesn't it explain what the variable is for, but there is a very strong convention in programming circles (not just Python, but hundreds of languages) that "i" is a generic variable name for an integer. Not a string. > print pypandoc.convert(i, 'latex', format='rst') > ef\{fig:abc\} > > because of the \r that is interpreted by python as special character. > > If I try to escape with '\' I don't seem to find a way out... Can you show what you are doing? Escaping the backslash with another backslash does work: py> for c in '\\ref': ... print(c, ord(c)) ... \ 92 r 114 e 101 f 102 so either you are doing something wrong, or the error lies elsewhere. -- Steven From al.basili at gmail.com Mon Mar 2 07:36:37 2015 From: al.basili at gmail.com (alb) Date: 2 Mar 2015 12:36:37 GMT Subject: rst and pypandoc References: Message-ID: Hi Dave, Dave Angel wrote: [] > You should be a lot more explicit with all three parts of that > statement. Try: > > > I'm trying to get a string of \ref{fig:A.B} but unfortunately I need to go through a conversion between rst and latex. This is because a simple text like this: this is a simple list of items: - item A. - item B. gets translated into latex by pypandoc as this: \begin{itemize} \item item A. \item item B. \end{itemize} And it's much simpler to write my document with rst markup rather than latex. So my question is what should my restructured text look like in order to get it through pypandoc and get the following: \ref{fig:abc} Apparently rst only allows the following type of references: - external hyperlink targets - internal hyperlink targets - indirect hyperlink targets - implicit hyperlink targets and I want to get a later that has a reference to a figure, but none of those seem to be able to do so. Therefore I thought about passing an inline text in my rst in order to get it through the conversion as is, but apparently I'm stuck with the various escaping mechanisms. My python script reads the text and passes it on to pypandoc: i = "%\n" % text o = pypandoc.convert(i, 'latex', format='rst') So if text is: this is some text with a reference to Figure \ref{fig:abc} I would like o to be like: this is some text with a reference to Figaure \ref{fig:abc} but I get: ef\{fig:abc\} Al From python at mrabarnett.plus.com Mon Mar 2 07:38:54 2015 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 02 Mar 2015 12:38:54 +0000 Subject: Python Worst Practices In-Reply-To: <54F3EBF5.3030701@davea.name> References: <7053A277-9687-49B0-9FDB-CB4DB3E76DEC@gmail.com> <54F0E38D.40006@davea.name> <54f274bb$0$13011$c3e8da3$5496439d@news.astraweb.com> <54F3C3FF.3040608@mrabarnett.plus.com> <54F3EBF5.3030701@davea.name> Message-ID: <54F459DE.8020706@mrabarnett.plus.com> On 2015-03-02 04:49, Dave Angel wrote: > On 03/01/2015 08:59 PM, MRAB wrote: >> On 2015-03-02 01:37, Dennis Lee Bieber wrote >>> >>> You'd be able to run it on a TI99/4 (in which the BASIC interpreter, >>> itself, was run on an interpreter... nothing like taking the first >>> "16-bit" >>> home computer and shackling it with an interpreted language that was >>> run on >>> an interpreted language) >>> >> The "16-bit" CPU had a 16-bit address bus (64K address space). If you >> were going to switch from an 8-bit processor to a 16-bit processor, one >> of the pluses you'd be looking for would the ability to directly >> address more than 64K. >> > > The 16 bit address bus permitted addressing of 64k words. On most > processors, that was 64k bytes, though I know one Harris had no bytes, > but every memory access was 16 bits. It therefore had the equivalent of > 128k bytes. Likewise I believe some of the DEC and DG minis had 128k > bytes of addressability. > I have (or had, not sure where it is!) a manual of the TMS9900 processor, and I'm sure it addresses 64k _bytes_. Wikipedia says "65,536 bytes or 32,768 words". > Usually, the term 8bit processor was referring to the size of the > register(s), not the address bus. All the 8 bit micro-processors had 16 > bit address buses. In fact, 4 bit processors generally had 12 to 16 bit > address buses as well. So a 4 bit processor with a 16 bit address bus > could address 32k bytes, a half byte (a nybble) at a time). > > The IBM PC's 8088 had an 8 bit data-bus and 20 address lines. But they > called it a 16bit processor, to try to distinguish it from 8 bit > processors like the 8080. Anyway, it was code compatible with the 8086, > which really did have a 16bit data bus and 20 bit address bus. > From steve+comp.lang.python at pearwood.info Mon Mar 2 07:45:10 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 02 Mar 2015 23:45:10 +1100 Subject: date References: Message-ID: <54f45b57$0$13004$c3e8da3$5496439d@news.astraweb.com> greymausg wrote: > I have a csv file, the first item on a line is the date in the format > 2015-03-02 I try to get that as a date by date(row[0]), but it barfs, > replying "Expecting an integer". (I am really trying to get the offset > in weeks from that date to today()) What is "date"? Where does it come from? If it is your own function, then we cannot help you unless you show us the code for it. If you mean the standard library date, then you should say so. py> from datetime import datetime py> today = datetime.today() py> astring = "2014-12-27" py> another_day = datetime.strptime(astring, "%Y-%m-%d") py> difference = today - another_day py> difference.days 65 py> difference.days/7 # weeks 9.285714285714286 -- Steven From gheskett at wdtv.com Mon Mar 2 08:07:12 2015 From: gheskett at wdtv.com (Gene Heskett) Date: Mon, 2 Mar 2015 08:07:12 -0500 Subject: Md5 is different in Windows and Linux In-Reply-To: References: Message-ID: <201503020807.12644.gheskett@wdtv.com> On Monday 02 March 2015 01:19:46 Sarvagya Pant wrote: > Hello, I am amazed that the md5 of a file given by python in windows > is different than that of linux. Consider the following code: > > import hashlib > def md5_for_file(f, block_size=2**20): > md5 = hashlib.md5() > while True: > data = f.read(block_size) > if not data: > break > md5.update(data) > return md5.hexdigest() > > f = open("somefile.txt") > print md5_for_file(f) > > When I run the program I get the checksum value: > 2f9cc8da53ee89762a34702f745d2956 > > But on this site http://onlinemd5.com/ and on linux it has value > E10D4E3847713472F51BC606852712F1. > > Why is there difference in value of Checksum computed by python in > windows and other system.? Line endings? 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 davea at davea.name Mon Mar 2 08:12:54 2015 From: davea at davea.name (Dave Angel) Date: Mon, 02 Mar 2015 08:12:54 -0500 Subject: Python Worst Practices In-Reply-To: <54F459DE.8020706@mrabarnett.plus.com> References: <7053A277-9687-49B0-9FDB-CB4DB3E76DEC@gmail.com> <54F0E38D.40006@davea.name> <54f274bb$0$13011$c3e8da3$5496439d@news.astraweb.com> <54F3C3FF.3040608@mrabarnett.plus.com> <54F3EBF5.3030701@davea.name> <54F459DE.8020706@mrabarnett.plus.com> Message-ID: <54F461D6.5040301@davea.name> On 03/02/2015 07:38 AM, MRAB wrote: > On 2015-03-02 04:49, Dave Angel wrote: >> On 03/01/2015 08:59 PM, MRAB wrote: >>> On 2015-03-02 01:37, Dennis Lee Bieber wrote >>>> >> >> The 16 bit address bus permitted addressing of 64k words. On most >> processors, that was 64k bytes, though I know one Harris had no bytes, >> but every memory access was 16 bits. It therefore had the equivalent of >> 128k bytes. Likewise I believe some of the DEC and DG minis had 128k >> bytes of addressability. >> > I have (or had, not sure where it is!) a manual of the TMS9900 > processor, and I'm sure it addresses 64k _bytes_. > > Wikipedia says "65,536 bytes or 32,768 words". > Like I said, on most processors, it was 64k bytes. interestingly enough I know of one architecture which used 128k for the 8-bit Z80, even though that processor only had 16 address lines. Being a server, the code was mostly static, and fit in 64k. But they also wanted 64k for data. So they used one of the processor status lines as a select between two banks of memory. When the processor was fetching an instruction, it got it from bank 0, while if it was fetching or writing data, it went to bank 1. Obviously they had a mode where it read and wrote from bank 0 as data, both for bootstrapping, and for overlays or whatever. -- DaveA From al.basili at gmail.com Mon Mar 2 08:51:04 2015 From: al.basili at gmail.com (alb) Date: 2 Mar 2015 13:51:04 GMT Subject: rst and pypandoc References: <54f458a5$0$13003$c3e8da3$5496439d@news.astraweb.com> Message-ID: Hi Steven, Steven D'Aprano wrote: [] > Since \r is an escape character, that will give you carriage return followed > by "ef{fig:abc". > > The solution to that is to either escape the backslash: > > i = '\\ref{fig:abc}' > > > or use a raw string: > > i = r'\\ref{fig:abc}' ok, maybe I wasn't clear from the very beginning, but searching for a solution is a journey that takes time and patience. The worngly named variable i (as noted below), contains the *i*nput of my text which is supposed to be restructured text. The output is what pypandoc spits out after conversion: i = "\\begin{tag}{%s}{%s}\n %s\n \\end{tag}" % (some, restructured, text) o = pypandoc.convert(i, 'latex', format='rst') Now if i contains some inline text, i.e. text I do not want to convert in any other format, I need my text to be formatted accordingly in order to inject some escape symbols in i. Rst escapes with "\", but unfortunately python also uses "\" for escaping! > > Oh, by the way, "i" is normally a terrible variable name for a string. Not > only doesn't it explain what the variable is for, but there is a very > strong convention in programming circles (not just Python, but hundreds of > languages) that "i" is a generic variable name for an integer. Not a > string. I'm not in the position to argue about good practices, I simply found more appropriate to have i for input and o for output, considering they are used like this: i = "some string" o = pypandoc.convert(i, ...) f.write(o) with very little risk to cause misunderstanding. > Can you show what you are doing? Escaping the backslash with another > backslash does work: > > py> for c in '\\ref': > ... print(c, ord(c)) > ... > \ 92 > r 114 > e 101 > f 102 > > so either you are doing something wrong, or the error lies elsewhere. As said above, the string is converted by pandoc first and then printed. At this point the escaping becomes tricky (at least to me). In [17]: inp = '\\ref{fig:abc}' In [18]: print pypandoc.convert(inp, 'latex', format='rst') ref\{fig:abc\} Al From davea at davea.name Mon Mar 2 09:08:17 2015 From: davea at davea.name (Dave Angel) Date: Mon, 02 Mar 2015 09:08:17 -0500 Subject: rst and pypandoc In-Reply-To: References: <54f458a5$0$13003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <54F46ED1.3000203@davea.name> On 03/02/2015 08:51 AM, alb wrote: > Hi Steven, > > Steven D'Aprano wrote: > [] >> Since \r is an escape character, that will give you carriage return followed >> by "ef{fig:abc". >> >> The solution to that is to either escape the backslash: >> >> i = '\\ref{fig:abc}' >> >> >> or use a raw string: >> >> i = r'\\ref{fig:abc}' Actually that'd be: i = r'\ref{fig:abc}' > > ok, maybe I wasn't clear from the very beginning, but searching for a > solution is a journey that takes time and patience. > > The worngly named variable i (as noted below), contains the *i*nput of > my text which is supposed to be restructured text. The output is what > pypandoc spits out after conversion: > > i = "\\begin{tag}{%s}{%s}\n %s\n \\end{tag}" % (some, restructured, text) > o = pypandoc.convert(i, 'latex', format='rst') > > Now if i contains some inline text, i.e. text I do not want to convert > in any other format, I need my text to be formatted accordingly in order > to inject some escape symbols in i. > > Rst escapes with "\", but unfortunately python also uses "\" for escaping! Only when the string is in a literal. If you've read it from a file, or built it by combining other strings, or... then the backslash is just another character to Python. > >> >> Oh, by the way, "i" is normally a terrible variable name for a string. Not >> only doesn't it explain what the variable is for, but there is a very >> strong convention in programming circles (not just Python, but hundreds of >> languages) that "i" is a generic variable name for an integer. Not a >> string. > > I'm not in the position to argue about good practices, I simply found > more appropriate to have i for input and o for output, considering they > are used like this: > > i = "some string" > o = pypandoc.convert(i, ...) > f.write(o) > > with very little risk to cause misunderstanding. How about "in" and "out"? Or perhaps some name that indicates what semantics the string represents, like "rst_string" and "html_string" or whatever they actually are? > >> Can you show what you are doing? Escaping the backslash with another >> backslash does work: >> >> py> for c in '\\ref': >> ... print(c, ord(c)) >> ... >> \ 92 >> r 114 >> e 101 >> f 102 >> >> so either you are doing something wrong, or the error lies elsewhere. > > As said above, the string is converted by pandoc first and then printed. > At this point the escaping becomes tricky (at least to me). > > In [17]: inp = '\\ref{fig:abc}' > > In [18]: print pypandoc.convert(inp, 'latex', format='rst') > ref\{fig:abc\} > What did you expect/desire the pyandoc output to be? Now that you don't have the embedded 0x0a, is there something else that's wrong? If it's in the internals of pyandoc, I'll probably be of no help. But your first question was about escaping; I'm not sure what it's about now. -- DaveA From breamoreboy at yahoo.co.uk Mon Mar 2 09:26:27 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 02 Mar 2015 14:26:27 +0000 Subject: date In-Reply-To: References: Message-ID: On 02/03/2015 12:25, Fabien wrote: > On 02.03.2015 12:55, greymausg wrote: >> I have a csv file, the first item on a line is the date in the format >> 2015-03-02 I try to get that as a date by date(row[0]), but it barfs, >> replying "Expecting an integer". (I am really trying to get the offset >> in weeks from that date to today()) > > Have you tried Pandas? http://pandas.pydata.org/ > > If your csv file has no other problems, the following should do the trick: > > import pandas as pd > df = pd.read_csv('file.csv', index_col=0, parse_dates= {"time" : [0]}) > > Cheers, > > Fabien > IMHO complete overkill. Give me the Steven D'Aprano solution any day of the week. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From python at mrabarnett.plus.com Mon Mar 2 09:37:50 2015 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 02 Mar 2015 14:37:50 +0000 Subject: rst and pypandoc In-Reply-To: References: <54f458a5$0$13003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <54F475BE.1020406@mrabarnett.plus.com> On 2015-03-02 13:51, alb wrote: > Hi Steven, > > Steven D'Aprano wrote: > [] >> Since \r is an escape character, that will give you carriage return followed >> by "ef{fig:abc". >> >> The solution to that is to either escape the backslash: >> >> i = '\\ref{fig:abc}' >> >> >> or use a raw string: >> >> i = r'\\ref{fig:abc}' > > ok, maybe I wasn't clear from the very beginning, but searching for a > solution is a journey that takes time and patience. > > The worngly named variable i (as noted below), contains the *i*nput of > my text which is supposed to be restructured text. The output is what > pypandoc spits out after conversion: > > i = "\\begin{tag}{%s}{%s}\n %s\n \\end{tag}" % (some, restructured, text) > o = pypandoc.convert(i, 'latex', format='rst') > > Now if i contains some inline text, i.e. text I do not want to convert > in any other format, I need my text to be formatted accordingly in order > to inject some escape symbols in i. > > Rst escapes with "\", but unfortunately python also uses "\" for escaping! > >> >> Oh, by the way, "i" is normally a terrible variable name for a string. Not >> only doesn't it explain what the variable is for, but there is a very >> strong convention in programming circles (not just Python, but hundreds of >> languages) that "i" is a generic variable name for an integer. Not a >> string. > > I'm not in the position to argue about good practices, I simply found > more appropriate to have i for input and o for output, considering they > are used like this: > > i = "some string" > o = pypandoc.convert(i, ...) > f.write(o) > > with very little risk to cause misunderstanding. > >> Can you show what you are doing? Escaping the backslash with another >> backslash does work: >> >> py> for c in '\\ref': >> ... print(c, ord(c)) >> ... >> \ 92 >> r 114 >> e 101 >> f 102 >> >> so either you are doing something wrong, or the error lies elsewhere. > > As said above, the string is converted by pandoc first and then printed. > At this point the escaping becomes tricky (at least to me). > > In [17]: inp = '\\ref{fig:abc}' > > In [18]: print pypandoc.convert(inp, 'latex', format='rst') > ref\{fig:abc\} > Have you tried escaping the escape character by doubling the backslash? inp = '\\\\ref{fig:abc}' or: inp = r'\\ref{fig:abc}' From steve+comp.lang.python at pearwood.info Mon Mar 2 09:39:55 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 03 Mar 2015 01:39:55 +1100 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> Message-ID: <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> Marko Rauhamaa wrote: > alister : > >> or as another analogy why don't you (Marco) try telling a Barber in >> Seville that he should be speaking Latin Spanish not that strange >> variation he uses? > > If the barber conference language were Latin, and some Spaniard insisted > on speaking Western Andalusian, I sure would consider that obnoxious. > > Similarly, I've heard some Finnish representatives in the Nordic Council > complain how the Danish insist on speaking Danish. The official language > there is Swedish. I'm reminded of the British Prime Minister David Lloyd George, who apparently made a habit of answering difficult or embarrassing questions in parliament in his native Welsh. >> I suspect the reaction you get will be far more severe than the one >> you are getting from we English (& Brits) > > I don't understand your reaction. The rest of us are willing to walk a > mile (say, Finnish -----> American English) and you are up in arms about > having to shift a foot (say, Scouse -> American English). "Not one inch!" Sometimes the small differences are more important than the big. Your Finnishness is not threatened by learning English, any more than Mark's Britishness would be threatened by him learning Russian. [Now there's a thought... with the historical relationships between Finland and Russia, I wonder whether Finns would be as blas? about using a foreign language if it were Russian rather than English? But I digress.] Whereas the comparatively small differences between British and American English are all the more important because they distinguish the two. Nobody is ever going to mistake Finland and the Finish people for Americans, even if you learn to speak American English. But for Britons to use American English is, in a way, to cease to be Britons at all. Personally, I think that monocultures are harmful and ought to be resisted, whether than monoculture is one-species-of-wheat, one-operating-system, or one-language. The English-speaking world is threatened by American cultural and linguistic monoculture[1], and that's a bad thing. The same applies to the rest of the world, but to a much lesser extent. Having a rich and varied cultural ecosystem is important, and regional differences in language and culture are an essential part in that. Variations in idiom and spelling are a good thing. They open our minds to new possibilities, remind us that we aren't all the same, and keep life fresh. I remember the first time I realised that when Indians talk about "a code" they aren't using "wrong English", they are using a regional variation. In British and American English, "code" in the programming sense[2] is a mass or uncountable noun, like air[3], milk, music and housework. You cannot have "three milks", you have to add some sort of unit to it: three litres of milk, five pieces of music, too much housework, five *pieces of code*. But in Indian English, you can count code: *five codes*. How wonderful! I'll probably never use it myself, but I am enriched just to know it exists. [1] Yes, I watch as many American movies and television shows as the next guy. I'm allowed to take the parts of their culture I approve of and reject the parts I don't. [2] As opposed to the sense of secret codes and ciphers. [3] In the sense of air that we breathe. One can still have "airs and graces", although we rarely quantify just how many airs somebody is putting on. -- Steven From python at mrabarnett.plus.com Mon Mar 2 09:40:01 2015 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 02 Mar 2015 14:40:01 +0000 Subject: rst and pypandoc In-Reply-To: <54F46ED1.3000203@davea.name> References: <54f458a5$0$13003$c3e8da3$5496439d@news.astraweb.com> <54F46ED1.3000203@davea.name> Message-ID: <54F47641.4000102@mrabarnett.plus.com> On 2015-03-02 14:08, Dave Angel wrote: > On 03/02/2015 08:51 AM, alb wrote: >> Hi Steven, >> >> Steven D'Aprano wrote: >>> [snip] >>> Oh, by the way, "i" is normally a terrible variable name for a string. Not >>> only doesn't it explain what the variable is for, but there is a very >>> strong convention in programming circles (not just Python, but hundreds of >>> languages) that "i" is a generic variable name for an integer. Not a >>> string. >> >> I'm not in the position to argue about good practices, I simply found >> more appropriate to have i for input and o for output, considering they >> are used like this: >> >> i = "some string" >> o = pypandoc.convert(i, ...) >> f.write(o) >> >> with very little risk to cause misunderstanding. > > How about "in" and "out"? Or perhaps some name that indicates what > semantics the string represents, like "rst_string" and "html_string" > or whatever they actually are? > [snip] "in" is a reserved word, but "in_" would be OK. From steve+comp.lang.python at pearwood.info Mon Mar 2 09:43:19 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 03 Mar 2015 01:43:19 +1100 Subject: rst and pypandoc References: <54f458a5$0$13003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <54f47707$0$12979$c3e8da3$5496439d@news.astraweb.com> Dave Angel wrote: > On 03/02/2015 08:51 AM, alb wrote: >> Hi Steven, >> >> Steven D'Aprano wrote: >> [] >>> Since \r is an escape character, that will give you carriage return >>> followed by "ef{fig:abc". >>> >>> The solution to that is to either escape the backslash: >>> >>> i = '\\ref{fig:abc}' >>> >>> >>> or use a raw string: >>> >>> i = r'\\ref{fig:abc}' > > Actually that'd be: > i = r'\ref{fig:abc}' D'oh! I mean, you spotted my deliberate mistake to check if you were paying attention. Well done! > How about "in" and "out"? Or perhaps some name that indicates what > semantics the string represents, like "rst_string" and "html_string" > or whatever they actually are? Can't use "in", it's a keyword. -- Steven From steve+comp.lang.python at pearwood.info Mon Mar 2 09:44:19 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 03 Mar 2015 01:44:19 +1100 Subject: date References: Message-ID: <54f47743$0$12979$c3e8da3$5496439d@news.astraweb.com> Mark Lawrence wrote: > Give me the Steven D'Aprano solution any day of > the week. Sounds ominous. Is that better or worse than the final solution? -- Steven From maus at mail.com Mon Mar 2 09:49:41 2015 From: maus at mail.com (greymausg) Date: 2 Mar 2015 14:49:41 GMT Subject: date References: <54f45b57$0$13004$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2015-03-02, Steven D'Aprano wrote: > greymausg wrote: > >> I have a csv file, the first item on a line is the date in the format >> 2015-03-02 I try to get that as a date by date(row[0]), but it barfs, >> replying "Expecting an integer". (I am really trying to get the offset >> in weeks from that date to today()) > > What is "date"? Where does it come from? > > If it is your own function, then we cannot help you unless you show us the > code for it. > > If you mean the standard library date, then you should say so. > > > py> from datetime import datetime > py> today = datetime.today() > py> astring = "2014-12-27" > py> another_day = datetime.strptime(astring, "%Y-%m-%d") > py> difference = today - another_day > py> difference.days > 65 > py> difference.days/7 # weeks > 9.285714285714286 > > Standard datetime.date, if it were not, I would have written. Will try, thanks for the info. -- greymaus . . ... From maus at mail.com Mon Mar 2 09:49:42 2015 From: maus at mail.com (greymausg) Date: 2 Mar 2015 14:49:42 GMT Subject: date References: Message-ID: On 2015-03-02, Fabien wrote: > On 02.03.2015 12:55, greymausg wrote: >> I have a csv file, the first item on a line is the date in the format >> 2015-03-02 I try to get that as a date by date(row[0]), but it barfs, >> replying "Expecting an integer". (I am really trying to get the offset >> in weeks from that date to today()) > > Have you tried Pandas? http://pandas.pydata.org/ > > If your csv file has no other problems, the following should do the trick: > > import pandas as pd > df = pd.read_csv('file.csv', index_col=0, parse_dates= {"time" : [0]}) Ta. Will try > > Cheers, > > Fabien > > > > -- greymaus . . ... From mail at timgolden.me.uk Mon Mar 2 09:50:34 2015 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 02 Mar 2015 14:50:34 +0000 Subject: date In-Reply-To: <54f47743$0$12979$c3e8da3$5496439d@news.astraweb.com> References: <54f47743$0$12979$c3e8da3$5496439d@news.astraweb.com> Message-ID: <54F478BA.8060107@timgolden.me.uk> On 02/03/2015 14:44, Steven D'Aprano wrote: > Mark Lawrence wrote: > >> Give me the Steven D'Aprano solution any day of >> the week. > > > Sounds ominous. Is that better or worse than the final solution? > > > Well if you can have it on any day of the week it can't be *that* final? TJG From steve+comp.lang.python at pearwood.info Mon Mar 2 10:09:17 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 03 Mar 2015 02:09:17 +1100 Subject: rst and pypandoc References: <54f458a5$0$13003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <54f47d1d$0$12984$c3e8da3$5496439d@news.astraweb.com> alb wrote: > Hi Steven, > > Steven D'Aprano wrote: > [] >> Since \r is an escape character, that will give you carriage return >> followed by "ef{fig:abc". >> >> The solution to that is to either escape the backslash: >> >> i = '\\ref{fig:abc}' >> >> >> or use a raw string: >> >> i = r'\\ref{fig:abc}' Dave has corrected my typo in the above: it should be r'\ref', the whole point of raw strings is that you don't need to escape the backslashes. > ok, maybe I wasn't clear from the very beginning, but searching for a > solution is a journey that takes time and patience. > > The worngly named variable i (as noted below), contains the *i*nput of > my text which is supposed to be restructured text. The output is what > pypandoc spits out after conversion: Ah, well that's not a bad convention for small utility functions, but I wouldn't want single-letter names to be used in anything bigger than, say, a dozen lines. Having i for input and o for output right next to each other helps too. But you're still swimming against the convention that i means an integer. Whether you decide it is worth going against that convention in your own code is up to you, but when asking for help, it is worth your while to be the least surprising or different as you can manage. > i = "\\begin{tag}{%s}{%s}\n %s\n \\end{tag}" % (some, restructured, text) > o = pypandoc.convert(i, 'latex', format='rst') > > Now if i contains some inline text, i.e. text I do not want to convert > in any other format, I need my text to be formatted accordingly in order > to inject some escape symbols in i. > > Rst escapes with "\", but unfortunately python also uses "\" for escaping! Yes, but only in string literals. In Python source code, "\r" makes a carriage return, but when reading from the keyboard (say, using the raw_input function), from a file, or anything other than a string literal, a string consisting of "\r" is just backslash-r. So, worst case, you can always assemble your strings like this: backslash = chr(92) i = (backslash + "begin{tag}{%s}{%s}\n %s\n " + backslash + "end{tag}" % (some, restructured, text)) although that is a PITA. I recommend using raw triple strings, and avoid needing \n escapes: i = r"""\begin{tag}{%s}{%s} %s \end{tag}""" % (some, restructured, text) >> Can you show what you are doing? Escaping the backslash with another >> backslash does work: >> >> py> for c in '\\ref': >> ... print(c, ord(c)) >> ... >> \ 92 >> r 114 >> e 101 >> f 102 >> >> so either you are doing something wrong, or the error lies elsewhere. > > As said above, the string is converted by pandoc first and then printed. > At this point the escaping becomes tricky (at least to me). > > In [17]: inp = '\\ref{fig:abc}' If you print inp at this point, you should see that it contains exactly what you expect: backslash, R E F etc. > In [18]: print pypandoc.convert(inp, 'latex', format='rst') > ref\{fig:abc\} and now the backslash is gone, and the braces are escaped. This suggests that the problems lies with pypandoc. Perhaps you need to add extra backslashes, so that pypandoc will convert a double-backslash to a single one. Consult your pypandoc documentation, and try this: inp = '\\\\ref{fig:abc}' # That's FOUR backslashes, to get \\ # or as a raw-string: inp = '\\ref{fig:abc}' assert inp[0] == inp[1] == chr(92) out = pypandoc.convert(inp, 'latex', format='rst') print out, out == r"\ref\{fig:abc\}" -- Steven From breamoreboy at yahoo.co.uk Mon Mar 2 10:24:50 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 02 Mar 2015 15:24:50 +0000 Subject: date In-Reply-To: <54f47743$0$12979$c3e8da3$5496439d@news.astraweb.com> References: <54f47743$0$12979$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 02/03/2015 14:44, Steven D'Aprano wrote: > Mark Lawrence wrote: > >> Give me the Steven D'Aprano solution any day of >> the week. > > > Sounds ominous. Is that better or worse than the final solution? > As in "this program will inadvertantly self distruct in five seconds"? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From marko at pacujo.net Mon Mar 2 10:30:42 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 02 Mar 2015 17:30:42 +0200 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87twy34dst.fsf@elektro.pacujo.net> Steven D'Aprano : > Marko Rauhamaa wrote: >> Similarly, I've heard some Finnish representatives in the Nordic >> Council complain how the Danish insist on speaking Danish. The >> official language there is Swedish. > > I'm reminded of the British Prime Minister David Lloyd George, who > apparently made a habit of answering difficult or embarrassing > questions in parliament in his native Welsh. What are the Danish embarrassed about? C++? C#? Delphi? ALGOL 60? BNF? > But for Britons to use American English is, in a way, to cease to be > Britons at all. Did Hugh Laurie have to turn in his British passport? -- But don't despair! I just ran into this (): Do you want to speak English fluently and with an American accent? -> Sick of being asked to repeat yourself? -> Tired of people not understanding you? -> Worried about losing your job or no one hiring you? -> Trouble being understood on the phone? -> Embarrassed or shy in social situations? If you answered ?yes? to any of the above questions, then I have great news for you! You CAN change your accent and start speaking English like an American. In less than 15 minutes a day and from the comfort of your own home. You just need to know the RIGHT way to practise. Our Ultimate American Accent Training Package gives you all the exercises and methods you need for improving your English pronunciation. Marko From alister.nospam.ware at ntlworld.com Mon Mar 2 10:32:33 2015 From: alister.nospam.ware at ntlworld.com (alister) Date: Mon, 2 Mar 2015 15:32:33 +0000 (UTC) Subject: Python Worst Practices References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> Message-ID: On Mon, 02 Mar 2015 14:19:45 +0200, Marko Rauhamaa wrote: > alister : > >> or as another analogy why don't you (Marco) try telling a Barber in >> Seville that he should be speaking Latin Spanish not that strange >> variation he uses? > > If the barber conference language were Latin, and some Spaniard insisted > on speaking Western Andalusian, I sure would consider that obnoxious. > > Similarly, I've heard some Finnish representatives in the Nordic Council > complain how the Danish insist on speaking Danish. The official language > there is Swedish. > >> I suspect the reaction you get will be far more severe than the one you >> are getting from we English (& Brits) > > I don't understand your reaction. The rest of us are willing to walk a > mile (say, Finnish -----> American English) and you are up in arms about > having to shift a foot (say, Scouse -> American English). > > > Marko Because the language is English not American. the Standard for English is by very definition UK English English is spoken badly enough as it is without deliberately speaking it worse! As I said earlier tell a Spaniard they need to learn Latin Spanish because traditional Spanish is not standard & see how far you get. if they are laid back about it try the same thing with he French -- Detroit is Cleveland without the glitter. From ian.g.kelly at gmail.com Mon Mar 2 10:34:15 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 2 Mar 2015 08:34:15 -0700 Subject: Design thought for callbacks In-Reply-To: <8A3659BC-9100-4A3A-9117-47227B3D290B@gmail.com> References: <33677AE8-B2FA-49F9-9304-C8D93784255D@gmail.com> <8A3659BC-9100-4A3A-9117-47227B3D290B@gmail.com> Message-ID: On Mon, Mar 2, 2015 at 4:04 AM, Cem Karan wrote: > On Feb 26, 2015, at 2:54 PM, Ian Kelly wrote: >> On Feb 26, 2015 4:00 AM, "Cem Karan" wrote: >> > >> > >> > On Feb 26, 2015, at 12:36 AM, Gregory Ewing wrote: >> > >> > > Cem Karan wrote: >> > >> I think I see what you're talking about now. Does WeakMethod >> > >> (https://docs.python.org/3/library/weakref.html#weakref.WeakMethod) solve >> > >> this problem? >> > > >> > > Yes, that looks like it would work. >> > >> > >> > Cool! >> >> Sometimes I wonder whether anybody reads my posts. I suggested a solution involving WeakMethod four days ago that additionally extends the concept to non-method callbacks (requiring a small amount of extra effort from the client in those cases, but I think that is unavoidable. There is no way that the framework can determine the appropriate lifetime for a closure-based callback.) > > I apologize about taking so long to reply to everyone's posts, but I've been busy at home. > > Ian, it took me a while to do some research to understand WHY what you were suggesting was important; you're right about storing the object as well as the method/function separately, but I think that WeakMethod might solve that completely, correct? Are there any cases where WeakMethod wouldn't work? WeakMethod only works for bound method objects. If you pass it a non-method function, you'll get a TypeError: >>> from weakref import WeakMethod >>> WeakMethod(lambda: None) Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3.4/weakref.py", line 49, in __new__ .format(type(meth))) from None TypeError: argument should be a bound method, not This check uses duck typing, so you could perhaps write a method-like class with __self__ and __func__ attributes and pass that to the WeakMethod constructor in the case of non-methods. There's a bigger issue with this however, which is that WeakMethod works by keeping weak references to *both* the object and the function, meaning that as soon as the function has no other references, the WeakMethod expires even if the object is still alive. This isn't a problem for methods because it's the transience of the method object, not the underlying function, that WeakMethod seeks to work around. But it doesn't by itself do anything to solve the problem of closures or lambdas that may themselves be transient. Revisiting the implementation I suggested previously, I want to make a correction. This would be better solved with a WeakValueDictionary: class Listenable: def __init__(self): self._callbacks = weakref.WeakValueDictionary() def listen(self, callback, owner=None): if owner is None: if isinstance(callback, types.MethodType): owner = weakref.WeakMethod(callback) else: owner = callback # TODO: Should anything happen if the callback is already in the dict? self._callbacks[callback] = owner def do_callbacks(self, message): for callback in self._callbacks.keys(): callback(message) This approach has two benefits over the previous one: it simplifies the callback management a bit, and it avoids making the assumption that the owner is hashable (it assumes instead that the callback is hashable, but I think that's reasonable). From fabien.maussion at gmail.com Mon Mar 2 10:42:19 2015 From: fabien.maussion at gmail.com (Fabien) Date: Mon, 02 Mar 2015 16:42:19 +0100 Subject: date References: Message-ID: On 02.03.2015 15:26, Mark Lawrence wrote: >> >> Have you tried Pandas? http://pandas.pydata.org/ >> >> If your csv file has no other problems, the following should do the >> trick: >> >> import pandas as pd >> df = pd.read_csv('file.csv', index_col=0, parse_dates= {"time" : [0]}) >> >> Cheers, >> >> Fabien >> > > IMHO complete overkill. Give me the Steven D'Aprano solution any day of > the week. Without knowing anything about the OP background, I still hope my suggestion is a good one. Pandas is one of the best thing that happened to me in my python life, I'm happy to at least suggest it. But yeah, if you just want to read the csv and do no data crunching on it, pandas is "overkill". Fabien From breamoreboy at yahoo.co.uk Mon Mar 2 10:45:16 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 02 Mar 2015 15:45:16 +0000 Subject: Python Worst Practices In-Reply-To: References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> Message-ID: On 02/03/2015 15:32, alister wrote: > On Mon, 02 Mar 2015 14:19:45 +0200, Marko Rauhamaa wrote: > >> alister : >> >>> or as another analogy why don't you (Marco) try telling a Barber in >>> Seville that he should be speaking Latin Spanish not that strange >>> variation he uses? >> >> If the barber conference language were Latin, and some Spaniard insisted >> on speaking Western Andalusian, I sure would consider that obnoxious. >> >> Similarly, I've heard some Finnish representatives in the Nordic Council >> complain how the Danish insist on speaking Danish. The official language >> there is Swedish. >> >>> I suspect the reaction you get will be far more severe than the one you >>> are getting from we English (& Brits) >> >> I don't understand your reaction. The rest of us are willing to walk a >> mile (say, Finnish -----> American English) and you are up in arms about >> having to shift a foot (say, Scouse -> American English). >> >> >> Marko > > Because the language is English not American. > the Standard for English is by very definition UK English > English is spoken badly enough as it is without deliberately speaking it > worse! > > > As I said earlier tell a Spaniard they need to learn Latin Spanish > because traditional Spanish is not standard & see how far you get. > if they are laid back about it try the same thing with he French > > This http://en.wikipedia.org/wiki/Canarian_Spanish is interesting. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rosuav at gmail.com Mon Mar 2 10:45:52 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 Mar 2015 02:45:52 +1100 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] In-Reply-To: <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 3, 2015 at 1:39 AM, Steven D'Aprano wrote: > Whereas the comparatively small differences between British and American > English are all the more important because they distinguish the two. Nobody > is ever going to mistake Finland and the Finish people for Americans, even > if you learn to speak American English. But for Britons to use American > English is, in a way, to cease to be Britons at all. Which, I suspect, is part of why the pound is still alive and well, and hasn't been replaced with the euro. Maybe some other countries don't mind becoming the United States of Europe, but the British resist the encroachment, and rightly so. > ... a mass or uncountable noun, like air[3], milk, music and > housework. You cannot have "three milks", you have to add some sort of unit > to it: three litres of milk... And yet, oddly enough, you wouldn't bat an eyelid if someone asks for "two sugars" in his tea. Or his hot chocolate... mmm, time for me to go make myself one, I think. Two sugars, a splosh of milk, caramel hot chocolate powder, and butter. Not "one butter", because that concept doesn't exist, but very definitely "two sugars", because the sugar comes in discrete units. (Not "discreet units", mind, although I do trust my sugar not to blab about the sorts of drinks I put it in.) > [1] Yes, I watch as many American movies and television shows as the next > guy. I'm allowed to take the parts of their culture I approve of and reject > the parts I don't. Part of resisting monoculture is accepting other people's cultures, not just sticking with your own. Embracing that difference. So go ahead: Watch "McHale's Navy" and "Yes Minister", and appreciate the comedy of both - decide for yourself which one you find more to your liking, but know that they both exist, and they represent different styles. (Aside: Even in an American TV show like Once Upon A Time, it's possible for non-American accents to be welcomed. Belle is played by an Aussie, and her distinctive accent is commented on in-universe. Somehow, she picked up an accent that's completely different from her father's and her mother's, but is its own particular style and speech. Maybe she learned the accent from one of her books.) We embrace Unicode in Python 3 because it allows us to welcome Russian, Icelandic, Arabic, and Chinese programmers and allow them to write variable names in their own languages, using their own scripts (or, in the case of Icelandic, a script very similar to ours but with a few additional letters). We should equally embrace American and British English - and Indian English, and Australian English, and any other variant that people want to code in. You want to write your code in North-East Scots? Sure. You want to write your code in Gaelic? No problem (though personally, I prefer garlic to Gaelic). You want to use "colour" instead of "color"? Also not a problem, and should be easy enough for someone to understand who normally spells it the other way. ChrisA From rosuav at gmail.com Mon Mar 2 10:51:28 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 Mar 2015 02:51:28 +1100 Subject: date In-Reply-To: References: <54f47743$0$12979$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 3, 2015 at 2:24 AM, Mark Lawrence wrote: > On 02/03/2015 14:44, Steven D'Aprano wrote: >> >> Mark Lawrence wrote: >> >>> Give me the Steven D'Aprano solution any day of >>> the week. >> >> >> >> Sounds ominous. Is that better or worse than the final solution? >> > > As in "this program will inadvertantly self distruct in five seconds"? It's usually implied as being externally enforced, so I'd say it's more akin to my solution to all manner of Windows problems. ChrisA From joel.goldstick at gmail.com Mon Mar 2 10:54:36 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Mon, 2 Mar 2015 10:54:36 -0500 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] In-Reply-To: References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> Message-ID: I like "Old Tricks". I learn lots of British english idioms. I'm from NYC On Mon, Mar 2, 2015 at 10:45 AM, Chris Angelico wrote: > On Tue, Mar 3, 2015 at 1:39 AM, Steven D'Aprano > wrote: >> Whereas the comparatively small differences between British and American >> English are all the more important because they distinguish the two. Nobody >> is ever going to mistake Finland and the Finish people for Americans, even >> if you learn to speak American English. But for Britons to use American >> English is, in a way, to cease to be Britons at all. > > Which, I suspect, is part of why the pound is still alive and well, > and hasn't been replaced with the euro. Maybe some other countries > don't mind becoming the United States of Europe, but the British > resist the encroachment, and rightly so. > >> ... a mass or uncountable noun, like air[3], milk, music and >> housework. You cannot have "three milks", you have to add some sort of unit >> to it: three litres of milk... > > And yet, oddly enough, you wouldn't bat an eyelid if someone asks for > "two sugars" in his tea. Or his hot chocolate... mmm, time for me to > go make myself one, I think. Two sugars, a splosh of milk, caramel hot > chocolate powder, and butter. Not "one butter", because that concept > doesn't exist, but very definitely "two sugars", because the sugar > comes in discrete units. > > (Not "discreet units", mind, although I do trust my sugar not to blab > about the sorts of drinks I put it in.) > >> [1] Yes, I watch as many American movies and television shows as the next >> guy. I'm allowed to take the parts of their culture I approve of and reject >> the parts I don't. > > Part of resisting monoculture is accepting other people's cultures, > not just sticking with your own. Embracing that difference. So go > ahead: Watch "McHale's Navy" and "Yes Minister", and appreciate the > comedy of both - decide for yourself which one you find more to your > liking, but know that they both exist, and they represent different > styles. > > (Aside: Even in an American TV show like Once Upon A Time, it's > possible for non-American accents to be welcomed. Belle is played by > an Aussie, and her distinctive accent is commented on in-universe. > Somehow, she picked up an accent that's completely different from her > father's and her mother's, but is its own particular style and speech. > Maybe she learned the accent from one of her books.) > > We embrace Unicode in Python 3 because it allows us to welcome > Russian, Icelandic, Arabic, and Chinese programmers and allow them to > write variable names in their own languages, using their own scripts > (or, in the case of Icelandic, a script very similar to ours but with > a few additional letters). We should equally embrace American and > British English - and Indian English, and Australian English, and any > other variant that people want to code in. You want to write your code > in North-East Scots? Sure. You want to write your code in Gaelic? No > problem (though personally, I prefer garlic to Gaelic). You want to > use "colour" instead of "color"? Also not a problem, and should be > easy enough for someone to understand who normally spells it the other > way. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick http://joelgoldstick.com From torriem at gmail.com Mon Mar 2 10:59:12 2015 From: torriem at gmail.com (Michael Torrie) Date: Mon, 02 Mar 2015 08:59:12 -0700 Subject: suggestions for functional style (singleton pattern?) In-Reply-To: References: <13v4falb4odnhtvss4qdatnn16sgiv5pgd@4ax.com> Message-ID: <54F488D0.2010906@gmail.com> On 03/02/2015 03:19 AM, Fabien wrote: > On 01.03.2015 06:05, Michael Torrie wrote: >> A module*is* a singleton pattern, particularly one >> that maintains state. I use sometimes use this feature for sharing >> config and other data between other modules (global state when it's >> required). > > I do this too, after some helping recommendations I got from this > discussion group. I find it neat to use a module for sharing config > states, but I always wondered: does this pattern fall into the "globals > are devil" category? In traditional languages, globals were considered evil in part because of the ambiguity they raised (a problem of scope, really). In a function if you see a reference to a variable, and if globals were used, you then have confusion over whether the variable is local or global (could be both if one covers the other). And globals could be set from anywhere. Debugging and logical patterns become a lot harder with this ambiguity and errors are introduced. Modules don't have the same problems when used as a store for globals for several reasons. First, because they have a namespace associated with them. You can tell at a glance which name in your function is a reference to this "global" module. Now if you did do a "from module import *" then you can't tell as easily what is coming from the module and what is locally defined. But the cool thing here is if you rebind a variable imported from a module in your local namespace, it actually doesn't change the "global" variable (attribute). Instead it just rebinds your local name. So if you want to change an attribute in the module, you have to refer to it via the module.attribute path. Secondly, one should rarely write to a module's namespace from outside that module (though you can). Instead treat the module in an OOP fashion, and write business methods to alter the module's state in a specific way. This encapsulation protects and insulates the module's users from implementation details that could change from time to time. Now I don't know of any way of implementing class-style properties on a module as you can do in a class, but if that were needed you would write a standard class and instantiate a singleton inside the module itself perhaps. As with all broad statements, saying globals are evil is simply not always true. From alister.nospam.ware at ntlworld.com Mon Mar 2 11:09:31 2015 From: alister.nospam.ware at ntlworld.com (alister) Date: Mon, 2 Mar 2015 16:09:31 +0000 (UTC) Subject: date References: <54f47743$0$12979$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, 03 Mar 2015 02:51:28 +1100, Chris Angelico wrote: > On Tue, Mar 3, 2015 at 2:24 AM, Mark Lawrence > wrote: >> On 02/03/2015 14:44, Steven D'Aprano wrote: >>> >>> Mark Lawrence wrote: >>> >>>> Give me the Steven D'Aprano solution any day of the week. >>> >>> >>> >>> Sounds ominous. Is that better or worse than the final solution? >>> >>> >> As in "this program will inadvertantly self distruct in five seconds"? > > It's usually implied as being externally enforced, so I'd say it's more > akin to my solution to all manner of Windows problems. > > ChrisA Is that the same as my solution to windows related problems? (Dad bought a new laptop on Sat it was sterilised (As in disinfected ) immediately & has never run Windowz - lucky thing). -- Loose bits sink chips. From rosuav at gmail.com Mon Mar 2 11:25:22 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 Mar 2015 03:25:22 +1100 Subject: date In-Reply-To: References: <54f47743$0$12979$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 3, 2015 at 3:09 AM, alister wrote: >>>> Sounds ominous. Is that better or worse than the final solution? >>>> >>>> >>> As in "this program will inadvertantly self distruct in five seconds"? >> >> It's usually implied as being externally enforced, so I'd say it's more >> akin to my solution to all manner of Windows problems. >> >> ChrisA > > Is that the same as my solution to windows related problems? > > (Dad bought a new laptop on Sat it was sterilised (As in disinfected ) > immediately & has never run Windowz - lucky thing). Yes. What Steven is referencing is: https://en.wikipedia.org/wiki/Final_Solution And is unrelated to this: https://en.wikipedia.org/wiki/Final_Problem ChrisA From travisgriggs at gmail.com Mon Mar 2 11:25:40 2015 From: travisgriggs at gmail.com (Travis Griggs) Date: Mon, 2 Mar 2015 08:25:40 -0800 Subject: Python Worst Practices In-Reply-To: <57g7faltd1rh4g1f5s6rjv0d45svfvqvs5@4ax.com> References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <57g7faltd1rh4g1f5s6rjv0d45svfvqvs5@4ax.com> Message-ID: <2139D5D1-A058-4D7F-A097-D1BFAFC91D5D@gmail.com> > On Mar 1, 2015, at 5:53 PM, Dennis Lee Bieber wrote: > > On Sun, 1 Mar 2015 20:16:26 +0000 (UTC), alister > declaimed the following: > >> >> The language is called English, the clue is in the name. interestingly >> most 'Brits' can switch between American English & English without too >> much trouble (I still have a problem with Chips) >> > Okay... Is that a reference to (US) Fries, or US usage reference to > (UK) Crisps. > > Might as well add the confusion of biscuit <> cookie (my biscuits look > like your scones)... And lets not bring up the subject of suspenders... > Bonnets, boots, and lifts. > > A pub's a bar; a bar's a gate; a gate's a street Reminds me of Richard Lederer?s writings. http://www.etni.org.il/farside/crazyenglish.htm Whether or not Brits should sprinkle the letter ?u? around for some extra spice, seems like the very smallest of our worries. From breamoreboy at yahoo.co.uk Mon Mar 2 11:41:52 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 02 Mar 2015 16:41:52 +0000 Subject: date In-Reply-To: References: Message-ID: On 02/03/2015 15:42, Fabien wrote: > On 02.03.2015 15:26, Mark Lawrence wrote: >>> >>> Have you tried Pandas? http://pandas.pydata.org/ >>> >>> If your csv file has no other problems, the following should do the >>> trick: >>> >>> import pandas as pd >>> df = pd.read_csv('file.csv', index_col=0, parse_dates= {"time" : [0]}) >>> >>> Cheers, >>> >>> Fabien >>> >> >> IMHO complete overkill. Give me the Steven D'Aprano solution any day of >> the week. > > Without knowing anything about the OP background, I still hope my > suggestion is a good one. Pandas is one of the best thing that happened > to me in my python life, I'm happy to at least suggest it. But yeah, if > you just want to read the csv and do no data crunching on it, pandas is > "overkill". > > Fabien I've used pandas myself and I'll admit to being very impressed. However the OP originally said 'I have a csv file, the first item on a line is the date in the format 2015-03-02 I try to get that as a date by date(row[0]), but it barfs, replying "Expecting an integer".' Without finding out exactly what the OP is trying to achieve, telling them to download a package such as pandas just to convert a string to a date is overkill when there's a solution in the stdlib. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Mon Mar 2 11:44:18 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 02 Mar 2015 16:44:18 +0000 Subject: date In-Reply-To: References: <54f47743$0$12979$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 02/03/2015 15:51, Chris Angelico wrote: > On Tue, Mar 3, 2015 at 2:24 AM, Mark Lawrence wrote: >> On 02/03/2015 14:44, Steven D'Aprano wrote: >>> >>> Mark Lawrence wrote: >>> >>>> Give me the Steven D'Aprano solution any day of >>>> the week. >>> >>> >>> >>> Sounds ominous. Is that better or worse than the final solution? >>> >> >> As in "this program will inadvertantly self distruct in five seconds"? > > It's usually implied as being externally enforced, so I'd say it's > more akin to my solution to all manner of Windows problems. > > ChrisA > Heard the joke about the three engineers in the car that breaks down? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From ian.g.kelly at gmail.com Mon Mar 2 11:51:45 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 2 Mar 2015 09:51:45 -0700 Subject: suggestions for functional style (singleton pattern?) In-Reply-To: <54F488D0.2010906@gmail.com> References: <13v4falb4odnhtvss4qdatnn16sgiv5pgd@4ax.com> <54F488D0.2010906@gmail.com> Message-ID: On Mon, Mar 2, 2015 at 8:59 AM, Michael Torrie wrote: > Now I don't know of any way of implementing class-style properties on a > module as you can do in a class, but if that were needed you would write > a standard class and instantiate a singleton inside the module itself > perhaps. This works, although I'm not sure that I would do it in real code. >>> class PropertyModule(types.ModuleType): ... @property ... def parrot(self): ... return "Norwegian Blue" ... >>> sys.modules['parrot_sketch'] = PropertyModule('parrot_sketch') >>> import parrot_sketch >>> parrot_sketch.parrot 'Norwegian Blue' Note that if the user does "from parrot_sketch import parrot", then the property is evaluated at import time and any changes won't be reflected in the local binding, which might cause some surprises. Also, this isn't really a singleton any longer since the user might just create another instance of the class, but you can hide the class and present just the module as the API. From alister.nospam.ware at ntlworld.com Mon Mar 2 12:02:45 2015 From: alister.nospam.ware at ntlworld.com (alister) Date: Mon, 2 Mar 2015 17:02:45 +0000 (UTC) Subject: Python Worst Practices References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <57g7faltd1rh4g1f5s6rjv0d45svfvqvs5@4ax.com> Message-ID: On Mon, 02 Mar 2015 08:25:40 -0800, Travis Griggs wrote: > seems like the very smallest of our worries. "There is no egg in eggplant" What the blood heck is eggplant? oh wait you mean aubergine this page is clearly about American English. We are even more obtuse, it stops Johnnie Foreigner knowing what we are up to - seems to be far more effective than Enigma :-) IIRC the Americans managed something similar with the Navaho. -- Falling in love is a lot like dying. You never get to do it enough to become good at it. From jon+usenet at unequivocal.co.uk Mon Mar 2 12:12:24 2015 From: jon+usenet at unequivocal.co.uk (Jon Ribbens) Date: Mon, 2 Mar 2015 17:12:24 +0000 (UTC) Subject: Python Worst Practices References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> Message-ID: On 2015-03-02, Dennis Lee Bieber wrote: > A pub's a bar; a bar's a gate; a gate's a street If each of those is supposed to be English first and then the American equivalent second, then I'm afraid the first one is misleading and the other two are just nonsense. From maus at mail.com Mon Mar 2 12:55:37 2015 From: maus at mail.com (greymausg) Date: 2 Mar 2015 17:55:37 GMT Subject: date References: <54f45b57$0$13004$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2015-03-02, greymausg wrote: > On 2015-03-02, Steven D'Aprano wrote: >> greymausg wrote: >> >>> I have a csv file, the first item on a line is the date in the format >>> 2015-03-02 I try to get that as a date by date(row[0]), but it barfs, >>> replying "Expecting an integer". (I am really trying to get the offset >>> in weeks from that date to today()) >> >> What is "date"? Where does it come from? >> >> If it is your own function, then we cannot help you unless you show us the >> code for it. >> >> If you mean the standard library date, then you should say so. >> >> >> py> from datetime import datetime >> py> today = datetime.today() >> py> astring = "2014-12-27" >> py> another_day = datetime.strptime(astring, "%Y-%m-%d") >> py> difference = today - another_day >> py> difference.days >> 65 >> py> difference.days/7 # weeks >> 9.285714285714286 >> >> > > Standard datetime.date, if it were not, I would have written. > Will try, thanks for the info. > > Thanks to all, the strptime did the trick, after I realized that I was comparing a 2digit year to a 4digit. -- greymaus . . ... From ceh329 at gmail.com Mon Mar 2 13:17:12 2015 From: ceh329 at gmail.com (Charles Heizer) Date: Mon, 2 Mar 2015 10:17:12 -0800 (PST) Subject: Sort list of dictionaries Message-ID: Hello, I'm new to python and I'm trying to find the right way to solve this issue I have. I'm trying to sort this list by name and then by version numbers. The problem I'm having is that I can not get the version numbers sorted with the highest at the top or sorted properly. mylist = [{'name': u'com.google.earth', 'version': u'7.1.2.2041'}, {'name': u'com.google.earth', 'version': u'7.1.2.2019'}, {'name': u'com.google.Chrome', 'version': u'40.0.2214.93'}, {'name': u'com.google.Chrome', 'version': u'40.0.2214.91'}, {'name': u'com.google.Chrome', 'version': u'40.0.2214.111'}, {'name': u'com.google.Chrome', 'version': u'39.0.2171.99'}, {'name': u'com.google.Chrome', 'version': u'39.0.2171.95'}, {'name': u'com.google.Chrome', 'version': u'39.0.2171.71'}, {'name': u'com.google.Chrome', 'version': u'38.0.2125.122'}, {'name': u'com.google.Chrome', 'version': u'38.0.2125.111'}, {'name': u'com.google.Chrome', 'version': u'38.0.2125.104'}, {'name': u'com.google.Chrome', 'version': u'38.0.2125.101'}, {'name': u'com.google.Chrome', 'version': u'37.0.2062.94'}, {'name': u'com.google.Chrome', 'version': u'37.0.2062.120'}, {'name': u'com.google.Chrome', 'version': u'36.0.1985.143'}, {'name': u'com.google.Chrome', 'version': u'36.0.1985.125'}, {'name': u'com.google.Chrome', 'version': u'35.0.1916.153'}, {'name': u'com.google.Chrome', 'version': u'35.0.1916.114'}, {'name': u'com.google.Chrome', 'version': u'34.0.1847.137'}, {'name': u'com.google.Chrome', 'version': u'34.0.1847.131'}, {'name': u'com.google.Chrome', 'version': u'34.0.1847.116'}, {'name': u'com.google.Chrome', 'version': u'33.0.1750.152'}, {'name': u'com.google.Chrome', 'version': u'33.0.1750.149'}, {'name': u'com.google.Chrome', 'version': u'33.0.1750.146'}, {'name': u'com.google.Chrome', 'version': u'32.0.1700.107'}, {'name': u'com.google.Chrome', 'version': u'31.0.1650.63'}, {'name': u'com.google.Chrome', 'version': u'31.0.1650.57'}] sortedlist = sorted(mylist , key=lambda x, y: x['name'] LooseVersion(elem['version'])), reverse=True) Thanks, Charlie From emile at fenx.com Mon Mar 2 13:31:59 2015 From: emile at fenx.com (Emile van Sebille) Date: Mon, 02 Mar 2015 10:31:59 -0800 Subject: Sort list of dictionaries In-Reply-To: References: Message-ID: On 3/2/2015 10:17 AM, Charles Heizer wrote: > Hello, > I'm new to python and I'm trying to find the right way to solve this issue I have. > > I'm trying to sort this list by name and then by version numbers. The problem I'm having is that I can not get the version numbers sorted with the highest at the top or sorted properly. > > mylist = [{'name': u'com.google.earth', 'version': u'7.1.2.2041'}, > {'name': u'com.google.earth', 'version': u'7.1.2.2019'}, > {'name': u'com.google.Chrome', 'version': u'40.0.2214.93'}, > {'name': u'com.google.Chrome', 'version': u'40.0.2214.91'}, > {'name': u'com.google.Chrome', 'version': u'40.0.2214.111'}, > {'name': u'com.google.Chrome', 'version': u'39.0.2171.99'}, > {'name': u'com.google.Chrome', 'version': u'39.0.2171.95'}, > {'name': u'com.google.Chrome', 'version': u'39.0.2171.71'}, > {'name': u'com.google.Chrome', 'version': u'38.0.2125.122'}, > {'name': u'com.google.Chrome', 'version': u'38.0.2125.111'}, > {'name': u'com.google.Chrome', 'version': u'38.0.2125.104'}, > {'name': u'com.google.Chrome', 'version': u'38.0.2125.101'}, > {'name': u'com.google.Chrome', 'version': u'37.0.2062.94'}, > {'name': u'com.google.Chrome', 'version': u'37.0.2062.120'}, > {'name': u'com.google.Chrome', 'version': u'36.0.1985.143'}, > {'name': u'com.google.Chrome', 'version': u'36.0.1985.125'}, > {'name': u'com.google.Chrome', 'version': u'35.0.1916.153'}, > {'name': u'com.google.Chrome', 'version': u'35.0.1916.114'}, > {'name': u'com.google.Chrome', 'version': u'34.0.1847.137'}, > {'name': u'com.google.Chrome', 'version': u'34.0.1847.131'}, > {'name': u'com.google.Chrome', 'version': u'34.0.1847.116'}, > {'name': u'com.google.Chrome', 'version': u'33.0.1750.152'}, > {'name': u'com.google.Chrome', 'version': u'33.0.1750.149'}, > {'name': u'com.google.Chrome', 'version': u'33.0.1750.146'}, > {'name': u'com.google.Chrome', 'version': u'32.0.1700.107'}, > {'name': u'com.google.Chrome', 'version': u'31.0.1650.63'}, > {'name': u'com.google.Chrome', 'version': u'31.0.1650.57'}] > > sortedlist = sorted(mylist , key=lambda x, y: x['name'] LooseVersion(elem['version'])), reverse=True) You'll need to fix LooseVersion or elem or both -- or show them so we can help. Emile > > Thanks, > Charlie > From davea at davea.name Mon Mar 2 13:32:23 2015 From: davea at davea.name (Dave Angel) Date: Mon, 02 Mar 2015 13:32:23 -0500 Subject: date In-Reply-To: References: <54f47743$0$12979$c3e8da3$5496439d@news.astraweb.com> Message-ID: <54F4ACB7.8040606@davea.name> On 03/02/2015 11:25 AM, Chris Angelico wrote: > On Tue, Mar 3, 2015 at 3:09 AM, alister > wrote: >>>>> Sounds ominous. Is that better or worse than the final solution? >>>>> >>>>> >>>> As in "this program will inadvertantly self distruct in five seconds"? >>> >>> It's usually implied as being externally enforced, so I'd say it's more >>> akin to my solution to all manner of Windows problems. >>> >>> ChrisA >> >> Is that the same as my solution to windows related problems? >> >> (Dad bought a new laptop on Sat it was sterilised (As in disinfected ) >> immediately & has never run Windowz - lucky thing). > > Yes. What Steven is referencing is: > > https://en.wikipedia.org/wiki/Final_Solution > > And is unrelated to this: > > https://en.wikipedia.org/wiki/Final_Problem > > ChrisA > And all of them unrelated to "The Last One" http://en.wikipedia.org/wiki/The_Last_One_%28software%29 which was hyped to be the last program ever to be needed... -- DaveA From ceh329 at gmail.com Mon Mar 2 13:38:48 2015 From: ceh329 at gmail.com (Charles Heizer) Date: Mon, 2 Mar 2015 10:38:48 -0800 (PST) Subject: Sort list of dictionaries In-Reply-To: References: Message-ID: <946797be-10e6-433b-9411-2db0d5697ac8@googlegroups.com> Sorry, sortedlist = sorted(mylist , key=lambda elem: "%s %s" % (elem['name'], LooseVersion(elem['version'])), reverse=True) This is what I was trying but LooseVersion() was not sorting version numbers like I thought it would. You will notice that Chrome version "40.0.2214.111" is higher than "40.0.2214.91" but in the end result it's not sorting it that way. Thanks, Charlie On Monday, March 2, 2015 at 10:32:40 AM UTC-8, Emile van Sebille wrote: > On 3/2/2015 10:17 AM, Charles Heizer wrote: > > Hello, > > I'm new to python and I'm trying to find the right way to solve this issue I have. > > > > I'm trying to sort this list by name and then by version numbers. The problem I'm having is that I can not get the version numbers sorted with the highest at the top or sorted properly. > > > > mylist = [{'name': u'com.google.earth', 'version': u'7.1.2.2041'}, > > {'name': u'com.google.earth', 'version': u'7.1.2.2019'}, > > {'name': u'com.google.Chrome', 'version': u'40.0.2214.93'}, > > {'name': u'com.google.Chrome', 'version': u'40.0.2214.91'}, > > {'name': u'com.google.Chrome', 'version': u'40.0.2214.111'}, > > {'name': u'com.google.Chrome', 'version': u'39.0.2171.99'}, > > {'name': u'com.google.Chrome', 'version': u'39.0.2171.95'}, > > {'name': u'com.google.Chrome', 'version': u'39.0.2171.71'}, > > {'name': u'com.google.Chrome', 'version': u'38.0.2125.122'}, > > {'name': u'com.google.Chrome', 'version': u'38.0.2125.111'}, > > {'name': u'com.google.Chrome', 'version': u'38.0.2125.104'}, > > {'name': u'com.google.Chrome', 'version': u'38.0.2125.101'}, > > {'name': u'com.google.Chrome', 'version': u'37.0.2062.94'}, > > {'name': u'com.google.Chrome', 'version': u'37.0.2062.120'}, > > {'name': u'com.google.Chrome', 'version': u'36.0.1985.143'}, > > {'name': u'com.google.Chrome', 'version': u'36.0.1985.125'}, > > {'name': u'com.google.Chrome', 'version': u'35.0.1916.153'}, > > {'name': u'com.google.Chrome', 'version': u'35.0.1916.114'}, > > {'name': u'com.google.Chrome', 'version': u'34.0.1847.137'}, > > {'name': u'com.google.Chrome', 'version': u'34.0.1847.131'}, > > {'name': u'com.google.Chrome', 'version': u'34.0.1847.116'}, > > {'name': u'com.google.Chrome', 'version': u'33.0.1750.152'}, > > {'name': u'com.google.Chrome', 'version': u'33.0.1750.149'}, > > {'name': u'com.google.Chrome', 'version': u'33.0.1750.146'}, > > {'name': u'com.google.Chrome', 'version': u'32.0.1700.107'}, > > {'name': u'com.google.Chrome', 'version': u'31.0.1650.63'}, > > {'name': u'com.google.Chrome', 'version': u'31.0.1650.57'}] > > > > sortedlist = sorted(mylist , key=lambda x, y: x['name'] LooseVersion(elem['version'])), reverse=True) > > You'll need to fix LooseVersion or elem or both -- or show them so we > can help. > > Emile > > > > > > > Thanks, > > Charlie > > From tiya.akrid at gmail.com Mon Mar 2 13:40:13 2015 From: tiya.akrid at gmail.com (tiya.akrid at gmail.com) Date: Mon, 2 Mar 2015 10:40:13 -0800 (PST) Subject: Direct Client Requirement for Data Application Engineer (Hadoop) - Sunnyvale CA Message-ID: <1f664be3-9b06-4455-8c26-bc230f303ba6@googlegroups.com> Hi Please let me know if you have anyone available for below position Position - Data Application Engineer Location: Sunnyvale, CA (local candidates ONLY) Interview Process - Onsite Duration - 6 months + contract The Marketing Science team is looking for a Software Data Application Developer with experience in working on Data platforms. Responsibilities: * Write data-driven, automation scripts for scraping, parsing through complex data. * Must have programming experience in Java, C++, Perl or Python * Strong understanding of database concepts * Maintain and create new automated test cases using Python/Perl/Shell * Must be an expert in SQL * Ability to come up with test scenarios and write test plans and test cases Qualifications: * Four or more years of development or test development experience in BI/DW * Strong understanding of Datawarehouse, Big Data and BI Analytics concepts * Demonstrated experience implementing automation frameworks using scripting languages/tools like Shell, Java, Python etc. * Hands-on experience with Hadoop and tools such as Hive, Sqoop, Pig, Impala and Spark is preferred * Experience using data driven tests to validate 3rd party API calls Please send word format resume along with below details for further process Hadoop _______years of experience Datawarehouse _______years of experience BI Analytics _______years of experience Scripting tools (shell / Java / Python) _______years of experience 3rd party API Calls _______years of experience Any experience with Hive / Sqoop / Pig / Impala/ Spark? Rates on c2c Availability Current Location Thanks Tiya Akrid Software Inc From ian.g.kelly at gmail.com Mon Mar 2 13:55:27 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 2 Mar 2015 11:55:27 -0700 Subject: Sort list of dictionaries In-Reply-To: <946797be-10e6-433b-9411-2db0d5697ac8@googlegroups.com> References: <946797be-10e6-433b-9411-2db0d5697ac8@googlegroups.com> Message-ID: On Mon, Mar 2, 2015 at 11:38 AM, Charles Heizer wrote: > Sorry, > > sortedlist = sorted(mylist , key=lambda elem: "%s %s" % (elem['name'], LooseVersion(elem['version'])), reverse=True) > > This is what I was trying but LooseVersion() was not sorting version numbers like I thought it would. You will notice that Chrome version "40.0.2214.111" is higher than "40.0.2214.91" but in the end result it's not sorting it that way. Because it's a string they're sorted lexicographically, and in that ordering "40.0.2214.111" is less than "40.0.2214.91". Instead of a string you should probably use some sort of version info tuple. A simple tuple of ints may suffice, although you may need to get a little cleverer if there are ever any version strings that aren't entirely dotted numeric. From davea at davea.name Mon Mar 2 13:55:53 2015 From: davea at davea.name (Dave Angel) Date: Mon, 02 Mar 2015 13:55:53 -0500 Subject: rst and pypandoc In-Reply-To: <54f47707$0$12979$c3e8da3$5496439d@news.astraweb.com> References: <54f458a5$0$13003$c3e8da3$5496439d@news.astraweb.com> <54f47707$0$12979$c3e8da3$5496439d@news.astraweb.com> Message-ID: <54F4B239.8010102@davea.name> On 03/02/2015 09:43 AM, Steven D'Aprano wrote: > Dave Angel wrote: > >> On 03/02/2015 08:51 AM, alb wrote: >>> Hi Steven, >>> >>> Steven D'Aprano wrote: >>>> >>>> or use a raw string: >>>> >>>> i = r'\\ref{fig:abc}' >> >> Actually that'd be: >> i = r'\ref{fig:abc}' > > > D'oh! > > I mean, you spotted my deliberate mistake to check if you were paying > attention. Well done! > > >> How about "in" and "out"? Or perhaps some name that indicates what >> semantics the string represents, like "rst_string" and "html_string" >> or whatever they actually are? > > Can't use "in", it's a keyword. > And D'oh right back at ya. Ironic isn't it that I make a second mistake in the same message I correct yours? -- DaveA From ceh329 at gmail.com Mon Mar 2 13:58:42 2015 From: ceh329 at gmail.com (Charles Heizer) Date: Mon, 2 Mar 2015 10:58:42 -0800 (PST) Subject: Sort list of dictionaries In-Reply-To: <946797be-10e6-433b-9411-2db0d5697ac8@googlegroups.com> References: <946797be-10e6-433b-9411-2db0d5697ac8@googlegroups.com> Message-ID: <8ccd65d8-3f1f-41ac-9092-9b0832d2fc49@googlegroups.com> Never mind, the light bulb finally went off. :-\ sortedlist = sorted(mylist , key=lambda elem: "%s %s" % ( elem['name'], (".".join([i.zfill(5) for i in elem['version'].split(".")])) ), reverse=True) On Monday, March 2, 2015 at 10:40:30 AM UTC-8, Charles Heizer wrote: > Sorry, > > sortedlist = sorted(mylist , key=lambda elem: "%s %s" % (elem['name'], LooseVersion(elem['version'])), reverse=True) > > This is what I was trying but LooseVersion() was not sorting version numbers like I thought it would. You will notice that Chrome version "40.0.2214.111" is higher than "40.0.2214.91" but in the end result it's not sorting it that way. > > Thanks, > Charlie > > On Monday, March 2, 2015 at 10:32:40 AM UTC-8, Emile van Sebille wrote: > > On 3/2/2015 10:17 AM, Charles Heizer wrote: > > > Hello, > > > I'm new to python and I'm trying to find the right way to solve this issue I have. > > > > > > I'm trying to sort this list by name and then by version numbers. The problem I'm having is that I can not get the version numbers sorted with the highest at the top or sorted properly. > > > > > > mylist = [{'name': u'com.google.earth', 'version': u'7.1.2.2041'}, > > > {'name': u'com.google.earth', 'version': u'7.1.2.2019'}, > > > {'name': u'com.google.Chrome', 'version': u'40.0.2214.93'}, > > > {'name': u'com.google.Chrome', 'version': u'40.0.2214.91'}, > > > {'name': u'com.google.Chrome', 'version': u'40.0.2214.111'}, > > > {'name': u'com.google.Chrome', 'version': u'39.0.2171.99'}, > > > {'name': u'com.google.Chrome', 'version': u'39.0.2171.95'}, > > > {'name': u'com.google.Chrome', 'version': u'39.0.2171.71'}, > > > {'name': u'com.google.Chrome', 'version': u'38.0.2125.122'}, > > > {'name': u'com.google.Chrome', 'version': u'38.0.2125.111'}, > > > {'name': u'com.google.Chrome', 'version': u'38.0.2125.104'}, > > > {'name': u'com.google.Chrome', 'version': u'38.0.2125.101'}, > > > {'name': u'com.google.Chrome', 'version': u'37.0.2062.94'}, > > > {'name': u'com.google.Chrome', 'version': u'37.0.2062.120'}, > > > {'name': u'com.google.Chrome', 'version': u'36.0.1985.143'}, > > > {'name': u'com.google.Chrome', 'version': u'36.0.1985.125'}, > > > {'name': u'com.google.Chrome', 'version': u'35.0.1916.153'}, > > > {'name': u'com.google.Chrome', 'version': u'35.0.1916.114'}, > > > {'name': u'com.google.Chrome', 'version': u'34.0.1847.137'}, > > > {'name': u'com.google.Chrome', 'version': u'34.0.1847.131'}, > > > {'name': u'com.google.Chrome', 'version': u'34.0.1847.116'}, > > > {'name': u'com.google.Chrome', 'version': u'33.0.1750.152'}, > > > {'name': u'com.google.Chrome', 'version': u'33.0.1750.149'}, > > > {'name': u'com.google.Chrome', 'version': u'33.0.1750.146'}, > > > {'name': u'com.google.Chrome', 'version': u'32.0.1700.107'}, > > > {'name': u'com.google.Chrome', 'version': u'31.0.1650.63'}, > > > {'name': u'com.google.Chrome', 'version': u'31.0.1650.57'}] > > > > > > sortedlist = sorted(mylist , key=lambda x, y: x['name'] LooseVersion(elem['version'])), reverse=True) > > > > You'll need to fix LooseVersion or elem or both -- or show them so we > > can help. > > > > Emile > > > > > > > > > > > > Thanks, > > > Charlie > > > From davea at davea.name Mon Mar 2 13:59:50 2015 From: davea at davea.name (Dave Angel) Date: Mon, 02 Mar 2015 13:59:50 -0500 Subject: Sort list of dictionaries In-Reply-To: <946797be-10e6-433b-9411-2db0d5697ac8@googlegroups.com> References: <946797be-10e6-433b-9411-2db0d5697ac8@googlegroups.com> Message-ID: <54F4B326.6000807@davea.name> On 03/02/2015 01:38 PM, Charles Heizer wrote: > Sorry, > > sortedlist = sorted(mylist , key=lambda elem: "%s %s" % (elem['name'], LooseVersion(elem['version'])), reverse=True) > > This is what I was trying but LooseVersion() was not sorting version numbers like I thought it would. You will notice that Chrome version "40.0.2214.111" is higher than "40.0.2214.91" but in the end result it's not sorting it that way. > Please don't top-post. put your remarks after whatever quoting you do. You still haven't posted your LooseVersion() function source. I agree with Emile that it's likely to be the problem. -- DaveA From sohcahtoa82 at gmail.com Mon Mar 2 14:06:56 2015 From: sohcahtoa82 at gmail.com (sohcahtoa82 at gmail.com) Date: Mon, 2 Mar 2015 11:06:56 -0800 (PST) Subject: Python Worst Practices In-Reply-To: References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> Message-ID: <7dcc8dfe-3430-44c7-a285-085758aac552@googlegroups.com> On Monday, March 2, 2015 at 9:13:21 AM UTC-8, Jon Ribbens wrote: > On 2015-03-02, Dennis Lee Bieber wrote: > > A pub's a bar; a bar's a gate; a gate's a street > > If each of those is supposed to be English first and then the American > equivalent second, then I'm afraid the first one is misleading and the > other two are just nonsense. American here. To me, a pub and a bar are different, but similar. A bar is where people go to get drinks. They might serve food, but rarely does anybody actually order some. A pub on the other hand, has a greater focus on food and is commonly visited to get food along with their beer. Of course, I imagine plenty of fellow Americans would disagree with me. From ben+python at benfinney.id.au Mon Mar 2 14:09:42 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 03 Mar 2015 06:09:42 +1100 Subject: rst and pypandoc References: <54f458a5$0$13003$c3e8da3$5496439d@news.astraweb.com> <54f47707$0$12979$c3e8da3$5496439d@news.astraweb.com> <54F4B239.8010102@davea.name> Message-ID: <85sidn1aix.fsf@benfinney.id.au> Dave Angel writes: > And D'oh right back at ya. Ironic isn't it that I make a second > mistake in the same message I correct yours? -- \ ?Truth would quickly cease to become stranger than fiction, | `\ once we got as used to it.? ?Henry L. Mencken | _o__) | Ben Finney From tiya.akrid at gmail.com Mon Mar 2 14:11:08 2015 From: tiya.akrid at gmail.com (tiya.akrid at gmail.com) Date: Mon, 2 Mar 2015 11:11:08 -0800 (PST) Subject: Direct Client Requirement for Software Engineer in Quality - Sunnyvale CA Message-ID: <5fad4479-15c2-42af-b766-72c53030dea1@googlegroups.com> Hi Please let me know if you have anyone suitable for the below position Job title: Software Engineer in Quality Location: Sunnyvale, CA Interview Process: Onsite Duration: 6 months + contract Responsibilities: Work on an existing application in the Marketing Science team focused on maintaining internal application as well making enhancements and new features to the system. Initially focus on quality by creating test plans, test data, data validation SQL scripts and analyze test results and then automate some of the testing and quality checks Adding more integration to new channels and sources of data via web services as well as custom data feeds Work closely with marketing business and technology teams and provide on-going support and guidance. Develop scalable and reusable processes and automation frameworks for analyzing data and delivering ongoing quality metrics (leveraging SQL, PL SQL, UNIX, PYTHON and other tools) Required Skills and Experience: 3 - 8 years' experience developing and testing highly distributed, complex eCommerce Platforms At least 3 years hands-on software programming, Automation Scripting, White box testing experience Python scripting experience, strong knowledge and experience in automated testing (API testing preferred), someone who has experience working in an Agile development environment, and someone who is comfortable owning the testing for a feature or project and working directly with API developers Extensive hands-on QA & white box testing, and automation. Nice to have - string prior QE , Python scripting Hands-on experience working with relational DB ( Oracle, MySQL, PostgreSQL) as well NoSQL DB such as Cassandra, Redshift Kindly send your resume with below details for further process Automation Scripting _________ years of experience White Box testing _________ years of experience Python Scripting _________ years of experience eCommerce Platforms _________ years of experience Rates on c2c Availability Current Location Thanks Tiya Akrid Software Inc tiya at akrid.us From sohcahtoa82 at gmail.com Mon Mar 2 14:14:17 2015 From: sohcahtoa82 at gmail.com (sohcahtoa82 at gmail.com) Date: Mon, 2 Mar 2015 11:14:17 -0800 (PST) Subject: Md5 is different in Windows and Linux In-Reply-To: References: Message-ID: On Monday, March 2, 2015 at 12:43:59 AM UTC-8, Sarvagya Pant wrote: > Hello, I am amazed that the? md5 of a file given by python in windows is different than that of linux. Consider the following code: > > import hashlib > def md5_for_file(f, block_size=2**20): > ??? md5 = hashlib.md5() > ??? while True: > ??????? data = f.read(block_size) > ??????? if not data: > ??????????? break > ??????? md5.update(data) > ??? return md5.hexdigest() > > f = open("somefile.txt") > print md5_for_file(f) > > > When I run the program I get the checksum value: 2f9cc8da53ee89762a34702f745d2956 > > But on this site http://onlinemd5.com/ and on linux it has value E10D4E3847713472F51BC606852712F1. > > > Why is there difference in value of Checksum computed by python in windows and other system.? > > -- > > sarvagya I don't know which is worse, the fact that you're composing your message in HTML, or the fact that you're using Comic Sans as your font. From davea at davea.name Mon Mar 2 14:16:04 2015 From: davea at davea.name (Dave Angel) Date: Mon, 02 Mar 2015 14:16:04 -0500 Subject: rst and pypandoc In-Reply-To: <85sidn1aix.fsf@benfinney.id.au> References: <54f458a5$0$13003$c3e8da3$5496439d@news.astraweb.com> <54f47707$0$12979$c3e8da3$5496439d@news.astraweb.com> <54F4B239.8010102@davea.name> <85sidn1aix.fsf@benfinney.id.au> Message-ID: <54F4B6F4.4030803@davea.name> On 03/02/2015 02:09 PM, Ben Finney wrote: > Dave Angel writes: > >> And D'oh right back at ya. Ironic isn't it that I make a second >> mistake in the same message I correct yours? > > > I guess that word is too small to qualify as a malapropism, a word which I usually pronounce "Mollypropism." -- DaveA From gvanem at yahoo.no Mon Mar 2 14:22:12 2015 From: gvanem at yahoo.no (Gisle Vanem) Date: Mon, 02 Mar 2015 20:22:12 +0100 Subject: Python27.dll could not be found In-Reply-To: <54F45701.6030006@davea.name> References: <54F45701.6030006@davea.name> Message-ID: <54F4B864.8020602@yahoo.no> Dave Angel wrote: > When I ran Windows, I had written a simple utility that searched the PATH for a specified file. > I called it which.bat to match the Linux equivalent. I've written a similar tool; envtool --path --python python27.dll Matches in %PATH: 15 May 2013 - 21:43:38: f:\ProgramFiler\Python27\python27.dll Matches in Python's sys.path[]: 15 May 2013 - 21:43:38: f:\programfiler\Python27\python27.dll (available at http://watt-32.net/misc/#envtool ) > You can look to see where the system thinks the Python executable is located by doing > > ftype .py > and seeing what it shows. Mine shows Python.File > > Then do > assoc Python.File > > to see an actual path. That will give you the path of python.exe. Not pythonXX.dll (as the OP had problems with). But by Windows DLL loading rules, it's IMHO safer to have pythonXX.dll in the directory of python[w].exe. On Windows, ACAICR the Python MSI installer puts pythonXX.dll in %Windir\system32. So it depends on how the OP installed his Python. -- --gv From __peter__ at web.de Mon Mar 2 14:23:13 2015 From: __peter__ at web.de (Peter Otten) Date: Mon, 02 Mar 2015 20:23:13 +0100 Subject: Sort list of dictionaries References: <946797be-10e6-433b-9411-2db0d5697ac8@googlegroups.com> <8ccd65d8-3f1f-41ac-9092-9b0832d2fc49@googlegroups.com> Message-ID: Charles Heizer wrote: > Never mind, the light bulb finally went off. :-\ > > sortedlist = sorted(mylist , key=lambda elem: "%s %s" % ( elem['name'], > (".".join([i.zfill(5) for i in elem['version'].split(".")])) ), > reverse=True) This lightbulb will break with version numbers > 99999 ;) Here are two alternatives: result = sorted( mylist, key=lambda elem: (elem['name'], LooseVersion(elem['version'])), reverse=True) result = sorted( mylist, key=lambda e: (e["name"], tuple(map(int, e["version"].split(".")))), reverse=True) Personally, I prefer to not use a lambda: def name_version(elem): return elem['name'], LooseVersion(elem['version']) result = sorted(mylist, key=name_version, reverse=True) From ginellobadellu at mail.com Mon Mar 2 14:37:09 2015 From: ginellobadellu at mail.com (MEMOCHE UNO) Date: Mon, 2 Mar 2015 11:37:09 -0800 (PST) Subject: -- redacted -- Message-ID: <4f5ceab4-d175-4b96-829b-8c8fab7f77f0@googlegroups.com> -- redacted -- From d at davea.name Mon Mar 2 14:44:17 2015 From: d at davea.name (Dave Angel) Date: Mon, 02 Mar 2015 14:44:17 -0500 Subject: Python27.dll could not be found In-Reply-To: <54F46ACB.1060204@davea.name> References: <54F46ACB.1060204@davea.name> Message-ID: <54F4BD91.3020108@davea.name> I INTENDED to send it to the list, but made the same mistake myself. -------- Forwarded Message -------- Subject: Re: Python27.dll could not be found Date: Mon, 02 Mar 2015 08:51:07 -0500 From: Dave Angel To: Sarvagya Pant Sarvaqya accidentally sent me private email, so I'm forwarding with comments to the list. On 03/02/2015 08:22 AM, Sarvagya Pant wrote: > Hi thanks to all. Python.dll was found in my C:/Windows/SysWOW64 dir. As my > executable depends upon python.dll, it was required if I have to deploy my > executable. So, was that directory on your PATH? If so, Windows should have just found it, and you'd have had no problem. If you're instead talking about building an install for other machines, that may or may not have Python 2.7 installed, you should say so. PythonXX.dll may very well load other files when your code loads and uses it, so an installation is usually a much more complex problem than what you stated. I have no idea what the best package manager is for Windows, but you could start by looking at: https://pypi.python.org/pypi/setuptools -- DaveA From davea at davea.name Mon Mar 2 14:45:10 2015 From: davea at davea.name (Dave Angel) Date: Mon, 02 Mar 2015 14:45:10 -0500 Subject: Python27.dll could not be found In-Reply-To: <54F4B864.8020602@yahoo.no> References: <54F45701.6030006@davea.name> <54F4B864.8020602@yahoo.no> Message-ID: <54F4BDC6.6080504@davea.name> On 03/02/2015 02:22 PM, Gisle Vanem wrote: > Dave Angel wrote: > >> When I ran Windows, I had written a simple utility that searched the >> PATH for a specified file. >> I called it which.bat to match the Linux equivalent. > > I've written a similar tool; envtool --path --python python27.dll > > Matches in %PATH: > 15 May 2013 - 21:43:38: f:\ProgramFiler\Python27\python27.dll > Matches in Python's sys.path[]: > 15 May 2013 - 21:43:38: f:\programfiler\Python27\python27.dll > > (available at http://watt-32.net/misc/#envtool ) > >> You can look to see where the system thinks the Python executable is >> located by doing >> >> ftype .py >> and seeing what it shows. Mine shows Python.File >> >> Then do >> assoc Python.File >> >> to see an actual path. > > That will give you the path of python.exe. Not pythonXX.dll (as the > OP had problems with). I just figured it was extra information the OP could use; finding the executable is a useful thing, even though different from finding the DLL. > > But by Windows DLL loading rules, it's IMHO safer to have pythonXX.dll > in the directory of python[w].exe. On Windows, ACAICR the Python MSI > installer puts pythonXX.dll in %Windir\system32. So it depends on how > the OP installed his Python. > > Doesn't do much good to have the DLL only in the python directory, if you're going to load it in a default way from a C++ program. Python.exe doesn't do much, it mainly parses the commandline and invokes the DLL. Other programs that want to call Python functions don't need the exe, and therefore count on the DLL being on the Windows path. The OP sent me a private message saying: "Python.dll was found in my C:/Windows/SysWOW64 dir" I responded and intended it to be posted to the list, but messed up. You should see it by now. -- DaveA From breamoreboy at yahoo.co.uk Mon Mar 2 15:02:18 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 02 Mar 2015 20:02:18 +0000 Subject: Python Worst Practices In-Reply-To: <87oaoc61wf.fsf@elektro.pacujo.net> References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <87oaoc61wf.fsf@elektro.pacujo.net> Message-ID: On 01/03/2015 17:52, Marko Rauhamaa wrote: > Mark Lawrence : > >> On 01/03/2015 17:01, Marko Rauhamaa wrote: >>> What you (or I) speak in our native surroundings is up to you (and >>> me). >>> >>> However, when I exhange software engineering ideas with you, I wish >>> both of us could stick to American English. >> >> Well I'm not going to, so tough, or is that togh? Colour, harbour, >> tyre, antogonise are the way I spell words, and I'm not changing the >> habits of a lifetime simply because I'm on a technical site. > > Wow, a somewhat Chauvinistic attitude, wouldn't you say? The French will > learn it. The Germans will learn it. Us Finns will learn it. Only you > won't learn it because you won't change the habits of a lifetime. > No I wouldn't, autistic is far more accurate. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rowen at uw.edu Mon Mar 2 15:25:34 2015 From: rowen at uw.edu (Russell Owen) Date: Mon, 02 Mar 2015 12:25:34 -0800 Subject: Picking apart a text line In-Reply-To: References: Message-ID: On 2/26/15 7:53 PM, memilanuk wrote: > So... okay. I've got a bunch of PDFs of tournament reports that I want > to sift thru for information. Ended up using 'pdftotext -layout > file.pdf file.txt' to extract the text from the PDF. Still have a few > little glitches to iron out there, but I'm getting decent enough results > for the moment to move on. > ... > So back to the lines of text I have stored as strings in a list. I > think I want to convert that to a list of lists, i.e. split each line > up, store that info in another list and ditch the whitespace. Or would > I be better off using dicts? Originally I was thinking of how to > process each line and split it them up based on what information was > where - some sort of nested for/if mess. Now I'm starting to think that > the lines of text are pretty uniform in structure i.e. the same field is > always in the same location, and that list slicing might be the way to > go, if a bit tedious to set up initially...? > > Any thoughts or suggestions from people who've gone down this particular > path would be greatly appreciated. I think I have a general > idea/direction, but I'm open to other ideas if the path I'm on is just > blatantly wrong. It sounds to me as if the best way to handle all this is keep the information it in a database, preferably one available from the network and centrally managed, so whoever enters the information in the first place enters it there. But I admit that setting such a thing up requires some overhead. Simpler alternatives include using SQLite, a simple file-based database system, or numpy structured arrays (arrays with named fields). Python includes a standard library module for sqlite and numpy is easy to install. -- Russell From jon+usenet at unequivocal.co.uk Mon Mar 2 17:21:00 2015 From: jon+usenet at unequivocal.co.uk (Jon Ribbens) Date: Mon, 2 Mar 2015 22:21:00 +0000 (UTC) Subject: Python Worst Practices References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <7dcc8dfe-3430-44c7-a285-085758aac552@googlegroups.com> Message-ID: On 2015-03-02, sohcahtoa82 at gmail.com wrote: > On Monday, March 2, 2015 at 9:13:21 AM UTC-8, Jon Ribbens wrote: >> On 2015-03-02, Dennis Lee Bieber wrote: >> > A pub's a bar; a bar's a gate; a gate's a street >> >> If each of those is supposed to be English first and then the American >> equivalent second, then I'm afraid the first one is misleading and the >> other two are just nonsense. > > American here. To me, a pub and a bar are different, but similar. > > A bar is where people go to get drinks. They might serve food, but > rarely does anybody actually order some. A pub on the other hand, > has a greater focus on food and is commonly visited to get food > along with their beer. > > Of course, I imagine plenty of fellow Americans would disagree with me. The distinction is nuanced and not well defined, but most British people would think your definition above is certainly not entirely wrong. They're definitely both places primarily for alcohol but which may serve other purposes. If there's more wood and brass it's probably a pub; if there's more glass and chrome and coloured lighting it's probably a bar. From al.basili at gmail.com Mon Mar 2 17:30:02 2015 From: al.basili at gmail.com (alb) Date: 2 Mar 2015 22:30:02 GMT Subject: rst and pypandoc References: <54f458a5$0$13003$c3e8da3$5496439d@news.astraweb.com> Message-ID: Hi Dave, Dave Angel wrote: [] >> Rst escapes with "\", but unfortunately python also uses "\" for escaping! > > Only when the string is in a literal. If you've read it from a file, or > built it by combining other strings, or... then the backslash is just > another character to Python. Holy s***t! that is enlightning. I'm not going to ask why is that so, but essentially this changes everything. Indeed I'm passing some strings as literal (as my example), some others are simply read from a file (well the file is read into a list of dictionaries and then I convert one of those keys into latex). The it would mean that the following text (in a file) should be swallowed by python as if the backslash was just another character: this is \some text unfortunately when I pass that to pypandoc, as if it was restructured text, I get the following: In [36]: f = open('test.txt', 'r') In [37]: s = f.read() In [38]: print s this is \some restructured text. In [39]: print pypandoc.convert(s, 'latex', format='rst') this is some restructured text. what happened to my backslash??? If I try to escape my backslash I get something worse: In [40]: f = open('test.txt', 'r') In [41]: s = f.read() In [42]: print s this is \\some restructured text. In [43]: print pypandoc.convert(s, 'latex', format='rst') this is \textbackslash{}some restructured text. since a literal backslash gets converted to a literal latex backslash. [] >> As said above, the string is converted by pandoc first and then printed. >> At this point the escaping becomes tricky (at least to me). >> >> In [17]: inp = '\\ref{fig:abc}' >> >> In [18]: print pypandoc.convert(inp, 'latex', format='rst') >> ref\{fig:abc\} >> > > What did you expect/desire the pyandoc output to be? Now that you don't > have the embedded 0x0a, is there something else that's wrong? I need to get \ref{fig:abc} in my latex file in order to get a reference. It seems to me I'm not able to pass inline text to pandoc and every backslash is treated...somehow. > If it's in the internals of pyandoc, I'll probably be of no help. But > your first question was about escaping; I'm not sure what it's about now. It's still about escaping in both python and restructured text since I want my substring (is part of the text) to pass unchanged through pypandoc. Al From al.basili at gmail.com Mon Mar 2 17:37:06 2015 From: al.basili at gmail.com (alb) Date: 2 Mar 2015 22:37:06 GMT Subject: rst and pypandoc References: <54f458a5$0$13003$c3e8da3$5496439d@news.astraweb.com> Message-ID: Hi MRAB, MRAB wrote: [] > Have you tried escaping the escape character by doubling the backslash? > > inp = '\\\\ref{fig:abc}' In [54]: inp = '\\\\ref{fig:abc}' In [55]: print pypandoc.convert(inp, 'latex', format='rst') \textbackslash{}ref\{fig:abc\} the backslash is considered as literal text for latex and is escaped with the appropriate command. > or: > > inp = r'\\ref{fig:abc}' > In [56]: inp = r'\\ref{fig:abc}' In [57]: print pypandoc.convert(inp, 'latex', format='rst') \textbackslash{}ref\{fig:abc\} same as above. The result I aim to would be: In [BINGO]: print pypandoc.convert(inp, 'latex', format='rst') \ref{fig:abc} Al From al.basili at gmail.com Mon Mar 2 17:40:41 2015 From: al.basili at gmail.com (alb) Date: 2 Mar 2015 22:40:41 GMT Subject: rst and pypandoc References: <54f458a5$0$13003$c3e8da3$5496439d@news.astraweb.com> Message-ID: Hi Dave, Dave Angel wrote: [] >>> or use a raw string: >>> >>> i = r'\\ref{fig:abc}' > > Actually that'd be: > i = r'\ref{fig:abc}' Could you explain why I then see the following difference: In [56]: inp = r'\\ref{fig:abc}' In [57]: print pypandoc.convert(inp, 'latex', format='rst') \textbackslash{}ref\{fig:abc\} In [58]: inp = r'\ref{fig:abc}' In [59]: print pypandoc.convert(inp, 'latex', format='rst') ref\{fig:abc\} The two results are clearly *not* the same, even though the two inp /claim/ to be the same... Al From greg.ewing at canterbury.ac.nz Mon Mar 2 17:45:39 2015 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 03 Mar 2015 11:45:39 +1300 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] In-Reply-To: <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > I remember the first time I realised that when Indians talk about "a > code" they aren't using "wrong English", they are using a regional > variation. I don't think this is confined to Indians. I've noticed that people from a Fortran scientific-computing background tend to use the word that way as well. -- Greg From rosuav at gmail.com Mon Mar 2 17:51:59 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 Mar 2015 09:51:59 +1100 Subject: rst and pypandoc In-Reply-To: References: <54f458a5$0$13003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 3, 2015 at 9:30 AM, alb wrote: > Hi Dave, > > Dave Angel wrote: > [] >>> Rst escapes with "\", but unfortunately python also uses "\" for escaping! >> >> Only when the string is in a literal. If you've read it from a file, or >> built it by combining other strings, or... then the backslash is just >> another character to Python. > > Holy s***t! that is enlightning. I'm not going to ask why is that so, > but essentially this changes everything. Indeed I'm passing some strings > as literal (as my example), some others are simply read from a file > (well the file is read into a list of dictionaries and then I convert > one of those keys into latex). You have two different things happening here. The first is the concept of a "string literal", and the second is how pandoc handles things. Python's string literals come in a few different forms, but the most common is the one that looks the same as in several other languages. You start with a quote character, you put all your stuff in the middle, and you finish with another quote: "Hello, world!" Trouble is, this makes it really hard to put quotes into your string: "I said, "Hello, world!"" That's not going to work properly! So we need to tell Python that those interior quotes aren't the end of the string. That's done with a backslash: "I said, \"Hello, world!\"" And of course, that means you have to escape the backslash if you want to have one in the text. But all of this is just for putting *string literals* into your source code. If it's not Python source code, these rules don't apply. You can read a line of text from the user and it'll be unchanged: >>> msg = input("Enter a string: ") Enter a string: This is a string, but not a "string literal". >>> print(msg) This is a string, but not a "string literal". (in Python 2, use raw_input instead of input) Same applies to reading from a file, or anywhere else. If it's not Python source code, it doesn't matter what characters are in the string, they're all just characters. > unfortunately when I pass that to pypandoc, as if it was restructured > text, I get the following: > > In [36]: f = open('test.txt', 'r') > > In [37]: s = f.read() > > In [38]: print s > this is \some restructured text. > > > In [39]: print pypandoc.convert(s, 'latex', format='rst') > this is some restructured text. > > what happened to my backslash??? That's something you'll have to figure out with pypandoc. I don't know how it interprets the backslash, so you'll have to dig into its documentation. At least now, though, you can print out your string and see that it really does have its backslash in it. ChrisA From breamoreboy at yahoo.co.uk Mon Mar 2 18:08:08 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 02 Mar 2015 23:08:08 +0000 Subject: rst and pypandoc In-Reply-To: References: <54f458a5$0$13003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 02/03/2015 22:40, alb wrote: > Hi Dave, > > Dave Angel wrote: > [] >>>> or use a raw string: >>>> >>>> i = r'\\ref{fig:abc}' >> >> Actually that'd be: >> i = r'\ref{fig:abc}' > > Could you explain why I then see the following difference: > > In [56]: inp = r'\\ref{fig:abc}' > > In [57]: print pypandoc.convert(inp, 'latex', format='rst') > \textbackslash{}ref\{fig:abc\} > > > In [58]: inp = r'\ref{fig:abc}' > > In [59]: print pypandoc.convert(inp, 'latex', format='rst') > ref\{fig:abc\} > > The two results are clearly *not* the same, even though the two inp > /claim/ to be the same... > > Al > The two inps are *not* the same. Steven D'Aprano mislead you with a typo, or so he claims :) Dave Angel pointed this out. Steven replied. You've either missed these emails or simply not read them. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From ben+python at benfinney.id.au Mon Mar 2 18:18:05 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 03 Mar 2015 10:18:05 +1100 Subject: rst and pypandoc References: <54f458a5$0$13003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <85lhjf0z0y.fsf@benfinney.id.au> Chris Angelico writes: > And of course, that means you have to escape the backslash if you want > to have one in the text. But all of this is just for putting *string > literals* into your source code. If it's not Python source code, these > rules don't apply. You can read a line of text from the user and it'll > be unchanged To put it another way: The source code is not the value itself. The string value is created *from* the characters in the source code, and the sequence of characters in the string value may be different. When the string value comes from somewhere else, it bypasses this interpretation of source code ? because it's not source code! String literals exist in your Python source code. They are not the same thing as the string value itself, and the sequence fo characters may be different. -- \ ?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 steve+comp.lang.python at pearwood.info Mon Mar 2 18:22:55 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 03 Mar 2015 10:22:55 +1100 Subject: rst and pypandoc References: <54f458a5$0$13003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <54f4f0d0$0$12995$c3e8da3$5496439d@news.astraweb.com> alb wrote: > Could you explain why I then see the following difference: > > In [56]: inp = r'\\ref{fig:abc}' > > In [57]: print pypandoc.convert(inp, 'latex', format='rst') > \textbackslash{}ref\{fig:abc\} > > > In [58]: inp = r'\ref{fig:abc}' > > In [59]: print pypandoc.convert(inp, 'latex', format='rst') > ref\{fig:abc\} > > The two results are clearly *not* the same, even though the two inp > /claim/ to be the same... The two inp are not the same. I'm sorry if I confused you with my earlier typo, but inp = r'\\ref{fig:abc}' starts with TWO backslashes, while: inp = r'\ref{fig:abc}' starts with ONE backslash. Not the same. I suspect you've been hitting your head against this problem for so long you're starting to shy at shadows. Take a step back, a deep breath, and remember your basic debugging skills: a = r'\\ref{fig:abc}' b = r'\ref{fig:abc}' print a == b print a, b print repr(a), repr(b) print len(a), len(b) I'm sure that you know how to do such simple things to investigate whether two inputs are in fact the same or not, and the fact that you failed to do so is just a sign of your frustration and stress. -- Steven From davea at davea.name Mon Mar 2 18:23:05 2015 From: davea at davea.name (Dave Angel) Date: Mon, 02 Mar 2015 18:23:05 -0500 Subject: rst and pypandoc In-Reply-To: References: <54f458a5$0$13003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <54F4F0D9.4000402@davea.name> On 03/02/2015 05:40 PM, alb wrote: > Hi Dave, > > Dave Angel wrote: > [] >>>> or use a raw string: >>>> >>>> i = r'\\ref{fig:abc}' >> >> Actually that'd be: >> i = r'\ref{fig:abc}' > > Could you explain why I then see the following difference: > > In [56]: inp = r'\\ref{fig:abc}' print inp and you should get \\ref{fig:abc} > > In [57]: print pypandoc.convert(inp, 'latex', format='rst') > \textbackslash{}ref\{fig:abc\} > > > In [58]: inp = r'\ref{fig:abc}' print inp and you should get \ref{fig:abc} This is NOT the same. The rules are not arbitrary. They're quite necessary, and it's the same for lots of different languages. When in a regular literal, the backslash is an escape character that combines with the following character. When in a raw literal, the backslash is a backslash, unless it's at the end of the string, in which case it's not the end of the string, it's an escaped quotation. (Or something. Just don't use *trailing* backslash in a raw literal) > > In [59]: print pypandoc.convert(inp, 'latex', format='rst') > ref\{fig:abc\} > > The two results are clearly *not* the same, even though the two inp > /claim/ to be the same... > When I said backslashes are not special in data read from a file, I should also say neither are quotes, or tabs, or anything else. Python just reads them in, and stuffs them into a string object. Newlines are special if you use readline(), but if you use read(), they're not special either (except on MSDOS compatible variants, which use two bytes for newline. Even there, if you read a file in "b" mode, they're not special either. So your code is going to mostly be getting strings from files, or from calculations, and these backslashes won't be special. It's only in *testing* that you usually deal with this literal stuff. Or in places where the data is fixed, and hardcoded in the source. -- DaveA From steve+comp.lang.python at pearwood.info Mon Mar 2 18:32:22 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 03 Mar 2015 10:32:22 +1100 Subject: rst and pypandoc References: <54f458a5$0$13003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <54f4f307$0$12979$c3e8da3$5496439d@news.astraweb.com> alb wrote: > In [39]: print pypandoc.convert(s, 'latex', format='rst') > this is some restructured text. > > what happened to my backslash??? You'll need to read your pypandoc documentation to see what it says about backslashes. > If I try to escape my backslash I get something worse: > > In [40]: f = open('test.txt', 'r') > > In [41]: s = f.read() > > In [42]: print s > this is \\some restructured text. > > > In [43]: print pypandoc.convert(s, 'latex', format='rst') > this is \textbackslash{}some restructured text. > > since a literal backslash gets converted to a literal latex backslash. Why is this a problem? Isn't the ultimate aim to pass it through latex, which will then covert the \textbackslash{} back into a backslash? If not, I have misunderstood something. If not, you could do something like this: s = 'this is %(b)ssome restructured text.' t = pypandoc.convert(s, 'latex', format='rst') assert t == 'this is %(b)ssome restructured text.' print t % {'b': '\\'} taking care to escape any actual percent signs in your text as '%%'. To be clear, what I'm doing here is using Python's % string interpolation to post-process the Latex output: - replace every '%' in your input string with '%%'; - replace every backslash in your input string with '%(b)s'; - convert; - post-process using %. -- Steven From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Mon Mar 2 18:45:31 2015 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Tue, 03 Mar 2015 00:45:31 +0100 Subject: Md5 is different in Windows and Linux In-Reply-To: References: Message-ID: Am 02.03.2015 20:14 schrieb sohcahtoa82 at gmail.com: > On Monday, March 2, 2015 at 12:43:59 AM UTC-8, Sarvagya Pant wrote: >> f = open("somefile.txt") This one is the problem. Under Windows, you have to open the file in binary to avoid that something "bad" happens with it. So just do f = open("somefile.txt", "rb") and you should be fine. > I don't know which is worse, the fact that you're composing your message in HTML, or the fact that you're using Comic Sans as your font. #2 wouldn't be possible without #1... Thomas From sturla.molden at gmail.com Mon Mar 2 19:23:39 2015 From: sturla.molden at gmail.com (Sturla Molden) Date: Tue, 3 Mar 2015 00:23:39 +0000 (UTC) Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] References: <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> Message-ID: <445511321447034146.109961sturla.molden-gmail.com@news.gmane.org> Steven D'Aprano wrote: > Variations in idiom and spelling are a good thing. They open our minds to > new possibilities, remind us that we aren't all the same, and keep life > fresh. I remember the first time I realised that when Indians talk about "a > code" they aren't using "wrong English", they are using a regional > variation. In British and American English, "code" in the programming > sense[2] is a mass or uncountable noun, like air[3], milk, music and > housework. I can assure you that in a veterinary sence, Yersey cows will produce a milk with higher fat content. In a lingustic sence the "a" is not a count -- that would be the word "one" --, it is the indefinite article. Here is the difference: The Enigma machine produced a code that only Alan Turing could break. If I say the Enigma machine produced one code that only Alan Turing could break, it means all the other codes could be broken by someone else. What if I say "this file contains a long Fortran code"? Or what if I say "this file contains one long Fortran code"? There is a subtile difference in meaning here. Sturla From steve+comp.lang.python at pearwood.info Mon Mar 2 20:00:25 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 03 Mar 2015 12:00:25 +1100 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] References: <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> Message-ID: <54f507ab$0$12996$c3e8da3$5496439d@news.astraweb.com> Sturla Molden wrote: > Steven D'Aprano wrote: > >> Variations in idiom and spelling are a good thing. They open our minds to >> new possibilities, remind us that we aren't all the same, and keep life >> fresh. I remember the first time I realised that when Indians talk about >> "a code" they aren't using "wrong English", they are using a regional >> variation. In British and American English, "code" in the programming >> sense[2] is a mass or uncountable noun, like air[3], milk, music and >> housework. > > I can assure you that in a veterinary sence, Yersey cows will produce a > milk with higher fat content. A good example of the complexity and subtlety of English grammar. I don't know enough linguistics to tell you what "a milk" in that sense is called, but it's not the same as "1 milk", "2 milks" etc. I'm not even sure what the purpose of the "a" is, since it reads fine without it. I chalk that up to "English is weird", like the way we sometimes refer to money as a mass noun ("two buckets of money", not "two monies") and other times we treat it as a mass plural noun ("please hand all monies to the bursar", but it would be weird to say "please hand five monies to the bursar"). Oh, and of course since language is complicated and speakers of language are lazy, there are contexts where one does say "two milks" as a short-hand, like we say "two sugars" when we mean "two spoonfuls of sugar" or "serves of sugar". The unit of measure is implied by context. > In a lingustic sence the "a" is not a count -- that would be the word > "one" --, it is the indefinite article. Here is the difference: > > The Enigma machine produced a code that only Alan Turing could break. If I > say the Enigma machine produced one code that only Alan Turing could > break, it means all the other codes could be broken by someone else. No. It means that there is one secret code that Turing, and only Turing, could break, and some unknown number (possibly zero, possibly millions) of codes that he could not break. Whether other people could break these other codes is not stated. Whether you say "a code" or "one code" (or "fifteen codes" for that matter) is irrelevant. There is a weak implication that if Turing cannot break the other codes, nobody else could either. That's not necessarily true in real life, but as a rough rule of thumb, we can reason like this: since there is one code that Turing can break but others cannot, he must be cleverer at breaking secret codes than everyone else. If he is cleverer at breaking codes, then it is unlikely that they could break codes that he cannot. If they could break an Enigma code, so could he. Therefore, if he cannot break them, neither can anyone else. > What if I say "this file contains a long Fortran code"? Or what if I say > "this file contains one long Fortran code"? There is a subtile difference > in meaning here. In British/American/Australian English, you wouldn't say either of those. You would say "a long piece of Fortran code" or "a long example of Fortran code". Or more likely, "a long Fortran program". Program is counted: there is no difficulty in B/A/A English to say "I have written 17 programs". We can substitute "one" for "a" and the meaning remains the same: "Here is a long example of Fortran code." "Here is one long example of Fortran code." In neither case does it imply that there is only one example of Fortran code which is long in the entire world. (This is bringing back memories of when I was, oh, four or so, when I got into a long argument with my teacher that "a hundred" and "one hundred" were different. You counted "ninety-nine, *a* hundred, a hundred and one, a hundred and two, ... a hundred and ninety-nine, *one* hundred, one hundred and one...") -- Steven From seth-p at outlook.com Mon Mar 2 20:01:02 2015 From: seth-p at outlook.com (Seth P) Date: Mon, 2 Mar 2015 17:01:02 -0800 (PST) Subject: tarfile vs zipfile Message-ID: <97542b34-5381-48c2-93bb-755d4ac49369@googlegroups.com> Is there a reason tarfile and zipfile don't use the same method/member names, where it makes sense? Consider the following six methods/members, which I would expect to be the same (with the possible exception of mtime vs date_time, which are of different types). It almost seems like someone went out of their way to make it difficult to use them interchangeably. tarfile zipfile TarFile ZipFile getmember(name) getinfo(name) getmembers() infolist() getnames() namelist() TarInfo ZipInfo name filename mtime date_time size file_size From ben+python at benfinney.id.au Mon Mar 2 20:12:39 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 03 Mar 2015 12:12:39 +1100 Subject: tarfile vs zipfile References: <97542b34-5381-48c2-93bb-755d4ac49369@googlegroups.com> Message-ID: <85h9u228ag.fsf@benfinney.id.au> Seth P writes: > Is there a reason tarfile and zipfile don't use the same method/member > names, where it makes sense? One likely explanation is that the modules's APIs were designed by different people unaware of the work of the other. -- \ ?We have to go forth and crush every world view that doesn't | `\ believe in tolerance and free speech.? ?David Brin | _o__) | Ben Finney From breamoreboy at yahoo.co.uk Mon Mar 2 20:44:40 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 03 Mar 2015 01:44:40 +0000 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] In-Reply-To: <445511321447034146.109961sturla.molden-gmail.com@news.gmane.org> References: <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> <445511321447034146.109961sturla.molden-gmail.com@news.gmane.org> Message-ID: On 03/03/2015 00:23, Sturla Molden wrote: > Steven D'Aprano wrote: > >> Variations in idiom and spelling are a good thing. They open our minds to >> new possibilities, remind us that we aren't all the same, and keep life >> fresh. I remember the first time I realised that when Indians talk about "a >> code" they aren't using "wrong English", they are using a regional >> variation. In British and American English, "code" in the programming >> sense[2] is a mass or uncountable noun, like air[3], milk, music and >> housework. > > I can assure you that in a veterinary sence, Yersey cows will produce a > milk with higher fat content. Yersey? > > In a lingustic sence the "a" is not a count -- that would be the word "one" > --, it is the indefinite article. Here is the difference: > > The Enigma machine produced a code that only Alan Turing could break. If I > say the Enigma machine produced one code that only Alan Turing could break, > it means all the other codes could be broken by someone else. No, it wasn't "a code" because not all the Enigma codes were broken. > > What if I say "this file contains a long Fortran code"? Or what if I say > "this file contains one long Fortran code"? There is a subtile difference > in meaning here. > You might think so but I disagree, in UK English it means one and the same thing, there is so subtle difference at all. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From python at mrabarnett.plus.com Mon Mar 2 21:09:12 2015 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 03 Mar 2015 02:09:12 +0000 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] In-Reply-To: References: <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> <445511321447034146.109961sturla.molden-gmail.com@news.gmane.org> Message-ID: <54F517C8.2010502@mrabarnett.plus.com> On 2015-03-03 01:44, Mark Lawrence wrote: > On 03/03/2015 00:23, Sturla Molden wrote: >> Steven D'Aprano wrote: >> >>> Variations in idiom and spelling are a good thing. They open our minds to >>> new possibilities, remind us that we aren't all the same, and keep life >>> fresh. I remember the first time I realised that when Indians talk about "a >>> code" they aren't using "wrong English", they are using a regional >>> variation. In British and American English, "code" in the programming >>> sense[2] is a mass or uncountable noun, like air[3], milk, music and >>> housework. >> >> I can assure you that in a veterinary sence, Yersey cows will produce a >> milk with higher fat content. > > Yersey? > >> >> In a lingustic sence the "a" is not a count -- that would be the word "one" >> --, it is the indefinite article. Here is the difference: >> >> The Enigma machine produced a code that only Alan Turing could break. If I >> say the Enigma machine produced one code that only Alan Turing could break, >> it means all the other codes could be broken by someone else. > > No, it wasn't "a code" because not all the Enigma codes were broken. > >> >> What if I say "this file contains a long Fortran code"? Or what if I say >> "this file contains one long Fortran code"? There is a subtile difference >> in meaning here. >> > > You might think so but I disagree, in UK English it means one and the > same thing, there is so subtle difference at all. > There might be a difference, like that between "this program contains a bug" and "this program contains one bug". From tjreedy at udel.edu Mon Mar 2 21:29:03 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 02 Mar 2015 21:29:03 -0500 Subject: tarfile vs zipfile In-Reply-To: <85h9u228ag.fsf@benfinney.id.au> References: <97542b34-5381-48c2-93bb-755d4ac49369@googlegroups.com> <85h9u228ag.fsf@benfinney.id.au> Message-ID: On 3/2/2015 8:12 PM, Ben Finney wrote: > Seth P writes: > >> Is there a reason tarfile and zipfile don't use the same method/member >> names, where it makes sense? The situation is known to some core developers, but is hard to change now. > One likely explanation is that the modules's APIs were designed by > different people unaware of the work of the other. Plus tartfiles come from unix world, whereas zip was used instead in Windows world. -- Terry Jan Reedy From rustompmody at gmail.com Mon Mar 2 21:33:14 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 2 Mar 2015 18:33:14 -0800 (PST) Subject: Uncanny valley of languages In-Reply-To: References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> Message-ID: On Monday, March 2, 2015 at 4:25:04 PM UTC+5:30, Jonas Wielicki wrote: > I wonder whether this discussion has anything to do with the Uncanny > Valley [1]. > [1]: https://en.wikipedia.org/wiki/Uncanny_valley That's right. And thanks for the reference. Had seen that some time but forgot the name and what/how to search for it From marfig at gmail.com Mon Mar 2 21:51:24 2015 From: marfig at gmail.com (Mario Figueiredo) Date: Tue, 03 Mar 2015 03:51:24 +0100 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> <87twy34dst.fsf@elektro.pacujo.net> Message-ID: <726afahrhnim716av2dnckrsd9n5j5kukj@4ax.com> On Mon, 02 Mar 2015 17:30:42 +0200, Marko Rauhamaa wrote: >Steven D'Aprano : > >> But for Britons to use American English is, in a way, to cease to be >> Britons at all. > >Did Hugh Laurie have to turn in his British passport? The concepts behind an actor performing and a programmer programming are so distinct, I don't think your reply warrants an answer (even though I suspect you would want to draw some cheap analogies). I don't know if you realize who bad your stance looks like from the position of someone who doesn't even use english as a primary development language. You are not telling just Brits they should use your flavored dialect, you are telling everyone else that on top of their efforts to learn the english language, they will have to care about national dialects, if they wish to... how did you put it before?... conform. I'm from a country where we face the same language issues as English. There are many dialects of the Portuguese language. It is spoken officially in 5 continents, it's the second fastest growing language in Europe and it is the fith most spoken language in the world. We tried to solve the problem by officially standardizing the written language between all dialects. There is today an official Portuguese language across all countries that should be a standard for written communication. It is mostly a mixture of the portuguese and brazillian dialects, government-approved by all countries of the CPLP. (As if governments should decide how people speak and write, but whatever). This worked out so well that 10 years later we are still missing formalized plugins for our programs and no one is insterested in doing them. So if I wish to code in standard portuguese (as opossed to pt-PT or pt-BR, for instance), I won't have many options in the way of spell checkers. So good luck to you too trying to impose your en-US flavor of standard english. I'm also wondering how you think your stance works out in community development environments. Namely, how will it look like to everyone else when your next pull request on github includes a project-wide rename of the variables/identifiers analogue, colour and analyse. Or when you let everyone else know how annoyed you are at the Pyjamas development team. Software development bases most of its success in its ability to communicate. Not just ideas, but also code. One of the strengths of Python is, they say, how easy the language communicates its code intentions to a layman. Contrary to what you are thinking, trying to impose your kind of language barriers, stiffles that communication process. By forcing everyone to adapt to a standard dialect you are slowing down the ability of the worldwide community to express their ideas as they have now to learn a written language on top of a programming language, and you are growing the window for errors where before there was none. From rustompmody at gmail.com Mon Mar 2 22:51:31 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 2 Mar 2015 19:51:31 -0800 (PST) Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] In-Reply-To: <726afahrhnim716av2dnckrsd9n5j5kukj@4ax.com> References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> <87twy34dst.fsf@elektro.pacujo.net> <726afahrhnim716av2dnckrsd9n5j5kukj@4ax.com> Message-ID: On Tuesday, March 3, 2015 at 8:21:53 AM UTC+5:30, Mario Figueiredo wrote: > On Mon, 02 Mar 2015 17:30:42 +0200, Marko Rauhamaa wrote: > > >Steven D'Aprano: > > > >> But for Britons to use American English is, in a way, to cease to be > >> Britons at all. > > > >Did Hugh Laurie have to turn in his British passport? > > The concepts behind an actor performing and a programmer programming > are so distinct, I don't think your reply warrants an answer (even > though I suspect you would want to draw some cheap analogies). > > I don't know if you realize who bad your stance looks like from the > position of someone who doesn't even use english as a primary > development language. I dont know what you are saying Mario or even whom you are addressing - Steven or Marko - some seems to apply to one some to the other However... While this exchange is going on here, a friend sent me this: So I stand among you as one who offers a small message of hope, that first, there are always people who dare to seek on the margin of society, who are not dependent on social acceptance, not dependent on social routine, and prefer a kind of free-floating existence under a state of risk. And among these people, if they are faithful to their own calling, to their own vocation, and to their own message from God, communication on the deepest level is possible. And the deepest level of communication is not communication, but communion. It is wordless. It is beyond words, and it is beyond speech, and it is beyond concept. Not that we discover a new unity. We discover an older unity . . . we are already one. But we imagine that we are not. And what we have to recover is our original unity. What we have to be is what we are. Fr. Thomas Merton From ben+python at benfinney.id.au Mon Mar 2 23:10:36 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 03 Mar 2015 15:10:36 +1100 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> <87twy34dst.fsf@elektro.pacujo.net> <726afahrhnim716av2dnckrsd9n5j5kukj@4ax.com> Message-ID: <85d24q201v.fsf@benfinney.id.au> Rustom Mody writes: > And among these people, if they are faithful to their own calling, to > their own vocation, and to their own message from God, communication > on the deepest level is possible. And the deepest level of > communication is not communication, but communion. It is wordless. It > is beyond words, and it is beyond speech, and it is beyond concept. > [? and on and on ?] That's amazing. That sounds so deep and resonant. Like the sound of an empty water tank being thumped with a stick. It's rare to see an empty echoing clamour distilled into a salad of words tossed together with no regard for their meaning, quite as well as that. Thank you. Meanwhile, those of us who actually want to communicate will try harder to have our utterances actually mean something, and communicate clearer than the white noise of false profundity. -- \ ?The deepest sin against the human mind is to believe things | `\ without evidence.? ?Thomas Henry Huxley, _Evolution and | _o__) Ethics_, 1893 | Ben Finney From marfig at gmail.com Mon Mar 2 23:32:15 2015 From: marfig at gmail.com (Mario Figueiredo) Date: Tue, 03 Mar 2015 05:32:15 +0100 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] References: <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> <87twy34dst.fsf@elektro.pacujo.net> <726afahrhnim716av2dnckrsd9n5j5kukj@4ax.com> Message-ID: <21dafa533nrsmktshd35kdbd13ahgj50bf@4ax.com> On Mon, 2 Mar 2015 19:51:31 -0800 (PST), Rustom Mody wrote: > >I dont know what you are saying Mario or even whom you are addressing I was replying directly to Marko. I don't think it is possible to establish a standard dialect for variable names in English or any other language. It doesn't even make sense as long as the code clearly communicates its intent. Any attempts at standardizing written language are just bound to failure due to natural cultural resistances, but also the way the spoken and written language evolve isn't going ever to agree with some official authority. As for your Thomas Merton quote, it didn't resonate with me. First I find it hilarious that a 20th century catholic monk speaks of people of faith as existing at the margin of society and accepting risk, particularly in the deeply conservative American society. That's a laugh right there. But the whole comunion thing, the going through God, and the accepting we are all one, is really not my flavor of morning tea. I'm a bit more down to earth and less heavenly oriented. We are all really different individuals, deeply separated by our own minds and sharing only a similar biology. That we can communicate at all, is rather satisfying. From marko at pacujo.net Mon Mar 2 23:32:47 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 03 Mar 2015 06:32:47 +0200 Subject: Python Worst Practices References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> Message-ID: <87bnka4s5s.fsf@elektro.pacujo.net> Dennis Lee Bieber : >>On 2015-03-02, Dennis Lee Bieber wrote: >>> A pub's a bar; a bar's a gate; a gate's a street > > Not based on some of what I found in York while on TDY... Where the > entries to the old town -- what an American might call a gate -- were all > named bar, and the streets passing through those tended to have > names ending in gate. "Micklegate Bar Museum", for example, where > Micklegate passes through the city wall. Otherside of the old town has > Goodramgate turning into Monksgate as it passes through... Monk Bar. > Walmgate passes through Walmgate Bar That meaning ultimately comes from: 3. (Northern England) A street; now used especially as a combining form to make the name of a street. . That's because the Danes once ruled the place: , . Marko From steve+comp.lang.python at pearwood.info Mon Mar 2 23:49:51 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 03 Mar 2015 15:49:51 +1100 Subject: Python Worst Practices References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> Message-ID: <54f53d72$0$11108$c3e8da3@news.astraweb.com> Jon Ribbens wrote: > On 2015-03-02, Dennis Lee Bieber wrote: >> A pub's a bar; a bar's a gate; a gate's a street > > If each of those is supposed to be English first and then the American > equivalent second, then I'm afraid the first one is misleading and the > other two are just nonsense. Unfortunately not nonsense. A pub (short for public drinking house) is another name for a bar. Yes, they sometimes differ in their connotations ("pubs are decorated in wood, bars in chrome") but essentially they are the same thing. A bar is also a rod of solid material, like a steel bar, and "a barrier or restriction to an action or advance". https://www.google.com.au/search?q=definition%3Abar and of course a gate is also a barrier or restriction. Indeed, we have "tollbar" and "tollgate" as synonyms: tollbar, tollgate - a gate or bar across a toll bridge or toll road which is lifted when the toll is paid http://www.thefreedictionary.com/gate so a bar is a type of gate. And, sure enough, there is an old meaning of "gate" which means "a way, road, street, or path". If you think that's bad, try pronouncing "ghoti" according to standard English rules: "gh" sounds like "f", like in "enough" (enuf). "o" sounds like "i", like in "women" (wimmin). "ti" sounds like "sh", like in "station" (stashun). So "ghoti" sounds like "fish". -- Steven From steve+comp.lang.python at pearwood.info Tue Mar 3 00:18:18 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 03 Mar 2015 16:18:18 +1100 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] References: <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> <445511321447034146.109961sturla.molden-gmail.com@news.gmane.org> Message-ID: <54f5441d$0$12991$c3e8da3$5496439d@news.astraweb.com> MRAB wrote: > There might be a difference, like that between "this program contains a > bug" and "this program contains one bug". Those two sentences mean exactly the same thing in standard American, British and Australian English. Pedants can argue whether "one bug" means *exactly* one bug, not more, or *at least* one bug, but they can make precisely the same arguments about "a bug". -- Steve From jsf80238 at gmail.com Tue Mar 3 00:33:35 2015 From: jsf80238 at gmail.com (Jason Friedman) Date: Mon, 2 Mar 2015 22:33:35 -0700 Subject: Sort list of dictionaries In-Reply-To: References: <946797be-10e6-433b-9411-2db0d5697ac8@googlegroups.com> Message-ID: >> This is what I was trying but LooseVersion() was not sorting version numbers like I thought it would. You will notice that Chrome version "40.0.2214.111" is higher than "40.0.2214.91" but in the end result it's not sorting it that way. > > Because it's a string they're sorted lexicographically, and in that > ordering "40.0.2214.111" is less than "40.0.2214.91". Instead of a > string you should probably use some sort of version info tuple. A > simple tuple of ints may suffice, although you may need to get a > little cleverer if there are ever any version strings that aren't > entirely dotted numeric. Also, Python 3.4 comes with an ipaddress module. >>> import ipaddress >>> address_string_1 = "2.2.3.4" >>> address_string_2 = "10.2.3.4" >>> address_string_2 > address_string_1 False >>> ip_address_1 = ipaddress.ip_address(address_string_1) >>> ip_address_2 = ipaddress.ip_address(address_string_2) >>> ip_address_2 > ip_address_1 True From greg.ewing at canterbury.ac.nz Tue Mar 3 00:40:23 2015 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 03 Mar 2015 18:40:23 +1300 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] In-Reply-To: References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> Message-ID: Chris Angelico wrote: > You want to > use "colour" instead of "color"? Also not a problem, and should be > easy enough for someone to understand who normally spells it the other > way. It's not a matter of failing to understand, it's about having more than one spelling of an identifier around imposing an extra cognitive burden. PEP 8 recommends against abbreviating identifiers because it's hard to remember which abbreviation is being used in any given context. Multiple alternative spellings have a similar effect. -- Greg From marfig at gmail.com Tue Mar 3 00:55:55 2015 From: marfig at gmail.com (Mario Figueiredo) Date: Tue, 03 Mar 2015 06:55:55 +0100 Subject: [Python 3.4.3, pip 6.0.8 ] Error installing Sphinx (on markupsafe install) Message-ID: Anyone else having problems installing Sphinx as of late? It installed perfectly fine for me under windows just a few weeks ago. But currently I get an error when trying to install it: I'm including the full error output. $ pip install -U sphinx --no-cache-dir Collecting sphinx Downloading Sphinx-1.2.3-py3-none-any.whl (1.2MB) 100% |################################| 1.2MB 225kB/s Collecting Pygments>=1.2 (from sphinx) Downloading Pygments-2.0.2-py3-none-any.whl (672kB) 100% |################################| 675kB 197kB/s Collecting Jinja2>=2.3 (from sphinx) Downloading Jinja2-2.7.3.tar.gz (378kB) 100% |################################| 380kB 117kB/s Requirement already up-to-date: docutils>=0.10 in c:\python34\lib\site-packages (from sphinx) Collecting markupsafe (from Jinja2>=2.3->sphinx) Downloading MarkupSafe-0.23.tar.gz Installing collected packages: markupsafe, Jinja2, Pygments, sphinx Running setup.py install for markupsafe building 'markupsafe._speedups' extension Traceback (most recent call last): File "", line 1, in File "C:\Users\Mario\AppData\Local\Temp\pip-build-ahunetv5\markupsafe\setup.py", line 120, in try_building_extension() File "C:\Users\Mario\AppData\Local\Temp\pip-build-ahunetv5\markupsafe\setup.py", line 99, in try_building_extension run_setup(True) File "C:\Users\Mario\AppData\Local\Temp\pip-build-ahunetv5\markupsafe\setup.py", line 93, in run_setup ext_modules=ext_modules, File "C:\Python34\lib\distutils\core.py", line 148, in setup dist.run_commands() File "C:\Python34\lib\distutils\dist.py", line 955, in run_commands self.run_command(cmd) File "C:\Python34\lib\distutils\dist.py", line 974, in run_command cmd_obj.run() File "C:\Python34\lib\site-packages\setuptools\command\install.py", line 61, in run return orig.install.run(self) File "C:\Python34\lib\distutils\command\install.py", line 539, in run self.run_command('build') File "C:\Python34\lib\distutils\cmd.py", line 313, in run_command self.distribution.run_command(command) File "C:\Python34\lib\distutils\dist.py", line 974, in run_command cmd_obj.run() File "C:\Python34\lib\distutils\command\build.py", line 126, in run self.run_command(cmd_name) File "C:\Python34\lib\distutils\cmd.py", line 313, in run_command self.distribution.run_command(command) File "C:\Python34\lib\distutils\dist.py", line 974, in run_command cmd_obj.run() File "C:\Users\Mario\AppData\Local\Temp\pip-build-ahunetv5\markupsafe\setup.py", line 41, in run build_ext.run(self) File "C:\Python34\lib\distutils\command\build_ext.py", line 339, in run self.build_extensions() File "C:\Python34\lib\distutils\command\build_ext.py", line 448, in build_extensions self.build_extension(ext) File "C:\Users\Mario\AppData\Local\Temp\pip-build-ahunetv5\markupsafe\setup.py", line 47, in build_extension build_ext.build_extension(self, ext) File "C:\Python34\lib\distutils\command\build_ext.py", line 503, in build_extension depends=ext.depends) File "C:\Python34\lib\distutils\msvc9compiler.py", line 460, in compile self.initialize() File "C:\Python34\lib\distutils\msvc9compiler.py", line 371, in initialize vc_env = query_vcvarsall(VERSION, plat_spec) File "C:\Python34\lib\site-packages\setuptools\msvc9_support.py", line 52, in query_vcvarsall return unpatched['query_vcvarsall'](version, *args, **kwargs) File "C:\Python34\lib\distutils\msvc9compiler.py", line 287, in query_vcvarsall raise ValueError(str(list(result.keys()))) ValueError: [] Complete output from command C:\Python34\python.exe -c "import setuptools, tokenize;__file__='C:\\Users\\Mario\\AppData\\Local\\Temp\\pip-build-ah unetv5\\markupsafe\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --recor d C:\Users\Mario\AppData\Local\Temp\pip-apsyryv5-record\install-record.txt --single-version-externally-managed --compile: running install running build running build_py creating build creating build\lib.win32-3.4 creating build\lib.win32-3.4\markupsafe copying markupsafe\tests.py -> build\lib.win32-3.4\markupsafe copying markupsafe\_compat.py -> build\lib.win32-3.4\markupsafe copying markupsafe\_constants.py -> build\lib.win32-3.4\markupsafe copying markupsafe\_native.py -> build\lib.win32-3.4\markupsafe copying markupsafe\__init__.py -> build\lib.win32-3.4\markupsafe running egg_info writing MarkupSafe.egg-info\PKG-INFO writing top-level names to MarkupSafe.egg-info\top_level.txt writing dependency_links to MarkupSafe.egg-info\dependency_links.txt warning: manifest_maker: standard file '-c' not found reading manifest file 'MarkupSafe.egg-info\SOURCES.txt' reading manifest template 'MANIFEST.in' writing manifest file 'MarkupSafe.egg-info\SOURCES.txt' copying markupsafe\_speedups.c -> build\lib.win32-3.4\markupsafe running build_ext building 'markupsafe._speedups' extension Traceback (most recent call last): File "", line 1, in File "C:\Users\Mario\AppData\Local\Temp\pip-build-ahunetv5\markupsafe\setup.py", line 120, in try_building_extension() File "C:\Users\Mario\AppData\Local\Temp\pip-build-ahunetv5\markupsafe\setup.py", line 99, in try_building_extension run_setup(True) File "C:\Users\Mario\AppData\Local\Temp\pip-build-ahunetv5\markupsafe\setup.py", line 93, in run_setup ext_modules=ext_modules, File "C:\Python34\lib\distutils\core.py", line 148, in setup dist.run_commands() File "C:\Python34\lib\distutils\dist.py", line 955, in run_commands self.run_command(cmd) File "C:\Python34\lib\distutils\dist.py", line 974, in run_command cmd_obj.run() File "C:\Python34\lib\site-packages\setuptools\command\install.py", line 61, in run return orig.install.run(self) File "C:\Python34\lib\distutils\command\install.py", line 539, in run self.run_command('build') File "C:\Python34\lib\distutils\cmd.py", line 313, in run_command self.distribution.run_command(command) File "C:\Python34\lib\distutils\dist.py", line 974, in run_command cmd_obj.run() File "C:\Python34\lib\distutils\command\build.py", line 126, in run self.run_command(cmd_name) File "C:\Python34\lib\distutils\cmd.py", line 313, in run_command self.distribution.run_command(command) File "C:\Python34\lib\distutils\dist.py", line 974, in run_command cmd_obj.run() File "C:\Users\Mario\AppData\Local\Temp\pip-build-ahunetv5\markupsafe\setup.py", line 41, in run build_ext.run(self) File "C:\Python34\lib\distutils\command\build_ext.py", line 339, in run self.build_extensions() File "C:\Python34\lib\distutils\command\build_ext.py", line 448, in build_extensions self.build_extension(ext) File "C:\Users\Mario\AppData\Local\Temp\pip-build-ahunetv5\markupsafe\setup.py", line 47, in build_extension build_ext.build_extension(self, ext) File "C:\Python34\lib\distutils\command\build_ext.py", line 503, in build_extension depends=ext.depends) File "C:\Python34\lib\distutils\msvc9compiler.py", line 460, in compile self.initialize() File "C:\Python34\lib\distutils\msvc9compiler.py", line 371, in initialize vc_env = query_vcvarsall(VERSION, plat_spec) File "C:\Python34\lib\site-packages\setuptools\msvc9_support.py", line 52, in query_vcvarsall return unpatched['query_vcvarsall'](version, *args, **kwargs) File "C:\Python34\lib\distutils\msvc9compiler.py", line 287, in query_vcvarsall raise ValueError(str(list(result.keys()))) ValueError: [] ---------------------------------------- Command "C:\Python34\python.exe -c "import setuptools, tokenize;__file__='C:\\Users\\Mario\\AppData\\Local\\Temp\\pip-build-ahunetv5\\markupsafe\\ setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record C:\Users\Mario\App Data\Local\Temp\pip-apsyryv5-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\Mario\AppDa ta\Local\Temp\pip-build-ahunetv5\markupsafe From greg.ewing at canterbury.ac.nz Tue Mar 3 01:06:38 2015 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 03 Mar 2015 19:06:38 +1300 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] In-Reply-To: References: <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> Message-ID: Sturla Molden wrote: > I can assure you that in a veterinary sence, Yersey cows will produce a > milk with higher fat content. There, "a milk" is really an abbreviation for "a type of milk". But people who talk about "a code" don't mean "a type of code", they're using it the way we would say "a program" or "a library". > What if I say "this file contains a long Fortran code"? Or what if I say > "this file contains one long Fortran code"? There is a subtile difference > in meaning here. There is, but the number of codes/pieces of code being referenced still equals 1. The difference is more that "this file contains a long Fortran code" suggests the file may contain other things as well, whereas "this file contains one long Fortran code" suggests that's the only thing it contains. Isn't English wonderful? -- Greg From greg.ewing at canterbury.ac.nz Tue Mar 3 01:06:41 2015 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 03 Mar 2015 19:06:41 +1300 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] In-Reply-To: <54f507ab$0$12996$c3e8da3$5496439d@news.astraweb.com> References: <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> <54f507ab$0$12996$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > "please hand all monies to the bursar", I think that's another case of an implied unit, the unit in this case being the money involved in one transaction. > but it would be weird to say "please hand five monies to the > bursar". It would, but I'm not sure I could explain exactly why. :-) >>In a lingustic sence the "a" is not a count -- that would be the word >>"one" --, it is the indefinite article. It still means one of something, though. If there's a difference, it's that it's somewhat more vague. "There's a fly in my soup!" is expressing surprise that there are more than zero flies present. You are referring to the first one you happen to see; there might be others, but they're not relevant. Whereas "There is one fly in my soup!" is being precise about the number of flies. -- Greg From greg.ewing at canterbury.ac.nz Tue Mar 3 01:40:11 2015 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 03 Mar 2015 19:40:11 +1300 Subject: rst and pypandoc In-Reply-To: References: <54f458a5$0$13003$c3e8da3$5496439d@news.astraweb.com> Message-ID: alb wrote: > The result I aim to would be: > > In [BINGO]: print pypandoc.convert(inp, 'latex', format='rst') > \ref{fig:abc} From a cursory reading of the pypandoc docs, it looks like enabling the raw_tex extension in pypandoc will give you what you want. Search for raw_tex on this page: http://johnmacfarlane.net/pandoc/README.html -- Greg From greg.ewing at canterbury.ac.nz Tue Mar 3 01:47:33 2015 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 03 Mar 2015 19:47:33 +1300 Subject: tarfile vs zipfile In-Reply-To: <97542b34-5381-48c2-93bb-755d4ac49369@googlegroups.com> References: <97542b34-5381-48c2-93bb-755d4ac49369@googlegroups.com> Message-ID: Seth P wrote: > Is there a reason tarfile and zipfile don't use the same method/member names, > where it makes sense? There was talk in the python-dev mailing list recently about creating a unified interface to the various archiving modules. You might like to keep an eye on what's happening there. -- Greg From rosuav at gmail.com Tue Mar 3 01:56:42 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 Mar 2015 17:56:42 +1100 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] In-Reply-To: References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 3, 2015 at 4:40 PM, Gregory Ewing wrote: > Chris Angelico wrote: >> >> You want to >> use "colour" instead of "color"? Also not a problem, and should be >> easy enough for someone to understand who normally spells it the other >> way. > > > It's not a matter of failing to understand, it's about > having more than one spelling of an identifier around > imposing an extra cognitive burden. > > PEP 8 recommends against abbreviating identifiers because > it's hard to remember which abbreviation is being used > in any given context. Multiple alternative spellings > have a similar effect. Aye, but that's only an issue if you use more than one. You're most welcome to use "colour" in a project, just be consistent. ChrisA From marko at pacujo.net Tue Mar 3 02:05:26 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 03 Mar 2015 09:05:26 +0200 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87zj7ud0i1.fsf@elektro.pacujo.net> Chris Angelico : > Aye, but that's only an issue if you use more than one. You're most > welcome to use "colour" in a project, just be consistent. Or "Farbe" or "couleur" or "v?ri" or... I *have* seen code like that. Marko From rosuav at gmail.com Tue Mar 3 02:07:04 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 Mar 2015 18:07:04 +1100 Subject: Sort list of dictionaries In-Reply-To: References: <946797be-10e6-433b-9411-2db0d5697ac8@googlegroups.com> Message-ID: On Tue, Mar 3, 2015 at 4:33 PM, Jason Friedman wrote: >>> This is what I was trying but LooseVersion() was not sorting version numbers like I thought it would. You will notice that Chrome version "40.0.2214.111" is higher than "40.0.2214.91" but in the end result it's not sorting it that way. >> >> Because it's a string they're sorted lexicographically, and in that >> ordering "40.0.2214.111" is less than "40.0.2214.91". Instead of a >> string you should probably use some sort of version info tuple. A >> simple tuple of ints may suffice, although you may need to get a >> little cleverer if there are ever any version strings that aren't >> entirely dotted numeric. > > Also, Python 3.4 comes with an ipaddress module. Heh, I think that miiiiiiiight be a bit abusive :) I'm not sure that you want to depend on the version numbers fitting inside the rules for IP addresses, especially given that the example has a component of "2214". The right way to compare version numbers is usually to split them on dots, then treat each part as a separate number. I say "usually" because there are complications like "alpha", "RC", "-git", "+deb7u1", and so on, but if the entire version number consists of digits and dots, then tuple(int(x) for x in version_number.split(".")) will give you a properly-sortable key. BTW, Jason: It's usually courteous to acknowledge who you're quoting. If you look at the top of my post here, you'll see that there's a line saying your name and email address, and the date/time that you made your post; but underneath that is just straight text, because your post didn't extend the same courtesy to the previous posters. When you trim quoted text, do please try to keep at least the first acknowledgement line - the one showing who you're actually quoting. Whether or not you keep additional headers is up to you (sometimes it's easy, but other times it's fiddly), but the first one is your responsibility. Thanks! ChrisA From rosuav at gmail.com Tue Mar 3 02:14:06 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 Mar 2015 18:14:06 +1100 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] In-Reply-To: <87zj7ud0i1.fsf@elektro.pacujo.net> References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> <87zj7ud0i1.fsf@elektro.pacujo.net> Message-ID: On Tue, Mar 3, 2015 at 6:05 PM, Marko Rauhamaa wrote: > Chris Angelico : > >> Aye, but that's only an issue if you use more than one. You're most >> welcome to use "colour" in a project, just be consistent. > > Or "Farbe" or "couleur" or "v?ri" or... > > I *have* seen code like that. And I've seen a number of proposals to build Python with its *keywords* localized. While there is a reasonable limit to this (for instance, I wouldn't expect the disassembly of CPython byte-code to have "STORE_FAST" translated into another language), there's nothing wrong with programmers being able to write their code in their languages. ChrisA From breamoreboy at yahoo.co.uk Tue Mar 3 02:15:19 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 03 Mar 2015 07:15:19 +0000 Subject: [Python 3.4.3, pip 6.0.8 ] Error installing Sphinx (on markupsafe install) In-Reply-To: References: Message-ID: On 03/03/2015 05:55, Mario Figueiredo wrote: > Anyone else having problems installing Sphinx as of late? It installed > perfectly fine for me under windows just a few weeks ago. But > currently I get an error when trying to install it: > > I'm including the full error output. > > $ pip install -U sphinx --no-cache-dir > > Running setup.py install for markupsafe > building 'markupsafe._speedups' extension > File "C:\Python34\lib\distutils\command\build_ext.py", line 339, > in run > self.build_extensions() > File "C:\Python34\lib\distutils\command\build_ext.py", line 448, > in build_extensions > self.build_extension(ext) > File > "C:\Users\Mario\AppData\Local\Temp\pip-build-ahunetv5\markupsafe\setup.py", > line 47, in build_extension > build_ext.build_extension(self, ext) > File "C:\Python34\lib\distutils\command\build_ext.py", line 503, > in build_extension > depends=ext.depends) > File "C:\Python34\lib\distutils\msvc9compiler.py", line 460, in > compile > self.initialize() > File "C:\Python34\lib\distutils\msvc9compiler.py", line 371, in > initialize > vc_env = query_vcvarsall(VERSION, plat_spec) > File > "C:\Python34\lib\site-packages\setuptools\msvc9_support.py", line 52, > in query_vcvarsall > return unpatched['query_vcvarsall'](version, *args, **kwargs) > File "C:\Python34\lib\distutils\msvc9compiler.py", line 287, in > query_vcvarsall > raise ValueError(str(list(result.keys()))) > ValueError: [] The problem is actually with the installation of the markupsafe dependancy. Further the output above tells me that you've not got Visual Studio 2010 installed. Simplest solution is to grab it from here http://www.lfd.uci.edu/~gohlke/pythonlibs/#markupsafe -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Tue Mar 3 02:20:51 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 03 Mar 2015 07:20:51 +0000 Subject: Python Worst Practices In-Reply-To: References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> Message-ID: On 03/03/2015 04:04, Dennis Lee Bieber wrote: > On Mon, 2 Mar 2015 17:12:24 +0000 (UTC), Jon Ribbens > declaimed the following: > >> On 2015-03-02, Dennis Lee Bieber wrote: >>> A pub's a bar; a bar's a gate; a gate's a street >> >> If each of those is supposed to be English first and then the American >> equivalent second, then I'm afraid the first one is misleading and the >> other two are just nonsense. > > Not based on some of what I found in York while on TDY... Where the > entries to the old town -- what an American might call a gate -- were all > named bar, and the streets passing through those tended to have > names ending in gate. "Micklegate Bar Museum", for example, where > Micklegate passes through the city wall. Otherside of the old town has > Goodramgate turning into Monksgate as it passes through... Monk Bar. > Walmgate passes through Walmgate Bar > > > The quote's not even mine -- I encountered it decades ago. > Come to sunny Christchurch, Dorset and you encounter the street/district that is simply "Bargates". -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Tue Mar 3 02:26:04 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 03 Mar 2015 07:26:04 +0000 Subject: tarfile vs zipfile In-Reply-To: References: <97542b34-5381-48c2-93bb-755d4ac49369@googlegroups.com> <85h9u228ag.fsf@benfinney.id.au> Message-ID: On 03/03/2015 02:29, Terry Reedy wrote: > On 3/2/2015 8:12 PM, Ben Finney wrote: >> Seth P writes: >> >>> Is there a reason tarfile and zipfile don't use the same method/member >>> names, where it makes sense? > > The situation is known to some core developers, but is hard to change now. > >> One likely explanation is that the modules's APIs were designed by >> different people unaware of the work of the other. > > Plus tartfiles come from unix world, whereas zip was used instead in > Windows world. > > Is the tart bit the thing that you can eat, a loose woman or something else, such as a typo? :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From steve+comp.lang.python at pearwood.info Tue Mar 3 02:38:04 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 03 Mar 2015 18:38:04 +1100 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> <87zj7ud0i1.fsf@elektro.pacujo.net> Message-ID: <54f564dd$0$13007$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > And I've seen a number of proposals to build Python with its > keywords localized. ChinesePython: http://www.chinesepython.org/english/english.html Teuton: http://www.fiber-space.de/EasyExtend/doc/teuton/teuton.htm -- Steve From steve+comp.lang.python at pearwood.info Tue Mar 3 02:55:08 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 03 Mar 2015 18:55:08 +1100 Subject: Sort list of dictionaries References: Message-ID: <54f568de$0$2877$c3e8da3$76491128@news.astraweb.com> Charles Heizer wrote: > Hello, > I'm new to python and I'm trying to find the right way to solve this issue > I have. > > I'm trying to sort this list by name and then by version numbers. The > problem I'm having is that I can not get the version numbers sorted with > the highest at the top or sorted properly. > > mylist = [{'name': u'com.google.earth', 'version': u'7.1.2.2041'}, > {'name': u'com.google.earth', 'version': u'7.1.2.2019'}, > {'name': u'com.google.Chrome', 'version': u'40.0.2214.93'}, > {'name': u'com.google.Chrome', 'version': u'40.0.2214.91'}, [...] > ] > > sortedlist = sorted(mylist , key=lambda x, y: x['name'] > LooseVersion(elem['version'])), reverse=True) There's a syntax error there. Is there supposed to be a comma between the x['name'] and the LooseVersion function call? Once you've fixed the syntax error, you can then fix the mysterious elem, and the fact that your key function takes too many arguments. The key function should take *one* argument, which in your case is a dict. So: def sort_by_version(d): name = d['name'] version = d['version'] return (name, [int(substr) for substr in version.split('.')]) sortedlist = sorted(mylist, key=sort_by_version) should get you started. It may not quiet do what you want, but you can adjust the sort_by_version function as needed. -- Steve From mal at europython.eu Tue Mar 3 03:34:29 2015 From: mal at europython.eu (M.-A. Lemburg) Date: Tue, 03 Mar 2015 09:34:29 +0100 Subject: EuroPython 2015: We have lift-off Message-ID: <54F57215.6090200@europython.eu> We are pleased to announce the launch of our all new EuroPython 2015 website. Over the last few weeks, we have been very busy setting up the infrastructure, talking to sponsors, getting the logo designed and the site prepared for the launch. So here it is: *** https://ep2015.europython.eu/ *** Many thanks go to our launch sponsors who have signed up early to give us that extra boost in motivation to get the conference and it?s website ramped up in only 6 weeks: Meet our Launch Sponsors ------------------------ * Diputaci?n Foral de Bizkaia * Google * Bilbao Ekintza * UPV/EHU * SkyAtlas * Blue Yonder * Continuum Analytics * Python Anywhere * ScrapingHub * 1000mercis * 2nd quadrant * Yelp * CodeSyntax * Asmatu * Hotel Ercilla * Neurita * Riverbank But that?s not all. We?ve also prepared an extra bonus for you: Early-bird Ticket Sales ----------------------- Later today, at 14:00 CET, we will be starting the early-bird ticket sales. Set your alarms for right after lunch to grab your tickets. We only have 350 early-bird tickets available and experience shows that they will be sold out fast. PS: We?d like to thank our friends at Python Italia for making the EuroPython website code used for 2011-2013 available for us to use. Enjoy, EuroPython 2015 Team http://www.europython-society.org/ From auriocus at gmx.de Tue Mar 3 03:51:04 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Tue, 03 Mar 2015 09:51:04 +0100 Subject: Python Worst Practices In-Reply-To: References: <54f1154c$0$12985$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 28.02.15 um 02:44 schrieb Chris Angelico: > On Sat, Feb 28, 2015 at 12:32 PM, wrote: >> For example, I've seen someone create a Socket class, then created an operator overload that allowed you to "add" a string to your socket to make the socket send the string, with the result being a status code indicating success or an error. >> > > Why not left shift the socket by that string, the result being the > original socket? At least that has precedent... > Are you trying to pick on C++ streams? I could never understand why anybody has problems with an arrow << that means "put into the left thing" instead of "shift the bits to the left". How often do you use bitshift operations in your programs as opposed to output? Ot would be equally silly to complain, that in Python you divide a string by a tuple, and the modulus gives you a formatted string. Christian From sturla.molden at gmail.com Tue Mar 3 04:17:48 2015 From: sturla.molden at gmail.com (Sturla Molden) Date: Tue, 3 Mar 2015 09:17:48 +0000 (UTC) Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] References: <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> <445511321447034146.109961sturla.molden-gmail.com@news.gmane.org> Message-ID: <790020957447067028.468853sturla.molden-gmail.com@news.gmane.org> Mark Lawrence wrote: >> I can assure you that in a veterinary sence, Yersey cows will produce a >> milk with higher fat content. > > Yersey? Eh, Jersey. From greg.ewing at canterbury.ac.nz Tue Mar 3 05:35:13 2015 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 03 Mar 2015 23:35:13 +1300 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] In-Reply-To: References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> <87zj7ud0i1.fsf@elektro.pacujo.net> Message-ID: Chris Angelico wrote: > And I've seen a number of proposals to build Python with its > *keywords* localized. While there is a reasonable limit to this (for > instance, I wouldn't expect the disassembly of CPython byte-code to > have "STORE_FAST" translated into another language), there's nothing > wrong with programmers being able to write their code in their > languages. Just for fun, I used Google Translate to turn a piece of my Python code into French. Some of the results were rather amusing. For example, it turned "mess" (short for "message") into "d?sordre", and "but" (short for "button") into "mais". It got "for", "in", "if", "else" and "return" right, though! # Original code def ask(mess, responses = ["OK", "Cancel"], default = 0, cancel = -1, wrap_width = 60, **kwds): box = Dialog(**kwds) d = box.margin lb = wrapped_label(mess, wrap_width) lb.topleft = (d, d) buts = [] for caption in responses: but = Button(caption, action = lambda x = caption: box.dismiss(x)) buts.append(but) brow = Row(buts, spacing = d, equalize = 'w') lb.width = max(lb.width, brow.width) col = Column([lb, brow], spacing = d, align ='r') col.topleft = (d, d) if default is not None: box.enter_response = responses[default] else: box.enter_response = None if cancel is not None: box.cancel_response = responses[cancel] else: box.cancel_response = None box.add(col) box.shrink_wrap() return box.present() # Translated code demander def (d?sordre, r?ponses = ["OK", "Annuler"], par d?faut = 0, annulent = -1, wrap_width = 60, kwds **): bo?te de dialogue = (** kwds) d = box.margin lb = wrapped_label (d?sordre, wrap_width) lb.topleft = (d, d) BUTS = [] pour la l?gende dans les r?ponses: mais = Bouton (l?gende, action = lambda x = l?gende: box.dismiss (x)) buts.append (mais) Brow = ROW (buts, l'espacement = d, ?galisent = 'W') lb.width = max (lb.width, brow.width) col = Colonne ([lb, le front], l'espacement = d, align = 'r') col.topleft = (d, d) si par d?faut ne est pas None: box.enter_response = r?ponses [d?faut] d'autre: box.enter_response = Aucun si annuler ne est pas None: box.cancel_response = r?ponses [Annuler] d'autre: box.cancel_response = Aucun box.add (col) box.shrink_wrap () retourner box.present () From greg.ewing at canterbury.ac.nz Tue Mar 3 05:39:03 2015 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 03 Mar 2015 23:39:03 +1300 Subject: tarfile vs zipfile In-Reply-To: References: <97542b34-5381-48c2-93bb-755d4ac49369@googlegroups.com> <85h9u228ag.fsf@benfinney.id.au> Message-ID: Mark Lawrence wrote: > On 03/03/2015 02:29, Terry Reedy wrote: > >> Plus tartfiles come from unix world, whereas zip was used instead in >> Windows world. >> > Is the tart bit the thing that you can eat, a loose woman or something > else, such as a typo? :) Tartfiles would be what you get from xxx sites, no? -- Greg From rustompmody at gmail.com Tue Mar 3 06:00:30 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 3 Mar 2015 03:00:30 -0800 (PST) Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] In-Reply-To: <21dafa533nrsmktshd35kdbd13ahgj50bf@4ax.com> References: <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> <87twy34dst.fsf@elektro.pacujo.net> <726afahrhnim716av2dnckrsd9n5j5kukj@4ax.com> <21dafa533nrsmktshd35kdbd13ahgj50bf@4ax.com> Message-ID: On Tuesday, March 3, 2015 at 10:02:30 AM UTC+5:30, Mario Figueiredo wrote: > On Mon, 2 Mar 2015 19:51:31 -0800 (PST), Rustom Mody wrote: > > > >I dont know what you are saying Mario or even whom you are addressing > > I was replying directly to Marko. I don't think it is possible to > establish a standard dialect for variable names in English or any > other language. Eh? There was some such suggestion?? All that I saw was suggestions like this: [Of course I may have missed some] Marko: | (Spelling deviations are actually minor nuisances. A bigger problem is | when a Brit thinks they can use their home accent in international | contexts.) > It doesn't even make sense as long as the code clearly > communicates its intent. Any attempts at standardizing written > language are just bound to failure due to natural cultural > resistances, but also the way the spoken and written language evolve > isn't going ever to agree with some official authority. > > As for your Thomas Merton quote, it didn't resonate with me. First I > find it hilarious that a 20th century catholic monk speaks of people > of faith as existing at the margin of society and accepting risk, > particularly in the deeply conservative American society. That's a > laugh right there. I dont understand what you are saying. Lets say you replace 'conservative' by something more definitively pejorative eg fundamentalist, backward etc Now replace 'American society' by 'Nazi Germany' Do you believe that everyone who was not a Jew was a Nazi? In actual fact I believe you would have found people on all points of the spectrum between "Full cooperation with the machinery" to "active resistance to the point of endangering one's existence" Likewise it seems only fair to acknowledge that Fr Thomas Merton seems to have had all sorts of difficulties trying to follow his vocation and that quote more or less reflects his difficulties. Of course you are welcome to your own individual allergic reactions. Some people need to be hospitalized if they eat one peanut. Likewise some people seem to stop hearing anything if some religion-associating word like 'God' appears. Generalizing from specific instance to paradigm is always a dicey business. Now personally I suffer no allergy to the word 'God' but in my younger days I suffered violent reaction to 'pop music' in particular the distortion of an electric guitar. Many years older and (hopefully!) wiser I find that the electric guitar captures Beethoven better than the official version see the two youtube clips at beginning of http://blog.languager.org/2011/02/cs-education-is-fat-and-weak-3.html A similar situation obtains (I believe!) vis-a-vis generic 'Christian priest' vs specific instance Thomas Merton From rosuav at gmail.com Tue Mar 3 06:12:09 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 Mar 2015 22:12:09 +1100 Subject: Python Worst Practices In-Reply-To: References: <54f1154c$0$12985$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 3, 2015 at 7:51 PM, Christian Gollwitzer wrote: > Am 28.02.15 um 02:44 schrieb Chris Angelico: >> On Sat, Feb 28, 2015 at 12:32 PM, wrote: >>> For example, I've seen someone create a Socket class, then created an operator overload that allowed you to "add" a string to your socket to make the socket send the string, with the result being a status code indicating success or an error. >>> >> >> Why not left shift the socket by that string, the result being the >> original socket? At least that has precedent... >> > > Are you trying to pick on C++ streams? I could never understand why > anybody has problems with an arrow << that means "put into the left > thing" instead of "shift the bits to the left". How often do you use > bitshift operations in your programs as opposed to output? Ot would be > equally silly to complain, that in Python you divide a string by a > tuple, and the modulus gives you a formatted string. I am, yes. Both your examples seem lovely and simple when you first look at them, but operator precedence means you get weird edge cases. In the case of string modulo, there's another edge case as a consequence of the operator being, by necessity, binary. A function call makes better sense here. Operator overloading in each case here is "cute", not optimally practical. ChrisA From jon+usenet at unequivocal.co.uk Tue Mar 3 06:15:04 2015 From: jon+usenet at unequivocal.co.uk (Jon Ribbens) Date: Tue, 3 Mar 2015 11:15:04 +0000 (UTC) Subject: Python Worst Practices References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> Message-ID: On 2015-03-03, Dennis Lee Bieber wrote: > On Mon, 2 Mar 2015 17:12:24 +0000 (UTC), Jon Ribbens > declaimed the following: >>On 2015-03-02, Dennis Lee Bieber wrote: >>> A pub's a bar; a bar's a gate; a gate's a street >> >>If each of those is supposed to be English first and then the American >>equivalent second, then I'm afraid the first one is misleading and the >>other two are just nonsense. > > Not based on some of what I found in York while on TDY... Where the > entries to the old town -- what an American might call a gate -- were all > named bar, and the streets passing through those tended to have > names ending in gate. "Micklegate Bar Museum", for example, where > Micklegate passes through the city wall. That's a proper noun. It's derived from *Old Norse*, which hasn't been spoken by anyone since about the year 1,300. It has nothing at all to do with English, let alone English as it is spoken by anyone alive today. From jon+usenet at unequivocal.co.uk Tue Mar 3 06:31:53 2015 From: jon+usenet at unequivocal.co.uk (Jon Ribbens) Date: Tue, 3 Mar 2015 11:31:53 +0000 (UTC) Subject: Python Worst Practices References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <54f53d72$0$11108$c3e8da3@news.astraweb.com> Message-ID: On 2015-03-03, Steven D'Aprano wrote: > Jon Ribbens wrote: >> On 2015-03-02, Dennis Lee Bieber wrote: >>> A pub's a bar; a bar's a gate; a gate's a street >> >> If each of those is supposed to be English first and then the American >> equivalent second, then I'm afraid the first one is misleading and the >> other two are just nonsense. > > Unfortunately not nonsense. Sorry, it is nonsense. Trust me, I've lived here all my life. > A pub (short for public drinking house) is another name for a bar. Yes, they > sometimes differ in their connotations ("pubs are decorated in wood, bars in > chrome") but essentially they are the same thing. No - as I said, it's highly misleading to pretend they are synonyms. > A bar is also a rod of solid material, like a steel bar, and "a barrier or > restriction to an action or advance". Yes. Your argument is similar to "a cat is a four-legged furry animal, a dog is a four-legged furry animal, therefore cats are dogs". If you saw a gate blocking (or even "barring") your path, no English person would say "that bar is in the way". > And, sure enough, there is an old meaning of "gate" which means "a > way, road, street, or path". Well, yes. Emphasis on "old". But it turns out that English as it was used historically before the USA even existed is not the same as English as it is used today in the UK, any more that it is the same as English in the USA today. From alister.nospam.ware at ntlworld.com Tue Mar 3 06:40:57 2015 From: alister.nospam.ware at ntlworld.com (alister) Date: Tue, 3 Mar 2015 11:40:57 +0000 (UTC) Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] References: <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> <87twy34dst.fsf@elektro.pacujo.net> <726afahrhnim716av2dnckrsd9n5j5kukj@4ax.com> <21dafa533nrsmktshd35kdbd13ahgj50bf@4ax.com> Message-ID: On Tue, 03 Mar 2015 03:00:30 -0800, Rustom Mody wrote: > I dont understand what you are saying. > Lets say you replace 'conservative' by something more definitively > pejorative eg fundamentalist, backward etc Now replace 'American > society' by 'Nazi Germany' finally we can call Godwins on this thread -- You may be sure that when a man begins to call himself a "realist," he is preparing to do something he is secretly ashamed of doing. -- Sydney Harris From mal at europython.eu Tue Mar 3 08:41:22 2015 From: mal at europython.eu (M.-A. Lemburg) Date: Tue, 03 Mar 2015 14:41:22 +0100 Subject: EuroPython 2015: We've opened the flood gates :-) Message-ID: <54F5BA02.4020106@europython.eu> As announced earlier today, we have opened the early-bird ticket sales for EuroPython 2015. You can save up to 25% on the early-bird tickets, so book your tickets while they last: *** https://ep2015.europython.eu/en/registration/ *** We only have 350 early-bird tickets available and expect them to be sold out in just a few days. Enjoy, -- EuroPython 2015 Team http://www.europython-society.org/ From lynto28 at gmail.com Tue Mar 3 09:06:47 2015 From: lynto28 at gmail.com (Didymus) Date: Tue, 3 Mar 2015 06:06:47 -0800 (PST) Subject: Logging custom level not print module properly?? Message-ID: <6676f6f6-94bf-4ed9-9a09-46beb4317e6c@googlegroups.com> Hi, I have setup custom levels (with the help of the Python community) for logging. I set this up as a class in a module "log.py" below. The problem I'm seeing is that no matter the file the the logging is happening in it always prints the module as "log", I've rcreated the testcase below: % python run.py [PWARNING log 22] Warning Message. [INFO run 8] Message. The log.py: """ Logging Module """ import common import logging # Custom PWARNING_NUM = 34 # Performance Warning... logging.addLevelName(PWARNING_NUM, "PWARNING") def pwarning(self, message, *args, **kws): """ Performance Warning Message Level """ # Yes, logger takes its '*args' as 'args'. self.log(PWARNING_NUM, message, *args, **kws) logging.Logger.pwarning = pwarning class SetLogging(): # Variables. fileHandler = None consoleHandler = None def __init__(self): """ Set Verbosity Level, set which ever is True...""" common.verbosity = 'INFO' self.setLogHandlers() def setverbosity(self, verbosity_level): """ Set what the logging level should be """ level = logging.getLevelName(verbosity_level) common.rootLogger.setLevel(level) def setLogHandlers(self): """ Set logging file and level. """ logFormatter = logging.Formatter("[%(levelname)s %(module)s %(lineno)d] %(message)s") common.rootLogger = logging.getLogger() # Add a File to log too... fileHandler = logging.FileHandler(common.LOG_FILENAME) fileHandler.setFormatter(logFormatter) common.rootLogger.addHandler(fileHandler) # Put the message on the Console as well.. consoleHandler = logging.StreamHandler() consoleHandler.setFormatter(logFormatter) common.rootLogger.addHandler(consoleHandler) self.setverbosity(common.verbosity) # Main if __name__ == '__main__': log = SetLogging() log.setLogHandlers() log.setverbosity('PMESSAGE') run.py: import common import log # common.LOG_FILENAME = '/tmp/runtest.log' # Set the File the log will write too based on the name and time stamp. log = log.SetLogging() # Set logging level and handlers. common.rootLogger.pwarning('Warning Message.') common.rootLogger.info('Message.') common.py: # Logging Verbosity and File. # rootLogger = None # Logger Handle, Undefined at the moment. LOG_FILENAME = '/tmp/python.log' # Log File full pathname. Not sure why the "def pwarning" isnt; picking up the module that the call is happening in correctly, but the standard INFO is. Thanks for any help in advanced. -Tom From antoon.pardon at rece.vub.ac.be Tue Mar 3 09:40:41 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 03 Mar 2015 15:40:41 +0100 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] In-Reply-To: <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> References: <87ioem8ftg.fsf@elektro.pacujo.net> <54f2c9c6$0$12991$c3e8da3$5496439d@news.astraweb.com> <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> Message-ID: <54F5C7E9.40908@rece.vub.ac.be> Op 02-03-15 om 15:39 schreef Steven D'Aprano: > Marko Rauhamaa wrote: > >> alister : >> >>> or as another analogy why don't you (Marco) try telling a Barber in >>> Seville that he should be speaking Latin Spanish not that strange >>> variation he uses? >> If the barber conference language were Latin, and some Spaniard insisted >> on speaking Western Andalusian, I sure would consider that obnoxious. >> >> Similarly, I've heard some Finnish representatives in the Nordic Council >> complain how the Danish insist on speaking Danish. The official language >> there is Swedish. > I'm reminded of the British Prime Minister David Lloyd George, who > apparently made a habit of answering difficult or embarrassing questions in > parliament in his native Welsh. > > >>> I suspect the reaction you get will be far more severe than the one >>> you are getting from we English (& Brits) >> I don't understand your reaction. The rest of us are willing to walk a >> mile (say, Finnish -----> American English) and you are up in arms about >> having to shift a foot (say, Scouse -> American English). > "Not one inch!" > > Sometimes the small differences are more important than the big. Your > Finnishness is not threatened by learning English, any more than Mark's > Britishness would be threatened by him learning Russian. > > [Now there's a thought... with the historical relationships between Finland > and Russia, I wonder whether Finns would be as blas? about using a foreign > language if it were Russian rather than English? But I digress.] > > Whereas the comparatively small differences between British and American > English are all the more important because they distinguish the two. Nobody > is ever going to mistake Finland and the Finish people for Americans, even > if you learn to speak American English. But for Britons to use American > English is, in a way, to cease to be Britons at all. Nonsense. Why should it be impossible for a Finish person speaking fluent American English do be mistaken for an American. This is mostly about personal attitude --- which can be culturally enforced. I regularly meet people from the Netherlands who came to live in Northern Belgium. Some have an attitude like you describe above and others don't and don't mind adapting their language without feeling any less a Dutchman. Then we have people whose native tongue is French, who seem to think they will somehow lose their French speaking identity by learning Dutch. > Personally, I think that monocultures are harmful and ought to be resisted, > whether than monoculture is one-species-of-wheat, one-operating-system, or > one-language. The English-speaking world is threatened by American cultural > and linguistic monoculture[1], and that's a bad thing. The same applies to > the rest of the world, but to a much lesser extent. Having a rich and > varied cultural ecosystem is important, and regional differences in > language and culture are an essential part in that. People adapting their language in order to be better understood by their audience doesn't make a mono culture. This is just one newsgroup/mailing list. Talking about mono culture because of adapting to one specific variant of a particular language here makes no more sense than talking about mono culture because the subject here is python and not other computer languages. -- Antoon Pardon From jsf80238 at gmail.com Tue Mar 3 09:45:20 2015 From: jsf80238 at gmail.com (Jason Friedman) Date: Tue, 3 Mar 2015 07:45:20 -0700 Subject: Sort list of dictionaries In-Reply-To: References: <946797be-10e6-433b-9411-2db0d5697ac8@googlegroups.com> Message-ID: On Tue, Mar 3, 2015 at 12:07 AM, Chris Angelico wrote: > Heh, I think that miiiiiiiight be a bit abusive :) I'm not sure that > you want to depend on the version numbers fitting inside the rules for > IP addresses, especially given that the example has a component of > "2214". > Indeed, I was mistaken >>> ipaddress.ip_address("1000.1.2.3") Traceback (most recent call last): File "", line 1, in File "/opt/python/lib/python3.4/ipaddress.py", line 54, in ip_address address) ValueError: '1000.1.2.3' does not appear to be an IPv4 or IPv6 address I was overcome by how neat I think the ipaddress module is. I have not used it yet, but I expect someday I will, and I appreciate how Python makes my job easier by doing much of my work for me. A colleague yesterday asked how I guaranteed my temporary file names would not collide with another file, and my answer was I don't have to worry about it, someone else figured it out with the tempfile module. From rosuav at gmail.com Tue Mar 3 09:50:49 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 Mar 2015 01:50:49 +1100 Subject: Sort list of dictionaries In-Reply-To: References: <946797be-10e6-433b-9411-2db0d5697ac8@googlegroups.com> Message-ID: On Wed, Mar 4, 2015 at 1:45 AM, Jason Friedman wrote: > I appreciate > how Python makes my job easier by doing much of my work for me. A > colleague yesterday asked how I guaranteed my temporary file names > would not collide with another file, and my answer was I don't have to > worry about it, someone else figured it out with the tempfile module. Though in that case, Python isn't actually the one doing most of the work - the tempfile module handballs responsibility to the lower-level functions. But yes, there's HEAPS that you don't have to worry about, because it's Someone Else's Problem. ChrisA From __peter__ at web.de Tue Mar 3 10:01:28 2015 From: __peter__ at web.de (Peter Otten) Date: Tue, 03 Mar 2015 16:01:28 +0100 Subject: Logging custom level not print module properly?? References: <6676f6f6-94bf-4ed9-9a09-46beb4317e6c@googlegroups.com> Message-ID: Didymus wrote: > Hi, > > I have setup custom levels (with the help of the Python community) for > logging. I set this up as a class in a module "log.py" below. The problem > I'm seeing is that no matter the file the the logging is happening in it > always prints the module as "log", I've rcreated the testcase below: > > % python run.py > [PWARNING log 22] Warning Message. > [INFO run 8] Message. > > The log.py: > > """ Logging Module """ > import common > import logging > > # Custom > PWARNING_NUM = 34 > > # Performance Warning... > logging.addLevelName(PWARNING_NUM, "PWARNING") > > def pwarning(self, message, *args, **kws): > """ Performance Warning Message Level """ > # Yes, logger takes its '*args' as 'args'. > self.log(PWARNING_NUM, message, *args, **kws) > > logging.Logger.pwarning = pwarning > > class SetLogging(): > # Variables. > fileHandler = None > consoleHandler = None > > def __init__(self): > """ Set Verbosity Level, set which ever is True...""" > common.verbosity = 'INFO' > self.setLogHandlers() > > def setverbosity(self, verbosity_level): > """ Set what the logging level should be """ > level = logging.getLevelName(verbosity_level) > common.rootLogger.setLevel(level) > > def setLogHandlers(self): > """ Set logging file and level. """ > logFormatter = logging.Formatter("[%(levelname)s %(module)s > %(lineno)d] %(message)s") common.rootLogger = logging.getLogger() > # Add a File to log too... > fileHandler = logging.FileHandler(common.LOG_FILENAME) > fileHandler.setFormatter(logFormatter) > common.rootLogger.addHandler(fileHandler) > # Put the message on the Console as well.. > consoleHandler = logging.StreamHandler() > consoleHandler.setFormatter(logFormatter) > common.rootLogger.addHandler(consoleHandler) > self.setverbosity(common.verbosity) > > # Main > if __name__ == '__main__': > log = SetLogging() > log.setLogHandlers() > log.setverbosity('PMESSAGE') > > > run.py: > import common > import log > # > common.LOG_FILENAME = '/tmp/runtest.log' # Set the File the log > will write too based on the name and time stamp. > log = log.SetLogging() > # Set logging level and handlers. > > common.rootLogger.pwarning('Warning Message.') > common.rootLogger.info('Message.') > > > common.py: > # Logging Verbosity and File. > # > rootLogger = None > # Logger Handle, Undefined at the moment. > LOG_FILENAME = '/tmp/python.log' > # Log File full pathname. > > > Not sure why the "def pwarning" isnt; picking up the module that the call > is happening in correctly, but the standard INFO is. Thanks for any help > in advanced. The findCaller() method determines that your pwarning() is not part of the logging machinery and thus presents the file containing the pwarning() function as the origin of the logging event. I see no easy and clean way to inform findCaller() to go up one more level (the unittest package checks for a global flag for that purpose), but that may be because I didn't look hard enough. If your usecase for custom levels is compelling I suggest that you override/replace findCaller() rather than go for the following hack... exec compile(''' # Custom PWARNING_NUM = 34 # Performance Warning... addLevelName(PWARNING_NUM, "PWARNING") def pwarning(self, message, *args, **kws): """ Performance Warning Message Level """ # Yes, logger takes its '*args' as 'args'. self.log(PWARNING_NUM, message, *args, **kws) Logger.pwarning = pwarning ''', logging.__file__.rstrip("co"), "exec") in vars(logging) ...which pretends that pwarning() is part of the logging/__init__.py module. From lynto28 at gmail.com Tue Mar 3 10:11:57 2015 From: lynto28 at gmail.com (Didymus) Date: Tue, 3 Mar 2015 07:11:57 -0800 (PST) Subject: Logging custom level not print module properly?? In-Reply-To: References: <6676f6f6-94bf-4ed9-9a09-46beb4317e6c@googlegroups.com> Message-ID: On Tuesday, March 3, 2015 at 10:02:02 AM UTC-5, Peter Otten wrote: > Didymus wrote: > > > Hi, > > > > I have setup custom levels (with the help of the Python community) for > > logging. I set this up as a class in a module "log.py" below. The problem > > I'm seeing is that no matter the file the the logging is happening in it > > always prints the module as "log", I've rcreated the testcase below: > > > > % python run.py > > [PWARNING log 22] Warning Message. > > [INFO run 8] Message. > > > > The log.py: > > > > """ Logging Module """ > > import common > > import logging > > > > # Custom > > PWARNING_NUM = 34 > > > > # Performance Warning... > > logging.addLevelName(PWARNING_NUM, "PWARNING") > > > > def pwarning(self, message, *args, **kws): > > """ Performance Warning Message Level """ > > # Yes, logger takes its '*args' as 'args'. > > self.log(PWARNING_NUM, message, *args, **kws) > > > > logging.Logger.pwarning = pwarning > > > > class SetLogging(): > > # Variables. > > fileHandler = None > > consoleHandler = None > > > > def __init__(self): > > """ Set Verbosity Level, set which ever is True...""" > > common.verbosity = 'INFO' > > self.setLogHandlers() > > > > def setverbosity(self, verbosity_level): > > """ Set what the logging level should be """ > > level = logging.getLevelName(verbosity_level) > > common.rootLogger.setLevel(level) > > > > def setLogHandlers(self): > > """ Set logging file and level. """ > > logFormatter = logging.Formatter("[%(levelname)s %(module)s > > %(lineno)d] %(message)s") common.rootLogger = logging.getLogger() > > # Add a File to log too... > > fileHandler = logging.FileHandler(common.LOG_FILENAME) > > fileHandler.setFormatter(logFormatter) > > common.rootLogger.addHandler(fileHandler) > > # Put the message on the Console as well.. > > consoleHandler = logging.StreamHandler() > > consoleHandler.setFormatter(logFormatter) > > common.rootLogger.addHandler(consoleHandler) > > self.setverbosity(common.verbosity) > > > > # Main > > if __name__ == '__main__': > > log = SetLogging() > > log.setLogHandlers() > > log.setverbosity('PMESSAGE') > > > > > > run.py: > > import common > > import log > > # > > common.LOG_FILENAME = '/tmp/runtest.log' # Set the File the log > > will write too based on the name and time stamp. > > log = log.SetLogging() > > # Set logging level and handlers. > > > > common.rootLogger.pwarning('Warning Message.') > > common.rootLogger.info('Message.') > > > > > > common.py: > > # Logging Verbosity and File. > > # > > rootLogger = None > > # Logger Handle, Undefined at the moment. > > LOG_FILENAME = '/tmp/python.log' > > # Log File full pathname. > > > > > > Not sure why the "def pwarning" isnt; picking up the module that the call > > is happening in correctly, but the standard INFO is. Thanks for any help > > in advanced. > > The findCaller() method determines that your pwarning() is not part of the > logging machinery and thus presents the file containing the pwarning() > function as the origin of the logging event. > > I see no easy and clean way to inform findCaller() to go up one more level > (the unittest package checks for a global flag for that purpose), but that > may be because I didn't look hard enough. > > If your usecase for custom levels is compelling I suggest that you > override/replace findCaller() rather than go for the following hack... > > exec compile(''' > # Custom > PWARNING_NUM = 34 > > # Performance Warning... > addLevelName(PWARNING_NUM, "PWARNING") > > def pwarning(self, message, *args, **kws): > """ Performance Warning Message Level """ > # Yes, logger takes its '*args' as 'args'. > self.log(PWARNING_NUM, message, *args, **kws) > > Logger.pwarning = pwarning > ''', logging.__file__.rstrip("co"), "exec") in vars(logging) > > ...which pretends that pwarning() is part of the logging/__init__.py module. Thanks! I'll take a look. I did find that if I changed the "self.log" to "self._log" it works correctly but gives me a pylint warning about acccess to a protected member _log.. def pwarning(self, message, *args, **kws): """ Performance Warning Message Level """ # Yes, logger takes its '*args' as 'args'. self._log(PWARNING_NUM, message, args, **kws) Still wondering what the correct Pythonic way to handle this. -Tom From ian.g.kelly at gmail.com Tue Mar 3 10:30:45 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 3 Mar 2015 08:30:45 -0700 Subject: Logging custom level not print module properly?? In-Reply-To: References: <6676f6f6-94bf-4ed9-9a09-46beb4317e6c@googlegroups.com> Message-ID: On Mar 3, 2015 8:16 AM, "Didymus" wrote: > I did find that if I changed the "self.log" to "self._log" it works correctly but gives me a pylint warning about acccess to a protected member _log.. > > def pwarning(self, message, *args, **kws): > """ Performance Warning Message Level """ > # Yes, logger takes its '*args' as 'args'. > self._log(PWARNING_NUM, message, args, **kws) > > Still wondering what the correct Pythonic way to handle this. I believe the common approach is to let each module define and use its own hierarchical logger named after the module, rather than have them all share the root logger. This way the name that is logged is based on which logger was used for logging and doesn't rely on the "module" attribute, which is populated through the vagaries of stack inspection. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ceh329 at gmail.com Tue Mar 3 10:56:39 2015 From: ceh329 at gmail.com (Charles Heizer) Date: Tue, 3 Mar 2015 07:56:39 -0800 (PST) Subject: Sort list of dictionaries In-Reply-To: References: <946797be-10e6-433b-9411-2db0d5697ac8@googlegroups.com> <8ccd65d8-3f1f-41ac-9092-9b0832d2fc49@googlegroups.com> Message-ID: <432a0d61-a8ba-46ca-bc53-318e234fe168@googlegroups.com> On Monday, March 2, 2015 at 11:23:37 AM UTC-8, Peter Otten wrote: > Charles Heizer wrote: > > > Never mind, the light bulb finally went off. :-\ > > > > sortedlist = sorted(mylist , key=lambda elem: "%s %s" % ( elem['name'], > > (".".join([i.zfill(5) for i in elem['version'].split(".")])) ), > > reverse=True) > > This lightbulb will break with version numbers > 99999 ;) > > Here are two alternatives: > > result = sorted( > mylist, > key=lambda elem: (elem['name'], LooseVersion(elem['version'])), > reverse=True) > > result = sorted( > mylist, > key=lambda e: (e["name"], tuple(map(int, e["version"].split(".")))), > reverse=True) > > > Personally, I prefer to not use a lambda: > > def name_version(elem): > return elem['name'], LooseVersion(elem['version']) > > result = sorted(mylist, key=name_version, reverse=True) Peter, thank you. Me being new to Python why don't you prefer to use a lambda? From p.f.moore at gmail.com Tue Mar 3 11:07:21 2015 From: p.f.moore at gmail.com (Paul Moore) Date: Tue, 3 Mar 2015 08:07:21 -0800 (PST) Subject: Reading all buffered bytes without blocking Message-ID: <4ad47d38-bd92-4516-bc60-60fddc9e0666@googlegroups.com> Is it possible to say to a BufferedReader stream "give me all the bytes you have available in the buffer, or do one OS call and give me everything you get back"? The problem is that the "number of bytes" argument to read1() isn't optional, so I can't do available_bytes = fd.read1(). I need this because I want to decode the returned bytes from UTF-8, and I *might* get a character split across the boundary of any arbitrary block size I choose. (I'm happy to ignore the possibility that the *source* did a flush part-way through a character). I don't really want to have to do incremental encoding if I can avoid it - it looks hard... Thanks, Paul From rosuav at gmail.com Tue Mar 3 11:09:01 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 Mar 2015 03:09:01 +1100 Subject: Sort list of dictionaries In-Reply-To: <432a0d61-a8ba-46ca-bc53-318e234fe168@googlegroups.com> References: <946797be-10e6-433b-9411-2db0d5697ac8@googlegroups.com> <8ccd65d8-3f1f-41ac-9092-9b0832d2fc49@googlegroups.com> <432a0d61-a8ba-46ca-bc53-318e234fe168@googlegroups.com> Message-ID: On Wed, Mar 4, 2015 at 2:56 AM, Charles Heizer wrote: >> Personally, I prefer to not use a lambda: >> >> def name_version(elem): >> return elem['name'], LooseVersion(elem['version']) >> >> result = sorted(mylist, key=name_version, reverse=True) > > Peter, thank you. Me being new to Python why don't you prefer to use a lambda? Using lambda is fine if it's really clear what's going on (usually, if it's an extremely simple function), but if your expression goes across multiple lines because of the function parameter, it's usually simpler to break the function out into a separate def statement and then use that. There's ultimately no difference[1] between a lambda function and a def function, apart from the fact that a function created with lambda always has the name "". ChrisA [1] Modulo bugs, eg a weird edge case with lambda and yield; certainly no intentional difference. From p.f.moore at gmail.com Tue Mar 3 11:48:38 2015 From: p.f.moore at gmail.com (Paul Moore) Date: Tue, 3 Mar 2015 08:48:38 -0800 (PST) Subject: Sort list of dictionaries In-Reply-To: References: <946797be-10e6-433b-9411-2db0d5697ac8@googlegroups.com> <8ccd65d8-3f1f-41ac-9092-9b0832d2fc49@googlegroups.com> <432a0d61-a8ba-46ca-bc53-318e234fe168@googlegroups.com> Message-ID: <18d22144-9fce-40a5-9be5-eeec43194394@googlegroups.com> On Tuesday, 3 March 2015 16:09:31 UTC, Chris Angelico wrote: > On Wed, Mar 4, 2015 at 2:56 AM, Charles Heizer wrote: > >> Personally, I prefer to not use a lambda: > >> > >> def name_version(elem): > >> return elem['name'], LooseVersion(elem['version']) > >> > >> result = sorted(mylist, key=name_version, reverse=True) > > > > Peter, thank you. Me being new to Python why don't you prefer to use a lambda? > > Using lambda is fine if it's really clear what's going on (usually, if > it's an extremely simple function), but if your expression goes across > multiple lines because of the function parameter, it's usually simpler > to break the function out into a separate def statement and then use > that. There's ultimately no difference[1] between a lambda function > and a def function, apart from the fact that a function created with > lambda always has the name "". > > ChrisA > > [1] Modulo bugs, eg a weird edge case with lambda and yield; certainly > no intentional difference. The main point is that a def gives your function a name, whereas lambda is unnamed. It sometimes feels harder to have to think of a name for something that seems simple, like your key function. But when you come back to it in a few months, the name is incredibly useful documentation as to what's going on. Paul From __peter__ at web.de Tue Mar 3 12:44:51 2015 From: __peter__ at web.de (Peter Otten) Date: Tue, 03 Mar 2015 18:44:51 +0100 Subject: Sort list of dictionaries References: <946797be-10e6-433b-9411-2db0d5697ac8@googlegroups.com> <8ccd65d8-3f1f-41ac-9092-9b0832d2fc49@googlegroups.com> <432a0d61-a8ba-46ca-bc53-318e234fe168@googlegroups.com> Message-ID: Charles Heizer wrote: > On Monday, March 2, 2015 at 11:23:37 AM UTC-8, Peter Otten wrote: >> Charles Heizer wrote: >> >> > Never mind, the light bulb finally went off. :-\ >> > >> > sortedlist = sorted(mylist , key=lambda elem: "%s %s" % ( elem['name'], >> > (".".join([i.zfill(5) for i in elem['version'].split(".")])) ), >> > reverse=True) >> >> This lightbulb will break with version numbers > 99999 ;) >> >> Here are two alternatives: >> >> result = sorted( >> mylist, >> key=lambda elem: (elem['name'], LooseVersion(elem['version'])), >> reverse=True) >> >> result = sorted( >> mylist, >> key=lambda e: (e["name"], tuple(map(int, e["version"].split(".")))), >> reverse=True) >> >> >> Personally, I prefer to not use a lambda: >> >> def name_version(elem): >> return elem['name'], LooseVersion(elem['version']) >> >> result = sorted(mylist, key=name_version, reverse=True) > > Peter, thank you. Me being new to Python why don't you prefer to use a > lambda? I find def name_version(elem): return elem['name'], LooseVersion(elem['version']) more readable than lambda elem: (elem['name'], LooseVersion(elem['version'])) and I can understand what >> result = sorted(mylist, key=name_version, reverse=True) is supposed to do without grokking the implementation of name_version() first. I can spot a potential bug -- are the names really supposed to occur in reverse order, not just the versions? -- again without a look at the implementation. If I intend to use the script more than once or if I want to rely on the result I can write unit tests for name_version() to increase confidence that it does what I expect. Finally I can add a docstring to make it more discoverable in the interactive interpreter. From rustompmody at gmail.com Tue Mar 3 13:03:52 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 3 Mar 2015 10:03:52 -0800 (PST) Subject: Newbie question about text encoding In-Reply-To: References: <54EC5FA4.6070703@davea.name> <201502241455.t1OEtffT016452@fido.openend.se> <201502241507.t1OF7aUm018883@fido.openend.se> <201502241524.t1OFO09k022270@fido.openend.se> <201502241620.t1OGKf4n002146@fido.openend.se> <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> Message-ID: <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> On Thursday, February 26, 2015 at 10:33:44 PM UTC+5:30, Terry Reedy wrote: > On 2/26/2015 8:24 AM, Chris Angelico wrote: > > On Thu, Feb 26, 2015 at 11:40 PM, Rustom Mody wrote: > >> Wrote something up on why we should stop using ASCII: > >> http://blog.languager.org/2015/02/universal-unicode.html > > I think that the main point of the post, that many Unicode chars are > truly planetary rather than just national/regional, is excellent. > You should add emoticons, but not call them or the above 'gibberish'. > I think that this part of your post is more 'unprofessional' than the > character blocks. It is very jarring and seems contrary to your main point. Ok Done References to gibberish removed from http://blog.languager.org/2015/02/universal-unicode.html What I was trying to say expanded here http://blog.languager.org/2015/03/whimsical-unicode.html [Hope the word 'whimsical' is less jarring and more accurate than 'gibberish'] From wxjmfauth at gmail.com Tue Mar 3 13:36:55 2015 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Tue, 3 Mar 2015 10:36:55 -0800 (PST) Subject: Newbie question about text encoding In-Reply-To: <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> References: <54EC5FA4.6070703@davea.name> <201502241455.t1OEtffT016452@fido.openend.se> <201502241507.t1OF7aUm018883@fido.openend.se> <201502241524.t1OFO09k022270@fido.openend.se> <201502241620.t1OGKf4n002146@fido.openend.se> <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> Message-ID: <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> Le mardi 3 mars 2015 19:04:06 UTC+1, Rustom Mody a ?crit?: > On Thursday, February 26, 2015 at 10:33:44 PM UTC+5:30, Terry Reedy wrote: > > On 2/26/2015 8:24 AM, Chris Angelico wrote: > > > On Thu, Feb 26, 2015 at 11:40 PM, Rustom Mody wrote: > > >> Wrote something up on why we should stop using ASCII: > > >> http://blog.languager.org/2015/02/universal-unicode.html > > > > I think that the main point of the post, that many Unicode chars are > > truly planetary rather than just national/regional, is excellent. > > > > > You should add emoticons, but not call them or the above 'gibberish'. > > I think that this part of your post is more 'unprofessional' than the > > character blocks. It is very jarring and seems contrary to your main point. > > Ok Done > > References to gibberish removed from > http://blog.languager.org/2015/02/universal-unicode.html > > What I was trying to say expanded here > http://blog.languager.org/2015/03/whimsical-unicode.html > [Hope the word 'whimsical' is less jarring and more accurate than 'gibberish'] ======== Emoji and Dingbats are now part of Unicode. They should be considered as well as a "1" or a "a" or a "mathematical alpha". So, there is nothing special to say about them. jmf From ci-r-upocone at gmx.com Tue Mar 3 13:40:31 2015 From: ci-r-upocone at gmx.com (MEMOCHE TRE) Date: Tue, 3 Mar 2015 10:40:31 -0800 (PST) Subject: -- redacted -- Message-ID: -- redacted -- From rosuav at gmail.com Tue Mar 3 13:43:53 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 Mar 2015 05:43:53 +1100 Subject: Newbie question about text encoding In-Reply-To: <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> References: <54EC5FA4.6070703@davea.name> <201502241455.t1OEtffT016452@fido.openend.se> <201502241507.t1OF7aUm018883@fido.openend.se> <201502241524.t1OFO09k022270@fido.openend.se> <201502241620.t1OGKf4n002146@fido.openend.se> <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> Message-ID: On Wed, Mar 4, 2015 at 5:03 AM, Rustom Mody wrote: > What I was trying to say expanded here > http://blog.languager.org/2015/03/whimsical-unicode.html > [Hope the word 'whimsical' is less jarring and more accurate than 'gibberish'] Re footnote #4: ? is a single character for compatibility reasons. ???? doesn't need to be a single character, because there are countably infinite vulgar fractions and only 0x110000 Unicode characters. ChrisA From megliomortoche at yahoo.com Tue Mar 3 13:55:34 2015 From: megliomortoche at yahoo.com (Dieffe Ventitre) Date: Tue, 3 Mar 2015 10:55:34 -0800 (PST) Subject: -- redacted -- In-Reply-To: <4f5ceab4-d175-4b96-829b-8c8fab7f77f0@googlegroups.com> References: <4f5ceab4-d175-4b96-829b-8c8fab7f77f0@googlegroups.com> Message-ID: -- redacted -- From storchaka at gmail.com Tue Mar 3 14:28:24 2015 From: storchaka at gmail.com (Serhiy Storchaka) Date: Tue, 03 Mar 2015 21:28:24 +0200 Subject: Reading all buffered bytes without blocking In-Reply-To: <4ad47d38-bd92-4516-bc60-60fddc9e0666@googlegroups.com> References: <4ad47d38-bd92-4516-bc60-60fddc9e0666@googlegroups.com> Message-ID: On 03.03.15 18:07, Paul Moore wrote: > Is it possible to say to a BufferedReader stream "give me all the bytes you have available in the buffer, or do one OS call and give me everything you get back"? The problem is that the "number of bytes" argument to read1() isn't optional, so I can't do available_bytes = fd.read1(). Just specify large size. From al.basili at gmail.com Tue Mar 3 15:35:43 2015 From: al.basili at gmail.com (alb) Date: 3 Mar 2015 20:35:43 GMT Subject: rst and pypandoc References: <54f458a5$0$13003$c3e8da3$5496439d@news.astraweb.com> <54f4f307$0$12979$c3e8da3$5496439d@news.astraweb.com> Message-ID: Hi Steven, Steven D'Aprano wrote: [] >> In [43]: print pypandoc.convert(s, 'latex', format='rst') >> this is \textbackslash{}some restructured text. >> >> since a literal backslash gets converted to a literal latex backslash. > > Why is this a problem? Isn't the ultimate aim to pass it through latex, > which will then covert the \textbackslash{} back into a backslash? If not, > I have misunderstood something. \textbackslash{} is a latex command to typeset a backslash into the text. This is not what I need. I need to have a string of the form "\some" (actually we are talking about \ref or \hyperref commands). > If not, you could do something like this: > > s = 'this is %(b)ssome restructured text.' > t = pypandoc.convert(s, 'latex', format='rst') > assert t == 'this is %(b)ssome restructured text.' > print t % {'b': '\\'} This is somehow what I'm doing now, but is very dirty and difficult to expand to other corner cases. Al From al.basili at gmail.com Tue Mar 3 15:37:20 2015 From: al.basili at gmail.com (alb) Date: 3 Mar 2015 20:37:20 GMT Subject: rst and pypandoc References: <54f458a5$0$13003$c3e8da3$5496439d@news.astraweb.com> Message-ID: Hi Mark, Mark Lawrence wrote: [] > The two inps are *not* the same. My bad. I did not notice the difference, thanks for pointing that out. Al From marfig at gmail.com Tue Mar 3 15:39:56 2015 From: marfig at gmail.com (Mario Figueiredo) Date: Tue, 03 Mar 2015 21:39:56 +0100 Subject: [Python 3.4.3, pip 6.0.8 ] Error installing Sphinx (on markupsafe install) References: Message-ID: <9i6cfah662ocnthshbadl9k45677l8a352@4ax.com> On Tue, 03 Mar 2015 07:15:19 +0000, Mark Lawrence wrote: >Further the output above tells me that you've not got >Visual Studio 2010 installed. I do. It's my principal development suite. But you put me in the right track. I took a closer look at the error messages and also noticed the references to vcvars. I was installing it from a shell where vcvars are enabled. I tried to install sphinx from a fresh clean shell and it went smoothly this time. Thanks. From al.basili at gmail.com Tue Mar 3 15:46:47 2015 From: al.basili at gmail.com (alb) Date: 3 Mar 2015 20:46:47 GMT Subject: rst and pypandoc References: <54f458a5$0$13003$c3e8da3$5496439d@news.astraweb.com> <54f4f0d0$0$12995$c3e8da3$5496439d@news.astraweb.com> Message-ID: Hi Steven, Steven D'Aprano wrote: [] >> The two results are clearly *not* the same, even though the two inp >> /claim/ to be the same... > > The two inp are not the same. Correct. My statement was wrong. [] > I'm sure that you know how to do such simple things to investigate whether > two inputs are in fact the same or not, and the fact that you failed to do > so is just a sign of your frustration and stress. You nailed it! Indeed there were all the symptoms of a stressed situation from the very beginning: 1. the OP was unclear and full of misleading information 2. part of the posts were misunderstood, hence causing more confusion than anything else. 3. my code has become a mess of workarounds, being far from pythonic. Now that the delivery date is passed behind me I'll have some time to clean up the mess and get everything straight. Being pragmatic and finding workaround is not bad but the mess should be cleaned up afterwards! Al From al.basili at gmail.com Tue Mar 3 15:50:16 2015 From: al.basili at gmail.com (alb) Date: 3 Mar 2015 20:50:16 GMT Subject: rst and pypandoc References: <54f458a5$0$13003$c3e8da3$5496439d@news.astraweb.com> Message-ID: Hi Gregory, Gregory Ewing wrote: [] > From a cursory reading of the pypandoc docs, it looks > like enabling the raw_tex extension in pypandoc will > give you what you want. > > Search for raw_tex on this page: > > http://johnmacfarlane.net/pandoc/README.html As far as I understood the docs, it seems this extension should be passed to pandoc through +EXTERNSION, but I don't seem to get it working: In [14]: print pypandoc.convert(s, 'latex', format="md+raw_tex") --------------------------------------------------------------------------- RuntimeError Traceback (most recent call last) in () ----> 1 print pypandoc.convert(s, 'latex', format="md+raw_tex") /usr/local/lib/python2.7/dist-packages/pypandoc.pyc in convert(source, to, format, extra_args, encoding) 25 ''' 26 return _convert(_read_file, _process_file, source, to, ---> 27 format, extra_args, encoding=encoding) 28 29 /usr/local/lib/python2.7/dist-packages/pypandoc.pyc in _convert(reader, processor, source, to, format, extra_args, encoding) 50 raise RuntimeError( 51 'Invalid input format! Expected one of these: ' + ---> 52 ', '.join(from_formats)) 53 54 if to not in to_formats: RuntimeError: Invalid input format! Expected one of these: native, json, markdown, markdown+lhs, rst, rst+lhs, docbook, textile, html, latex, latex+lhs From p.f.moore at gmail.com Tue Mar 3 16:10:11 2015 From: p.f.moore at gmail.com (Paul Moore) Date: Tue, 3 Mar 2015 13:10:11 -0800 (PST) Subject: Reading all buffered bytes without blocking In-Reply-To: References: <4ad47d38-bd92-4516-bc60-60fddc9e0666@googlegroups.com> Message-ID: On Tuesday, 3 March 2015 19:29:19 UTC, Serhiy Storchaka wrote: > On 03.03.15 18:07, Paul Moore wrote: > > Is it possible to say to a BufferedReader stream "give me all the bytes you have available in the buffer, or do one OS call and give me everything you get back"? The problem is that the "number of bytes" argument to read1() isn't optional, so I can't do available_bytes = fd.read1(). > > Just specify large size. Thanks. Looking at the source, it appears that a large size will allocate a buffer that size for the data even if the amount actually read is small (thinking about it, of couse it has to, doh, because the syscall needs it). Anyway, it's a pretty microscopic risk in practice, and when I looked at them, the incremental codecs (codecs.iterdecode) really aren't that hard to use, so I can do it that way if it matters enough. For what it's worth, in case anyone wants to know, incremental decoding looks like this: def get(): while True: data = process.stdout.read(1000) if not data: break yield data for data in codecs.iterdecode(get(), encoding): sys.stdout.write(data) sys.stdout.flush() Thanks. Paul From greg.ewing at canterbury.ac.nz Tue Mar 3 17:27:36 2015 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 04 Mar 2015 11:27:36 +1300 Subject: rst and pypandoc In-Reply-To: References: <54f458a5$0$13003$c3e8da3$5496439d@news.astraweb.com> Message-ID: alb wrote: > RuntimeError: Invalid input format! Expected one of these: native, json, > markdown, markdown+lhs, rst, rst+lhs, docbook, textile, html, latex, > latex+lhs It looks like it's expecting the base format to be spelled "markdown", not abbreviated to "md". (The python wrapper expands "md" to "markdown", but not if it's followed by any + or - options.) So try: pypandoc.convert(s, 'latex', format="markdown+raw_tex") BTW, I just installed pandoc on MacOSX to try this out, and it seems that raw_tex is enabled by default for me -- I have to turn it *off* with format="markdown-raw_tex" in order to get the behaviour you're seeing. Maybe a different version? My pandoc says it's version 1.12.0.1. -- Greg From auriocus at gmx.de Tue Mar 3 17:46:47 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Tue, 03 Mar 2015 23:46:47 +0100 Subject: Python Worst Practices In-Reply-To: References: <54f1154c$0$12985$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 03.03.15 um 12:12 schrieb Chris Angelico: > On Tue, Mar 3, 2015 at 7:51 PM, Christian Gollwitzer wrote: > >> Are you trying to pick on C++ streams? I could never understand why >> anybody has problems with an arrow << that means "put into the left >> thing" instead of "shift the bits to the left". How often do you use >> bitshift operations in your programs as opposed to output? Ot would be >> equally silly to complain, that in Python you divide a string by a >> tuple, and the modulus gives you a formatted string. > > I am, yes. Both your examples seem lovely and simple when you first > look at them, but operator precedence means you get weird edge cases. > In the case of string modulo, there's another edge case as a > consequence of the operator being, by necessity, binary. A function > call makes better sense here. I can agree with the argument that operator precedence can make problems; e.g. this cout< Operator overloading in each case here is "cute", not optimally practical. Maybe just sub-optimal? With today's C++ one could use a variadic template and still have type-safe compile-time bound output formatting. This hasn't been possible in the original iostream library back then. Christian From rosuav at gmail.com Tue Mar 3 18:12:19 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 Mar 2015 10:12:19 +1100 Subject: Python Worst Practices In-Reply-To: References: <54f1154c$0$12985$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Mar 4, 2015 at 9:46 AM, Christian Gollwitzer wrote: > I can agree with the argument that operator precedence can make > problems; e.g. this > > cout< > does not output the truth value of a==b, but instead outputs a and > compares the stream to b (which will usually fail to compile, but still). > > But the argument that << is a left-shift and nothing else is silly. << > for bitshift is nothing more intuitive than % for modulus (where in math > does this symbol occur?) or [] for indexing. We just got used to it, and > to me << as an arrow for putting someting into a stream seems pretty > obvious. I don't mind the idea of << meaning something other than left-shift. The problem comes usually when you try to use a binary operator in place of a variadic function, and suddenly you need a pile of hacks to get around operator overloading. If you use << to add a flag to a flag-set (where the "flag-set" might be an integer that retains bit-flags, or a set that retains strings, or whatever), that would make reasonable sense. You take one thing on the left, one thing on the right, and produce a result. (Or you'd use <<= for that, which still looks fine. Then it does an assignment instead of producing a result.) If you create a Path object that responds to binary division with a new Path that combines the left and right sides, that also makes very good sense. The slash means "next path component" rather than "divide", and it still is binary - there's no logical difference between these: Path("/etc") / "network" / "interfaces" (Path("/etc") / "network") / "interfaces" The problems come from needing more than two components at each step, like with string formatting. You could write it like this: "Hello, %s from %s!" % name % location but then it'd be really hard to track down errors - the modulo operator would have to handle the first percent sign and leave any others unchanged. Plus there'd need to be some weird and funky magic to mark the "current interpolation position" in order to cope with %% becoming %, and the possibility that the person's name contains a percent sign. No, string interpolation needs more than two arguments. So either you have to mandatorially package the args up into an iterable: "Hello, %s from %s!" % (name, location) which is very easy to forget (just look at what happens when you use the Python DB API 2.0 and use "cur.execute(sql, single_argument)" - you have to package that up into a one-tuple), or you have a special case for non-tuple arguments, which is what Python has done. This is great, except in the situation where you want to accept *any arbitrary object* as your argument, eg for %r; you have to package that one up, otherwise a tuple will behave very oddly. Hence, hacks on hacks to get around the limitations of binary operators. >> Operator overloading in each case here is "cute", not optimally practical. > > Maybe just sub-optimal? With today's C++ one could use a variadic > template and still have type-safe compile-time bound output formatting. > This hasn't been possible in the original iostream library back then. I'm not sure how that would work, but the main question is: How is it advantageous over a simple call? Actually, here's a simple way to do it: Make the stream object callable. cout("Hello, world!\n"); You can take as many args as you want, precedence and associativity won't bite you, and it still reads reasonably well. The operator method has to prove that it's better than that. ChrisA From tjreedy at udel.edu Tue Mar 3 18:30:15 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 03 Mar 2015 18:30:15 -0500 Subject: Newbie question about text encoding In-Reply-To: <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> References: <54EC5FA4.6070703@davea.name> <201502241455.t1OEtffT016452@fido.openend.se> <201502241507.t1OF7aUm018883@fido.openend.se> <201502241524.t1OFO09k022270@fido.openend.se> <201502241620.t1OGKf4n002146@fido.openend.se> <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> Message-ID: On 3/3/2015 1:03 PM, Rustom Mody wrote: > On Thursday, February 26, 2015 at 10:33:44 PM UTC+5:30, Terry Reedy wrote: >> You should add emoticons, but not call them or the above 'gibberish'. >> I think that this part of your post is more 'unprofessional' than the >> character blocks. It is very jarring and seems contrary to your main point. > > Ok Done > > References to gibberish removed from > http://blog.languager.org/2015/02/universal-unicode.html > > What I was trying to say expanded here > http://blog.languager.org/2015/03/whimsical-unicode.html > [Hope the word 'whimsical' is less jarring and more accurate than 'gibberish'] I agree with both. -- Terry Jan Reedy From marcos.al.azevedo at gmail.com Tue Mar 3 20:12:26 2015 From: marcos.al.azevedo at gmail.com (Marcos Almeida Azevedo) Date: Wed, 4 Mar 2015 09:12:26 +0800 Subject: tarfile vs zipfile In-Reply-To: References: <97542b34-5381-48c2-93bb-755d4ac49369@googlegroups.com> <85h9u228ag.fsf@benfinney.id.au> Message-ID: On Tue, Mar 3, 2015 at 6:39 PM, Gregory Ewing wrote: > Mark Lawrence wrote: > >> On 03/03/2015 02:29, Terry Reedy wrote: >> >> Plus tartfiles come from unix world, whereas zip was used instead in >>> Windows world. >>> >>> Is the tart bit the thing that you can eat, a loose woman or something >> else, such as a typo? :) >> > > Tartfiles would be what you get from xxx sites, no? > tartfiles is the compressed air that comes from behind and flies around unwanted by the public > > -- > Greg > -- > https://mail.python.org/mailman/listinfo/python-list > -- Marcos | I love PHP, Linux, and Java -------------- next part -------------- An HTML attachment was scrubbed... URL: From rustompmody at gmail.com Tue Mar 3 21:53:36 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 3 Mar 2015 18:53:36 -0800 (PST) Subject: Newbie question about text encoding In-Reply-To: References: <54EC5FA4.6070703@davea.name> <201502241455.t1OEtffT016452@fido.openend.se> <201502241507.t1OF7aUm018883@fido.openend.se> <201502241524.t1OFO09k022270@fido.openend.se> <201502241620.t1OGKf4n002146@fido.openend.se> <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> Message-ID: <18d9d5a7-dfb9-4e13-ada3-5ef97cf0543d@googlegroups.com> On Wednesday, March 4, 2015 at 12:14:11 AM UTC+5:30, Chris Angelico wrote: > On Wed, Mar 4, 2015 at 5:03 AM, Rustom Mody wrote: > > What I was trying to say expanded here > > http://blog.languager.org/2015/03/whimsical-unicode.html > > [Hope the word 'whimsical' is less jarring and more accurate than 'gibberish'] > > Re footnote #4: ? is a single character for compatibility reasons. > ???? ... ^^^ Neat Thanks [And figured out some of quopri module along the way figuring that out] From steve+comp.lang.python at pearwood.info Tue Mar 3 21:54:27 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 04 Mar 2015 13:54:27 +1100 Subject: Newbie question about text encoding References: <54EC5FA4.6070703@davea.name> <201502241455.t1OEtffT016452@fido.openend.se> <201502241507.t1OF7aUm018883@fido.openend.se> <201502241524.t1OFO09k022270@fido.openend.se> <201502241620.t1OGKf4n002146@fido.openend.se> <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> Message-ID: <54f673e4$0$12980$c3e8da3$5496439d@news.astraweb.com> Rustom Mody wrote: > On Thursday, February 26, 2015 at 10:33:44 PM UTC+5:30, Terry Reedy wrote: >> On 2/26/2015 8:24 AM, Chris Angelico wrote: >> > On Thu, Feb 26, 2015 at 11:40 PM, Rustom Mody wrote: >> >> Wrote something up on why we should stop using ASCII: >> >> http://blog.languager.org/2015/02/universal-unicode.html >> >> I think that the main point of the post, that many Unicode chars are >> truly planetary rather than just national/regional, is excellent. > > > >> You should add emoticons, but not call them or the above 'gibberish'. >> I think that this part of your post is more 'unprofessional' than the >> character blocks. It is very jarring and seems contrary to your main >> point. > > Ok Done > > References to gibberish removed from > http://blog.languager.org/2015/02/universal-unicode.html I consider it unethical to make semantic changes to a published work in place without acknowledgement. Fixing minor typos or spelling errors, or dead links, is okay. But any edit that changes the meaning should be commented on, either by an explicit note on the page itself, or by striking out the previous content and inserting the new. As for the content of the essay, it is currently rather unfocused. It appears to be more of a list of "here are some Unicode characters I think are interesting, divided into subgroups, oh and here are some I personally don't have any use for, which makes them silly" than any sort of discussion about the universality of Unicode. That makes it rather idiosyncratic and parochial. Why should obscure maths symbols be given more importance than obscure historical languages? I think that the universality of Unicode could be explained in a single sentence: "It is the aim of Unicode to be the one character set anyone needs to represent every character, ideogram or symbol (but not necessarily distinct glyph) from any existing or historical human language." I can expand on that, but in a nutshell that is it. You state: "APL and Z Notation are two notable languages APL is a programming language and Z a specification language that did not tie themselves down to a restricted charset ..." but I don't think that is correct. I'm pretty sure that neither APL nor Z allowed you to define new characters. They might not have used ASCII alone, but they still had a restricted character set. It was merely less restricted than ASCII. You make a comment about Cobol's relative unpopularity, but (1) Cobol doesn't require you to write out numbers as English words, and (2) Cobol is still used, there are uncounted billions of lines of Cobol code being used, and if the number of Cobol programmers is less now than it was 16 years ago, there are still a lot of them. Academics and FOSS programmers don't think much of Cobol, but it has to count as one of the most amazing success stories in the field of programming languages, despite its lousy design. You list ideographs such as Cuneiform under "Icons". They are not icons. They are a mixture of symbols used for consonants, syllables, and logophonetic, consonantal alphabetic and syllabic signs. That sits them firmly in the same categories as modern languages with consonants, ideogram languages like Chinese, and syllabary languages like Cheyenne. Just because native readers of Cuneiform are all dead doesn't make Cuneiform unimportant. There are probably more people who need to write Cuneiform than people who need to write APL source code. You make a comment: "To me ? a unicode-layman ? it looks unprofessional? Billions of computing devices world over, each having billions of storage words having their storage wasted on blocks such as these??" But that is nonsense, and it contradicts your earlier quoting of Dave Angel. Why are you so worried about an (illusionary) minor optimization? Whether code points are allocated or not doesn't affect how much space they take up. There are millions of unused Unicode code points today. If they are allocated tomorrow, the space your documents take up will not increase one byte. Allocating code points to Cuneiform has not increased the space needed by Unicode at all. Two bytes alone is not enough for even existing human languages (thanks China). For hardware related reasons, it is faster and more efficient to use four bytes than three, so the obvious and "dumb" (in the simplest thing which will work) way to store Unicode is UTF-32, which takes a full four bytes per code point, regardless of whether there are 65537 code points or 1114112. That makes it less expensive than floating point numbers, which take eight. Would you like to argue that floating point doubles are "unprofessional" and wasteful? As Dave pointed out, and you apparently agreed with him enough to quote him TWICE (once in each of two blog posts), history of computing is full of premature optimizations for space. (In fact, some of these may have been justified by the technical limitations of the day.) Technically Unicode is also limited, but it is limited to over one million code points, 1114112 to be exact, although some of them are reserved as invalid for technical reasons, and there is no indication that we'll ever run out of space in Unicode. In practice, there are three common Unicode encodings that nearly all Unicode documents will use. * UTF-8 will use between one and (by memory) four bytes per code point. For Western European languages, that will be mostly one or two bytes per character. * UTF-16 uses a fixed two bytes per code point in the Basic Multilingual Plane, which is enough for nearly all Western European writing and much East Asian writing as well. For the rest, it uses a fixed four bytes per code point. * UTF-32 uses a fixed four bytes per code point. Hardly anyone uses this as a storage format. In *all three cases*, the existence of hieroglyphs and cuneiform in Unicode doesn't change the space used. If you actually include a few hieroglyphs to your document, the space increases only by the actual space used by those hieroglyphs: four bytes per hieroglyph. At no time does the existence of a single hieroglyph in your document force you to expand the non-hieroglyph characters to use more space. > What I was trying to say expanded here > http://blog.languager.org/2015/03/whimsical-unicode.html You have at least two broken links, referring to a non-existent page: http://blog.languager.org/2015/03/unicode-universal-or-whimsical.html This essay seems to be even more rambling and unfocused than the first. What does the cost of semi-conductor plants have to do with whether or not programmers support Unicode in their applications? Your point about the UTF-8 "BOM" is valid only if you interpret it as a Byte Order Mark. But if you interpret it as an explicit UTF-8 signature or mark, it isn't so silly. If your text begins with the UTF-8 mark, treat it as UTF-8. It's no more silly than any other heuristic, like HTML encoding tags or text editor's encoding cookies. Your discussion of "complexifiers and simplifiers" doesn't seem to be terribly relevant, or at least if it is relevant, you don't give any reason for it. The whole thing about Moore's Law and the cost of semi-conductor plants seems irrelevant to Unicode except in the most over-generalised sense of "things are bigger today than in the past, we've gone from five-bit Baudot codes to 23 bit Unicode". Yeah, okay. So what's your point? You agree that 16-bits are not enough, and yet you critice Unicode for using more than 16-bits on wasteful, whimsical gibberish like Cuneiform? That is an inconsistent position to take. UTF-16 is not half-arsed Unicode support. UTF-16 is full Unicode support. The problem is when your language treats UTF-16 as a fixed-width two-byte format instead of a variable-width, two- or four-byte format. (That's more or less like the old, obsolete, UCS-2 standard.) There are all sorts of good ways to solve the problem of surrogate pairs and the SMPs in UTF-16. If some programming languages or software fails to do so, they are buggy, not UTF-16. After explaining that 16 bits are not enough, you then propose a 16 bit standard. /face-palm UTF-16 cannot break the fixed with invariant, because it has no fixed width invariant. That's like arguing against UTF-8 because it breaks the fixed width invariant "all characters are single byte ASCII characters". If you cannot handle SMP characters, you are not supporting Unicode. You suggest that Chinese users should be looking at Big5 or GB. I really, really don't think so. - Neither is universal. What makes you think that Chinese writers need to use maths symbols, or include (say) Thai or Russian in their work any less than Western writers do? - Neither even support all of Chinese. Big5 supports Traditional Chinese, but not Simplified Chinese. GB supports Simplified Chinese, but not Traditional Chinese. - Big5 likewise doesn't support placenames, many people's names, and other less common parts of Chinese. - Big5 is a shift-system, like Shift-JIS, and suffers from the same sort of data corruption issues. - There is no one single Big5 standard, but a whole lot of vendor extensions. You say: "I just want to suggest that the Unicode consortium going overboard in adding zillions of codepoints of nearly zero usefulness, is in fact undermining unicode?s popularity and spread." Can you demonstrate this? Can you show somebody who says "Well, I was going to support full Unicode, but since they added a snowman, I'm going to stick to ASCII"? The "whimsical" characters you are complaining about were important enough to somebody to spend significant amounts of time and money to write up a proposal, have it go through the Unicode Consortium bureaucracy, and eventually have it accepted. That's not easy or cheap, and people didn't add a snowman on a whim. They did it because there are a whole lot of people who want a shared standard for map symbols. It is easy to mock what is not important to you. I daresay kids adding emoji to their 10 character tweets would mock all the useless maths symbols in Unicode too. -- Steven From rosuav at gmail.com Tue Mar 3 22:02:48 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 Mar 2015 14:02:48 +1100 Subject: Newbie question about text encoding In-Reply-To: <54f673e4$0$12980$c3e8da3$5496439d@news.astraweb.com> References: <54EC5FA4.6070703@davea.name> <201502241455.t1OEtffT016452@fido.openend.se> <201502241507.t1OF7aUm018883@fido.openend.se> <201502241524.t1OFO09k022270@fido.openend.se> <201502241620.t1OGKf4n002146@fido.openend.se> <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <54f673e4$0$12980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Mar 4, 2015 at 1:54 PM, Steven D'Aprano wrote: > It is easy to mock what is not important to you. I daresay kids adding emoji > to their 10 character tweets would mock all the useless maths symbols in > Unicode too. Definitely! Who ever sings "do you wanna build an integral sign"? ChrisA From faruk at vt.edu Tue Mar 3 22:25:13 2015 From: faruk at vt.edu (faruk at vt.edu) Date: Tue, 3 Mar 2015 19:25:13 -0800 (PST) Subject: Setting PYTHONPATH does not allow importing module Message-ID: <2d13a257-797e-4481-a838-974128ffa81e@googlegroups.com> I have the following directory /home/me/projects/modulename. I update PYTHONPATH using the following command: export PYTHONPATH=$PYTHONPATH:/home/me/projects/modulename It seems to have been added: [me at machine ~]$ python -c "import sys; print(sys.path)" ['',... '/home/me', '/home/me/projects/modulename', ...] But import modulename does not work: [me at machine ~]$ python -c "import modulename" Traceback (most recent call last): File "", line 1, in ImportError: No module named modulename Does anyone know what's wrong? From liuerfire at gmail.com Tue Mar 3 22:37:40 2015 From: liuerfire at gmail.com (liuerfire Wang) Date: Wed, 4 Mar 2015 11:37:40 +0800 Subject: Setting PYTHONPATH does not allow importing module In-Reply-To: <2d13a257-797e-4481-a838-974128ffa81e@googlegroups.com> References: <2d13a257-797e-4481-a838-974128ffa81e@googlegroups.com> Message-ID: Is there a file named __init__.py in the modulename dir? Best regards On Wed, Mar 4, 2015 at 11:25 AM, wrote: > I have the following directory /home/me/projects/modulename. > > I update PYTHONPATH using the following command: > export PYTHONPATH=$PYTHONPATH:/home/me/projects/modulename > > It seems to have been added: > [me at machine ~]$ python -c "import sys; print(sys.path)" > ['',... '/home/me', '/home/me/projects/modulename', ...] > > But import modulename does not work: > [me at machine ~]$ python -c "import modulename" > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named modulename > > Does anyone know what's wrong? > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From faruk at vt.edu Tue Mar 3 22:41:47 2015 From: faruk at vt.edu (faruk at vt.edu) Date: Tue, 3 Mar 2015 19:41:47 -0800 (PST) Subject: Setting PYTHONPATH does not allow importing module In-Reply-To: References: <2d13a257-797e-4481-a838-974128ffa81e@googlegroups.com> Message-ID: On Tuesday, March 3, 2015 at 10:37:54 PM UTC-5, liuerfire Wang wrote: > Is there a file named __init__.py in the modulename dir? > > > > > > > > > Best regards > > > > > > On Wed, Mar 4, 2015 at 11:25 AM, wrote: > I have the following directory /home/me/projects/modulename. > > > > I update PYTHONPATH using the following command: > > export PYTHONPATH=$PYTHONPATH:/home/me/projects/modulename > > > > It seems to have been added: > > [me at machine ~]$ python -c "import sys; print(sys.path)" > > ['',... '/home/me', '/home/me/projects/modulename', ...] > > > > But import modulename does not work: > > [me at machine ~]$ python -c "import modulename" > > Traceback (most recent call last): > > ? File "", line 1, in > > ImportError: No module named modulename > > > > Does anyone know what's wrong? > > -- > > https://mail.python.org/mailman/listinfo/python-list Yes, there is an __init__.py file in the directory /home/me/modulename From zachary.ware+pylist at gmail.com Tue Mar 3 22:42:38 2015 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Tue, 3 Mar 2015 21:42:38 -0600 Subject: Setting PYTHONPATH does not allow importing module In-Reply-To: <2d13a257-797e-4481-a838-974128ffa81e@googlegroups.com> References: <2d13a257-797e-4481-a838-974128ffa81e@googlegroups.com> Message-ID: On Tue, Mar 3, 2015 at 9:25 PM, wrote: > I have the following directory /home/me/projects/modulename. > > I update PYTHONPATH using the following command: > export PYTHONPATH=$PYTHONPATH:/home/me/projects/modulename > > It seems to have been added: > [me at machine ~]$ python -c "import sys; print(sys.path)" > ['',... '/home/me', '/home/me/projects/modulename', ...] > > But import modulename does not work: > [me at machine ~]$ python -c "import modulename" > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named modulename > > Does anyone know what's wrong? Try adding /home/me/projects to PYTHONPATH instead of /home/me/projects/modulename. -- Zach From faruk at vt.edu Tue Mar 3 22:42:46 2015 From: faruk at vt.edu (faruk at vt.edu) Date: Tue, 3 Mar 2015 19:42:46 -0800 (PST) Subject: Setting PYTHONPATH does not allow importing module In-Reply-To: References: <2d13a257-797e-4481-a838-974128ffa81e@googlegroups.com> Message-ID: On Tuesday, March 3, 2015 at 10:37:54 PM UTC-5, liuerfire Wang wrote: > Is there a file named __init__.py in the modulename dir? > > > > > > > > > Best regards > > > > > > On Wed, Mar 4, 2015 at 11:25 AM, wrote: > I have the following directory /home/me/projects/modulename. > > > > I update PYTHONPATH using the following command: > > export PYTHONPATH=$PYTHONPATH:/home/me/projects/modulename > > > > It seems to have been added: > > [me at machine ~]$ python -c "import sys; print(sys.path)" > > ['',... '/home/me', '/home/me/projects/modulename', ...] > > > > But import modulename does not work: > > [me at machine ~]$ python -c "import modulename" > > Traceback (most recent call last): > > ? File "", line 1, in > > ImportError: No module named modulename > > > > Does anyone know what's wrong? > > -- > > https://mail.python.org/mailman/listinfo/python-list Yes, there is an __init__.py in the directory /home/me/projects/modulename From faruk at vt.edu Tue Mar 3 22:47:28 2015 From: faruk at vt.edu (faruk at vt.edu) Date: Tue, 3 Mar 2015 19:47:28 -0800 (PST) Subject: Setting PYTHONPATH does not allow importing module In-Reply-To: References: <2d13a257-797e-4481-a838-974128ffa81e@googlegroups.com> Message-ID: On Tuesday, March 3, 2015 at 10:43:27 PM UTC-5, Zachary Ware wrote: > On Tue, Mar 3, 2015 at 9:25 PM, wrote: > > I have the following directory /home/me/projects/modulename. > > > > I update PYTHONPATH using the following command: > > export PYTHONPATH=$PYTHONPATH:/home/me/projects/modulename > > > > It seems to have been added: > > [me at machine ~]$ python -c "import sys; print(sys.path)" > > ['',... '/home/me', '/home/me/projects/modulename', ...] > > > > But import modulename does not work: > > [me at machine ~]$ python -c "import modulename" > > Traceback (most recent call last): > > File "", line 1, in > > ImportError: No module named modulename > > > > Does anyone know what's wrong? > > Try adding /home/me/projects to PYTHONPATH instead of > /home/me/projects/modulename. > > -- > Zach Ah, that worked! Yes, I see that the modulename must be visible. Thanks a lot! From rustompmody at gmail.com Tue Mar 3 23:05:08 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 3 Mar 2015 20:05:08 -0800 (PST) Subject: Newbie question about text encoding In-Reply-To: <54f673e4$0$12980$c3e8da3$5496439d@news.astraweb.com> References: <54EC5FA4.6070703@davea.name> <201502241455.t1OEtffT016452@fido.openend.se> <201502241507.t1OF7aUm018883@fido.openend.se> <201502241524.t1OFO09k022270@fido.openend.se> <201502241620.t1OGKf4n002146@fido.openend.se> <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <54f673e4$0$12980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <601f597e-719a-4721-9620-1a7ea43de57d@googlegroups.com> On Wednesday, March 4, 2015 at 8:24:40 AM UTC+5:30, Steven D'Aprano wrote: > Rustom Mody wrote: > > > On Thursday, February 26, 2015 at 10:33:44 PM UTC+5:30, Terry Reedy wrote: > >> On 2/26/2015 8:24 AM, Chris Angelico wrote: > >> > On Thu, Feb 26, 2015 at 11:40 PM, Rustom Mody wrote: > >> >> Wrote something up on why we should stop using ASCII: > >> >> http://blog.languager.org/2015/02/universal-unicode.html > >> > >> I think that the main point of the post, that many Unicode chars are > >> truly planetary rather than just national/regional, is excellent. > > > > > > > >> You should add emoticons, but not call them or the above 'gibberish'. > >> I think that this part of your post is more 'unprofessional' than the > >> character blocks. It is very jarring and seems contrary to your main > >> point. > > > > Ok Done > > > > References to gibberish removed from > > http://blog.languager.org/2015/02/universal-unicode.html > > I consider it unethical to make semantic changes to a published work in > place without acknowledgement. Fixing minor typos or spelling errors, or > dead links, is okay. But any edit that changes the meaning should be > commented on, either by an explicit note on the page itself, or by striking > out the previous content and inserting the new. Dunno What you are grumping about? Anyway the attribution is made more explicit ? footnote 5 in http://blog.languager.org/2015/03/whimsical-unicode.html. Note Terry Reedy's post who mainly objected was already acked earlier. Ive just added one more ack? And JFTR the 'publication' (O how archaic!) is the whole blog not a single page just as it is for any other dead-tree publication. > > As for the content of the essay, it is currently rather unfocused. True. It > appears to be more of a list of "here are some Unicode characters I think > are interesting, divided into subgroups, oh and here are some I personally > don't have any use for, which makes them silly" than any sort of discussion > about the universality of Unicode. That makes it rather idiosyncratic and > parochial. Why should obscure maths symbols be given more importance than > obscure historical languages? Idiosyncratic ? parochial > > I think that the universality of Unicode could be explained in a single > sentence: > > "It is the aim of Unicode to be the one character set anyone needs to > represent every character, ideogram or symbol (but not necessarily distinct > glyph) from any existing or historical human language." > > I can expand on that, but in a nutshell that is it. > > > You state: > > "APL and Z Notation are two notable languages APL is a programming language > and Z a specification language that did not tie themselves down to a > restricted charset ..." Tsk Tsk ? dihonest snipping. I wrote | APL and Z Notation are two notable languages APL is a programming language | and Z a specification language that did not tie themselves down to a | restricted charset even in the day that ASCII ruled. so its clear that the restricted applies to ASCII > > You list ideographs such as Cuneiform under "Icons". They are not icons. > They are a mixture of symbols used for consonants, syllables, and > logophonetic, consonantal alphabetic and syllabic signs. That sits them > firmly in the same categories as modern languages with consonants, ideogram > languages like Chinese, and syllabary languages like Cheyenne. Ok changed to iconic. Obviously 2-3 millenia ago, when people spoke hieroglyphs or cuneiform they were languages. In 2015 when someone sees them and recognizes them, they are 'those things that Sumerians/Egyptians wrote' No one except a rare expert knows those languages > > Just because native readers of Cuneiform are all dead doesn't make Cuneiform > unimportant. There are probably more people who need to write Cuneiform > than people who need to write APL source code. > > You make a comment: > > "To me ? a unicode-layman ? it looks unprofessional? Billions of computing > devices world over, each having billions of storage words having their > storage wasted on blocks such as these??" > > But that is nonsense, and it contradicts your earlier quoting of Dave Angel. > Why are you so worried about an (illusionary) minor optimization? 2 < 4 as far as I am concerned. [If you disagree one man's illusionary is another's waking] > > Whether code points are allocated or not doesn't affect how much space they > take up. There are millions of unused Unicode code points today. If they > are allocated tomorrow, the space your documents take up will not increase > one byte. > > Allocating code points to Cuneiform has not increased the space needed by > Unicode at all. Two bytes alone is not enough for even existing human > languages (thanks China). For hardware related reasons, it is faster and > more efficient to use four bytes than three, so the obvious and "dumb" (in > the simplest thing which will work) way to store Unicode is UTF-32, which > takes a full four bytes per code point, regardless of whether there are > 65537 code points or 1114112. That makes it less expensive than floating > point numbers, which take eight. Would you like to argue that floating > point doubles are "unprofessional" and wasteful? > > As Dave pointed out, and you apparently agreed with him enough to quote him > TWICE (once in each of two blog posts), history of computing is full of > premature optimizations for space. (In fact, some of these may have been > justified by the technical limitations of the day.) Technically Unicode is > also limited, but it is limited to over one million code points, 1114112 to > be exact, although some of them are reserved as invalid for technical > reasons, and there is no indication that we'll ever run out of space in > Unicode. > > In practice, there are three common Unicode encodings that nearly all > Unicode documents will use. > > * UTF-8 will use between one and (by memory) four bytes per code > point. For Western European languages, that will be mostly one > or two bytes per character. > > * UTF-16 uses a fixed two bytes per code point in the Basic Multilingual > Plane, which is enough for nearly all Western European writing and > much East Asian writing as well. For the rest, it uses a fixed four > bytes per code point. > > * UTF-32 uses a fixed four bytes per code point. Hardly anyone uses > this as a storage format. > > > In *all three cases*, the existence of hieroglyphs and cuneiform in Unicode > doesn't change the space used. If you actually include a few hieroglyphs to > your document, the space increases only by the actual space used by those > hieroglyphs: four bytes per hieroglyph. At no time does the existence of a > single hieroglyph in your document force you to expand the non-hieroglyph > characters to use more space. > > > > What I was trying to say expanded here > > http://blog.languager.org/2015/03/whimsical-unicode.html > > You have at least two broken links, referring to a non-existent page: > > http://blog.languager.org/2015/03/unicode-universal-or-whimsical.html Thanks corrected > > This essay seems to be even more rambling and unfocused than the first. What > does the cost of semi-conductor plants have to do with whether or not > programmers support Unicode in their applications? > > Your point about the UTF-8 "BOM" is valid only if you interpret it as a Byte > Order Mark. But if you interpret it as an explicit UTF-8 signature or mark, > it isn't so silly. If your text begins with the UTF-8 mark, treat it as > UTF-8. It's no more silly than any other heuristic, like HTML encoding tags > or text editor's encoding cookies. > > Your discussion of "complexifiers and simplifiers" doesn't seem to be > terribly relevant, or at least if it is relevant, you don't give any reason > for it. The whole thing about Moore's Law and the cost of semi-conductor > plants seems irrelevant to Unicode except in the most over-generalised > sense of "things are bigger today than in the past, we've gone from > five-bit Baudot codes to 23 bit Unicode". Yeah, okay. So what's your point? - Most people need only 16 bits. - Many notable examples of software fail going from 16 to 23. - If you are a software writer, and you fail going 16 to 23 its ok but try to give useful errors > > You agree that 16-bits are not enough, and yet you critice Unicode for using > more than 16-bits on wasteful, whimsical gibberish like Cuneiform? That is > an inconsistent position to take. | ?-assed unicode support ? BMP-only ? is better than 1/100-assed? support ? | ASCII. BMP-only Unicode is universal enough but within practical limits | whereas full (7.0) Unicode is 'really' universal at a cost of performance and | whimsicality. Do you disagree that BMP-only = 16 bits? > > UTF-16 is not half-arsed Unicode support. UTF-16 is full Unicode support. > > The problem is when your language treats UTF-16 as a fixed-width two-byte > format instead of a variable-width, two- or four-byte format. (That's more > or less like the old, obsolete, UCS-2 standard.) There are all sorts of > good ways to solve the problem of surrogate pairs and the SMPs in UTF-16. > If some programming languages or software fails to do so, they are buggy, > not UTF-16. > > After explaining that 16 bits are not enough, you then propose a 16 bit > standard. /face-palm > > UTF-16 cannot break the fixed with invariant, because it has no fixed width > invariant. That's like arguing against UTF-8 because it breaks the fixed > width invariant "all characters are single byte ASCII characters". > > If you cannot handle SMP characters, you are not supporting Unicode. 7.0 > > > You suggest that Chinese users should be looking at Big5 or GB. I really, > really don't think so. > > - Neither is universal. What makes you think that Chinese writers need > to use maths symbols, or include (say) Thai or Russian in their work > any less than Western writers do? > > - Neither even support all of Chinese. Big5 supports Traditional > Chinese, but not Simplified Chinese. GB supports Simplified > Chinese, but not Traditional Chinese. > > - Big5 likewise doesn't support placenames, many people's names, and > other less common parts of Chinese. > > - Big5 is a shift-system, like Shift-JIS, and suffers from the same sort > of data corruption issues. > > - There is no one single Big5 standard, but a whole lot of vendor > extensions. > > > You say: > > "I just want to suggest that the Unicode consortium going overboard in > adding zillions of codepoints of nearly zero usefulness, is in fact > undermining unicode?s popularity and spread." > > Can you demonstrate this? Can you show somebody who says "Well, I was going > to support full Unicode, but since they added a snowman, I'm going to stick > to ASCII"? I gave a list of softwares which goof/break going BMP to 7.0 unicode > > The "whimsical" characters you are complaining about were important enough > to somebody to spend significant amounts of time and money to write up a > proposal, have it go through the Unicode Consortium bureaucracy, and > eventually have it accepted. That's not easy or cheap, and people didn't > add a snowman on a whim. They did it because there are a whole lot of > people who want a shared standard for map symbols. > > It is easy to mock what is not important to you. I daresay kids adding emoji > to their 10 character tweets would mock all the useless maths symbols in > Unicode too. Head para of section 5 has: | However (the following) are (in the standard)! So lets use them! Looks like mocking to you The only mocking is at 5.1. And even here I dont mock the users of these blocks ? now or millenia ago. I only mock the unicode consortium for putting them into unicode ---------------------- ? And somewhere around here we get into G?delian problems -- known to programmers under the form "Write a program that prints itself". Likewise Acks. I am going to deal with the G?del-loop by the device: - Address real issues/objects - Smile at grumpiness From rustompmody at gmail.com Tue Mar 3 23:16:02 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 3 Mar 2015 20:16:02 -0800 (PST) Subject: Newbie question about text encoding In-Reply-To: <601f597e-719a-4721-9620-1a7ea43de57d@googlegroups.com> References: <54EC5FA4.6070703@davea.name> <201502241455.t1OEtffT016452@fido.openend.se> <201502241507.t1OF7aUm018883@fido.openend.se> <201502241524.t1OFO09k022270@fido.openend.se> <201502241620.t1OGKf4n002146@fido.openend.se> <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <54f673e4$0$12980$c3e8da3$5496439d@news.astraweb.com> <601f597e-719a-4721-9620-1a7ea43de57d@googlegroups.com> Message-ID: On Wednesday, March 4, 2015 at 9:35:28 AM UTC+5:30, Rustom Mody wrote: > On Wednesday, March 4, 2015 at 8:24:40 AM UTC+5:30, Steven D'Aprano wrote: > > Rustom Mody wrote: > > > > > On Thursday, February 26, 2015 at 10:33:44 PM UTC+5:30, Terry Reedy wrote: > > >> On 2/26/2015 8:24 AM, Chris Angelico wrote: > > >> > On Thu, Feb 26, 2015 at 11:40 PM, Rustom Mody wrote: > > >> >> Wrote something up on why we should stop using ASCII: > > >> >> http://blog.languager.org/2015/02/universal-unicode.html > > >> > > >> I think that the main point of the post, that many Unicode chars are > > >> truly planetary rather than just national/regional, is excellent. > > > > > > > > > > > >> You should add emoticons, but not call them or the above 'gibberish'. > > >> I think that this part of your post is more 'unprofessional' than the > > >> character blocks. It is very jarring and seems contrary to your main > > >> point. > > > > > > Ok Done > > > > > > References to gibberish removed from > > > http://blog.languager.org/2015/02/universal-unicode.html > > > > I consider it unethical to make semantic changes to a published work in > > place without acknowledgement. Fixing minor typos or spelling errors, or > > dead links, is okay. But any edit that changes the meaning should be > > commented on, either by an explicit note on the page itself, or by striking > > out the previous content and inserting the new. > > Dunno What you are grumping about? > > Anyway the attribution is made more explicit ? footnote 5 in > http://blog.languager.org/2015/03/whimsical-unicode.html. > > Note Terry Reedy's post who mainly objected was already acked earlier. > Ive just added one more ack? > And JFTR the 'publication' (O how archaic!) is the whole blog not a single page just as it is for any other dead-tree publication. > > > > > As for the content of the essay, it is currently rather unfocused. > > True. > > It > > appears to be more of a list of "here are some Unicode characters I think > > are interesting, divided into subgroups, oh and here are some I personally > > don't have any use for, which makes them silly" than any sort of discussion > > about the universality of Unicode. That makes it rather idiosyncratic and > > parochial. Why should obscure maths symbols be given more importance than > > obscure historical languages? > > Idiosyncratic ? parochial > > > > > > I think that the universality of Unicode could be explained in a single > > sentence: > > > > "It is the aim of Unicode to be the one character set anyone needs to > > represent every character, ideogram or symbol (but not necessarily distinct > > glyph) from any existing or historical human language." > > > > I can expand on that, but in a nutshell that is it. > > > > > > You state: > > > > "APL and Z Notation are two notable languages APL is a programming language > > and Z a specification language that did not tie themselves down to a > > restricted charset ..." > > Tsk Tsk ? dihonest snipping. I wrote > > | APL and Z Notation are two notable languages APL is a programming language > | and Z a specification language that did not tie themselves down to a > | restricted charset even in the day that ASCII ruled. > > so its clear that the restricted applies to ASCII > > > > You list ideographs such as Cuneiform under "Icons". They are not icons. > > They are a mixture of symbols used for consonants, syllables, and > > logophonetic, consonantal alphabetic and syllabic signs. That sits them > > firmly in the same categories as modern languages with consonants, ideogram > > languages like Chinese, and syllabary languages like Cheyenne. > > Ok changed to iconic. > Obviously 2-3 millenia ago, when people spoke hieroglyphs or cuneiform they were languages. > In 2015 when someone sees them and recognizes them, they are 'those things that > Sumerians/Egyptians wrote' No one except a rare expert knows those languages > > > > > Just because native readers of Cuneiform are all dead doesn't make Cuneiform > > unimportant. There are probably more people who need to write Cuneiform > > than people who need to write APL source code. > > > > You make a comment: > > > > "To me ? a unicode-layman ? it looks unprofessional? Billions of computing > > devices world over, each having billions of storage words having their > > storage wasted on blocks such as these??" > > > > But that is nonsense, and it contradicts your earlier quoting of Dave Angel. > > Why are you so worried about an (illusionary) minor optimization? > > 2 < 4 as far as I am concerned. > [If you disagree one man's illusionary is another's waking] > > > > > Whether code points are allocated or not doesn't affect how much space they > > take up. There are millions of unused Unicode code points today. If they > > are allocated tomorrow, the space your documents take up will not increase > > one byte. > > > > Allocating code points to Cuneiform has not increased the space needed by > > Unicode at all. Two bytes alone is not enough for even existing human > > languages (thanks China). For hardware related reasons, it is faster and > > more efficient to use four bytes than three, so the obvious and "dumb" (in > > the simplest thing which will work) way to store Unicode is UTF-32, which > > takes a full four bytes per code point, regardless of whether there are > > 65537 code points or 1114112. That makes it less expensive than floating > > point numbers, which take eight. Would you like to argue that floating > > point doubles are "unprofessional" and wasteful? > > > > As Dave pointed out, and you apparently agreed with him enough to quote him > > TWICE (once in each of two blog posts), history of computing is full of > > premature optimizations for space. (In fact, some of these may have been > > justified by the technical limitations of the day.) Technically Unicode is > > also limited, but it is limited to over one million code points, 1114112 to > > be exact, although some of them are reserved as invalid for technical > > reasons, and there is no indication that we'll ever run out of space in > > Unicode. > > > > In practice, there are three common Unicode encodings that nearly all > > Unicode documents will use. > > > > * UTF-8 will use between one and (by memory) four bytes per code > > point. For Western European languages, that will be mostly one > > or two bytes per character. > > > > * UTF-16 uses a fixed two bytes per code point in the Basic Multilingual > > Plane, which is enough for nearly all Western European writing and > > much East Asian writing as well. For the rest, it uses a fixed four > > bytes per code point. > > > > * UTF-32 uses a fixed four bytes per code point. Hardly anyone uses > > this as a storage format. > > > > > > In *all three cases*, the existence of hieroglyphs and cuneiform in Unicode > > doesn't change the space used. If you actually include a few hieroglyphs to > > your document, the space increases only by the actual space used by those > > hieroglyphs: four bytes per hieroglyph. At no time does the existence of a > > single hieroglyph in your document force you to expand the non-hieroglyph > > characters to use more space. > > > > > > > What I was trying to say expanded here > > > http://blog.languager.org/2015/03/whimsical-unicode.html > > > > You have at least two broken links, referring to a non-existent page: > > > > http://blog.languager.org/2015/03/unicode-universal-or-whimsical.html > > Thanks corrected > > > > > This essay seems to be even more rambling and unfocused than the first. What > > does the cost of semi-conductor plants have to do with whether or not > > programmers support Unicode in their applications? > > > > Your point about the UTF-8 "BOM" is valid only if you interpret it as a Byte > > Order Mark. But if you interpret it as an explicit UTF-8 signature or mark, > > it isn't so silly. If your text begins with the UTF-8 mark, treat it as > > UTF-8. It's no more silly than any other heuristic, like HTML encoding tags > > or text editor's encoding cookies. > > > > Your discussion of "complexifiers and simplifiers" doesn't seem to be > > terribly relevant, or at least if it is relevant, you don't give any reason > > for it. The whole thing about Moore's Law and the cost of semi-conductor > > plants seems irrelevant to Unicode except in the most over-generalised > > sense of "things are bigger today than in the past, we've gone from > > five-bit Baudot codes to 23 bit Unicode". Yeah, okay. So what's your point? > > - Most people need only 16 bits. > - Many notable examples of software fail going from 16 to 23. > - If you are a software writer, and you fail going 16 to 23 its ok but try to > give useful errors Uh? 21 Thats what makes 3 chars per 64-bit word a possibility. A possibility that can become realistic if/when Intel decides to add 'packed-unicode' string instructions. From zachary.ware+pylist at gmail.com Tue Mar 3 23:35:10 2015 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Tue, 3 Mar 2015 22:35:10 -0600 Subject: Setting PYTHONPATH does not allow importing module In-Reply-To: References: <2d13a257-797e-4481-a838-974128ffa81e@googlegroups.com> Message-ID: On Tue, Mar 3, 2015 at 9:47 PM, wrote: > On Tuesday, March 3, 2015 at 10:43:27 PM UTC-5, Zachary Ware wrote: >> Try adding /home/me/projects to PYTHONPATH instead of >> /home/me/projects/modulename. > > Ah, that worked! Yes, I see that the modulename must be visible. Thanks a lot! No problem, glad I could help :) -- Zach From rustompmody at gmail.com Tue Mar 3 23:45:13 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 3 Mar 2015 20:45:13 -0800 (PST) Subject: Newbie question about text encoding In-Reply-To: <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> References: <54EC5FA4.6070703@davea.name> <201502241455.t1OEtffT016452@fido.openend.se> <201502241507.t1OF7aUm018883@fido.openend.se> <201502241524.t1OFO09k022270@fido.openend.se> <201502241620.t1OGKf4n002146@fido.openend.se> <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> Message-ID: <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> On Wednesday, March 4, 2015 at 12:07:06 AM UTC+5:30, jmf wrote: > Le mardi 3 mars 2015 19:04:06 UTC+1, Rustom Mody a ?crit?: > > On Thursday, February 26, 2015 at 10:33:44 PM UTC+5:30, Terry Reedy wrote: > > > On 2/26/2015 8:24 AM, Chris Angelico wrote: > > > > On Thu, Feb 26, 2015 at 11:40 PM, Rustom Mody wrote: > > > >> Wrote something up on why we should stop using ASCII: > > > >> http://blog.languager.org/2015/02/universal-unicode.html > > > > > > I think that the main point of the post, that many Unicode chars are > > > truly planetary rather than just national/regional, is excellent. > > > > > > > > > You should add emoticons, but not call them or the above 'gibberish'. > > > I think that this part of your post is more 'unprofessional' than the > > > character blocks. It is very jarring and seems contrary to your main point. > > > > Ok Done > > > > References to gibberish removed from > > http://blog.languager.org/2015/02/universal-unicode.html > > > > What I was trying to say expanded here > > http://blog.languager.org/2015/03/whimsical-unicode.html > > [Hope the word 'whimsical' is less jarring and more accurate than 'gibberish'] > > ======== > > Emoji and Dingbats are now part of Unicode. > They should be considered as well as a "1" or a "a" > or a "mathematical alpha". > So, there is nothing special to say about them. > > jmf Maybe you missed this section: http://blog.languager.org/2015/03/whimsical-unicode.html#half-assed It lists some examples of software that somehow break/goof going from BMP-only unicode to 7.0 unicode. IOW the suggestion is that the the two-way classification - ASCII - Unicode is less useful and accurate than the 3-way - ASCII - BMP - Unicode Personally I would be pleased if ? were used for the math-lambda and ? left alone for Greek-speaking users' identifiers. However one should draw a line between personal preferences and a univeral(izable) standard. As of now, ? works in blogger whereas ? breaks blogger -- gets replaced by ?. Similar breakages are current in Java, Javascript, Emacs, Mysql, Idle and Windows, various fonts etc etc. [Only one of these is remotely connected with python] So BMP is practical, 7.0 is idealistic. You are free too pick ?? From rosuav at gmail.com Tue Mar 3 23:54:57 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 Mar 2015 15:54:57 +1100 Subject: Newbie question about text encoding In-Reply-To: <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> References: <54EC5FA4.6070703@davea.name> <201502241455.t1OEtffT016452@fido.openend.se> <201502241507.t1OF7aUm018883@fido.openend.se> <201502241524.t1OFO09k022270@fido.openend.se> <201502241620.t1OGKf4n002146@fido.openend.se> <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> Message-ID: On Wed, Mar 4, 2015 at 3:45 PM, Rustom Mody wrote: > > It lists some examples of software that somehow break/goof going from BMP-only > unicode to 7.0 unicode. > > IOW the suggestion is that the the two-way classification > - ASCII > - Unicode > > is less useful and accurate than the 3-way > > - ASCII > - BMP > - Unicode How is that more useful? Aside from storage optimizations (in which the significant breaks would be Latin-1, UCS-2, and UCS-4), the BMP is not significantly different from the rest of Unicode. Also, the expansion from 16-bit was back in Unicode 2.0, not 7.0. Why do you keep talking about 7.0 as if it's a recent change? ChrisA From rustompmody at gmail.com Wed Mar 4 00:05:40 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 3 Mar 2015 21:05:40 -0800 (PST) Subject: Newbie question about text encoding In-Reply-To: References: <54EC5FA4.6070703@davea.name> <201502241455.t1OEtffT016452@fido.openend.se> <201502241507.t1OF7aUm018883@fido.openend.se> <201502241524.t1OFO09k022270@fido.openend.se> <201502241620.t1OGKf4n002146@fido.openend.se> <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> Message-ID: <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> On Wednesday, March 4, 2015 at 10:25:24 AM UTC+5:30, Chris Angelico wrote: > On Wed, Mar 4, 2015 at 3:45 PM, Rustom Mody wrote: > > > > It lists some examples of software that somehow break/goof going from BMP-only > > unicode to 7.0 unicode. > > > > IOW the suggestion is that the the two-way classification > > - ASCII > > - Unicode > > > > is less useful and accurate than the 3-way > > > > - ASCII > > - BMP > > - Unicode > > How is that more useful? Aside from storage optimizations (in which > the significant breaks would be Latin-1, UCS-2, and UCS-4), the BMP is > not significantly different from the rest of Unicode. Sorry... Dont understand. > > Also, the expansion from 16-bit was back in Unicode 2.0, not 7.0. Why > do you keep talking about 7.0 as if it's a recent change? It is 2015 as of now. 7.0 is the current standard. The need for the adjective 'current' should be pondered upon. In practice, standards change. However if a standard changes so frequently that that users have to play catching cook and keep asking: "Which version?" they are justified in asking "Are the standard-makers doing due diligence?" From llanitedave at birdandflower.com Wed Mar 4 00:43:50 2015 From: llanitedave at birdandflower.com (llanitedave) Date: Tue, 3 Mar 2015 21:43:50 -0800 (PST) Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] In-Reply-To: References: <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> <87twy34dst.fsf@elektro.pacujo.net> <726afahrhnim716av2dnckrsd9n5j5kukj@4ax.com> <21dafa533nrsmktshd35kdbd13ahgj50bf@4ax.com> Message-ID: Seems the ultimate in irony when a language invented by a Dutchman and named after a British comedy troupe gets bogged down in an argument about whether its users are sufficiently "American". From ethan at stoneleaf.us Wed Mar 4 01:33:06 2015 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 03 Mar 2015 22:33:06 -0800 Subject: http: connection reset by peer Message-ID: <54F6A722.1000706@stoneleaf.us> This may seem off-topic, but it's an issue for my roundup server which is written in Python, so hopefully that will buy me some slack. ;) And, yes, I did post a message to the Roundup Users mailing list first, but haven't received any replies. So, the basic problem is: I login to the roundup server -- I can search, create new issues, post new messages via both email and the web interface, and I can attach files... but only via email; if I try to attach a file via the web interface I immediately get a connection reset message. I have tried with FireFox and Midori, with and without Apache in the middle as a proxy server, I have googled all day long looking for answers, and I've been coming up empty. The server is ubuntu 12.04, Roundup is at 1.5.0, and Firefox has been several versions, and Midori is 0.4.3. Roundup has been slightly modified to support timezones, reverse date order for listings, auto-nosy -- nothing major. Any clues greatly appreciated. -- ~Ethan~ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: OpenPGP digital signature URL: From felecislewis at yahoo.com Wed Mar 4 01:41:12 2015 From: felecislewis at yahoo.com (felecislewis) Date: Tue, 3 Mar 2015 22:41:12 -0800 (PST) Subject: Fun Approaches To Lose Weight Message-ID: <1425451272060-5088072.post@n6.nabble.com> How do you eat lentils? Garcinia Cambogia Gummy Silly question you could say but I would like to know tell you, don't eat lentils natural. Phytic acid and tannins are anti-nutrients that are inside the lentil seeds; your actually don't wish to ingest that. The preparation of lentil seeds is straightforward and speedy. Some forms of lentil seeds do need you to overnight soaked before cooking. Nonetheless, many do not involve the pre-treating, just boil over a stove-top or place in the stove. Twenty to half an hour is actually all it takes for cooking period; nevertheless it is determined by all of the the lentil seeds. And whatis good is that if you cook peas with additional foods, it rapidly absorbs the flavors in the additional food which makes it that much nicer. http://garciniawowfacts.com/garcinia-cambogia-gummy/ -- View this message in context: http://python.6.x6.nabble.com/Fun-Approaches-To-Lose-Weight-tp5088072.html Sent from the Python - python-list mailing list archive at Nabble.com. From cl at isbd.net Wed Mar 4 04:14:16 2015 From: cl at isbd.net (cl at isbd.net) Date: Wed, 4 Mar 2015 09:14:16 +0000 Subject: Setting PYTHONPATH does not allow importing module References: <2d13a257-797e-4481-a838-974128ffa81e@googlegroups.com> Message-ID: <80visb-t3s.ln1@esprimo.zbmc.eu> faruk at vt.edu wrote: > I have the following directory /home/me/projects/modulename. > > I update PYTHONPATH using the following command: > export PYTHONPATH=$PYTHONPATH:/home/me/projects/modulename > > It seems to have been added: > [me at machine ~]$ python -c "import sys; print(sys.path)" > ['',... '/home/me', '/home/me/projects/modulename', ...] > > But import modulename does not work: > [me at machine ~]$ python -c "import modulename" > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named modulename > Don't you have that one level wrong, to import you need the directory where the name is to be on PYTHONPATH. I.e. you should have:- export PYTHONPATH=$PYTHONPATH:/home/me/projects/ If you think about it this makes sense! -- Chris Green ? From rosuav at gmail.com Wed Mar 4 04:26:15 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 Mar 2015 20:26:15 +1100 Subject: http: connection reset by peer In-Reply-To: <54F6A722.1000706@stoneleaf.us> References: <54F6A722.1000706@stoneleaf.us> Message-ID: On Wed, Mar 4, 2015 at 5:33 PM, Ethan Furman wrote: > I login to the roundup server -- I can search, create new issues, post new messages via both email and the web > interface, and I can attach files... but only via email; if I try to attach a file via the web interface I immediately > get a connection reset message. > > I have tried with FireFox and Midori, with and without Apache in the middle as a proxy server, I have googled all day > long looking for answers, and I've been coming up empty. Do you have Mozilla Firebug, and if so, can you try the file attachment with Firebug active? At very least, you should be able to see exactly what request is getting reset, and then you could try to simulate that exact request with a simpler harness (like a Python program - see, on-topic now!). ChrisA From wxjmfauth at gmail.com Wed Mar 4 05:16:54 2015 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 4 Mar 2015 02:16:54 -0800 (PST) Subject: Newbie question about text encoding In-Reply-To: <54f6bee5$0$11122$c3e8da3@news.astraweb.com> References: <54EC5FA4.6070703@davea.name> <201502241455.t1OEtffT016452@fido.openend.se> <201502241507.t1OF7aUm018883@fido.openend.se> <201502241524.t1OFO09k022270@fido.openend.se> <201502241620.t1OGKf4n002146@fido.openend.se> <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <54f673e4$0$12980$c3e8da3$5496439d@news.astraweb.com> <601f597e-719a-4721-9620-1a7ea43de57d@googlegroups.com> <54f6bee5$0$11122$c3e8da3@news.astraweb.com> Message-ID: <0b4484c7-b213-49ee-9098-1eeeb3aabcb6@googlegroups.com> Le mercredi 4 mars 2015 09:14:42 UTC+1, Steven D'Aprano a ?crit?: > > o_O > > People don't speak hieroglyphs, except in Asterisk The Gaul comics. People > speak words. > > http://www.asterix.com/asterix-de-a-a-z/les-personnages/tumeheris.html jmf From fomcl at yahoo.com Wed Mar 4 07:12:17 2015 From: fomcl at yahoo.com (Albert-Jan Roskam) Date: Wed, 4 Mar 2015 04:12:17 -0800 Subject: io.open vs. codecs.open Message-ID: <1425471137.86149.YahooMailBasic@web163801.mail.gq1.yahoo.com> Hi, Is there a (use case) difference between codecs.open and io.open? What is the difference? A small difference that I just discovered is that codecs.open(somefile).read() returns a bytestring if no encoding is specified*), but a unicode string if an encoding is specified. io.open always returns a unicode string. *) I had never tried that before. I would have expected that encoding would default to e.g locale.getpreferredencoding(). Thank you! Regards, Albert-Jan ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From marko at pacujo.net Wed Mar 4 08:16:18 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 04 Mar 2015 15:16:18 +0200 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] References: <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> <87twy34dst.fsf@elektro.pacujo.net> <726afahrhnim716av2dnckrsd9n5j5kukj@4ax.com> <21dafa533nrsmktshd35kdbd13ahgj50bf@4ax.com> Message-ID: <87fv9k2999.fsf@elektro.pacujo.net> llanitedave : > Seems the ultimate in irony when a language invented by a Dutchman and > named after a British comedy troupe gets bogged down in an argument > about whether its users are sufficiently "American". No, the ultimate irony is that people don't understand what is being talked about. Reminds me of a situation decades back when a (Lutheran) Finnish theology professor was suspected of heresy. It went like this: Faithful Crowd: The professor won't accept the truth of the Bible even though the Bible states it is the word of God. Professor: You are saying the Bible is true because it says so. If that is a valid criterion, the Quran is even more obviously true. Faithful Crowd: Did you hear that! The professor's saying the Quran is truer than the Bible! Marko PS Before you get out your pitchforks, please note that this posting is *not* making a statement on the truth in the Bible and/or the Quran. From marfig at gmail.com Wed Mar 4 08:41:00 2015 From: marfig at gmail.com (Mario Figueiredo) Date: Wed, 04 Mar 2015 14:41:00 +0100 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] References: <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> <87twy34dst.fsf@elektro.pacujo.net> <726afahrhnim716av2dnckrsd9n5j5kukj@4ax.com> <21dafa533nrsmktshd35kdbd13ahgj50bf@4ax.com> <87fv9k2999.fsf@elektro.pacujo.net> Message-ID: On Wed, 04 Mar 2015 15:16:18 +0200, Marko Rauhamaa wrote: > >No, the ultimate irony is that people don't understand what is being >talked about. > Care to summarize then? Because the one thing I'm seeing is your assertion that people should write identifiers in a more standard way following an us-eng dialect and you jab at the British by accusing them of being more resistant to this than non-english speakers (which is just a blanket statement). From mal at europython.eu Wed Mar 4 08:49:30 2015 From: mal at europython.eu (M.-A. Lemburg) Date: Wed, 04 Mar 2015 14:49:30 +0100 Subject: EuroPython 2015: We've sold half of the available early-bird tickets already Message-ID: <54F70D6A.8020705@europython.eu> We have 350 early-bird tickets available. Half of those have been sold by now in an amazing rush to our registration page: *** https://ep2015.europython.eu/en/registration/ *** We would like to thank everyone who bought a ticket and put trust in us to make the conference an interesting and inspiring event - even without knowing the talks and topics which will be covered in the conference. We?d also like to apologize for the Paypal payment system not working yesterday. This is fixed, so you can use Paypal to pay your tickets if you don?t want to use a credit card. Enjoy, -- EuroPython 2015 Team http://www.europython-society.org/ From rustompmody at gmail.com Wed Mar 4 09:45:02 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 4 Mar 2015 06:45:02 -0800 (PST) Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] In-Reply-To: <87fv9k2999.fsf@elektro.pacujo.net> References: <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> <87twy34dst.fsf@elektro.pacujo.net> <726afahrhnim716av2dnckrsd9n5j5kukj@4ax.com> <21dafa533nrsmktshd35kdbd13ahgj50bf@4ax.com> <87fv9k2999.fsf@elektro.pacujo.net> Message-ID: On Wednesday, March 4, 2015 at 6:46:32 PM UTC+5:30, Marko Rauhamaa wrote: > llanitedave : > > > Seems the ultimate in irony when a language invented by a Dutchman and > > named after a British comedy troupe gets bogged down in an argument > > about whether its users are sufficiently "American". > > No, the ultimate irony is that people don't understand what is being > talked about. > > Reminds me of a situation decades back when a (Lutheran) Finnish > theology professor was suspected of heresy. It went like this: > > Faithful Crowd: The professor won't accept the truth of the Bible > even though the Bible states it is the word of God. > > Professor: You are saying the Bible is true because it says so. If > that is a valid criterion, the Quran is even more obviously true. > > Faithful Crowd: Did you hear that! The professor's saying the Quran > is truer than the Bible! > Ha! Ha!! Reminds me of Bertrand Russel's: Man is said to be a logical animal. All my life Ive tried to find evidence of that. From ewerybody at gmail.com Wed Mar 4 10:41:36 2015 From: ewerybody at gmail.com (ewerybody at gmail.com) Date: Wed, 4 Mar 2015 07:41:36 -0800 (PST) Subject: Unable to install xmldiff package on WIndows7 In-Reply-To: References: Message-ID: On Saturday, March 3, 2012 at 3:45:32 AM UTC+1, gwang wrote: > On Jan 3, 11:47 am, hisan wrote: > > Hi All > > > > i have downloaded "xmldiff-0.6.10" from their official site (http://www.logilab.org/859). > > I have tried installing the same on my 32 bit Windows 7 OS using the > > command "setup.py install" but below exceptions are thrown in the > > console. > > please help me out in installing this package on Windows > > > > Exceptions thrown while installing > > > > C:\Users\santosh\Downloads\xmldiff-0.6.10>setup.py build > > running build > > running build_py > > package init file '.\test\__init__.py' not found (or not a regular > > file) > > package init file '.\test\__init__.py' not found (or not a regular > > file) > > running build_ext > > building 'xmldiff.maplookup' extension > > gcc -mno-cygwin -mdll -O -Wall -ID:\Python26\include -ID:\Python26\PC - > > c extensions/maplookup.c -o b > > uild\temp.win32-2.6\Release\extensions\maplookup.o > > error: command 'gcc' failed: No such file or directory > > edit maplookup.c and comment away the line : #include . > At least that's what worked for me. Darn! This thing is quite dead isn't it? :/ I installed cygwin with the gcc for c and tried it with different versions of python. I always end up having this pile of errors: >In file included from C:/Python27/include/Python.h:58:0, > from extensions/maplookup.c:1: >C:/Python27/include/pyport.h:886:2: error: #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)." > #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)." > ^ >In file included from C:/Python27/include/Python.h:86:0, > from extensions/maplookup.c:1: >C:/Python27/include/intobject.h:46:35: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'PyInt_AsUnsignedLongLongMask' > PyAPI_FUNC(unsigned PY_LONG_LONG) PyInt_AsUnsignedLongLongMask(PyObject *); > ^ >In file included from C:/Python27/include/Python.h:88:0, > from extensions/maplookup.c:1: >C:/Python27/include/longobject.h:50:1: warning: parameter names (without types) in function declaration > PyAPI_FUNC(PyObject *) PyLong_FromLongLong(PY_LONG_LONG); > ^ >In file included from C:/Python27/include/Python.h:58:0, > from extensions/maplookup.c:1: >C:/Python27/include/pyconfig.h:302:23: error: unknown type name '__int64' > # define PY_LONG_LONG __int64 > ^ >C:/Python27/include/pyport.h:793:34: note: in definition of macro 'PyAPI_FUNC' > # define PyAPI_FUNC(RTYPE) RTYPE > ^ >C:/Python27/include/longobject.h:52:12: note: in expansion of macro 'PY_LONG_LONG' > PyAPI_FUNC(PY_LONG_LONG) PyLong_AsLongLong(PyObject *); > ^ >In file included from C:/Python27/include/Python.h:88:0, > from extensions/maplookup.c:1: >C:/Python27/include/longobject.h:53:35: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'PyLong_AsUnsignedLongLong' > PyAPI_FUNC(unsigned PY_LONG_LONG) PyLong_AsUnsignedLongLong(PyObject *); > ^ >C:/Python27/include/longobject.h:54:35: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'PyLong_AsUnsignedLongLongMask' > PyAPI_FUNC(unsigned PY_LONG_LONG) PyLong_AsUnsignedLongLongMask(PyObject *); > ^ >In file included from C:/Python27/include/Python.h:58:0, > from extensions/maplookup.c:1: >C:/Python27/include/pyconfig.h:302:23: error: unknown type name '__int64' > # define PY_LONG_LONG __int64 > ^ >C:/Python27/include/pyport.h:793:34: note: in definition of macro 'PyAPI_FUNC' > # define PyAPI_FUNC(RTYPE) RTYPE > ^ >C:/Python27/include/longobject.h:55:12: note: in expansion of macro 'PY_LONG_LONG' > PyAPI_FUNC(PY_LONG_LONG) PyLong_AsLongLongAndOverflow(PyObject *, int *); well... that was a x64 cygwin. Didn't try with a 32 one yet but with py26,27,27_64 no difference. After all: This project has quite some dust already. Is there no alternative?!?! I can't believe nodal diffing hasen't evolved... From ethan at stoneleaf.us Wed Mar 4 10:58:49 2015 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 04 Mar 2015 07:58:49 -0800 Subject: http: connection reset by peer In-Reply-To: References: <54F6A722.1000706@stoneleaf.us> Message-ID: <54F72BB9.9000207@stoneleaf.us> On 03/04/2015 01:26 AM, Chris Angelico wrote: > On Wed, Mar 4, 2015 at 5:33 PM, Ethan Furman wrote: >> >> I login to the roundup server -- I can search, create new issues, post new messages via both email and the web >> interface, and I can attach files... but only via email; if I try to attach a file via the web interface I immediately >> get a connection reset message. >> >> I have tried with FireFox and Midori, with and without Apache in the middle as a proxy server, I have googled all day >> long looking for answers, and I've been coming up empty. > > Do you have Mozilla Firebug, and if so, can you try the file > attachment with Firebug active? I do, and I'll try. > At very least, you should be able to > see exactly what request is getting reset, and then you could try to > simulate that exact request with a simpler harness (like a Python > program - see, on-topic now!). Heh, thanks. -- ~Ethan~ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: OpenPGP digital signature URL: From marko at pacujo.net Wed Mar 4 11:55:00 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 04 Mar 2015 18:55:00 +0200 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] References: <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> <87twy34dst.fsf@elektro.pacujo.net> <726afahrhnim716av2dnckrsd9n5j5kukj@4ax.com> <21dafa533nrsmktshd35kdbd13ahgj50bf@4ax.com> <87fv9k2999.fsf@elektro.pacujo.net> Message-ID: <87a8zs3dp7.fsf@elektro.pacujo.net> Mario Figueiredo : > Care to summarize then? > > Because the one thing I'm seeing is your assertion that people should > write identifiers in a more standard way following an us-eng dialect > and you jab at the British by accusing them of being more resistant to > this than non-english speakers (which is just a blanket statement). I don't remember jabbing at anybody. It is fact (proudly proclaimed on this forum as well) that most English-speakers believe their native accents are suitable for international communication. Marko From leighhaugen at gmail.com Wed Mar 4 14:00:29 2015 From: leighhaugen at gmail.com (Leigh Haugen) Date: Wed, 4 Mar 2015 11:00:29 -0800 (PST) Subject: Senior Python Applications Developer/Leader. Michigan contract @$90/hr. Skills: Agile, Java, PHP, HTML5, CSS3, JavaScript, jQuery, Amazon Web Services (AWS) Message-ID: Senior Python Applications Developer/Leader. Key Skills: Agile, Java, PHP, HTML5, CSS3, JavaScript, jQuery, Amazon Web Services (AWS) Direct client. H1B is OK. Ann Arbor, Michigan. Initial six month contract, probably good through the end of 2015. We can pay up to $90/hr. & possibly higher for the right candidate. Skills, Experience, and Characteristics ? Proven experience in Object Oriented programming using Java, Python or PHP (at least one year of Python experience is required). ? Experience using MVC frameworks like Spring, Django or Zend. ? Experience using profiling tools to analyze and optimize application performance like App Dynamics and New Relic. ? Familiarity with HTML, CSS, and JavaScript including common libraries like jQuery, Foundation, and Backbone. ? Familiarity with web technology stack (e.g. HTTP, cookies, headers, caching, CDN, and security). ? Willingness and ability to learn new approaches and emerging technology. ? Strong communication and interpersonal skills. The Role This Software Developer position is for our development team to implement critical reporting capabilities. You will be designing, developing and maintaining applications and APIs that are deployed on our cloud delivered platform. You will be a crucial part of a dynamic, energized and agile team delivering leading edge reporting solutions. Our organization and this role will provide you with an opportunity few other companies can offer including: ? Leveraging technologies including: AWS, Java, Python, and HDFS. ? Agile teams that follow continuous deployment and test automation best practices allowing for rapid application development and frequent deployments. We complete an average of 80 production deployments each week. ? Developers are using the same architecture, technologies and tools as companies like Netflix, Etsy, and Amazon.com. ? This is a unique opportunity to be on the leading edge of building large-scale, cloud delivered web applications that host hundreds of millions of sessions annually. When joining the development team, you can expect to receive tool and product training. We have an excellent on-boarding program, which enables new engineers to become productive very quickly. A lead will work closely with you as you begin engaging your assigned agile team. We will provide you with constant support as we work to make you comfortable in your new environment. Those in leadership roles will work tirelessly to set you up for success. Leigh Haugen Managing Partner KDMM / eTek leigh at kdmmcorp.com (248) 719-0789 From steve+comp.lang.python at pearwood.info Wed Mar 4 14:14:37 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 05 Mar 2015 06:14:37 +1100 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] References: <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> <87twy34dst.fsf@elektro.pacujo.net> <726afahrhnim716av2dnckrsd9n5j5kukj@4ax.com> <21dafa533nrsmktshd35kdbd13ahgj50bf@4ax.com> <87fv9k2999.fsf@elektro.pacujo.net> Message-ID: <54f7599d$0$12988$c3e8da3$5496439d@news.astraweb.com> Marko Rauhamaa wrote: > llanitedave : > >> Seems the ultimate in irony when a language invented by a Dutchman and >> named after a British comedy troupe gets bogged down in an argument >> about whether its users are sufficiently "American". > > No, the ultimate irony is that people don't understand what is being > talked about. Care to enlighten us then? Because your anecdote doesn't appear to have even the most tenuous relationship to this discussion. > Reminds me of a situation decades back when a (Lutheran) Finnish > theology professor was suspected of heresy. It went like this: [...] -- Steven From mount.sarah at gmail.com Wed Mar 4 14:20:55 2015 From: mount.sarah at gmail.com (Sarah Mount) Date: Wed, 4 Mar 2015 19:20:55 +0000 Subject: Call for Papers - Programming Language Evolution Workshop 2015 Message-ID: 2nd Workshop on Programming Language Evolution (PLE) 2015 (colocated with ECOOP 2015, Prague, Czech Republic) http://2015.ecoop.org/track/PLE-2015-papers Call for papers --------------- Programming languages tend to evolve in response to user needs, hardware advances, and research developments. Language evolution artefacts may include new compilers and interpreters or new language standards. Evolving programming languages is however challenging at various levels. Firstly, the impact on developers can be negative. For example, if two language versions are incompatible (e.g., Python 2 and 3) developers must choose to either co-evolve their codebase (which may be costly) or reject the new language version (which may have support implications). Secondly, evaluating a proposed language change is difficult; language designers often lack the infrastructure to assess the change. This may lead to older features remaining in future language versions to maintain backward compatibility, increasing the language's complexity (e.g., FORTRAN 77 to Fortran 90). Thirdly, new language features may interact badly with existing features, leading to unforeseen bugs and ambiguities (e.g., the addition of Java generics). This workshop brings together researchers and developers to tackle the important challenges faced by programming language evolution, to share new ideas and insights, and to advance programming language design. Topics include (but are not limited to): * Programming language and software co-evolution * Empirical studies and evidence-driven evolution * Language-version integration and interoperation * Historical retrospectives and experience reports * Tools and IDE support for source-code mining and refactoring/rejuvenation * Gradual feature introductions (e.g., optional type systems) We are accepting two kinds of submission: * Full papers (maximum 8 pages, ACM SIGPLAN 2 column, 9pt) * Talk abstracts (may include an extended abstract, upto 3 pages in ACM SIGPLAN format). We are proud to be supported by the Software Sustainability Institute (http://software.ac.uk) Submission and publication -------------------------- Please submit your abstracts/papers via EasyChair (https://easychair.org/conferences/?conf=ple15). Papers will be subject to full peer review, and talk abstracts will be subject to light peer-review/selection. Accepted submissions will be published in the ACM DL. Any paper submitted must adhere to ACM SIGPLAN's republication policy. If you have any questions relating to the suitability of a submission please contact the program chairs at ple15 at easychair.org. Important dates --------------- All deadlines are 'anywhere-on-Earth'. * Submission: Thursday 2nd April 2015 * Notification: Friday 1st May 2015 * Workshop: Tuesday 7th July 2015 Workshop format --------------- The workshop schedule will comprise presentations given for accepted papers, short talks, and a keynote presentation by Bjarne Stroustrup. Depending on submissions, an afternoon discussion may be included. Workshop organisation --------------------- Program chairs: * Raoul-Gabriel Urma (raoul.urma at cl.cam.ac.uk) * Dominic Orchard (d.orchard at imperial.ac.uk) General chair: * Alan Mycroft Program committee: * Heather Miller (Ecole Polytechnique Federale de Lausanne, Switzerland) * Sarah Mount (University of Wolverhampton, UK) * Alan Mycroft (University of Cambridge, UK) * Dominic Orchard (co-chair) (Imperial College London, UK) * Jeff Overbey (Auburn University, AL, US) * Max Schaefer (Semmle Ltd., Oxford, UK) * Raoul-Gabriel Urma (co-chair) (University of Cambridge, UK) -- Dr. Sarah Mount, Senior Lecturer, University of Wolverhampton website: http://www.snim2.org/ twitter: @snim2 -------------- next part -------------- An HTML attachment was scrubbed... URL: From ginellobadellu at mail.com Wed Mar 4 14:21:30 2015 From: ginellobadellu at mail.com (MEMOCHE UNO) Date: Wed, 4 Mar 2015 11:21:30 -0800 (PST) Subject: -- redacted -- In-Reply-To: <4f5ceab4-d175-4b96-829b-8c8fab7f77f0@googlegroups.com> References: <4f5ceab4-d175-4b96-829b-8c8fab7f77f0@googlegroups.com> Message-ID: <45fca5b3-becf-4242-b88f-bac6378a1367@googlegroups.com> -- redacted -- From ginellobadellu at mail.com Wed Mar 4 14:23:29 2015 From: ginellobadellu at mail.com (MEMOCHE UNO) Date: Wed, 4 Mar 2015 11:23:29 -0800 (PST) Subject: -- redacted -- Message-ID: <29b591ce-669f-43e8-b571-bfa13c2483b1@googlegroups.com> -- redacted -- From ethan at stoneleaf.us Wed Mar 4 14:28:05 2015 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 04 Mar 2015 11:28:05 -0800 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] In-Reply-To: <54f7599d$0$12988$c3e8da3$5496439d@news.astraweb.com> References: <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> <87twy34dst.fsf@elektro.pacujo.net> <726afahrhnim716av2dnckrsd9n5j5kukj@4ax.com> <21dafa533nrsmktshd35kdbd13ahgj50bf@4ax.com> <87fv9k2999.fsf@elektro.pacujo.net> <54f7599d$0$12988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <54F75CC5.7010405@stoneleaf.us> On 03/04/2015 11:14 AM, Steven D'Aprano wrote: > > [...] > > > Wow -- a new level of succinctness! ;) -- ~Ethan~ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: OpenPGP digital signature URL: From marko at pacujo.net Wed Mar 4 14:33:01 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 04 Mar 2015 21:33:01 +0200 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] References: <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> <87twy34dst.fsf@elektro.pacujo.net> <726afahrhnim716av2dnckrsd9n5j5kukj@4ax.com> <21dafa533nrsmktshd35kdbd13ahgj50bf@4ax.com> <87fv9k2999.fsf@elektro.pacujo.net> <54f7599d$0$12988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8761ag36du.fsf@elektro.pacujo.net> Steven D'Aprano : > Care to enlighten us then? Because your anecdote doesn't appear to > have even the most tenuous relationship to this discussion. English-speaker, when you name things in your Python programs, you had better stick to American spellings. Even more important, when you talk about Python or other computer stuff to a non-English-speaker, try to emulate the accent most people around the world are most familiar with, American English. If you find that overwhelming, try to speak like a BBC newsreader. Your native accent can be very difficult to understand. Marko From steve+comp.lang.python at pearwood.info Wed Mar 4 14:56:08 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 05 Mar 2015 06:56:08 +1100 Subject: io.open vs. codecs.open References: Message-ID: <54f76359$0$13012$c3e8da3$5496439d@news.astraweb.com> Albert-Jan Roskam wrote: > Hi, > > Is there a (use case) difference between codecs.open and io.open? What is > the difference? A small difference that I just discovered is that > codecs.open(somefile).read() returns a bytestring if no encoding is > specified*), but a unicode string if an encoding is specified. io.open > always returns a unicode string. What version of Python are you using? In Python 3, io.open is used as the built-in open. I believe this is guaranteed, and not just an implementation detail. The signatures and capabilities are quite different: codecs.open: open(filename, mode='rb', encoding=None, errors='strict', buffering=1) io.open: open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None) io.open does *not* always produce Unicode strings. If you pass 'rb' as the mode, the file is opened in binary mode, not text mode, and the read() method will return bytes. As usual, help() in the interactive interpreter is your friend. help(codecs.open) and help(io.open) will explain the many differences between them, including that codecs.open always opens the file in binary mode. As for use-cases, I think that codecs.open is mostly a left-over from the Python 2 days when the built-in open had a much simpler interface and fewer capabilities. In Python 2, built-in open doesn't take an encoding argument, so if you want to use something other than binary mode or the default encoding, you were supposed to use codecs.open. In Python 2.6, the io module was added to Python 2 to aid in porting to Python 3. The docs say: New in version 2.6. The io module provides the Python interfaces to stream handling. Under Python 2.x, this is proposed as an alternative to the built-in file object, but in Python 3.x it is the default interface to access files and streams. https://docs.python.org/2/library/io.html To summarise: * In Python 2, if you want to supply an encoding to open, use codecs.open (before 2.6) or io.open (2.6 and later); * If you want the enhanced capabilities of Python 3 open, use io.open; * In Python 3, io.open is the same thing as built-in open; * And codecs.open is (I think) mostly there for backwards compatibility. -- Steven From random832 at fastmail.us Wed Mar 4 15:00:56 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Wed, 04 Mar 2015 15:00:56 -0500 Subject: io.open vs. codecs.open In-Reply-To: <1425471137.86149.YahooMailBasic@web163801.mail.gq1.yahoo.com> References: <1425471137.86149.YahooMailBasic@web163801.mail.gq1.yahoo.com> Message-ID: <1425499256.1921729.235572821.6D2347F6@webmail.messagingengine.com> On Wed, Mar 4, 2015, at 07:12, Albert-Jan Roskam wrote: > Hi, > > Is there a (use case) difference between codecs.open and io.open? What is > the difference? > A small difference that I just discovered is that > codecs.open(somefile).read() returns a bytestring if no encoding is > specified*), but a unicode string if an encoding is specified. io.open > always returns a unicode string. I think this is a historical accident. Originally, in python 2, built-in open only returned byte strings. Later, codecs was added, and then io was added after that. Python 3 changed the built-in functions to use the same classes as io, and now io.open and built-in open are the same. In new Python 3 code, you should probably always use builtin open. Use binary mode (mode option has "b" in it) if you want byte strings. From breamoreboy at yahoo.co.uk Wed Mar 4 15:10:52 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 04 Mar 2015 20:10:52 +0000 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] In-Reply-To: <8761ag36du.fsf@elektro.pacujo.net> References: <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> <87twy34dst.fsf@elektro.pacujo.net> <726afahrhnim716av2dnckrsd9n5j5kukj@4ax.com> <21dafa533nrsmktshd35kdbd13ahgj50bf@4ax.com> <87fv9k2999.fsf@elektro.pacujo.net> <54f7599d$0$12988$c3e8da3$5496439d@news.astraweb.com> <8761ag36du.fsf@elektro.pacujo.net> Message-ID: On 04/03/2015 19:33, Marko Rauhamaa wrote: > Steven D'Aprano : > >> Care to enlighten us then? Because your anecdote doesn't appear to >> have even the most tenuous relationship to this discussion. > > English-speaker, when you name things in your Python programs, you had > better stick to American spellings. > > Even more important, when you talk about Python or other computer stuff > to a non-English-speaker, try to emulate the accent most people around > the world are most familiar with, American English. If you find that > overwhelming, try to speak like a BBC newsreader. Your native accent can > be very difficult to understand. > > > Marko > This sums up perfectly why you made it onto my dream team so quickly. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From steve+comp.lang.python at pearwood.info Wed Mar 4 15:11:21 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 05 Mar 2015 07:11:21 +1100 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] References: <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> <87twy34dst.fsf@elektro.pacujo.net> <726afahrhnim716av2dnckrsd9n5j5kukj@4ax.com> <21dafa533nrsmktshd35kdbd13ahgj50bf@4ax.com> <87fv9k2999.fsf@elektro.pacujo.net> <54f7599d$0$12988$c3e8da3$5496439d@news.astraweb.com> <8761ag36du.fsf@elektro.pacujo.net> Message-ID: <54f766ea$0$12992$c3e8da3$5496439d@news.astraweb.com> Marko Rauhamaa wrote: > Steven D'Aprano : > >> Care to enlighten us then? Because your anecdote doesn't appear to >> have even the most tenuous relationship to this discussion. > > English-speaker, when you name things in your Python programs, you had > better stick to American spellings. > > Even more important, when you talk about Python or other computer stuff > to a non-English-speaker, try to emulate the accent most people around > the world are most familiar with, American English. If you find that > overwhelming, try to speak like a BBC newsreader. Your native accent can > be very difficult to understand. Yes, that's exactly what I thought your point was. So I am utterly perplexed why you said: "No, the ultimate irony is that people don't understand what is being talked about." and gave an irrelevant anecdote about using a source's claim to divinity as evidence of divinity. It seems to me that people in this thread *do* understand what is being talked about, but just disagree with your conclusion about making American English the mandatory spelling for programs. As for your comments about spoken accents, I sympathise. But changing accents is very hard for most people (although a very few people find it incredibly easy). Even professionals typically need to have voice coaches to teach them to change accents successfully. One of the problems is that most people don't hear their own accent. My wife usually has a fairly generic English accent that most people think is American, but within seconds of beginning to talk to another Irish person she is speaking in a full-blown Irish accent, and she is *completely* unaware of it. -- Steven From breamoreboy at yahoo.co.uk Wed Mar 4 15:15:59 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 04 Mar 2015 20:15:59 +0000 Subject: io.open vs. codecs.open In-Reply-To: <54f76359$0$13012$c3e8da3$5496439d@news.astraweb.com> References: <54f76359$0$13012$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 04/03/2015 19:56, Steven D'Aprano wrote: > Albert-Jan Roskam wrote: > >> Hi, >> >> Is there a (use case) difference between codecs.open and io.open? What is >> the difference? A small difference that I just discovered is that >> codecs.open(somefile).read() returns a bytestring if no encoding is >> specified*), but a unicode string if an encoding is specified. io.open >> always returns a unicode string. > > What version of Python are you using? > > In Python 3, io.open is used as the built-in open. I believe this is > guaranteed, and not just an implementation detail. > > The signatures and capabilities are quite different: > > codecs.open: > > open(filename, mode='rb', encoding=None, errors='strict', buffering=1) > > io.open: > > open(file, mode='r', buffering=-1, encoding=None, > errors=None, newline=None, closefd=True, opener=None) > > io.open does *not* always produce Unicode strings. If you pass 'rb' as the > mode, the file is opened in binary mode, not text mode, and the read() > method will return bytes. > > As usual, help() in the interactive interpreter is your friend. > help(codecs.open) and help(io.open) will explain the many differences > between them, including that codecs.open always opens the file in binary > mode. > > As for use-cases, I think that codecs.open is mostly a left-over from the > Python 2 days when the built-in open had a much simpler interface and fewer > capabilities. In Python 2, built-in open doesn't take an encoding argument, > so if you want to use something other than binary mode or the default > encoding, you were supposed to use codecs.open. > > In Python 2.6, the io module was added to Python 2 to aid in porting to > Python 3. The docs say: > > New in version 2.6. > > The io module provides the Python interfaces to stream handling. > Under Python 2.x, this is proposed as an alternative to the > built-in file object, but in Python 3.x it is the default > interface to access files and streams. > > https://docs.python.org/2/library/io.html > > > To summarise: > > * In Python 2, if you want to supply an encoding to open, use codecs.open > (before 2.6) or io.open (2.6 and later); > > * If you want the enhanced capabilities of Python 3 open, use io.open; > > * In Python 3, io.open is the same thing as built-in open; > > * And codecs.open is (I think) mostly there for backwards compatibility. > See http://bugs.python.org/issue8796 "Deprecate codecs.open()". -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From auriocus at gmx.de Wed Mar 4 15:27:43 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Wed, 04 Mar 2015 21:27:43 +0100 Subject: Python Worst Practices In-Reply-To: References: <54f1154c$0$12985$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 04.03.15 um 00:12 schrieb Chris Angelico: > The problems come from needing more than two components at each step, > like with string formatting. You could write it like this: > > "Hello, %s from %s!" % name % location > > but then it'd be really hard to track down errors - the modulo > operator would have to handle the first percent sign and leave any > others unchanged. Plus there'd need to be some weird and funky magic > to mark the "current interpolation position" in order to cope with %% > becoming %, and the possibility that the person's name contains a > percent sign. boost::format does it like this, but not in a magic string processing way as you desribe it. The string is parsed and some funny template magic ensures that the arguments are inserted into it. >>> Operator overloading in each case here is "cute", not optimally practical. >> >> Maybe just sub-optimal? With today's C++ one could use a variadic >> template and still have type-safe compile-time bound output formatting. >> This hasn't been possible in the original iostream library back then. > > I'm not sure how that would work, but the main question is: How is it > advantageous over a simple call? Actually, here's a simple way to do > it: Make the stream object callable. > > cout("Hello, world!\n"); Well variadic templates make it possible to do this: string name="Chris"; int age=36; cout("Hello ", name, "your age is ", age); with any number of arguments of any (supported) type. This seems trivial in Python, but is quite hard to do for a statically compiled language. A type-safe printf-style function is one of the prime examples for variadic templates: http://en.wikipedia.org/wiki/Variadic_template > You can take as many args as you want, precedence and associativity > won't bite you, and it still reads reasonably well. The operator > method has to prove that it's better than that. Agreed. The operator method was necessary in C++ because there simply was no other way to create this interface. C++11 gained a lot more features, but iostreams is still the thing from the very first design of C++. Christian From timothy.c.delaney at gmail.com Wed Mar 4 15:40:21 2015 From: timothy.c.delaney at gmail.com (Tim Delaney) Date: Thu, 5 Mar 2015 07:40:21 +1100 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] In-Reply-To: <54f766ea$0$12992$c3e8da3$5496439d@news.astraweb.com> References: <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> <87twy34dst.fsf@elektro.pacujo.net> <726afahrhnim716av2dnckrsd9n5j5kukj@4ax.com> <21dafa533nrsmktshd35kdbd13ahgj50bf@4ax.com> <87fv9k2999.fsf@elektro.pacujo.net> <54f7599d$0$12988$c3e8da3$5496439d@news.astraweb.com> <8761ag36du.fsf@elektro.pacujo.net> <54f766ea$0$12992$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5 March 2015 at 07:11, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > > As for your comments about spoken accents, I sympathise. But changing > accents is very hard for most people (although a very few people find it > incredibly easy). Even professionals typically need to have voice coaches > to teach them to change accents successfully. One of the problems is that > most people don't hear their own accent. My wife usually has a fairly > generic English accent that most people think is American, but within > seconds of beginning to talk to another Irish person she is speaking in a > full-blown Irish accent, and she is *completely* unaware of it. This is very much the case - any time someone is reacquainted with their native accent they tend to strongly slip back into it, and it takes some time to get their more neutral accent back. A related thing is when you have multiple multi-lingual people talking together where at least two of their languages match (or are close enough for most uses e.g. Spanish and Portuguese). They'll slip in and out of multiple languages depending on which best expresses what they're trying to say, and no one will involved realise. Tim Delaney -------------- next part -------------- An HTML attachment was scrubbed... URL: From emile at fenx.com Wed Mar 4 17:39:29 2015 From: emile at fenx.com (Emile van Sebille) Date: Wed, 04 Mar 2015 14:39:29 -0800 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] In-Reply-To: References: <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> <87twy34dst.fsf@elektro.pacujo.net> <726afahrhnim716av2dnckrsd9n5j5kukj@4ax.com> <21dafa533nrsmktshd35kdbd13ahgj50bf@4ax.com> <87fv9k2999.fsf@elektro.pacujo.net> <54f7599d$0$12988$c3e8da3$5496439d@news.astraweb.com> <8761ag36du.fsf@elektro.pacujo.net> <54f766ea$0$12992$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/4/2015 12:40 PM, Tim Delaney wrote: > A related thing is when you have multiple multi-lingual people talking > together where at least two of their languages match (or are close > enough for most uses e.g. Spanish and Portuguese). They'll slip in and > out of multiple languages depending on which best expresses what they're > trying to say, and no one will involved realise. Except for my poor grandmother who hadn't understood a word my mother had said the previous ten minutes. :) Emile From timothy.c.delaney at gmail.com Wed Mar 4 18:36:07 2015 From: timothy.c.delaney at gmail.com (Tim Delaney) Date: Thu, 5 Mar 2015 10:36:07 +1100 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] In-Reply-To: References: <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> <87twy34dst.fsf@elektro.pacujo.net> <726afahrhnim716av2dnckrsd9n5j5kukj@4ax.com> <21dafa533nrsmktshd35kdbd13ahgj50bf@4ax.com> <87fv9k2999.fsf@elektro.pacujo.net> <54f7599d$0$12988$c3e8da3$5496439d@news.astraweb.com> <8761ag36du.fsf@elektro.pacujo.net> <54f766ea$0$12992$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5 March 2015 at 09:39, Emile van Sebille wrote: > On 3/4/2015 12:40 PM, Tim Delaney wrote: > >> A related thing is when you have multiple multi-lingual people talking >> together where at least two of their languages match (or are close >> enough for most uses e.g. Spanish and Portuguese). They'll slip in and >> out of multiple languages depending on which best expresses what they're >> trying to say, and no one will involved realise. >> > > Except for my poor grandmother who hadn't understood a word my mother had > said the previous ten minutes. :) The phenomenon I'm talking about involves people switching languages mid-sentence without the participants noticing. It mainly occurs with people who grew up speaking multiple languages, and commonly switch between them in their thoughts. If your grandmother learned her second/third/etc languages after she was a teenager then it's likely she mainly thinks in one language and translates to others. It can also be seen with people who have recently had long-term saturation exposure to a second language - for example, exchange students who have just come back from a year's stay. When I'd recently returned from Brasil (20-odd years ago now ...) there was one time when everyone was a native (Australia) english speaker and had a mix of latin-based second languages - that was close enough for it to happen. Tim Delaney -------------- next part -------------- An HTML attachment was scrubbed... URL: From xiaokun3 at gmail.com Wed Mar 4 20:34:04 2015 From: xiaokun3 at gmail.com (Xrrific) Date: Wed, 4 Mar 2015 17:34:04 -0800 (PST) Subject: HELP!! How to ask a girl out with a simple witty Python code?? Message-ID: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> Guys, please Help!!! I am trying to impress a girl who is learning python and want ask her out at the same time. Could you please come up with something witty incorporating a simple python line like If...then... but..etc. You will make me a very happy man!!! Thank you very much!!! From marcos.al.azevedo at gmail.com Wed Mar 4 20:37:21 2015 From: marcos.al.azevedo at gmail.com (Marcos Almeida Azevedo) Date: Thu, 5 Mar 2015 09:37:21 +0800 Subject: HELP!! How to ask a girl out with a simple witty Python code?? In-Reply-To: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> References: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> Message-ID: Why does it need to be nerdy. Why not just buy her a good book on Python? On Thu, Mar 5, 2015 at 9:34 AM, Xrrific wrote: > Guys, please Help!!! > > I am trying to impress a girl who is learning python and want ask her out > at the same time. > > Could you please come up with something witty incorporating a simple > python line like If...then... but..etc. > > You will make me a very happy man!!! > > Thank you very much!!! > -- > https://mail.python.org/mailman/listinfo/python-list > -- Marcos | I love PHP, Linux, and Java -------------- next part -------------- An HTML attachment was scrubbed... URL: From sohcahtoa82 at gmail.com Wed Mar 4 20:44:01 2015 From: sohcahtoa82 at gmail.com (sohcahtoa82 at gmail.com) Date: Wed, 4 Mar 2015 17:44:01 -0800 (PST) Subject: HELP!! How to ask a girl out with a simple witty Python code?? In-Reply-To: References: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> Message-ID: <73f6248f-04bd-44ed-bb1d-3b8c7bc6667e@googlegroups.com> Something something don't top post. Add responses to the bottom. BLah blah blah On Wednesday, March 4, 2015 at 5:37:55 PM UTC-8, Marcos Almeida Azevedo wrote: > Why does it need to be nerdy. Why not just buy her a good book on Python? > > > > On Thu, Mar 5, 2015 at 9:34 AM, Xrrific wrote: > Guys, please Help!!! > > > > I am trying to impress a girl who is learning python and want ask her out at the same time. > > > > Could you please come up with something witty incorporating a simple python line like If...then... but..etc. > > > > You will make me a very happy man!!! > > > > Thank you very much!!! > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > Marcos | I love PHP, Linux, and Java Because nothing is quite as romantic as a Python book, right? From roy at panix.com Wed Mar 4 20:46:50 2015 From: roy at panix.com (Roy Smith) Date: Wed, 04 Mar 2015 20:46:50 -0500 Subject: HELP!! How to ask a girl out with a simple witty Python code?? References: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> Message-ID: In article <8c09473e-92df-40ac-b083-d2b3a2b75188 at googlegroups.com>, Xrrific wrote: > Guys, please Help!!! > > I am trying to impress a girl who is learning python and want ask her out at > the same time. > > Could you please come up with something witty incorporating a simple python > line like If...then... but..etc. > > You will make me a very happy man!!! > > Thank you very much!!! I don't know about witty, but I'm sure you guys will make a cute tuple. From tjreedy at udel.edu Wed Mar 4 20:50:10 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 04 Mar 2015 20:50:10 -0500 Subject: HELP!! How to ask a girl out with a simple witty Python code?? In-Reply-To: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> References: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> Message-ID: On 3/4/2015 8:34 PM, Xrrific wrote: > Guys, please Help!!! Gals might know better how to impress a girl. > I am trying to impress a girl who is learning python and want ask her out at the same time. Start by not being sexist about the fitness of females for Python programming. Make sure she knows that at least parts of the Python community welcomes anybody and everybody. PyLadies is one example of that. -- Terry Jan Reedy From ryan.stuart.85 at gmail.com Wed Mar 4 21:00:50 2015 From: ryan.stuart.85 at gmail.com (Ryan Stuart) Date: Thu, 05 Mar 2015 02:00:50 +0000 Subject: HELP!! How to ask a girl out with a simple witty Python code?? References: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> Message-ID: On Thu, 5 Mar 2015 at 11:35 Xrrific wrote: > Could you please come up with something witty incorporating a simple > python line like If...then... but..etc. > Send her this: import base64 print(base64.b64decode('CkhpLCAKVGhpcyBpcyBzb21lb25lIGZyb20gdGhlIHB5dGhvbiBtYWlsaW5nIGxpc3QuIFRoaXMgZ3V5IChoZSBwb3N0ZWQgdW5kZXIgdGhlIG5hbWUgYFhycmlmaWNgKSBwb3N0ZWQgaGVyZSBhc2tpbmcgZm9yIHNvbWUgY29kZSB0aGF0IHdvdWxkIGltcHJlc3MgeW91LiBJdCB3YXMgdmVyeSB0ZW1wdGluZyB0byBwdXQgc29tZXRoaW5nIHZlcnkgb2ZmZW5zaXZlIGluIHRoaXMgbWVzc2FnZSEgUmF0aGVyLCBoZXJlIGlzIHNvbWUgYXNjaWkgYXJ0LgoKICAgICAgICAgICAsCiAgICAgICwsICAgJSUgICAsICAgLAogICAgIDolJSU7IDslJSUgOyUgICUlOgogICAgICA6JSUlICUlJSUgJSUgJSU6ICAgCiAgICAgOiUlJSUlICUlJSUgJSAlJSU6IAogICAgIDolJSUlJSUgJSUlJSAlJSUlOgogICAgICA6JSUlJSUgJSUlICUlJSU6CiAgICAgICA6JSUlJSAlJSAlJSUlOgogICAgICAgIDolJSUlJSAlJSUlOgogICAgICAgICA6JSUlJSAlJSU6IAogICAgICAgICAgJiU6JSY6JSYKICAgICAgICAgICAmJjomOiYKICAgICAgICAgICAgJiYmJgogICAgICAgICAgICA7JiY7ICAgICA7CiAgICAgICAgICAgICA6OiAgICA7Ozs7CiAgICAgICAgICAgICA6OiAgIDs7Ozs7CiAgICAgICAgICAgICA6OiAgOzs7Ozs7CiAgICAgICAgICAgICA6OiA7Ozs7OzsKICAgICAgIDsgICAgIDo6IDs7Ozs7CiAgICAgIDs7ICAgICA6Ojs7OzsgCiAgICAgOzs7OyAgICA6OjsgCiAgICAgOzs7OzsgICA6OgogICAgIDs7Ozs7OyAgOjoKICAgICAgOzs7OzsgIDo6CiAgICAgICAgOzs7OyA6OgogICAgICAgICAgIDs7OjoKICAgICAgICAgICAgOzo6CiAgICAgICAgICAgICA6OgogICAgICAgICAgICAgOjoKICAgICAgICAgICAgIDo6CiAgICAgICAgICAgICA6OgogICAgICAgICAgICAgOjoKICAgICAgICAgICAgIDo6CiAgICAgICAgICAgICA6OgogICAgICAgICAgICAgOjoKClAuUy4gWWVzIGl0IGlzIGEgbGl0dGxlIGxhbWUgdGhhdCBoZSBwb3N0ZWQgb24gdGhlIG1haWxpbmcgbGlzdCBmb3IgdGhpcywgYnV0IGl0J3MgdGhlIHRob3VnaHQgdGhhdCBjb3VudHMhCg==')) Cheers > > You will make me a very happy man!!! > > Thank you very much!!! > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Wed Mar 4 21:22:55 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 05 Mar 2015 13:22:55 +1100 Subject: HELP!! How to ask a girl out with a simple witty Python code?? References: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> Message-ID: <858ufc18u8.fsf@benfinney.id.au> Terry Reedy writes: > On 3/4/2015 8:34 PM, Xrrific wrote: > > I am trying to impress a girl who is learning python and want ask > > her out at the same time. > > Start by not being sexist about the fitness of females for Python > programming. Make sure she knows that at least parts of the Python > community welcomes anybody and everybody. Impress her by approaching her with the intent to befriend her. Demonstrate that, by learning Python, she hasn't exposed herself to more men trying to ?ask her out? as a result. That would really make a good impression. -- \ ?The good thing about science is that it's true whether or not | `\ you believe in it.? ?Neil deGrasse Tyson, 2011-02-04 | _o__) | Ben Finney From marfig at gmail.com Wed Mar 4 21:44:02 2015 From: marfig at gmail.com (Mario Figueiredo) Date: Thu, 05 Mar 2015 03:44:02 +0100 Subject: HELP!! How to ask a girl out with a simple witty Python code?? References: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> Message-ID: On Wed, 4 Mar 2015 17:34:04 -0800 (PST), Xrrific wrote: >I am trying to impress a girl who is learning python and want ask her out at the same time. > >Could you please come up with something witty incorporating a simple python line like If...then... but..etc. How about not using python at all. Not even talking about it, unless she brings it up. And if she brings it up you say that there's perhaps better things for you two to be doing than talking about programming? From sohcahtoa82 at gmail.com Wed Mar 4 21:50:15 2015 From: sohcahtoa82 at gmail.com (sohcahtoa82 at gmail.com) Date: Wed, 4 Mar 2015 18:50:15 -0800 (PST) Subject: HELP!! How to ask a girl out with a simple witty Python code?? In-Reply-To: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> References: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> Message-ID: On Wednesday, March 4, 2015 at 5:34:16 PM UTC-8, Xrrific wrote: > Guys, please Help!!! > > I am trying to impress a girl who is learning python and want ask her out at the same time. > > Could you please come up with something witty incorporating a simple python line like If...then... but..etc. > > You will make me a very happy man!!! > > Thank you very much!!! You're asking a bunch of nerds for dating advice? From rosuav at gmail.com Wed Mar 4 22:00:35 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 Mar 2015 14:00:35 +1100 Subject: HELP!! How to ask a girl out with a simple witty Python code?? In-Reply-To: References: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> Message-ID: On Thu, Mar 5, 2015 at 1:50 PM, wrote: > On Wednesday, March 4, 2015 at 5:34:16 PM UTC-8, Xrrific wrote: >> Guys, please Help!!! >> >> I am trying to impress a girl who is learning python and want ask her out at the same time. >> >> Could you please come up with something witty incorporating a simple python line like If...then... but..etc. >> >> You will make me a very happy man!!! >> >> Thank you very much!!! > > You're asking a bunch of nerds for dating advice? Some of these nerds are married, others have at least had a successful romantic life. Granted, dating advice isn't _quite_ on-topic for python-list, but still, I'm sure there are plenty of people here who are not the stereotypical nerd "all brains, no ..." that Chris Knight didn't want to appear as. ChrisA From rustompmody at gmail.com Wed Mar 4 22:38:04 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 4 Mar 2015 19:38:04 -0800 (PST) Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] In-Reply-To: <8761ag36du.fsf@elektro.pacujo.net> References: <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> <87twy34dst.fsf@elektro.pacujo.net> <726afahrhnim716av2dnckrsd9n5j5kukj@4ax.com> <21dafa533nrsmktshd35kdbd13ahgj50bf@4ax.com> <87fv9k2999.fsf@elektro.pacujo.net> <54f7599d$0$12988$c3e8da3$5496439d@news.astraweb.com> <8761ag36du.fsf@elektro.pacujo.net> Message-ID: On Thursday, March 5, 2015 at 1:03:13 AM UTC+5:30, Marko Rauhamaa wrote: > Steven D'Aprano: > > > Care to enlighten us then? Because your anecdote doesn't appear to > > have even the most tenuous relationship to this discussion. > > Even more important, when you talk about Python or other computer stuff > to a non-English-speaker, try to emulate the accent most people around > the world are most familiar with, American English. If you find that > overwhelming, try to speak like a BBC newsreader. Your native accent can > be very difficult to understand. You keep talking of accent. At first I thought you were using the word figuratively or else joking. Im now beginning to wonder if you mean it literally. If so have you patented a new AOIP protocol? If not do you give tuitions? in ESP/telepathy/Voodoo? I'll be happy to pay ---------- ?GG is red-lining tuitions -- heh! From marko at pacujo.net Thu Mar 5 00:19:42 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 05 Mar 2015 07:19:42 +0200 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] References: <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> <87twy34dst.fsf@elektro.pacujo.net> <726afahrhnim716av2dnckrsd9n5j5kukj@4ax.com> <21dafa533nrsmktshd35kdbd13ahgj50bf@4ax.com> <87fv9k2999.fsf@elektro.pacujo.net> <54f7599d$0$12988$c3e8da3$5496439d@news.astraweb.com> <8761ag36du.fsf@elektro.pacujo.net> Message-ID: <87mw3s10nl.fsf@elektro.pacujo.net> Rustom Mody : > You keep talking of accent. > At first I thought you were using the word figuratively or else joking. > Im now beginning to wonder if you mean it literally. > If so have you patented a new AOIP protocol? > If not do you give tuitions? in ESP/telepathy/Voodoo? I'll be happy to > pay Where I work, people do use voice still occasionally to communicate. Marko From srikrishnamohan at gmail.com Thu Mar 5 00:58:49 2015 From: srikrishnamohan at gmail.com (km) Date: Thu, 5 Mar 2015 11:28:49 +0530 Subject: HELP!! How to ask a girl out with a simple witty Python code?? In-Reply-To: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> References: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> Message-ID: show her your python and and impress her. Regards, Krishna On Thu, Mar 5, 2015 at 7:04 AM, Xrrific wrote: > Guys, please Help!!! > > I am trying to impress a girl who is learning python and want ask her out > at the same time. > > Could you please come up with something witty incorporating a simple > python line like If...then... but..etc. > > You will make me a very happy man!!! > > Thank you very much!!! > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu Mar 5 01:21:50 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 Mar 2015 17:21:50 +1100 Subject: Do not run this code. Message-ID: import base64; exec(base64.b64decode(b"eD0neD0lcjsgZXhlYyh4JSV4KSc7IGV4ZWMoeCV4KQ==")) Or do, but don't blame me if Python crashes out badly. It seems Py3 is safer than Py2 here. ChrisA From ben+python at benfinney.id.au Thu Mar 5 01:44:30 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 05 Mar 2015 17:44:30 +1100 Subject: Do not run this code. References: Message-ID: <854mq00wq9.fsf@benfinney.id.au> Chris Angelico writes: > import base64; exec(?) That's all I need to know. Code with ?exec()? calls, I consider unsafe by default. -- \ Lucifer: ?Just sign the Contract, sir, and the Piano is yours.? | `\ Ray: ?Sheesh! This is long! Mind if I sign it now and read it | _o__) later?? ?http://www.achewood.com/ | Ben Finney From DaveFarrance at OMiTTHiSyahooANDTHiS.co.uk Thu Mar 5 02:39:22 2015 From: DaveFarrance at OMiTTHiSyahooANDTHiS.co.uk (Dave Farrance) Date: Thu, 05 Mar 2015 07:39:22 +0000 Subject: Do not run this code. References: Message-ID: Ben Finney wrote: >Chris Angelico writes: > >> import base64; exec(?) > >That's all I need to know. Code with ?exec()? calls, I consider unsafe >by default. Indeed. replacing exec with print... >>> print(base64.b64decode(b"eD0neD0lcjsgZXhlYyh4JSV4KSc7IGV4ZWMoeCV4KQ==")) x='x=%r; exec(x%%x)'; exec(x%x) so, discarding that second exec... >>> x='x=%r; exec(x%%x)' >>> print(x) x=%r; exec(x%%x) So it recurses, and if that second exec had been left in then it would be a fork bomb. From rosuav at gmail.com Thu Mar 5 02:57:21 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 Mar 2015 18:57:21 +1100 Subject: Do not run this code. In-Reply-To: <854mq00wq9.fsf@benfinney.id.au> References: <854mq00wq9.fsf@benfinney.id.au> Message-ID: On Thu, Mar 5, 2015 at 5:44 PM, Ben Finney wrote: > Chris Angelico writes: > >> import base64; exec(?) > > That's all I need to know. Code with ?exec()? calls, I consider unsafe > by default. Well yes, there is that :) ChrisA From ian.g.kelly at gmail.com Thu Mar 5 02:59:19 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 5 Mar 2015 00:59:19 -0700 Subject: Do not run this code. In-Reply-To: References: Message-ID: On Thu, Mar 5, 2015 at 12:39 AM, Dave Farrance wrote: > Ben Finney wrote: > >>Chris Angelico writes: >> >>> import base64; exec(?) >> >>That's all I need to know. Code with ?exec()? calls, I consider unsafe >>by default. > > Indeed. replacing exec with print... > >>>> print(base64.b64decode(b"eD0neD0lcjsgZXhlYyh4JSV4KSc7IGV4ZWMoeCV4KQ==")) > x='x=%r; exec(x%%x)'; exec(x%x) > > so, discarding that second exec... > >>>> x='x=%r; exec(x%%x)' >>>> print(x) > x=%r; exec(x%%x) > > So it recurses, and if that second exec had been left in then it would be > a fork bomb. In order to be a fork bomb, it would have to call fork at some point. This is just a race to see whether you'll run out of memory before the recursion limit is reached. From marfig at gmail.com Thu Mar 5 04:16:23 2015 From: marfig at gmail.com (Mario Figueiredo) Date: Thu, 05 Mar 2015 10:16:23 +0100 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] References: <21dafa533nrsmktshd35kdbd13ahgj50bf@4ax.com> <87fv9k2999.fsf@elektro.pacujo.net> <54f7599d$0$12988$c3e8da3$5496439d@news.astraweb.com> <8761ag36du.fsf@elektro.pacujo.net> <87mw3s10nl.fsf@elektro.pacujo.net> Message-ID: <9u6gfatl6vuutusoicald6f5sdp50ouic7@4ax.com> On Thu, 05 Mar 2015 07:19:42 +0200, Marko Rauhamaa wrote: > >Where I work, people do use voice still occasionally to communicate. > Communications skills... the bane of any software developer. Pronunciation is just another obstacle to cross on top of the natural barrier that is transmitting complex computer science ideas through natural language. An ascii file with some code does a much better job at that. Most bugs start in a our mouths, no matter how many times we brush our teeth. In any case, communication is a two-way process. If you can't understand British accent, you should make an effort to do so. It will enrich your communication skills and that is an important skill to have. Might even land you a better job. If instead you prefer to demand british people to speak in your accent, because you are in your country and people should speak with your accent and all that bullshit, and you can't understand them and they should make an effort, waa-waa, that is fine. I'm sure you are otherwise a a friendly and communicative character. From jornws0718 at xs4all.nl Thu Mar 5 06:15:03 2015 From: jornws0718 at xs4all.nl (Oscar) Date: 05 Mar 2015 11:15:03 GMT Subject: Reading all buffered bytes without blocking References: <4ad47d38-bd92-4516-bc60-60fddc9e0666@googlegroups.com> Message-ID: <54f83ab7$0$2849$e4fe514c@news2.news.xs4all.nl> In article , wrote: >>>> buffer = ('a'*998 + '\u20ac').encode('utf-8')[:1000] >>>> buffer.decode('utf-8') >Traceback (most recent call last): > File "", line 1, in >UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 998-999: >unexpected end of data >>>> >>>> # BOUM hmm... >>> import sys as jmr >>> input = jmr.stdin.fileno() >>> output = jmr.stdout.fileno() >>> value = output / input Traceback (most recent call last): File "", line 1, in ZeroDivisionError: integer division or modulo by zero >>> # BOUM -- [J|O|R] <- .signature.gz From marko at pacujo.net Thu Mar 5 08:39:34 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 05 Mar 2015 15:39:34 +0200 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] References: <21dafa533nrsmktshd35kdbd13ahgj50bf@4ax.com> <87fv9k2999.fsf@elektro.pacujo.net> <54f7599d$0$12988$c3e8da3$5496439d@news.astraweb.com> <8761ag36du.fsf@elektro.pacujo.net> <87mw3s10nl.fsf@elektro.pacujo.net> <9u6gfatl6vuutusoicald6f5sdp50ouic7@4ax.com> Message-ID: <87pp8n5zs9.fsf@elektro.pacujo.net> Mario Figueiredo : > If instead you prefer to demand british people to speak in your > accent, because you are in your country I'm in Finland, mind you. Finnish (the H?me dialect, specifically) is my native language. I'm not suggesting my international coworkers should address me in my language, let alone my home dialect. Marko From steve+comp.lang.python at pearwood.info Thu Mar 5 09:06:01 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 06 Mar 2015 01:06:01 +1100 Subject: Newbie question about text encoding References: <201502241524.t1OFO09k022270@fido.openend.se> <201502241620.t1OGKf4n002146@fido.openend.se> <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> Message-ID: <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> Rustom Mody wrote: > On Wednesday, March 4, 2015 at 10:25:24 AM UTC+5:30, Chris Angelico wrote: >> On Wed, Mar 4, 2015 at 3:45 PM, Rustom Mody wrote: >> > >> > It lists some examples of software that somehow break/goof going from >> > BMP-only unicode to 7.0 unicode. >> > >> > IOW the suggestion is that the the two-way classification >> > - ASCII >> > - Unicode >> > >> > is less useful and accurate than the 3-way >> > >> > - ASCII >> > - BMP >> > - Unicode >> >> How is that more useful? Aside from storage optimizations (in which >> the significant breaks would be Latin-1, UCS-2, and UCS-4), the BMP is >> not significantly different from the rest of Unicode. > > Sorry... Dont understand. Chris is suggesting that going from BMP to all of Unicode is not the hard part. Going from ASCII to the BMP part of Unicode is the hard part. If you can do that, you can go the rest of the way easily. I mostly agree with Chris. Supporting *just* the BMP is non-trivial in UTF-8 and UTF-32, since that goes against the grain of the system. You would have to program in artificial restrictions that otherwise don't exist. UTF-16 is different, and that's probably why you think supporting all of Unicode is hard. With UTF-16, there really is an obvious distinction between the BMP and the SMP: that's where you jump from a single 2-byte unit to a pair of 2-byte units. But that distinction doesn't exist in UTF-8 or UTF-32: - In UTF-8, about 99.8% of the BMP requires multiple bytes. Whether you support the SMP or not doesn't change the fact that you have to deal with multi-byte characters. - In UTF-32, everything is fixed-width whether it is in the BMP or not. In both cases, supporting the SMPs is no harder than supporting the BMP. It's only UTF-16 that makes the SMP seem hard. Conclusion: faulty implementations of UTF-16 which incorrectly handle surrogate pairs should be replaced by non-faulty implementations, or changed to UTF-8 or UTF-32; incomplete Unicode implementations which assume that Unicode is 16-bit only (e.g. UCS-2) are obsolete and should be upgraded. Wrong conclusion: SMPs are unnecessary and unneeded, and we need a new standard that is just like obsolete Unicode version 1. Unicode version 1 is obsolete for a reason. 16 bits is not enough for even existing languages, let alone all the code points and characters that are used in human communication. >> Also, the expansion from 16-bit was back in Unicode 2.0, not 7.0. Why >> do you keep talking about 7.0 as if it's a recent change? > > It is 2015 as of now. 7.0 is the current standard. > > The need for the adjective 'current' should be pondered upon. What's your point? The UTF encodings have not changed since they were first introduced. They have been stable for at least twenty years: UTF-8 has existed since 1993, and UTF-16 since 1996. Since version 2.0 of Unicode in 1996, the standard has made "stability guarantees" that no code points will be renamed or removed. Consequently, there has only been one version which removed characters, version 1.1. Since then, new versions of the standard have only added characters, never moved, renamed or deleted them. http://unicode.org/policies/stability_policy.html Some highlights in Unicode history: Unicode 1.0 (1991): initial version, defined 7161 code points. In January 1993, Rob Pike and Ken Thompson announced the design and working implementation of the UTF-8 encoding. 1.1 (1993): defined 34233 characters, finalised Han Unification. Removed some characters from the 1.0 set. This is the first and only time any code points have been removed. 2.0 (1996): First version to include code points in the Supplementary Multilingual Planes. Defined 38950 code points. Introduced the UTF-16 encoding. 3.1 (2001): Defined 94205 code points, including 42711 additional Han ideographs, bringing the total number of CJK code points alone to 71793, too many to fit in 16 bits. 2006: The People's Republic Of China mandates support for the GB-18030 character set for all software products sold in the PRC. GB-18030 supports the entire Unicode range, include the SMPs. Since this date, all software sold in China must support the SMPs. 6.0 (2010): The first emoji or emoticons were added to Unicode. 7.0 (2014): 113021 code points defined in total. > In practice, standards change. > However if a standard changes so frequently that that users have to play > catching cook and keep asking: "Which version?" they are justified in > asking "Are the standard-makers doing due diligence?" Since Unicode has stability guarantees, and the encodings have not changed in twenty years and will not change in the future, this argument is bogus. Updating to a new version of the standard means, to a first approximation, merely allocating some new code points which had previously been undefined but are now defined. (Code points can be flagged deprecated, but they will never be removed.) -- Steven From tim_grove at sil.org Thu Mar 5 09:51:39 2015 From: tim_grove at sil.org (Timothy W. Grove) Date: Thu, 05 Mar 2015 14:51:39 +0000 Subject: win32api.LoadKeyboardLayout; any solutions for OSX? Message-ID: <54F86D7B.60504@sil.org> I was looking for a way to change keyboard layouts from within a Python 3 / PyQt4 application. Win32api.LoadKeyboardLayout has come to my rescue on Windows, but is anyone aware of a cross-platform or OSX specific solution for Apple Mac? Thanks for any suggestions. Best regards, Tim From mese1979 at gmail.com Thu Mar 5 12:31:33 2015 From: mese1979 at gmail.com (Mehdi) Date: Thu, 5 Mar 2015 09:31:33 -0800 (PST) Subject: Make standalone gui-enabled app for LINUX Message-ID: <413fc3f5-38c3-4477-8495-366852e583e7@googlegroups.com> Hi I know there are tools like cx_freeze or nuitka for making a linux standalone python app. but i couldn't find a good tutorial about how to making a portable gui-enabled python3 app in linux. by gui-enabled i mean application which use any gui libs like pygobject, qt or wx. I know most of linux distros have python installed(usually version 2) and a package manager to install packages with their dependencies(rpm or deb). but i'm thinking of really portable app with all dependencies included to run easily almost on every linux OSs with no trouble even for new or less experienced linux users. So again how can i make a portable python3 + gui(pygobject, qt, wx) for linux? I found some helpful guide for windows, but what about linux? Thanks. From phil at riverbankcomputing.com Thu Mar 5 13:20:36 2015 From: phil at riverbankcomputing.com (Phil Thompson) Date: Thu, 05 Mar 2015 18:20:36 +0000 Subject: Make standalone gui-enabled app for LINUX In-Reply-To: <413fc3f5-38c3-4477-8495-366852e583e7@googlegroups.com> References: <413fc3f5-38c3-4477-8495-366852e583e7@googlegroups.com> Message-ID: On 05/03/2015 5:31 pm, Mehdi wrote: > Hi > I know there are tools like cx_freeze or nuitka for making a linux > standalone python app. but i couldn't find a good tutorial about how > to making a portable gui-enabled python3 app in linux. by gui-enabled > i mean application which use any gui libs like pygobject, qt or wx. > I know most of linux distros have python installed(usually version 2) > and a package manager to install packages with their dependencies(rpm > or deb). but i'm thinking of really portable app with all dependencies > included to run easily almost on every linux OSs with no trouble even > for new or less experienced linux users. > So again how can i make a portable python3 + gui(pygobject, qt, wx) for > linux? > I found some helpful guide for windows, but what about linux? I haven't announced this on the list yet, but... http://pyqt.sourceforge.net/Docs/pyqtdeploy/ Phil From sohcahtoa82 at gmail.com Thu Mar 5 13:28:29 2015 From: sohcahtoa82 at gmail.com (sohcahtoa82 at gmail.com) Date: Thu, 5 Mar 2015 10:28:29 -0800 (PST) Subject: HELP!! How to ask a girl out with a simple witty Python code?? In-Reply-To: References: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> Message-ID: <2906370c-58c7-4d8b-8db3-2ea3773b9578@googlegroups.com> On Wednesday, March 4, 2015 at 7:08:34 PM UTC-8, Chris Angelico wrote: > On Thu, Mar 5, 2015 at 1:50 PM, wrote: > > On Wednesday, March 4, 2015 at 5:34:16 PM UTC-8, Xrrific wrote: > >> Guys, please Help!!! > >> > >> I am trying to impress a girl who is learning python and want ask her out at the same time. > >> > >> Could you please come up with something witty incorporating a simple python line like If...then... but..etc. > >> > >> You will make me a very happy man!!! > >> > >> Thank you very much!!! > > > > You're asking a bunch of nerds for dating advice? > > Some of these nerds are married, others have at least had a successful > romantic life. Granted, dating advice isn't _quite_ on-topic for > python-list, but still, I'm sure there are plenty of people here who > are not the stereotypical nerd "all brains, no ..." that Chris Knight > didn't want to appear as. > > ChrisA I should have known better than to make a joke on this mailing list. Someone is bound to get their panties all up in a bunch. From ethan at stoneleaf.us Thu Mar 5 13:37:13 2015 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 05 Mar 2015 10:37:13 -0800 Subject: http: connection reset by peer In-Reply-To: References: <54F6A722.1000706@stoneleaf.us> Message-ID: <54F8A259.7040808@stoneleaf.us> On 03/04/2015 01:26 AM, Chris Angelico wrote: > Do you have Mozilla Firebug, and if so, can you try the file > attachment with Firebug active? At very least, you should be able to > see exactly what request is getting reset, and then you could try to > simulate that exact request with a simpler harness (like a Python > program - see, on-topic now!). "The connection to the server was reset while the page was loading." After mucking about with it with no results, I went on to another job -- when I came back to this one it was working. -- ~Ethan~ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: OpenPGP digital signature URL: From ben+python at benfinney.id.au Thu Mar 5 13:46:48 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 06 Mar 2015 05:46:48 +1100 Subject: HELP!! How to ask a girl out with a simple witty Python code?? References: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> <2906370c-58c7-4d8b-8db3-2ea3773b9578@googlegroups.com> Message-ID: <85zj7rz3hj.fsf@benfinney.id.au> sohcahtoa82 at gmail.com writes: > I should have known better than to make a joke on this mailing list. > Someone is bound to get their panties all up in a bunch. You should have known better than to make gendered slurs. Claiming ?it was a joke? doesn't alter the sexism of your remarks. Cut that out. -- \ ?True greatness is measured by how much freedom you give to | `\ others, not by how much you can coerce others to do what you | _o__) want.? ?Larry Wall | Ben Finney From hayesstw at telkomsa.net Thu Mar 5 14:45:59 2015 From: hayesstw at telkomsa.net (Steve Hayes) Date: Thu, 05 Mar 2015 21:45:59 +0200 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] References: <87twy34dst.fsf@elektro.pacujo.net> <726afahrhnim716av2dnckrsd9n5j5kukj@4ax.com> <21dafa533nrsmktshd35kdbd13ahgj50bf@4ax.com> <87fv9k2999.fsf@elektro.pacujo.net> <54f7599d$0$12988$c3e8da3$5496439d@news.astraweb.com> <8761ag36du.fsf@elektro.pacujo.net> Message-ID: On Wed, 04 Mar 2015 21:33:01 +0200, Marko Rauhamaa wrote: >Steven D'Aprano : > >> Care to enlighten us then? Because your anecdote doesn't appear to >> have even the most tenuous relationship to this discussion. > >English-speaker, when you name things in your Python programs, you had >better stick to American spellings. > >Even more important, when you talk about Python or other computer stuff >to a non-English-speaker, try to emulate the accent most people around >the world are most familiar with, American English. If you find that >overwhelming, try to speak like a BBC newsreader. Your native accent can >be very difficult to understand. Are things named in Python named with an accent? Can you tell what my accent is like when I write in this newsgroup? -- Steve Hayes from Tshwane, South Africa Web: http://www.khanya.org.za/stevesig.htm Blog: http://khanya.wordpress.com E-mail - see web page, or parse: shayes at dunelm full stop org full stop uk From random832 at fastmail.us Thu Mar 5 14:59:05 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Thu, 05 Mar 2015 14:59:05 -0500 Subject: Newbie question about text encoding In-Reply-To: <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> References: <201502241524.t1OFO09k022270@fido.openend.se> <201502241620.t1OGKf4n002146@fido.openend.se> <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1425585545.2920267.236111133.082FA065@webmail.messagingengine.com> On Thu, Mar 5, 2015, at 09:06, Steven D'Aprano wrote: > I mostly agree with Chris. Supporting *just* the BMP is non-trivial in > UTF-8 > and UTF-32, since that goes against the grain of the system. You would > have > to program in artificial restrictions that otherwise don't exist. UTF-8 is already restricted from representing values above 0x10FFFF, whereas UTF-8 can "naturally" represent values up to 0x1FFFFF in four bytes, up to 0x3FFFFFF in five bytes, and 0x7FFFFFFF in six bytes. If anything, the BMP represents a natural boundary, since it coincides with values that can be represented in three bytes. Likewise, UTF-32 can obviously represent values up to 0xFFFFFFFF. You're programming in artificial restrictions either way, it's just a question of what those restrictions are. From marko at pacujo.net Thu Mar 5 15:10:00 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 05 Mar 2015 22:10:00 +0200 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] References: <87twy34dst.fsf@elektro.pacujo.net> <726afahrhnim716av2dnckrsd9n5j5kukj@4ax.com> <21dafa533nrsmktshd35kdbd13ahgj50bf@4ax.com> <87fv9k2999.fsf@elektro.pacujo.net> <54f7599d$0$12988$c3e8da3$5496439d@news.astraweb.com> <8761ag36du.fsf@elektro.pacujo.net> Message-ID: <87fv9j1a07.fsf@elektro.pacujo.net> Steve Hayes : > On Wed, 04 Mar 2015 21:33:01 +0200, Marko Rauhamaa >>English-speaker, when you name things in your Python programs, you had >>better stick to American spellings. >> >>Even more important, when you talk about Python or other computer stuff >>to a non-English-speaker, try to emulate the accent most people around >>the world are most familiar with, American English. If you find that >>overwhelming, try to speak like a BBC newsreader. Your native accent can >>be very difficult to understand. > > Are things named in Python named with an accent? > > Can you tell what my accent is like when I write in this newsgroup? It's clear my accent is clouding my message. Marko From rosuav at gmail.com Thu Mar 5 15:18:14 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Mar 2015 07:18:14 +1100 Subject: http: connection reset by peer In-Reply-To: <54F8A259.7040808@stoneleaf.us> References: <54F6A722.1000706@stoneleaf.us> <54F8A259.7040808@stoneleaf.us> Message-ID: On Fri, Mar 6, 2015 at 5:37 AM, Ethan Furman wrote: > On 03/04/2015 01:26 AM, Chris Angelico wrote: > >> Do you have Mozilla Firebug, and if so, can you try the file >> attachment with Firebug active? At very least, you should be able to >> see exactly what request is getting reset, and then you could try to >> simulate that exact request with a simpler harness (like a Python >> program - see, on-topic now!). > > "The connection to the server was reset while the page was loading." > > After mucking about with it with no results, I went on to another job -- when I came back to this one it was working. Huh. Well, if it recurs, see what you can find out about it... otherwise, problem solved! ChrisA From breamoreboy at yahoo.co.uk Thu Mar 5 15:28:03 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 05 Mar 2015 20:28:03 +0000 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] In-Reply-To: References: <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> <87twy34dst.fsf@elektro.pacujo.net> <726afahrhnim716av2dnckrsd9n5j5kukj@4ax.com> <21dafa533nrsmktshd35kdbd13ahgj50bf@4ax.com> <87fv9k2999.fsf@elektro.pacujo.net> <54f7599d$0$12988$c3e8da3$5496439d@news.astraweb.com> <8761ag36du.fsf@elektro.pacujo.net> Message-ID: On 05/03/2015 03:38, Rustom Mody wrote: > On Thursday, March 5, 2015 at 1:03:13 AM UTC+5:30, Marko Rauhamaa wrote: >> Steven D'Aprano: >> >>> Care to enlighten us then? Because your anecdote doesn't appear to >>> have even the most tenuous relationship to this discussion. >> >> Even more important, when you talk about Python or other computer stuff >> to a non-English-speaker, try to emulate the accent most people around >> the world are most familiar with, American English. If you find that >> overwhelming, try to speak like a BBC newsreader. Your native accent can >> be very difficult to understand. > > You keep talking of accent. > At first I thought you were using the word figuratively or else joking. > Im now beginning to wonder if you mean it literally. > If so have you patented a new AOIP protocol? > If not do you give tuitions? in ESP/telepathy/Voodoo? I'll be happy to pay > > ---------- > ?GG is red-lining tuitions -- heh! > I like the idea of some visitor to Scotland mentioning some speaker's English accent. I'm not so keen on the idea of the said visitor being introduced to the Scottish handshake. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From auriocus at gmx.de Thu Mar 5 16:27:41 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Thu, 05 Mar 2015 22:27:41 +0100 Subject: Make standalone gui-enabled app for LINUX In-Reply-To: <413fc3f5-38c3-4477-8495-366852e583e7@googlegroups.com> References: <413fc3f5-38c3-4477-8495-366852e583e7@googlegroups.com> Message-ID: Am 05.03.15 um 18:31 schrieb Mehdi: > Hi > I know there are tools like cx_freeze or nuitka for making a linux standalone python app. but i couldn't find a good tutorial about how to making a portable gui-enabled python3 app in linux. by gui-enabled i mean application which use any gui libs like pygobject, qt or wx. > I know most of linux distros have python installed(usually version 2) and a package manager to install packages with their dependencies(rpm or deb). but i'm thinking of really portable app with all dependencies included to run easily almost on every linux OSs with no trouble even for new or less experienced linux users. > So again how can i make a portable python3 + gui(pygobject, qt, wx) for linux? > I found some helpful guide for windows, but what about linux? > > Thanks. > Use pyinstaller. It creates a "portable app", i.e. either single file or directory which can be run on (nearly) any system. However the resulting files can be awfully big. I use it with a relatively small program that depends on numpy/matplolib, and that pulls in ~100 MB worth of libraries. Christian From tjreedy at udel.edu Thu Mar 5 16:34:01 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 05 Mar 2015 16:34:01 -0500 Subject: what is wrong with d.clear()? In-Reply-To: References: Message-ID: On 12/22/2014 3:54 PM, Rick Johnson wrote: > On Monday, December 22, 2014 12:16:03 PM UTC-6, sohca... at gmail.com wrote: >> On Monday, December 22, 2014 12:16:15 AM UTC-8, shawool wrote: >> >> [snip: OP's adolescent accessorizing] @_@ >> >> Is there a reason you're composing your messages with a >> large, colored font Shit's obnoxious, yo. > > Whilst i don't share shawool's penchant of utilizing the > brutish urban vernacular, i must agree that he has a valid > point. > > Please don't be tempted to use large fonts (or very small > fonts), typically anything around 12 pts will suffice. Also, > using any font color besides black, or background color > besides white, should be limited except to *VERY* rare > occasions. Posts on this list are supposed to be plain text. Let me decide what font color and size I want for reading. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Thu Mar 5 17:15:05 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 06 Mar 2015 09:15:05 +1100 Subject: HELP!! How to ask a girl out with a simple witty Python code?? References: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> <2906370c-58c7-4d8b-8db3-2ea3773b9578@googlegroups.com> Message-ID: <54f8d56a$0$12984$c3e8da3$5496439d@news.astraweb.com> Ben Finney wrote: > sohcahtoa82 at gmail.com writes: > >> I should have known better than to make a joke on this mailing list. >> Someone is bound to get their panties all up in a bunch. > > You should have known better than to make gendered slurs. Claiming ?it > was a joke? doesn't alter the sexism of your remarks. Cut that out. "You're asking a bunch of nerds for dating advice?" Sohcatoa's lousy joke applies to all sexes equally, whether they are male, female, intersex, or indeed non-gendered advanced alien intelligences. (Possibly not *that* advanced if they are hanging around here...) Sorry to say that the only sexism displayed here is your apparent assumption that nerds are all [fe]male, or that the people on this list are all [fe]males. Both men and women can be nerds too, and I know people of both cis-genders and at least three of trans-genders who are clueless about dating. Funnily enough, all but one of them are nerds of one type or another. Despite the efforts of a lot of neo-Victorian feminists determined to repeat the sins of the past, "sexism" does not mean "anything even vaguely related to sexual activity or the potential for sexual activity". Nor is any mild joke made at the (self-)expense of some random subgroup of people "sexism", whether than joke is based on a stereotype or not. -- Steven From random832 at fastmail.us Thu Mar 5 17:26:53 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Thu, 05 Mar 2015 17:26:53 -0500 Subject: Is nan in (nan,) correct? Message-ID: <1425594413.2960487.236174005.017A4298@webmail.messagingengine.com> It's been brought up on Stack Overflow that the "in" operator (on tuples, and by my testing on dict and list, as well as dict lookup) uses object identity as a shortcut, and returns true immediately if the object being tested *is* an element of the container. However, the contains operation does not specify whether object identity or equality is to be used. In effect, the built-in container types use a hybrid test: "a is b or a == b". My question is, is this a *correct* implementation of the operator, or are objects "supposed to" use a basis of equality for these tests? From steve+comp.lang.python at pearwood.info Thu Mar 5 17:33:41 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 06 Mar 2015 09:33:41 +1100 Subject: Newbie question about text encoding References: <201502241524.t1OFO09k022270@fido.openend.se> <201502241620.t1OGKf4n002146@fido.openend.se> <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> Message-ID: <54f8d9c6$0$12993$c3e8da3$5496439d@news.astraweb.com> random832 at fastmail.us wrote: > On Thu, Mar 5, 2015, at 09:06, Steven D'Aprano wrote: >> I mostly agree with Chris. Supporting *just* the BMP is non-trivial in >> UTF-8 >> and UTF-32, since that goes against the grain of the system. You would >> have >> to program in artificial restrictions that otherwise don't exist. > > UTF-8 is already restricted from representing values above 0x10FFFF, > whereas UTF-8 can "naturally" represent values up to 0x1FFFFF in four > bytes, up to 0x3FFFFFF in five bytes, and 0x7FFFFFFF in six bytes. If > anything, the BMP represents a natural boundary, since it coincides with > values that can be represented in three bytes. Likewise, UTF-32 can > obviously represent values up to 0xFFFFFFFF. You're programming in > artificial restrictions either way, it's just a question of what those > restrictions are. Good points, but they don't greatly change my conclusion. If you are implementing UTF-8 or UTF-32, it is no harder to deal with code points in the SMP than those in the BMP. -- Steven From ben+python at benfinney.id.au Thu Mar 5 17:59:51 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 06 Mar 2015 09:59:51 +1100 Subject: HELP!! How to ask a girl out with a simple witty Python code?? References: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> <2906370c-58c7-4d8b-8db3-2ea3773b9578@googlegroups.com> <54f8d56a$0$12984$c3e8da3$5496439d@news.astraweb.com> Message-ID: <85lhjbyrrs.fsf@benfinney.id.au> Steven D'Aprano writes: > Ben Finney wrote: > > > sohcahtoa82 at gmail.com writes: > > > >> I should have known better than to make a joke on this mailing > >> list. Someone is bound to get their panties all up in a bunch. > > > > You should have known better than to make gendered slurs. Claiming > > ?it was a joke? doesn't alter the sexism of your remarks. Cut that > > out. > > "You're asking a bunch of nerds for dating advice?" ?get their panties all up in a bunch? is a gendered slur. It is implying the person is female, as though the person should feel insulted by that. It uses the female gender as an insult. That's not welcoming to anyone female, and we should all be welcoming to anyone of any gender here ? which includes not using any gender as the punch-line of a joke. -- \ ?Pinky, are you pondering what I'm pondering?? ?I think so, | `\ Brain, but Zero Mostel times anything will still give you Zero | _o__) Mostel.? ?_Pinky and The Brain_ | Ben Finney From mvoicem at gmail.com Thu Mar 5 18:05:36 2015 From: mvoicem at gmail.com (m) Date: Fri, 06 Mar 2015 00:05:36 +0100 Subject: [OT]Re: what is wrong with d.clear()? In-Reply-To: References: <9f54b6e1-598a-44ea-953f-0de17d9809c2@googlegroups.com> <5498d492$0$12978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <54f8e140$0$2172$65785112@news.neostrada.pl> W dniu 23.12.2014 o 11:25, Steve Hayes pisze: >> >[1] Or worse, one of those shitty messages that include a plain text part >> >that says "Your mail program cannot read this email. Please upgrade to a >> >better mail program." > I usually reply to those saying "So why did you send it to me?" > > I suspect that in most cases the senders do not know that that is what their > mail program is sending, and do it to let them know that their mesdsage could > not be read. I suspect that in most cases sender don't understand what do you mean saying "So why did you send it to me?". p. m. From breamoreboy at yahoo.co.uk Thu Mar 5 18:07:13 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 05 Mar 2015 23:07:13 +0000 Subject: HELP!! How to ask a girl out with a simple witty Python code?? In-Reply-To: <85lhjbyrrs.fsf@benfinney.id.au> References: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> <2906370c-58c7-4d8b-8db3-2ea3773b9578@googlegroups.com> <54f8d56a$0$12984$c3e8da3$5496439d@news.astraweb.com> <85lhjbyrrs.fsf@benfinney.id.au> Message-ID: On 05/03/2015 22:59, Ben Finney wrote: > Steven D'Aprano writes: > >> Ben Finney wrote: >> >>> sohcahtoa82 at gmail.com writes: >>> >>>> I should have known better than to make a joke on this mailing >>>> list. Someone is bound to get their panties all up in a bunch. >>> >>> You should have known better than to make gendered slurs. Claiming >>> ?it was a joke? doesn't alter the sexism of your remarks. Cut that >>> out. >> >> "You're asking a bunch of nerds for dating advice?" > > ?get their panties all up in a bunch? is a gendered slur. It is implying > the person is female, as though the person should feel insulted by that. > It uses the female gender as an insult. > > That's not welcoming to anyone female, and we should all be welcoming to > anyone of any gender here ? which includes not using any gender as the > punch-line of a joke. > I just wish this kind of approach was used consistently across the board. That way we wouldn't have had to put up with the appalling slurs from our RUE (Resident Unicode Expert) for perhaps two years. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From sohcahtoa82 at gmail.com Thu Mar 5 18:11:45 2015 From: sohcahtoa82 at gmail.com (sohcahtoa82 at gmail.com) Date: Thu, 5 Mar 2015 15:11:45 -0800 (PST) Subject: Is nan in (nan,) correct? In-Reply-To: References: Message-ID: On Thursday, March 5, 2015 at 2:27:12 PM UTC-8, rand... at fastmail.us wrote: > It's been brought up on Stack Overflow that the "in" operator (on > tuples, and by my testing on dict and list, as well as dict lookup) uses > object identity as a shortcut, and returns true immediately if the > object being tested *is* an element of the container. However, the > contains operation does not specify whether object identity or equality > is to be used. In effect, the built-in container types use a hybrid > test: "a is b or a == b". > > My question is, is this a *correct* implementation of the operator, or > are objects "supposed to" use a basis of equality for these tests? I would argue that if `a is b` then it is obvious that `a == b`, so if all you care about is whether or not `a == b`, then it shouldn't matter if `a is b` is checked first. It could greatly speed up comparisons for objects that are expensive to compare. I would also argue that the "in" operator *SHOULD* be using equality of value. Otherwise, if it only used equality of identity, testing if user input is valid by seeing if it is "in" a list of valid inputs wouldn't work. Testing identity in this case would *never* be true unless you were dealing with a select number of integers. >>> i = input() 5 >>> i is 5 True >>> i = intput() 999999 >>> i is 999999 False >>> i in [1, 2, 3, 999999] True From ben+python at benfinney.id.au Thu Mar 5 18:20:10 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 06 Mar 2015 10:20:10 +1100 Subject: Is nan in (nan,) correct? References: Message-ID: <85h9tzyqtx.fsf@benfinney.id.au> sohcahtoa82 at gmail.com writes: > I would argue that if `a is b` then it is obvious that `a == b` It may be obvious, but it's not necessarily true. Some commonly-used values ? for example, an ?null? ? are not equal to themselves, by definition. It is fine to define such a type in Python, because ?is? does not necessarily imply ?==?. > I would also argue that the "in" operator *SHOULD* be using equality > of value. Hopefully you can see how that argument is incorrect. -- \ ?Yesterday I told a chicken to cross the road. It said, ?What | `\ for??? ?Steven Wright | _o__) | Ben Finney From rosuav at gmail.com Thu Mar 5 18:25:05 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Mar 2015 10:25:05 +1100 Subject: Is nan in (nan,) correct? In-Reply-To: References: Message-ID: On Fri, Mar 6, 2015 at 10:11 AM, wrote: > I would argue that if `a is b` then it is obvious that `a == b` This is not true for float("nan"), though. The question is, is your above statement a valid optimization for the 'in' operator, or not? And no, it isn't, because it's not perfectly safe. However, there are other invariants that mean that 'in' has to allow object identity to count; for instance: for elem in collection: assert elem in collection should never assert-fail. ChrisA From sohcahtoa82 at gmail.com Thu Mar 5 18:27:32 2015 From: sohcahtoa82 at gmail.com (sohcahtoa82 at gmail.com) Date: Thu, 5 Mar 2015 15:27:32 -0800 (PST) Subject: Is nan in (nan,) correct? In-Reply-To: References: Message-ID: <5cfab73a-ec0b-488b-8787-72e7640dc352@googlegroups.com> On Thursday, March 5, 2015 at 3:20:16 PM UTC-8, Ben Finney wrote: > sohcahtoa82 at gmail.com writes: > > > I would argue that if `a is b` then it is obvious that `a == b` > > It may be obvious, but it's not necessarily true. Some commonly-used > values - for example, an "null" - are not equal to themselves, by > definition. > > It is fine to define such a type in Python, because 'is' does not > necessarily imply '=='. > > > I would also argue that the "in" operator *SHOULD* be using equality > > of value. > > Hopefully you can see how that argument is incorrect. > > -- > \ "Yesterday I told a chicken to cross the road. It said, 'What | > `\ for?'" --Steven Wright | > _o__) | > Ben Finney Do you have an example of where `a is b` but `a != b` in Python? `None == None` is True. From ben+python at benfinney.id.au Thu Mar 5 18:39:59 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 06 Mar 2015 10:39:59 +1100 Subject: Is nan in (nan,) correct? References: <5cfab73a-ec0b-488b-8787-72e7640dc352@googlegroups.com> Message-ID: <85d24nypww.fsf@benfinney.id.au> sohcahtoa82 at gmail.com writes: > On Thursday, March 5, 2015 at 3:20:16 PM UTC-8, Ben Finney wrote: > > It is fine to define such a type in Python, because 'is' does not > > necessarily imply '=='. > > Do you have an example of where `a is b` but `a != b` in Python? Maybe I misunderstand your question, but you've already been discussing such an example. Here it is for clarity:: >>> nan = float("NaN") >>> (nan is nan) == (nan == nan) False >>> nan is nan True >>> nan == nan False > `None == None` is True. Right, the Python `None` is not the null I was describing. Python does allow for a null with the semantics I described, because ?is? does not imply ?==?. -- \ ?We suffer primarily not from our vices or our weaknesses, but | `\ from our illusions.? ?Daniel J. Boorstin, historian, 1914?2004 | _o__) | Ben Finney From rosuav at gmail.com Thu Mar 5 18:40:19 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Mar 2015 10:40:19 +1100 Subject: Is nan in (nan,) correct? In-Reply-To: <5cfab73a-ec0b-488b-8787-72e7640dc352@googlegroups.com> References: <5cfab73a-ec0b-488b-8787-72e7640dc352@googlegroups.com> Message-ID: On Fri, Mar 6, 2015 at 10:27 AM, wrote: > Do you have an example of where `a is b` but `a != b` in Python? `None == None` is True. Check out the subject line. >>> nan = float("nan") >>> nan is nan # obviously True >>> nan != nan # IEEE 754 mandates True ChrisA From marfig at gmail.com Thu Mar 5 18:57:29 2015 From: marfig at gmail.com (Mario Figueiredo) Date: Fri, 06 Mar 2015 00:57:29 +0100 Subject: [Python 3.4] Rationale for readonly slice data attributes Message-ID: What is the rationale behind making the slice class data attributes readonly? I've built a __getitem__ method for a Map class that contains a list of Cell instance objects. __getitem__ maps this list into a matrix:: # get cell at cartesian coordinates 12, 4 # will map to the 1048th position in the cells list mmap = Map() print(mmap[12, 4]) All is working well and it even supports slicing:: # return all cells with x between 3 and 6 and y up until 4 mmap = Map() [print(cell) for cell in mmap(3:6, :4)] This last example is one case in which I missed the ability to change the the `start` and `stop` attributes of the slice class in order for the maping to occur that allows a 2-dimensions access to a 1-dimension list. It was solved by taking another turn, but it proved to me that the slice data attributes are more useful if they are writable, and this clashes tremendously with the principles of data encapsulation that underline the requirements for a readonly property. In other words, if it needs to be accessed, don't hide it. If it needs to be written, don't lock it. Now, normally I take these things for granted. Rules are rules and their reasons are often fairly obvious. But in this case I'm at loss. I can't find a reason for this class attributes to have been made into readonly properties. From tjreedy at udel.edu Thu Mar 5 20:20:23 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 05 Mar 2015 20:20:23 -0500 Subject: Is nan in (nan,) correct? In-Reply-To: <1425594413.2960487.236174005.017A4298@webmail.messagingengine.com> References: <1425594413.2960487.236174005.017A4298@webmail.messagingengine.com> Message-ID: Nothing about nans is 'correct'. They are a CS invention On 3/5/2015 5:26 PM, random832 at fastmail.us wrote: > It's been brought up on Stack Overflow that the "in" operator (on > tuples, and by my testing on dict and list, as well as dict lookup) uses > object identity as a shortcut, and returns true immediately if the > object being tested *is* an element of the container. However, the > contains operation does not specify whether object identity or equality > is to be used. In effect, the built-in container types use a hybrid > test: "a is b or a == b". > > My question is, is this a *correct* implementation of the operator, The current implementation of 'in' is 'correct' in that it reflects the intentions of GvR and other core developers. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Thu Mar 5 21:09:22 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 06 Mar 2015 13:09:22 +1100 Subject: Is nan in (nan,) correct? References: Message-ID: <54f90c53$0$12994$c3e8da3$5496439d@news.astraweb.com> random832 at fastmail.us wrote: > It's been brought up on Stack Overflow that the "in" operator (on > tuples, and by my testing on dict and list, as well as dict lookup) uses > object identity as a shortcut, and returns true immediately if the > object being tested *is* an element of the container. However, the > contains operation does not specify whether object identity or equality > is to be used. In effect, the built-in container types use a hybrid > test: "a is b or a == b". > > My question is, is this a *correct* implementation of the operator, or > are objects "supposed to" use a basis of equality for these tests? This has been discussed multiple times on the python-dev mailing list, and each time the conclusion is the same: Using `is` to optimize the `in` operator is perfectly acceptable for the vast bulk of values in Python. There are only a few, like floating point NANs, where `a is b` does not imply `a == b`, and it is acceptable for container-types like tuple and list to assume reflexivity (that x == x). Since reflexivity is *almost* universal, and using object identity permits very substantial optimizations, the core developers agreed that built-in contain types may assume that `x is y` implies `x == y`. Users of NANs and other non-reflexive types can subclass or define their own membership function. -- Steven From steve+comp.lang.python at pearwood.info Thu Mar 5 21:53:37 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 06 Mar 2015 13:53:37 +1100 Subject: HELP!! How to ask a girl out with a simple witty Python code?? References: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> <2906370c-58c7-4d8b-8db3-2ea3773b9578@googlegroups.com> <54f8d56a$0$12984$c3e8da3$5496439d@news.astraweb.com> Message-ID: <54f916b2$0$12980$c3e8da3$5496439d@news.astraweb.com> Ben Finney wrote: > Steven D'Aprano writes: > >> Ben Finney wrote: >> >> > sohcahtoa82 at gmail.com writes: >> > >> >> I should have known better than to make a joke on this mailing >> >> list. Someone is bound to get their panties all up in a bunch. >> > >> > You should have known better than to make gendered slurs. Claiming >> > ?it was a joke? doesn't alter the sexism of your remarks. Cut that >> > out. >> >> "You're asking a bunch of nerds for dating advice?" > > ?get their panties all up in a bunch? is a gendered slur. Ah, sorry about misunderstanding you. It wasn't clear to me that you were referring to that specific comment rather than the original comment. > It is implying > the person is female, as though the person should feel insulted by that. > It uses the female gender as an insult. Why do you interpret that as insulting to women merely on the basis of being *female*? Wearing panties/knickers is something anyone can do, of any gender and sexual orientation. "Panties in a bunch" (or "knickers in a twist") is a put-down on the basis of excessive sensitivity, not femaleness. It seems to me that far from challenging sexual stereotypes, mainstream feminist thought actually *reinforces* it: as evidence, you assumed that only women wear panties, therefore any reference to panty-wearing is therefore a slur on women. It's only gender specific if you accept the sexist gendered stereotype that all women are by definition thin-skinned and excessively sensitive. The women I know are nothing like that, and consequently most of them are quite happy to use "knickers in a twist" as a *non-gendered* put-down on the basis of perceived behaviour, not sex. It seems to my wife, and I agree with her, that mainstream feminism has lost its way and is no longer about gender equality, but is now about enforcing a neo-Victorian pseudo-politeness where nobody ever has to be exposed to anything uncomfortable or that threatens to disturb them out of their comfort zone. Hence the focus on codes of conduct, so-called "safe places", trigger warnings and the like. Once upon a time, a safe place meant somewhere where a battered woman could take shelter from her batterer. Now, it apparently means a way to ostracise an actor for his personal religious beliefs. (I'm referring to the Internet storm-in-a-teacup over Adam Baldwin at Supanova.) I do not buy into that philosophy, and neither do most of the woman I know. -- Steven From ben+python at benfinney.id.au Thu Mar 5 21:55:32 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 06 Mar 2015 13:55:32 +1100 Subject: Is nan in (nan,) correct? References: <54f90c53$0$12994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <858ufazvff.fsf@benfinney.id.au> Steven D'Aprano writes: > Since reflexivity is *almost* universal, and using object identity > permits very substantial optimizations, the core developers agreed > that built-in contain types may assume that `x is y` implies `x == y`. > Users of NANs and other non-reflexive types can subclass or define > their own membership function. On a type (such as a hypothetical SQL NULL type) which does not have reflexivity ? i.e. that ?(x is x) == (x == x)? may be False ? which method needs to be implemented so items *containing* values of that type will have the expected semantics? I can only think of ?footype.__contains__?, but that's a method of the *container* type, and the ?in? operator doesn't consult that method of the items themselves. So, given the hypothetical NullType:: class NullType(object): """ A type whose value never equals any other. This type's values will behave correctly when tested for membership in a collection:: >>> foo = NullType() >>> bar = NullType() >>> foo is foo True >>> foo is bar False >>> foo == foo False >>> foo == bar False >>> quux = [foo, "spam"] >>> "spam" in quux True >>> foo in quux True >>> bar in quux False """ def __eq__(self, value): return False def __method_which_the_in_operator_interrogates__(self, collection): """ Method which the ?is? operator interrogates for membership. """ return is_a_member_of(container, self) What method of NullType replaces the hypothetical ?__method_which_the_in_operator_interrogates__?, which I've implemented to as you describe ?define their own membership function?, in order to get the correct behaviour in the doctest above? -- \ ?Why am I an atheist? I ask you: Why is anybody not an atheist? | `\ Everyone starts out being an atheist.? ?Andy Rooney, _Boston | _o__) Globe_ 1982-05-30 | Ben Finney From ethan at stoneleaf.us Thu Mar 5 22:18:08 2015 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 05 Mar 2015 19:18:08 -0800 Subject: Is nan in (nan,) correct? In-Reply-To: <858ufazvff.fsf@benfinney.id.au> References: <54f90c53$0$12994$c3e8da3$5496439d@news.astraweb.com> <858ufazvff.fsf@benfinney.id.au> Message-ID: <54F91C70.6020303@stoneleaf.us> On 03/05/2015 06:55 PM, Ben Finney wrote: > class NullType(object): > """ A type whose value never equals any other. > > This type's values will behave correctly when tested for > membership in a collection:: > > >>> foo = NullType() > >>> bar = NullType() > >>> foo is foo > True > >>> foo is bar > False > >>> foo == foo > False > >>> foo == bar > False > >>> quux = [foo, "spam"] > >>> "spam" in quux > True > >>> foo in quux > True Did you mean False here? Because True is current behavior. -- ~Ethan~ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: OpenPGP digital signature URL: From ben+python at benfinney.id.au Thu Mar 5 22:23:22 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 06 Mar 2015 14:23:22 +1100 Subject: HELP!! How to ask a girl out with a simple witty Python code?? References: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> <2906370c-58c7-4d8b-8db3-2ea3773b9578@googlegroups.com> <54f8d56a$0$12984$c3e8da3$5496439d@news.astraweb.com> <54f916b2$0$12980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <85385izu51.fsf@benfinney.id.au> Steven D'Aprano writes: > Ben Finney wrote: > > > ?get their panties all up in a bunch? is a gendered slur. > > Why do you interpret that as insulting to women merely on the basis of > being *female*? I think your question is in bad faith. You know as well as I do, and I'm confident the person who wrote the slur knows, that ?panties? strongly connotes *female* underwear. > It seems to me that far from challenging sexual stereotypes, > mainstream feminist thought actually *reinforces* it: as evidence, you > assumed that only women wear panties, therefore any reference to > panty-wearing is therefore a slur on women. No. I'm saying that it's clear the person saying ?get their panties all up in a bunch? fully intends to convey specifically *female* underwear, and thereby to use implied femininity as an insult. Yes, of course I know some people who aren't female wear panties. Yes, of course I know some women wear underwear that isn't panties. Don't try to change the topic with absurd logical extremes that I didn't raise. I'm talking about the implication of the comment as a gendered insult. > It's only gender specific if you accept the sexist gendered stereotype > that all women are by definition thin-skinned and excessively > sensitive. Bullshit. I said nothing about the sensitivity of anyone. Individual women you may know ? even *all* women, everywhere ? could be as tough as nails, and it doesn't address the point I'm raising. Whether any particular woman is targeted or not, the comment I'm responding to invokes female gender as an implied insult. That's unwelcoming to women, and I don't want such unwelcoming attitudes in this community. -- \ ?Too many pieces of music finish too long after the end.? ?Igor | `\ Stravinskey | _o__) | Ben Finney From ben+python at benfinney.id.au Thu Mar 5 22:26:15 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 06 Mar 2015 14:26:15 +1100 Subject: Is nan in (nan,) correct? References: <54f90c53$0$12994$c3e8da3$5496439d@news.astraweb.com> <858ufazvff.fsf@benfinney.id.au> <54F91C70.6020303@stoneleaf.us> Message-ID: <85wq2uyffs.fsf@benfinney.id.au> Ethan Furman writes: > On 03/05/2015 06:55 PM, Ben Finney wrote: > > > class NullType(object): > > """ A type whose value never equals any other. > > > > This type's values will behave correctly when tested for > > membership in a collection:: > > > > >>> foo = NullType() > > >>> bar = NullType() > > >>> foo is foo > > True > > >>> foo is bar > > False > > >>> foo == foo > > False > > >>> foo == bar > > False > > >>> quux = [foo, "spam"] > > >>> "spam" in quux > > True > > >>> foo in quux > > True > > Did you mean False here? Because True is current behavior. Isn't the point at issue that the Python interpreter *may* optimise by assuming ?is implies equality?, so the ?in? operator can fail if that assumption is false? I thought the problem was that types with custom behaviour, as with the ?NullType? example, needed to deal specially with the ?is implies equality? optimisation Steven explained. If that's the correct behaviour, and we can *depend* on it being correct, then I don't see what the problem is. -- \ ?What I have to do is see, at any rate, that I do not lend | `\ myself to the wrong which I condemn.? ?Henry Thoreau, _Civil | _o__) Disobedience_ | Ben Finney From rosuav at gmail.com Thu Mar 5 22:37:36 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Mar 2015 14:37:36 +1100 Subject: HELP!! How to ask a girl out with a simple witty Python code?? In-Reply-To: <85385izu51.fsf@benfinney.id.au> References: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> <2906370c-58c7-4d8b-8db3-2ea3773b9578@googlegroups.com> <54f8d56a$0$12984$c3e8da3$5496439d@news.astraweb.com> <54f916b2$0$12980$c3e8da3$5496439d@news.astraweb.com> <85385izu51.fsf@benfinney.id.au> Message-ID: On Fri, Mar 6, 2015 at 2:23 PM, Ben Finney wrote: > Steven D'Aprano writes: > >> Ben Finney wrote: >> >> > ?get their panties all up in a bunch? is a gendered slur. >> >> Why do you interpret that as insulting to women merely on the basis of >> being *female*? > > I think your question is in bad faith. You know as well as I do, and I'm > confident the person who wrote the slur knows, that ?panties? strongly > connotes *female* underwear. Allow me to summarize this subthread: * sohcahtoa makes a comment implying that this list is full of nerds who know nothing about dating. Gender-nonspecific and most likely self-deprecating as much as insulting. * I responded with a reference to a nerdy movie ("Real Genius", and if you haven't seen it, go grab it - it's funny), which perhaps was not recognized, leading to the post in which: * sohcahtoa misunderstands me and thinks I was offended at his post (which I wasn't), and gets his hackles up, thinking the original nerd-dating-advice comment shouldn't have been offensive * Two people then go back and forth about whether or not the previous three posts were offensive. The whole field of getting vicariously offended is a mess. It's virtually impossible to judge what will and what will not cause offense (sure, there are some easy cases, and if you use a six-letter word beginning with "n" to refer to someone with more skin melanin than yourself, then you will be very rightly shouted down - but most cases aren't anything like that clear, and even that word wasn't originally offensive in itself), and we have interminable debates about what should and shouldn't be said. Can we please keep these sub-threads short? Once it's gone through a couple of rounds of response, it's not going to get anywhere new. All we have is people getting annoyed on behalf of an unspecified person or group of people, and offense being given and taken and regifted like Christmas presents from your distant relatives. I'm sure there's something more interesting to talk about... like the rate at which the grass is growing. Thanks! ChrisA From ethan at stoneleaf.us Thu Mar 5 22:44:56 2015 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 05 Mar 2015 19:44:56 -0800 Subject: Is nan in (nan,) correct? In-Reply-To: <85wq2uyffs.fsf@benfinney.id.au> References: <54f90c53$0$12994$c3e8da3$5496439d@news.astraweb.com> <858ufazvff.fsf@benfinney.id.au> <54F91C70.6020303@stoneleaf.us> <85wq2uyffs.fsf@benfinney.id.au> Message-ID: <54F922B8.30802@stoneleaf.us> On 03/05/2015 07:26 PM, Ben Finney wrote: > Ethan Furman writes: > >> On 03/05/2015 06:55 PM, Ben Finney wrote: >> >>> class NullType(object): >>> """ A type whose value never equals any other. >>> >>> This type's values will behave correctly when tested for >>> membership in a collection:: >>> >>> >>> foo = NullType() >>> >>> bar = NullType() >>> >>> foo is foo >>> True >>> >>> foo is bar >>> False >>> >>> foo == foo >>> False >>> >>> foo == bar >>> False >>> >>> quux = [foo, "spam"] >>> >>> "spam" in quux >>> True >>> >>> foo in quux >>> True >> >> Did you mean False here? Because True is current behavior. > > Isn't the point at issue that the Python interpreter *may* optimise by > assuming ?is implies equality?, so the ?in? operator can fail if that > assumption is false? No, it's not a /may/, it's a /does/, and that it can be optimized is a bonus. > I thought the problem was that types with custom behaviour, as with the > ?NullType? example, needed to deal specially with the ?is implies > equality? optimisation Steven explained. The NaN-type objects cannot deal with it directly, as that behavior is in the container. > If that's the correct behaviour, and we can *depend* on it being > correct, then I don't see what the problem is. Well, we can depend on it for native Python types -- but if you write your own container, along with your own __contains__, then you might unwittingly do `for item in self.container: if item == target: return True` and then NaN (or NullType, or what-have-you) would not work "correctly" [1] for your container. -- ~Ethan~ [1] Otherwise known as: how Python does it. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: OpenPGP digital signature URL: From ethan at stoneleaf.us Thu Mar 5 22:48:49 2015 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 05 Mar 2015 19:48:49 -0800 Subject: How fast does your grass grow? [was Re: HELP!! How to ask a girl out with a simple witty Python code??] In-Reply-To: References: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> <2906370c-58c7-4d8b-8db3-2ea3773b9578@googlegroups.com> <54f8d56a$0$12984$c3e8da3$5496439d@news.astraweb.com> <54f916b2$0$12980$c3e8da3$5496439d@news.astraweb.com> <85385izu51.fsf@benfinney.id.au> Message-ID: <54F923A1.5040901@stoneleaf.us> On 03/05/2015 07:37 PM, Chris Angelico wrote: > I'm sure there's something more interesting to talk about... like the > rate at which the grass is growing. My grass doesn't grow -- I ripped it all out and put down pea-gravel and planter boxes. Oh, wait, I have some bamboo in the back -- that's a grass, isn't it? Hmmm, well, it grows fast enough that my dogs haven't managed to eat it gone yet. :) -- ~Ethan~ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: OpenPGP digital signature URL: From rosuav at gmail.com Thu Mar 5 22:49:02 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Mar 2015 14:49:02 +1100 Subject: Is nan in (nan,) correct? In-Reply-To: <85wq2uyffs.fsf@benfinney.id.au> References: <54f90c53$0$12994$c3e8da3$5496439d@news.astraweb.com> <858ufazvff.fsf@benfinney.id.au> <54F91C70.6020303@stoneleaf.us> <85wq2uyffs.fsf@benfinney.id.au> Message-ID: On Fri, Mar 6, 2015 at 2:26 PM, Ben Finney wrote: > Isn't the point at issue that the Python interpreter *may* optimise by > assuming ?is implies equality?, so the ?in? operator can fail if that > assumption is false? > > I thought the problem was that types with custom behaviour, as with the > ?NullType? example, needed to deal specially with the ?is implies > equality? optimisation Steven explained. > > If that's the correct behaviour, and we can *depend* on it being > correct, then I don't see what the problem is. I'm not sure it's just an optimization. Compare this post from python-dev, where Nick Coghlan discusses the same topic: https://mail.python.org/pipermail/python-dev/2014-July/135476.html ChrisA From breamoreboy at yahoo.co.uk Thu Mar 5 22:59:38 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 06 Mar 2015 03:59:38 +0000 Subject: HELP!! How to ask a girl out with a simple witty Python code?? In-Reply-To: <85385izu51.fsf@benfinney.id.au> References: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> <2906370c-58c7-4d8b-8db3-2ea3773b9578@googlegroups.com> <54f8d56a$0$12984$c3e8da3$5496439d@news.astraweb.com> <54f916b2$0$12980$c3e8da3$5496439d@news.astraweb.com> <85385izu51.fsf@benfinney.id.au> Message-ID: On 06/03/2015 03:23, Ben Finney wrote: > Steven D'Aprano writes: > >> Ben Finney wrote: >> >>> ?get their panties all up in a bunch? is a gendered slur. >> >> Why do you interpret that as insulting to women merely on the basis of >> being *female*? > > I think your question is in bad faith. You know as well as I do, and I'm > confident the person who wrote the slur knows, that ?panties? strongly > connotes *female* underwear. > >> It seems to me that far from challenging sexual stereotypes, >> mainstream feminist thought actually *reinforces* it: as evidence, you >> assumed that only women wear panties, therefore any reference to >> panty-wearing is therefore a slur on women. > > No. I'm saying that it's clear the person saying ?get their panties all > up in a bunch? fully intends to convey specifically *female* underwear, > and thereby to use implied femininity as an insult. > > Yes, of course I know some people who aren't female wear panties. Yes, > of course I know some women wear underwear that isn't panties. Don't try > to change the topic with absurd logical extremes that I didn't raise. > > I'm talking about the implication of the comment as a gendered insult. > >> It's only gender specific if you accept the sexist gendered stereotype >> that all women are by definition thin-skinned and excessively >> sensitive. > > Bullshit. I said nothing about the sensitivity of anyone. Individual > women you may know ? even *all* women, everywhere ? could be as tough as > nails, and it doesn't address the point I'm raising. > > Whether any particular woman is targeted or not, the comment I'm > responding to invokes female gender as an implied insult. That's > unwelcoming to women, and I don't want such unwelcoming attitudes in > this community. > I'd rather be reading about the 4,773 open issues on the bug tracker. As I consider this rather more important than some completely tangential load of cobblers, would you and MR D'Aprano be kind enough to go and have your 12, 3 minute rounds elsewhere, thanks? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rosuav at gmail.com Thu Mar 5 23:04:49 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Mar 2015 15:04:49 +1100 Subject: How fast does your grass grow? [was Re: HELP!! How to ask a girl out with a simple witty Python code??] In-Reply-To: <54F923A1.5040901@stoneleaf.us> References: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> <2906370c-58c7-4d8b-8db3-2ea3773b9578@googlegroups.com> <54f8d56a$0$12984$c3e8da3$5496439d@news.astraweb.com> <54f916b2$0$12980$c3e8da3$5496439d@news.astraweb.com> <85385izu51.fsf@benfinney.id.au> <54F923A1.5040901@stoneleaf.us> Message-ID: On Fri, Mar 6, 2015 at 2:48 PM, Ethan Furman wrote: > On 03/05/2015 07:37 PM, Chris Angelico wrote: > >> I'm sure there's something more interesting to talk about... like the >> rate at which the grass is growing. > > My grass doesn't grow -- I ripped it all out and put down pea-gravel and planter boxes. > > Oh, wait, I have some bamboo in the back -- that's a grass, isn't it? Hmmm, well, it grows fast enough that my dogs > haven't managed to eat it gone yet. :) Our grass is actually growing at the moment, which is unusual for Australia at this time of year. Usually it's in a state of bronzing part way through December, and basically stays that way until well into February. ChrisA From random832 at fastmail.us Thu Mar 5 23:37:06 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Thu, 05 Mar 2015 23:37:06 -0500 Subject: Is nan in (nan,) correct? In-Reply-To: References: <54f90c53$0$12994$c3e8da3$5496439d@news.astraweb.com> <858ufazvff.fsf@benfinney.id.au> <54F91C70.6020303@stoneleaf.us> <85wq2uyffs.fsf@benfinney.id.au> Message-ID: <1425616626.2734684.236278461.1D91F36F@webmail.messagingengine.com> On Thu, Mar 5, 2015, at 22:49, Chris Angelico wrote: > I'm not sure it's just an optimization. Compare this post from > python-dev, where Nick Coghlan discusses the same topic: > > https://mail.python.org/pipermail/python-dev/2014-July/135476.html If it is a bug for NaN to "infect" containers' behavior, we need to take a serious look at sort(). From breamoreboy at yahoo.co.uk Thu Mar 5 23:46:01 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 06 Mar 2015 04:46:01 +0000 Subject: Is nan in (nan,) correct? In-Reply-To: <1425616626.2734684.236278461.1D91F36F@webmail.messagingengine.com> References: <54f90c53$0$12994$c3e8da3$5496439d@news.astraweb.com> <858ufazvff.fsf@benfinney.id.au> <54F91C70.6020303@stoneleaf.us> <85wq2uyffs.fsf@benfinney.id.au> <1425616626.2734684.236278461.1D91F36F@webmail.messagingengine.com> Message-ID: On 06/03/2015 04:37, random832 at fastmail.us wrote: > On Thu, Mar 5, 2015, at 22:49, Chris Angelico wrote: >> I'm not sure it's just an optimization. Compare this post from >> python-dev, where Nick Coghlan discusses the same topic: >> >> https://mail.python.org/pipermail/python-dev/2014-July/135476.html > > If it is a bug for NaN to "infect" containers' behavior, we need to take > a serious look at sort(). > I entirely agree. With the extremely serious bug that was reported (and fixed) just a few days ago in the Python sorting algorithm and/or code, it is quite clear to me that it probably needs a major rethink. After you :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rustompmody at gmail.com Thu Mar 5 23:53:08 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 5 Mar 2015 20:53:08 -0800 (PST) Subject: Newbie question about text encoding In-Reply-To: <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> References: <201502241524.t1OFO09k022270@fido.openend.se> <201502241620.t1OGKf4n002146@fido.openend.se> <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thursday, March 5, 2015 at 7:36:32 PM UTC+5:30, Steven D'Aprano wrote: > Rustom Mody wrote: > > > On Wednesday, March 4, 2015 at 10:25:24 AM UTC+5:30, Chris Angelico wrote: > >> On Wed, Mar 4, 2015 at 3:45 PM, Rustom Mody wrote: > >> > > >> > It lists some examples of software that somehow break/goof going from > >> > BMP-only unicode to 7.0 unicode. > >> > > >> > IOW the suggestion is that the the two-way classification > >> > - ASCII > >> > - Unicode > >> > > >> > is less useful and accurate than the 3-way > >> > > >> > - ASCII > >> > - BMP > >> > - Unicode > >> > >> How is that more useful? Aside from storage optimizations (in which > >> the significant breaks would be Latin-1, UCS-2, and UCS-4), the BMP is > >> not significantly different from the rest of Unicode. > > > > Sorry... Dont understand. > > Chris is suggesting that going from BMP to all of Unicode is not the hard > part. Going from ASCII to the BMP part of Unicode is the hard part. If you > can do that, you can go the rest of the way easily. Depends where the going is starting from. I specifically names Java, Javascript, Windows... among others. Here's some quotes from the supplementary chars doc of Java http://www.oracle.com/technetwork/articles/javase/supplementary-142654.html | Supplementary characters are characters in the Unicode standard whose code | points are above U+FFFF, and which therefore cannot be described as single | 16-bit entities such as the char data type in the Java programming language. | Such characters are generally rare, but some are used, for example, as part | of Chinese and Japanese personal names, and so support for them is commonly | required for government applications in East Asian countries... | The introduction of supplementary characters unfortunately makes the | character model quite a bit more complicated. | Unicode was originally designed as a fixed-width 16-bit character encoding. | The primitive data type char in the Java programming language was intended to | take advantage of this design by providing a simple data type that could hold | any character.... Version 5.0 of the J2SE is required to support version 4.0 | of the Unicode standard, so it has to support supplementary characters. My conclusion: Early adopters of unicode -- Windows and Java -- were punished for their early adoption. You can blame the unicode consortium, you can blame the babel of human languages, particularly that some use characters and some only (the equivalent of) what we call words. Or you can skip the blame-game and simply note the fact that large segments of extant code-bases are currently in bug-prone or plain buggy state. This includes not just bug-prone-system code such as Java and Windows but seemingly working code such as python 3. > > I mostly agree with Chris. Supporting *just* the BMP is non-trivial in UTF-8 > and UTF-32, since that goes against the grain of the system. You would have > to program in artificial restrictions that otherwise don't exist. Yes UTF-8 and UTF-32 make most of the objections to unicode 7.0 irrelevant. Large segments of the > > UTF-16 is different, and that's probably why you think supporting all of > Unicode is hard. With UTF-16, there really is an obvious distinction > between the BMP and the SMP: that's where you jump from a single 2-byte > unit to a pair of 2-byte units. But that distinction doesn't exist in UTF-8 > or UTF-32: > > - In UTF-8, about 99.8% of the BMP requires multiple bytes. Whether you > support the SMP or not doesn't change the fact that you have to deal > with multi-byte characters. > > - In UTF-32, everything is fixed-width whether it is in the BMP or not. > > In both cases, supporting the SMPs is no harder than supporting the BMP. > It's only UTF-16 that makes the SMP seem hard. > > Conclusion: faulty implementations of UTF-16 which incorrectly handle > surrogate pairs should be replaced by non-faulty implementations, or > changed to UTF-8 or UTF-32; incomplete Unicode implementations which assume > that Unicode is 16-bit only (e.g. UCS-2) are obsolete and should be > upgraded. Imagine for a moment a thought experiment -- we are not on a python but a java forum and please rewrite the above para. Are you addressing the vanilla java programmer? Language implementer? Designer? The Java-funders -- earlier Sun, now Oracle? > > Wrong conclusion: SMPs are unnecessary and unneeded, and we need a new > standard that is just like obsolete Unicode version 1. > > Unicode version 1 is obsolete for a reason. 16 bits is not enough for even > existing languages, let alone all the code points and characters that are > used in human communication. > > > >> Also, the expansion from 16-bit was back in Unicode 2.0, not 7.0. Why > >> do you keep talking about 7.0 as if it's a recent change? > > > > It is 2015 as of now. 7.0 is the current standard. > > > > The need for the adjective 'current' should be pondered upon. > > What's your point? > > The UTF encodings have not changed since they were first introduced. They > have been stable for at least twenty years: UTF-8 has existed since 1993, > and UTF-16 since 1996. > > Since version 2.0 of Unicode in 1996, the standard has made "stability > guarantees" that no code points will be renamed or removed. Consequently, > there has only been one version which removed characters, version 1.1. > Since then, new versions of the standard have only added characters, never > moved, renamed or deleted them. > > http://unicode.org/policies/stability_policy.html > > Some highlights in Unicode history: > > Unicode 1.0 (1991): initial version, defined 7161 code points. > > In January 1993, Rob Pike and Ken Thompson announced the design and working > implementation of the UTF-8 encoding. > > 1.1 (1993): defined 34233 characters, finalised Han Unification. Removed > some characters from the 1.0 set. This is the first and only time any code > points have been removed. > > 2.0 (1996): First version to include code points in the Supplementary > Multilingual Planes. Defined 38950 code points. Introduced the UTF-16 > encoding. > > 3.1 (2001): Defined 94205 code points, including 42711 additional Han > ideographs, bringing the total number of CJK code points alone to 71793, > too many to fit in 16 bits. > > 2006: The People's Republic Of China mandates support for the GB-18030 > character set for all software products sold in the PRC. GB-18030 supports > the entire Unicode range, include the SMPs. Since this date, all software > sold in China must support the SMPs. > > 6.0 (2010): The first emoji or emoticons were added to Unicode. > > 7.0 (2014): 113021 code points defined in total. > > > > In practice, standards change. > > However if a standard changes so frequently that that users have to play > > catching cook and keep asking: "Which version?" they are justified in > > asking "Are the standard-makers doing due diligence?" > > Since Unicode has stability guarantees, and the encodings have not changed > in twenty years and will not change in the future, this argument is bogus. > Updating to a new version of the standard means, to a first approximation, > merely allocating some new code points which had previously been undefined > but are now defined. > > (Code points can be flagged deprecated, but they will never be removed.) Its not about new code points; its about "Fits in 2 bytes" to "Does not fit in 2 bytes" If you call that argument bogus I call you a non computer scientist. [Essentially this is my issue with the consortium it seems to be working like a bunch of linguists not computer scientists] Here is Roy's Smith post that first started me thinking that something may be wrong with SMP https://groups.google.com/d/msg/comp.lang.python/loYWMJnPtos/GHMC0cX_hfgJ Some parts are here some earlier and from my memory. If details wrong please correct: - 200 million records - Containing 4 strings with SMP characters - System made with python and mysql. SMP works with python, breaks mysql. So whole system broke due to those 4 in 200,000,000 records I know enough (or not enough) of unicode to be chary of statistical conclusions from the above. My conclusion is essentially an 'existence-proof': SMP-chars can break systems. The breakage is costly-fied by the combination - layman statistical assumptions - BMP ? SMP exercises different code-paths It is necessary but not sufficient to test print "hello world" in ASCII, BMP, SMP. You also have to write the hello world in the database -- mysql Read it from the webform -- javascript etc etc You could also choose do with "astral crap" (Roy's words) what we all do with crap -- throw it out as early as possible. From rosuav at gmail.com Fri Mar 6 00:20:21 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Mar 2015 16:20:21 +1100 Subject: Newbie question about text encoding In-Reply-To: References: <201502241524.t1OFO09k022270@fido.openend.se> <201502241620.t1OGKf4n002146@fido.openend.se> <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 6, 2015 at 3:53 PM, Rustom Mody wrote: > My conclusion: Early adopters of unicode -- Windows and Java -- were punished > for their early adoption. You can blame the unicode consortium, you can > blame the babel of human languages, particularly that some use characters > and some only (the equivalent of) what we call words. > > Or you can skip the blame-game and simply note the fact that large segments of > extant code-bases are currently in bug-prone or plain buggy state. For most of the 1990s, I was writing code in REXX, on OS/2. An even earlier adopter, REXX didn't have Unicode support _at all_, but instead had facilities for working with DBCS strings. You can't get everything right AND be the first to produce anything. Python didn't make Unicode strings the default until 3.0, but that's not Unicode's fault. > This includes not just bug-prone-system code such as Java and Windows but > seemingly working code such as python 3. > > Here is Roy's Smith post that first started me thinking that something may > be wrong with SMP > https://groups.google.com/d/msg/comp.lang.python/loYWMJnPtos/GHMC0cX_hfgJ > > Some parts are here some earlier and from my memory. > If details wrong please correct: > - 200 million records > - Containing 4 strings with SMP characters > - System made with python and mysql. SMP works with python, breaks mysql. > So whole system broke due to those 4 in 200,000,000 records > > I know enough (or not enough) of unicode to be chary of statistical conclusions > from the above. > My conclusion is essentially an 'existence-proof': Hang on hang on. Why are you blaming Python or SMP characters for this? The problem here is MySQL, which doesn't adequately cope with the full Unicode range. (Or, didn't then, or doesn't with its default settings. I believe you can configure current versions of MySQL to work correctly, though I haven't actually checked. PostgreSQL gets it right, that's good enough for me.) > SMP-chars can break systems. > The breakage is costly-fied by the combination > - layman statistical assumptions > - BMP ? SMP exercises different code-paths Broken systems can be shown up by anything. Suppose you have a program that breaks when it gets a NUL character (not unknown in C code); is the fault with the Unicode consortium for allocating something at codepoint 0, or the code that can't cope with a perfectly normal character? > You could also choose do with "astral crap" (Roy's words) what we all do with > crap -- throw it out as early as possible. There's only one character that fits that description, and that's 1F4A9. Everything else is just "astral characters", and you shouldn't have any difficulties with them. ChrisA From ian.g.kelly at gmail.com Fri Mar 6 01:36:47 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 5 Mar 2015 23:36:47 -0700 Subject: [Python 3.4] Rationale for readonly slice data attributes In-Reply-To: References: Message-ID: On Thu, Mar 5, 2015 at 4:57 PM, Mario Figueiredo wrote: > What is the rationale behind making the slice class data attributes > readonly? > > I've built a __getitem__ method for a Map class that contains a list > of Cell instance objects. __getitem__ maps this list into a matrix:: > > # get cell at cartesian coordinates 12, 4 > # will map to the 1048th position in the cells list > mmap = Map() > print(mmap[12, 4]) > > All is working well and it even supports slicing:: > > # return all cells with x between 3 and 6 and y up until 4 > mmap = Map() > [print(cell) for cell in mmap(3:6, :4)] > > This last example is one case in which I missed the ability to change > the the `start` and `stop` attributes of the slice class in order for > the maping to occur that allows a 2-dimensions access to a 1-dimension > list. I'm not following what it is that you want to accomplish in this example by modifying the slice object. > It was solved by taking another turn, but it proved to me that the > slice data attributes are more useful if they are writable, and this > clashes tremendously with the principles of data encapsulation that > underline the requirements for a readonly property. In other words, if > it needs to be accessed, don't hide it. If it needs to be written, > don't lock it. > > Now, normally I take these things for granted. Rules are rules and > their reasons are often fairly obvious. But in this case I'm at loss. > I can't find a reason for this class attributes to have been made into > readonly properties. You also can't mutate bound methods, range objects, or ints. Do any of those bother you? Immutable types are often desirable because they're easier to reason about, especially when concurrency enters the picture. As an example, suppose I'm iterating over a view constructed by slicing some collection. What should happen if the slice is suddenly altered in mid-iteration? Because slice objects are immutable, this is a question that doesn't even need an answer. slice is about as light-weight a class as they come. If you need to modify a slice, is there any reason you can't just construct a new one? Lastly, if you really want a mutable "slice", you can work around this by using a 3-element list and construct a slice from it on demand. From abhi.darkness at gmail.com Fri Mar 6 01:44:22 2015 From: abhi.darkness at gmail.com (Abhiram R) Date: Fri, 6 Mar 2015 12:14:22 +0530 Subject: Speeding up permutations generation Message-ID: Hi all, Is there a way to generate permutations of large arrays of sizes say,in the hundreds, faster than in the time itertools.permutations() can return? ?-Abhiram.R *~Never give up* -------------- next part -------------- An HTML attachment was scrubbed... URL: From jonas at wielicki.name Fri Mar 6 01:58:58 2015 From: jonas at wielicki.name (Jonas Wielicki) Date: Fri, 06 Mar 2015 07:58:58 +0100 Subject: Python Worst Practices In-Reply-To: References: <7053A277-9687-49B0-9FDB-CB4DB3E76DEC@gmail.com> <54F0E38D.40006@davea.name> <54f274bb$0$13011$c3e8da3$5496439d@news.astraweb.com> Message-ID: <54F95032.9010000@wielicki.name> On 01.03.2015 03:43, Chris Angelico wrote: > Imagine if all > your Python code ran twice as fast (that's slightly better than the > IronPython figure quoted!), but worked only on BSD Unix and Mac OS. Is > that something that'll make a fledgling language succeed? I heard that Swift and Objective-C are quite popular these days. regards, jwi From ian.g.kelly at gmail.com Fri Mar 6 02:10:06 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 6 Mar 2015 00:10:06 -0700 Subject: Speeding up permutations generation In-Reply-To: References: Message-ID: On Thu, Mar 5, 2015 at 11:44 PM, Abhiram R wrote: > Hi all, > Is there a way to generate permutations of large arrays of sizes say,in the > hundreds, faster than in the time itertools.permutations() can return? A list of 100 elements has approximately 9.33 x 10**157 permutations. If you could somehow generate one permutation every yoctosecond, exhausting them would still take more than a hundred orders of magnitude longer than the age of the universe. From ben+python at benfinney.id.au Fri Mar 6 02:57:42 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 06 Mar 2015 18:57:42 +1100 Subject: HELP!! How to ask a girl out with a simple witty Python code?? References: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> <2906370c-58c7-4d8b-8db3-2ea3773b9578@googlegroups.com> <54f8d56a$0$12984$c3e8da3$5496439d@news.astraweb.com> <54f916b2$0$12980$c3e8da3$5496439d@news.astraweb.com> <85385izu51.fsf@benfinney.id.au> Message-ID: <85mw3qy2vd.fsf@benfinney.id.au> Chris Angelico writes: > * Two people then go back and forth about whether or not the previous > three posts were offensive. I called out a specific gendered slur as such. Nothing to do with ?offense?, and I made no such claim. > The whole field of getting vicariously offended is a mess. It's a good thing I was not doing that, then. I was calling out an anti-female slur where I saw it. > All we have is people getting annoyed on behalf of an unspecified > person or group of people If you missed the specified group, I'll say it again: Anyone who is female had their gender used as though it were an insult. That's not welcoming to women, and if it goes unchallenged then we give the perception it is acceptable. It is not, so we must say so as clearly as we can. Where people have further misrepresented my complaint or my position, I've necessarily corrected them. Hopefully I've been clear enough that no-one needs to once more impute words or motivations to me that I never expressed. -- \ ?The number of UNIX installations has grown to 10, with more | `\ expected.? ?Unix Programmer's Manual, 2nd Ed., 1972-06-12 | _o__) | Ben Finney From rustompmody at gmail.com Fri Mar 6 03:00:28 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 6 Mar 2015 00:00:28 -0800 (PST) Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] In-Reply-To: <87mw3s10nl.fsf@elektro.pacujo.net> References: <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> <87twy34dst.fsf@elektro.pacujo.net> <726afahrhnim716av2dnckrsd9n5j5kukj@4ax.com> <21dafa533nrsmktshd35kdbd13ahgj50bf@4ax.com> <87fv9k2999.fsf@elektro.pacujo.net> <54f7599d$0$12988$c3e8da3$5496439d@news.astraweb.com> <8761ag36du.fsf@elektro.pacujo.net> <87mw3s10nl.fsf@elektro.pacujo.net> Message-ID: <9ccfd0c7-1310-44de-a493-6019a1773ae1@googlegroups.com> On Thursday, March 5, 2015 at 10:49:54 AM UTC+5:30, Marko Rauhamaa wrote: > Rustom Mody: > > > You keep talking of accent. > > At first I thought you were using the word figuratively or else joking. > > Im now beginning to wonder if you mean it literally. > > If so have you patented a new AOIP protocol? > > If not do you give tuitions? in ESP/telepathy/Voodoo? I'll be happy to > > pay > > Where I work, people do use voice still occasionally to communicate. I really dont understand what we are communicating (or not) about... Can you hear my accent? I certainly cant hear yours If you are talking of accent (aural/physical just to be clear) of your co-workers how is that more on-topic or relevant to this list than the weather in Finland. [Yeah its been freakish weather out here for the last 10 days -- global warming? And is global warming on topic for this list?] Just to be clear -- I am going to be one of the tail-enders complaining about on/off-topicness. But someone or other will complain I guess. If on the other hand you are being slightly metaphorical and using 'accent' to talk of (say) Mark's britishisms? then please disambiguate for better communication. But more to the point its still not clear (to me) whether you are objecting to - to Mark - to British accent - to British spellings in software - to anyone/anywhere international, using non-international format ?Personally I find Mark's britishisms sometimes funny eg I found this https://groups.google.com/d/msg/comp.lang.python/EfloMHB3DjQ/ZdY3Vn_6rpsJ hilarious even though I could not decipher more than 70% of the british accent. Sometimes though I find it irrelevant/unnecessary/undecipherable. Personally I am not going to object to him nor am I going to object to anyone objecting to him. From mese1979 at gmail.com Fri Mar 6 03:14:07 2015 From: mese1979 at gmail.com (Mehdi) Date: Fri, 6 Mar 2015 00:14:07 -0800 (PST) Subject: Make standalone gui-enabled app for LINUX In-Reply-To: References: <413fc3f5-38c3-4477-8495-366852e583e7@googlegroups.com> Message-ID: <0f6e6f37-60df-4683-8c2d-d4a0a34bf98b@googlegroups.com> I have no experience with pyqt and so pyqtdeploy but it seems what i need. > I haven't announced this on the list yet, but... > > http://pyqt.sourceforge.net/Docs/pyqtdeploy/ > > Phil But i think pyinstaller doesn't work with python3. On Friday, March 6, 2015 at 12:58:11 AM UTC+3:30, Christian Gollwitzer wrote: > Use pyinstaller. It creates a "portable app", i.e. either single file or > directory which can be run on (nearly) any system. However the resulting > files can be awfully big. I use it with a relatively small program that > depends on numpy/matplolib, and that pulls in ~100 MB worth of libraries. > > Christian From abhi.darkness at gmail.com Fri Mar 6 03:24:48 2015 From: abhi.darkness at gmail.com (Abhiram R) Date: Fri, 6 Mar 2015 13:54:48 +0530 Subject: Speeding up permutations generation In-Reply-To: References: Message-ID: > > A list of 100 elements has approximately 9.33 x 10**157 permutations. > If you could somehow generate one permutation every yoctosecond, > exhausting them would still take more than a hundred orders of > magnitude longer than the age of the universe. > -- > https://mail.python.org/mailman/listinfo/python-list > ?True that :D I may have exaggerated on the number. Let's consider something more practically manageable? => 50 elements with a 50! permutation. Is there a solution now? ?-Abhiram.R *~Never give up* -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Fri Mar 6 03:31:40 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 06 Mar 2015 08:31:40 +0000 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] In-Reply-To: <9ccfd0c7-1310-44de-a493-6019a1773ae1@googlegroups.com> References: <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> <87twy34dst.fsf@elektro.pacujo.net> <726afahrhnim716av2dnckrsd9n5j5kukj@4ax.com> <21dafa533nrsmktshd35kdbd13ahgj50bf@4ax.com> <87fv9k2999.fsf@elektro.pacujo.net> <54f7599d$0$12988$c3e8da3$5496439d@news.astraweb.com> <8761ag36du.fsf@elektro.pacujo.net> <87mw3s10nl.fsf@elektro.pacujo.net> <9ccfd0c7-1310-44de-a493-6019a1773ae1@googlegroups.com> Message-ID: On 06/03/2015 08:00, Rustom Mody wrote: > On Thursday, March 5, 2015 at 10:49:54 AM UTC+5:30, Marko Rauhamaa wrote: >> Rustom Mody: >> >>> You keep talking of accent. >>> At first I thought you were using the word figuratively or else joking. >>> Im now beginning to wonder if you mean it literally. >>> If so have you patented a new AOIP protocol? >>> If not do you give tuitions? in ESP/telepathy/Voodoo? I'll be happy to >>> pay >> >> Where I work, people do use voice still occasionally to communicate. > > I really dont understand what we are communicating (or not) about... > > Can you hear my accent? I certainly cant hear yours > If you are talking of accent (aural/physical just to be clear) of your co-workers > how is that more on-topic or relevant to this list than the weather in Finland. > [Yeah its been freakish weather out here for the last 10 days -- global warming? > And is global warming on topic for this list?] > Just to be clear -- I am going to be one of the tail-enders complaining about > on/off-topicness. But someone or other will complain I guess. > > If on the other hand you are being slightly metaphorical and using 'accent' > to talk of (say) Mark's britishisms? then please disambiguate for better communication. > > But more to the point its still not clear (to me) whether you are objecting to > - to Mark > - to British accent British accent, Christmas is early this year so ho, ho, ho. Nobody in this country ever guesses where I was born and bred, they all think I'm from the South West or the West Country. Irish, Scottish, Welsh, English alone are different. Most foreigners wouldn't have a dog's chance in hell of understanding a Geordie or a Glaswegian. Move 50 miles and you can hear a completely different accent. British accent indeed. > - to British spellings in software > - to anyone/anywhere international, using non-international format > > > ?Personally I find Mark's britishisms sometimes funny eg I found this > https://groups.google.com/d/msg/comp.lang.python/EfloMHB3DjQ/ZdY3Vn_6rpsJ hilarious even though I could not decipher more than 70% of the british accent. > Sometimes though I find it irrelevant/unnecessary/undecipherable. > > Personally I am not going to object to him nor am I going to object to anyone > objecting to him. > Anybody objecting about me will be accused by me of discrimination against autistic people. Now there is a not very subtle hint that might penetrate one or two of the thicker skins on the thicker heads that participate here. Thankfully the numbers of such people are extremely small or we could have had WWIII. Which could have happened when Global Crossing bought Racal Telecommunications and tried to stop us Brits using our kettles to make our cuppas. Now that is seriously brain dead. And they turned out to be a bit naughty with the books :( -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Fri Mar 6 03:34:17 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 06 Mar 2015 08:34:17 +0000 Subject: Speeding up permutations generation In-Reply-To: References: Message-ID: On 06/03/2015 06:44, Abhiram R wrote: > Hi all, > Is there a way to generate permutations of large arrays of sizes say,in > the hundreds, faster than in the time itertools.permutations() can return? > > ?-Abhiram.R > /~Never give up/ > If there is I'd guess that you'd use numpy http://www.numpy.org/. The more mathematically minded may well be able to give better answers. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From wolfgang.maier at biologie.uni-freiburg.de Fri Mar 6 03:44:39 2015 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Fri, 06 Mar 2015 09:44:39 +0100 Subject: Speeding up permutations generation In-Reply-To: References: Message-ID: On 03/06/2015 09:34 AM, Mark Lawrence wrote: > On 06/03/2015 06:44, Abhiram R wrote: >> Hi all, >> Is there a way to generate permutations of large arrays of sizes say,in >> the hundreds, faster than in the time itertools.permutations() can >> return? >> >> ?-Abhiram.R >> /~Never give up/ >> > > If there is I'd guess that you'd use numpy http://www.numpy.org/. The > more mathematically minded may well be able to give better answers. > Well, numpy would be faster if you could call into it once and retrieve all permutations as an array. This would allow you to do all calculations in C, while itertools.permutations has to jump back and forth between C and Pyhon code. However, 50! is still ~ 3*10^64. So where would you want to store the array of these many permutations ? From rustompmody at gmail.com Fri Mar 6 04:02:35 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 6 Mar 2015 01:02:35 -0800 (PST) Subject: Newbie question about text encoding In-Reply-To: References: <201502241524.t1OFO09k022270@fido.openend.se> <201502241620.t1OGKf4n002146@fido.openend.se> <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> Message-ID: <01dd9b83-db3e-4e7d-9022-dc6af75eb570@googlegroups.com> On Friday, March 6, 2015 at 10:50:35 AM UTC+5:30, Chris Angelico wrote: > On Fri, Mar 6, 2015 at 3:53 PM, Rustom Mody wrote: > > My conclusion: Early adopters of unicode -- Windows and Java -- were punished > > for their early adoption. You can blame the unicode consortium, you can > > blame the babel of human languages, particularly that some use characters > > and some only (the equivalent of) what we call words. > > > > Or you can skip the blame-game and simply note the fact that large segments of > > extant code-bases are currently in bug-prone or plain buggy state. > > For most of the 1990s, I was writing code in REXX, on OS/2. An even > earlier adopter, REXX didn't have Unicode support _at all_, but > instead had facilities for working with DBCS strings. You can't get > everything right AND be the first to produce anything. Python didn't > make Unicode strings the default until 3.0, but that's not Unicode's > fault. > > > This includes not just bug-prone-system code such as Java and Windows but > > seemingly working code such as python 3. > > > > Here is Roy's Smith post that first started me thinking that something may > > be wrong with SMP > > https://groups.google.com/d/msg/comp.lang.python/loYWMJnPtos/GHMC0cX_hfgJ > > > > Some parts are here some earlier and from my memory. > > If details wrong please correct: > > - 200 million records > > - Containing 4 strings with SMP characters > > - System made with python and mysql. SMP works with python, breaks mysql. > > So whole system broke due to those 4 in 200,000,000 records > > > > I know enough (or not enough) of unicode to be chary of statistical conclusions > > from the above. > > My conclusion is essentially an 'existence-proof': > > Hang on hang on. Why are you blaming Python or SMP characters for > this? The problem here is MySQL, which doesn't adequately cope with > the full Unicode range. (Or, didn't then, or doesn't with its default > settings. I believe you can configure current versions of MySQL to > work correctly, though I haven't actually checked. PostgreSQL gets it > right, that's good enough for me.) > > > SMP-chars can break systems. > > The breakage is costly-fied by the combination > > - layman statistical assumptions > > - BMP ? SMP exercises different code-paths > > Broken systems can be shown up by anything. Suppose you have a program > that breaks when it gets a NUL character (not unknown in C code); is > the fault with the Unicode consortium for allocating something at > codepoint 0, or the code that can't cope with a perfectly normal > character? Strawman. Lets please stick to UTF-16 shall we? Now tell me: - Is it broken or not? - Is it widely used or not? - Should programmers be careful of it or not? - Should programmers be warned about it or not? From rustompmody at gmail.com Fri Mar 6 04:06:26 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 6 Mar 2015 01:06:26 -0800 (PST) Subject: Newbie question about text encoding In-Reply-To: <01dd9b83-db3e-4e7d-9022-dc6af75eb570@googlegroups.com> References: <201502241524.t1OFO09k022270@fido.openend.se> <201502241620.t1OGKf4n002146@fido.openend.se> <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <01dd9b83-db3e-4e7d-9022-dc6af75eb570@googlegroups.com> Message-ID: On Friday, March 6, 2015 at 2:33:11 PM UTC+5:30, Rustom Mody wrote: > Lets please stick to UTF-16 shall we? > > Now tell me: > - Is it broken or not? > - Is it widely used or not? > - Should programmers be careful of it or not? > - Should programmers be warned about it or not? Also: Can a programmer who is away from UTF-16 in one part of the system (say by using python3) assume he is safe all over? From rustompmody at gmail.com Fri Mar 6 04:50:34 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 6 Mar 2015 01:50:34 -0800 (PST) Subject: Is nan in (nan,) correct? In-Reply-To: References: Message-ID: On Friday, March 6, 2015 at 3:57:12 AM UTC+5:30, rand... at fastmail.us wrote: > It's been brought up on Stack Overflow that the "in" operator (on > tuples, and by my testing on dict and list, as well as dict lookup) uses > object identity as a shortcut, and returns true immediately if the > object being tested *is* an element of the container. However, the > contains operation does not specify whether object identity or equality > is to be used. In effect, the built-in container types use a hybrid > test: "a is b or a == b". > > My question is, is this a *correct* implementation of the operator, or > are objects "supposed to" use a basis of equality for these tests? nan is an illegal or bogus value. As usual legalizing the illegal is always fraught with increasing conundrums. The most (to me) classic instance of this is denotational semantics. In DS one tries to give semantics to programs by mapping programs to math-functions across some domains However some programs crash. What should be the semantics of such a program. We say its a partial function ? undefined at the crash-points. But partial functions are not nearly as tractable (to mathematicians!) as total functions. So we invent a bogus value ? (called bottom) and totalize all functions by mapping to this. Very nice? So nice in fact that we wish to add ? to our programming language And now all hell breaks loose because the question x == ? is the halting problem. And people love this problem so much they keep replicating it: - C and null (or Pascal/Lisp and Nil) [Hoare's billion dollar mistake https://en.wikipedia.org/wiki/Tony_Hoare#Apologies_and_retractions ] - nul in SQL ? Should two nuls compare as same or different? There are good (and different!) reasons for both answers - Python and None - Floats and nans My own thoughts on this (not very well thought out, I admit) The letter of the IEEE standard talks of nans and their details The spirit of the standard is that nans capture exception-al computations ie nan represents an exception In a language like python with decent exceptions we do not need nans. Of course there are all sorts of corner cases eg data source is something outside python etc From rosuav at gmail.com Fri Mar 6 04:54:00 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Mar 2015 20:54:00 +1100 Subject: Newbie question about text encoding In-Reply-To: <01dd9b83-db3e-4e7d-9022-dc6af75eb570@googlegroups.com> References: <201502241524.t1OFO09k022270@fido.openend.se> <201502241620.t1OGKf4n002146@fido.openend.se> <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <01dd9b83-db3e-4e7d-9022-dc6af75eb570@googlegroups.com> Message-ID: On Fri, Mar 6, 2015 at 8:02 PM, Rustom Mody wrote: >> Broken systems can be shown up by anything. Suppose you have a program >> that breaks when it gets a NUL character (not unknown in C code); is >> the fault with the Unicode consortium for allocating something at >> codepoint 0, or the code that can't cope with a perfectly normal >> character? > > Strawman. Not really, no. I know of lots of programs that can't handle embedded NULs, and which fail in various ways when given them (the most common is simple truncation, but it's by far not the only way). And it's exactly the same: a program that purports to handle arbitrary Unicode text should be able to handle arbitrary Unicode text, not "Unicode text as long as it contains only codepoints within the range X-Y". It doesn't matter whether the code chokes on U+0000, U+005C, U+FFFC, or U+1F4A3 - if your code blows up, it's a failure in your code. > Lets please stick to UTF-16 shall we? > > Now tell me: > - Is it broken or not? > - Is it widely used or not? > - Should programmers be careful of it or not? > - Should programmers be warned about it or not? No, UTF-16 is not itself broken. (It would be if we expected codepoints >0x10FFFF, and it's because of UTF-16 that that's the cap on Unicode, but it's looking unlikely that we'll be needing any more than that anyway.) What's broken is code that tries to treat UTF-16 as if it's UCS-2, and then breaks on surrogate pairs. Yes, it's widely used. Programmers should probably be warned about it, but only because its tradeoffs are generally poorer than UTF-8's. If you use it correctly, there's no problem. > Also: > Can a programmer who is away from UTF-16 in one part of the system (say by using python3) > assume he is safe all over? I don't know what you mean here. Do you mean that your Python 3 program is "at risk" in some way because there might be some other program that misuses UTF-16? Well, sure. And there might be some other program that misuses buffer sizes, SQL queries, or shell invocations, and makes your overall system vulnerable to buffer overruns or injection attacks. These are significantly more likely AND more serious than UTF-16 misuses. And you still have not proven anything about SMP characters being a problem, but only that code can be broken. Broken code is still broken code, no matter what your actual brokenness. ChrisA From rosuav at gmail.com Fri Mar 6 04:59:14 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Mar 2015 20:59:14 +1100 Subject: Speeding up permutations generation In-Reply-To: References: Message-ID: On Fri, Mar 6, 2015 at 7:24 PM, Abhiram R wrote: >> A list of 100 elements has approximately 9.33 x 10**157 permutations. >> If you could somehow generate one permutation every yoctosecond, >> exhausting them would still take more than a hundred orders of >> magnitude longer than the age of the universe. >> -- >> https://mail.python.org/mailman/listinfo/python-list > > > True that :D I may have exaggerated on the number. Let's consider something > more practically manageable => 50 elements with a 50! permutation. > Is there a solution now? > Is the actual generation of permutations your problem? You mentioned that you're using itertools, so I would expect that you're simply iterating over that; I hope you're not immediately trying to construct a list of them all, because that would cost the memory that Mark's response talks about. Have you actually profiled your code and found that generating permutations is the bottleneck, or did you just guess? Because even experienced programmers - even extremely experienced Python programmers - are usually wrong when they guess about the slowest part of a program. The only way to know is to measure. ChrisA From rosuav at gmail.com Fri Mar 6 05:01:06 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Mar 2015 21:01:06 +1100 Subject: Is nan in (nan,) correct? In-Reply-To: References: Message-ID: On Fri, Mar 6, 2015 at 8:50 PM, Rustom Mody wrote: > In a language like python with decent exceptions we do not need nans. Not so. I could perhaps accept that we don't need signalling NaNs, as they can be replaced with exceptions, but quiet NaNs are by definition _not_ exceptions. ChrisA From marko at pacujo.net Fri Mar 6 05:03:31 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 06 Mar 2015 12:03:31 +0200 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] References: <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> <87twy34dst.fsf@elektro.pacujo.net> <726afahrhnim716av2dnckrsd9n5j5kukj@4ax.com> <21dafa533nrsmktshd35kdbd13ahgj50bf@4ax.com> <87fv9k2999.fsf@elektro.pacujo.net> <54f7599d$0$12988$c3e8da3$5496439d@news.astraweb.com> <8761ag36du.fsf@elektro.pacujo.net> <87mw3s10nl.fsf@elektro.pacujo.net> <9ccfd0c7-1310-44de-a493-6019a1773ae1@googlegroups.com> Message-ID: <87k2yu5tos.fsf@elektro.pacujo.net> Rustom Mody : > I really dont understand what we are communicating (or not) about... > > Can you hear my accent? If we met at a Python conference, I would hear it and hopefully even understand it. > But more to the point its still not clear (to me) whether you are objecting to > - to Mark > - to British accent > - to British spellings in software > - to anyone/anywhere international, using non-international format I'm objecting (mildly) to British spellings in source code and technical documentation. I'm objecting (more strongly) to local English accents in settings including but not limited to: - conference speeches with international audiences - group discussions with international participants - teleconferences with international participants In my experience, it is harder to understand most British English accents than, say, a run-of-the-mill Chinese engineer trying to speak English. It has to do with pronunciation, speed and eloquence (too much of it with native speakers). Marko From marko at pacujo.net Fri Mar 6 05:06:47 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 06 Mar 2015 12:06:47 +0200 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] References: <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> <87twy34dst.fsf@elektro.pacujo.net> <726afahrhnim716av2dnckrsd9n5j5kukj@4ax.com> <21dafa533nrsmktshd35kdbd13ahgj50bf@4ax.com> <87fv9k2999.fsf@elektro.pacujo.net> <54f7599d$0$12988$c3e8da3$5496439d@news.astraweb.com> <8761ag36du.fsf@elektro.pacujo.net> <87mw3s10nl.fsf@elektro.pacujo.net> <9ccfd0c7-1310-44de-a493-6019a1773ae1@googlegroups.com> Message-ID: <87fv9i5tjc.fsf@elektro.pacujo.net> Mark Lawrence : > British accent, Christmas is early this year so ho, ho, ho. Nobody in > this country ever guesses where I was born and bred, they all think > I'm from the South West or the West Country. Irish, Scottish, Welsh, > English alone are different. Most foreigners wouldn't have a dog's > chance in hell of understanding a Geordie or a Glaswegian. Move 50 > miles and you can hear a completely different accent. British accent > indeed. The accents on the British isles are indeed much more diverse than in the colonies. They can also be very hard to understand, sometimes for native English-speakers as well. Marko From rustompmody at gmail.com Fri Mar 6 05:07:34 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 6 Mar 2015 02:07:34 -0800 (PST) Subject: Newbie question about text encoding In-Reply-To: References: <201502241524.t1OFO09k022270@fido.openend.se> <201502241620.t1OGKf4n002146@fido.openend.se> <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <01dd9b83-db3e-4e7d-9022-dc6af75eb570@googlegroups.com> Message-ID: On Friday, March 6, 2015 at 3:24:48 PM UTC+5:30, Chris Angelico wrote: > On Fri, Mar 6, 2015 at 8:02 PM, Rustom Mody wrote: > >> Broken systems can be shown up by anything. Suppose you have a program > >> that breaks when it gets a NUL character (not unknown in C code); is > >> the fault with the Unicode consortium for allocating something at > >> codepoint 0, or the code that can't cope with a perfectly normal > >> character? > > > > Strawman. > > Not really, no. I know of lots of programs that can't handle embedded > NULs, and which fail in various ways when given them (the most common > is simple truncation, but it's by far not the only way). Ah well if you insist on pursuing the nul-char example... No the unicode consortium (or ASCII equivalent) is not wrong in allocating codepoint 0 Nor the code that "can't cope with a perfectly normal character?" But with C for having a data structure called string with a 'hole' in it. And it's > exactly the same: a program that purports to handle arbitrary Unicode > text should be able to handle arbitrary Unicode text, not "Unicode > text as long as it contains only codepoints within the range X-Y". It > doesn't matter whether the code chokes on U+0000, U+005C, U+FFFC, or > U+1F4A3 - if your code blows up, it's a failure in your code. > > > Lets please stick to UTF-16 shall we? > > > > Now tell me: > > - Is it broken or not? > > - Is it widely used or not? > > - Should programmers be careful of it or not? > > - Should programmers be warned about it or not? > > No, UTF-16 is not itself broken. (It would be if we expected > codepoints >0x10FFFF, and it's because of UTF-16 that that's the cap > on Unicode, but it's looking unlikely that we'll be needing any more > than that anyway.) What's broken is code that tries to treat UTF-16 as > if it's UCS-2, and then breaks on surrogate pairs. > > Yes, it's widely used. Programmers should probably be warned about it, > but only because its tradeoffs are generally poorer than UTF-8's. If > you use it correctly, there's no problem. > > > Also: > > Can a programmer who is away from UTF-16 in one part of the system (say by using python3) > > assume he is safe all over? > > I don't know what you mean here. Do you mean that your Python 3 > program is "at risk" in some way because there might be some other > program that misuses UTF-16? Yes some other program/library/API etc connected to the python one > Well, sure. And there might be some other > program that misuses buffer sizes, SQL queries, or shell invocations, > and makes your overall system vulnerable to buffer overruns or > injection attacks. These are significantly more likely AND more > serious than UTF-16 misuses. And you still have not proven anything > about SMP characters being a problem, but only that code can be > broken. Broken code is still broken code, no matter what your actual > brokenness. Roy Smith (and many other links Ive cited) prove exactly that - an SMP character broke the code. Note: I have no objection to people supporting full unicode 7. Im just saying it may be significantly harder than just "Use python3 and you are done" From rosuav at gmail.com Fri Mar 6 05:09:24 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Mar 2015 21:09:24 +1100 Subject: Python Worst Practices In-Reply-To: <54F95032.9010000@wielicki.name> References: <7053A277-9687-49B0-9FDB-CB4DB3E76DEC@gmail.com> <54F0E38D.40006@davea.name> <54f274bb$0$13011$c3e8da3$5496439d@news.astraweb.com> <54F95032.9010000@wielicki.name> Message-ID: On Fri, Mar 6, 2015 at 5:58 PM, Jonas Wielicki wrote: > On 01.03.2015 03:43, Chris Angelico wrote: >> Imagine if all >> your Python code ran twice as fast (that's slightly better than the >> IronPython figure quoted!), but worked only on BSD Unix and Mac OS. Is >> that something that'll make a fledgling language succeed? > > I heard that Swift and Objective-C are quite popular these days. > > regards, > jwi In other words, it requires major pushing from the platform vendor. It'd be impossible for some third-party to make a language that successful, I expect. And even *with* that kind of pushing, it's pretty chancy; there was a time (maybe times, I don't remember) when Microsoft tried hard to require "managed code" everywhere (aka ".NET runtime only"), and the push-back was so strong that they had to abandon the requirement. But somehow, people accept rules about phone apps that they wouldn't accept about desktop apps... crazy stuff. ChrisA From rustompmody at gmail.com Fri Mar 6 05:22:54 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 6 Mar 2015 02:22:54 -0800 (PST) Subject: Is nan in (nan,) correct? In-Reply-To: References: Message-ID: <87443f8f-3bd8-4b88-84c1-d20a2fc8cc19@googlegroups.com> On Friday, March 6, 2015 at 3:31:58 PM UTC+5:30, Chris Angelico wrote: > On Fri, Mar 6, 2015 at 8:50 PM, Rustom Mody wrote: > > In a language like python with decent exceptions we do not need nans. > > Not so. I could perhaps accept that we don't need signalling NaNs, as > they can be replaced with exceptions, but quiet NaNs are by definition > _not_ exceptions. My impression (maybe I am wrong): "Catch an exception and ignore it" is a way of converting signalling to quiet With the added advantage of being able to tweak the specs of what happens when nan op normal to one's taste From gheskett at wdtv.com Fri Mar 6 05:32:03 2015 From: gheskett at wdtv.com (Gene Heskett) Date: Fri, 6 Mar 2015 05:32:03 -0500 Subject: Speeding up permutations generation In-Reply-To: References: Message-ID: <201503060532.03842.gheskett@wdtv.com> On Friday 06 March 2015 03:24:48 Abhiram R wrote: > > A list of 100 elements has approximately 9.33 x 10**157 > > permutations. If you could somehow generate one permutation every > > yoctosecond, exhausting them would still take more than a hundred > > orders of magnitude longer than the age of the universe. > > -- > > https://mail.python.org/mailman/listinfo/python-list > > ?True that :D I may have exaggerated on the number. Let's consider > something more practically manageable? => 50 elements with a 50! > permutation. > Is there a solution now? Yes, but its now only 8.881784197e+84 elements so it is still not a practical target. Doing all elements of a matrix is generally equ to n!, and 50 raised to the 50th power is still a number that will probably use up this suns remaining lifetime doing it in assembly. If submitted and accepted to BOINC with its parallelism potential. And Seagate/Western Digital's combined output for about that same time to store the result. I'd choose any other, perhaps less exhaustive method. Or a more practical size of dataset parameters. > ?-Abhiram.R > *~Never give up* 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 breamoreboy at yahoo.co.uk Fri Mar 6 05:33:01 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 06 Mar 2015 10:33:01 +0000 Subject: Speeding up permutations generation In-Reply-To: References: Message-ID: On 06/03/2015 09:59, Chris Angelico wrote: > On Fri, Mar 6, 2015 at 7:24 PM, Abhiram R wrote: >>> A list of 100 elements has approximately 9.33 x 10**157 permutations. >>> If you could somehow generate one permutation every yoctosecond, >>> exhausting them would still take more than a hundred orders of >>> magnitude longer than the age of the universe. >>> -- >>> https://mail.python.org/mailman/listinfo/python-list >> >> >> True that :D I may have exaggerated on the number. Let's consider something >> more practically manageable => 50 elements with a 50! permutation. >> Is there a solution now? >> > > Is the actual generation of permutations your problem? You mentioned > that you're using itertools, so I would expect that you're simply > iterating over that; I hope you're not immediately trying to construct > a list of them all, because that would cost the memory that Mark's > response talks about. Have you actually profiled your code and found > that generating permutations is the bottleneck, or did you just guess? > Because even experienced programmers - even extremely experienced > Python programmers - are usually wrong when they guess about the > slowest part of a program. The only way to know is to measure. > > ChrisA > s/Mark/Wolfgang/ ? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From davea at davea.name Fri Mar 6 06:22:34 2015 From: davea at davea.name (Dave Angel) Date: Fri, 06 Mar 2015 06:22:34 -0500 Subject: Speeding up permutations generation In-Reply-To: <201503060532.03842.gheskett@wdtv.com> References: <201503060532.03842.gheskett@wdtv.com> Message-ID: <54F98DFA.4090503@davea.name> On 03/06/2015 05:32 AM, Gene Heskett wrote: > > > On Friday 06 March 2015 03:24:48 Abhiram R wrote: >>> A list of 100 elements has approximately 9.33 x 10**157 >>> permutations. If you could somehow generate one permutation every >>> yoctosecond, exhausting them would still take more than a hundred >>> orders of magnitude longer than the age of the universe. >>> -- >>> https://mail.python.org/mailman/listinfo/python-list >> >> ?True that :D I may have exaggerated on the number. Let's consider >> something more practically manageable? => 50 elements with a 50! >> permutation. >> Is there a solution now? > > Yes, but its now only 8.881784197e+84 elements so it is still not a > practical target. Doing all elements of a matrix is generally equ to > n!, and 50 raised to the 50th power is still a number that will probably > use up this suns remaining lifetime doing it in assembly. Sorry, but 50! is not even close to 50**50. The latter is 85 digits as you say, but 50! is "only" 64. 30414093201713378043612608166064768844377641568960512000000000000L Still an enormous number of course, so an exhaustive visit to all those permutations is still impossible on a conventional computer. -- DaveA From davea at davea.name Fri Mar 6 06:29:06 2015 From: davea at davea.name (Dave Angel) Date: Fri, 06 Mar 2015 06:29:06 -0500 Subject: Speeding up permutations generation In-Reply-To: References: Message-ID: <54F98F82.8070905@davea.name> On 03/06/2015 01:44 AM, Abhiram R wrote: > Hi all, > Is there a way to generate permutations of large arrays of sizes say,in the > hundreds, faster than in the time itertools.permutations() can return? > When dealing with large loops like that (or even permutations of 50, which is also gy-normous [1]), you have to consider what work you plan to do in the loop. Even if the generation were instantaneous, you still presumably are going to have some code in the loop. If you expect to do it on a set of 50, you're going to have to narrow down the possibilities with some approach other than brute force. What's the problem you were hoping to solve in the next trillion years? [1] 50! = 30414093201713378043612608166064768844377641568960512000000000000L -- DaveA From alister.nospam.ware at ntlworld.com Fri Mar 6 06:53:40 2015 From: alister.nospam.ware at ntlworld.com (alister) Date: Fri, 6 Mar 2015 11:53:40 +0000 (UTC) Subject: HELP!! How to ask a girl out with a simple witty Python code?? References: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> <2906370c-58c7-4d8b-8db3-2ea3773b9578@googlegroups.com> <54f8d56a$0$12984$c3e8da3$5496439d@news.astraweb.com> <54f916b2$0$12980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, 06 Mar 2015 14:23:22 +1100, Ben Finney wrote: > > No. I'm saying that it's clear the person saying ?get their panties all > up in a bunch? fully intends to convey specifically *female* underwear, > and thereby to use implied femininity as an insult. > > Yes, of course I know some people who aren't female wear panties. Yes, > of course I know some women wear underwear that isn't panties. Don't try > to change the topic with absurd logical extremes that I didn't raise. > > I'm talking about the implication of the comment as a gendered insult. > >> It's only gender specific if you accept the sexist gendered stereotype >> that all women are by definition thin-skinned and excessively >> sensitive. > > Bullshit. I said nothing about the sensitivity of anyone. Individual > women you may know ? even *all* women, everywhere ? could be as tough as > nails, and it doesn't address the point I'm raising. > > Whether any particular woman is targeted or not, the comment I'm > responding to invokes female gender as an implied insult. That's > unwelcoming to women, and I don't want such unwelcoming attitudes in > this community. I have not seen one female poster on this site claim to be offended by the comment or even consider it to be a slur. I doubt that the original poster of the comment intended it to be either & most people reading it would have known that (regardless of their gender) one thing i personally find offensive is when someone raises an issue on someone else's behalf because they THINK they MIGHT get offended without bothering to check. I am not female so this particular instance does not relate to me but an example from a few years ago was when a popular UK soap made an extreme effort not to show a cross or Christmas tree during a church wedding in case it "offended not-Christians". I am a non-Christian & found that decision offensive. -- Never trust an operating system you don't have sources for. From rosuav at gmail.com Fri Mar 6 07:02:35 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Mar 2015 23:02:35 +1100 Subject: Speeding up permutations generation In-Reply-To: References: Message-ID: On Fri, Mar 6, 2015 at 9:33 PM, Mark Lawrence wrote: >> Is the actual generation of permutations your problem? You mentioned >> that you're using itertools, so I would expect that you're simply >> iterating over that; I hope you're not immediately trying to construct >> a list of them all, because that would cost the memory that Mark's >> response talks about. Have you actually profiled your code and found >> that generating permutations is the bottleneck, or did you just guess? >> Because even experienced programmers - even extremely experienced >> Python programmers - are usually wrong when they guess about the >> slowest part of a program. The only way to know is to measure. >> >> ChrisA >> > > s/Mark/Wolfgang/ ? Oops, yes, my bad. I read the rest of the thread, then went back up and replied to the most appropriate post for what I wanted to say, and then named the wrong person out of the two following posters. My apologies, Mark and Wolfgang! ChrisA From hayesstw at telkomsa.net Fri Mar 6 07:34:12 2015 From: hayesstw at telkomsa.net (Steve Hayes) Date: Fri, 06 Mar 2015 14:34:12 +0200 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] References: <21dafa533nrsmktshd35kdbd13ahgj50bf@4ax.com> <87fv9k2999.fsf@elektro.pacujo.net> <54f7599d$0$12988$c3e8da3$5496439d@news.astraweb.com> <8761ag36du.fsf@elektro.pacujo.net> <87mw3s10nl.fsf@elektro.pacujo.net> <9ccfd0c7-1310-44de-a493-6019a1773ae1@googlegroups.com> Message-ID: <1k7jfaptbnluc8cfl1fctci1lbbfs6h61m@4ax.com> On Fri, 6 Mar 2015 00:00:28 -0800 (PST), Rustom Mody wrote: >On Thursday, March 5, 2015 at 10:49:54 AM UTC+5:30, Marko Rauhamaa wrote: >> Rustom Mody: >> >> > You keep talking of accent. >> > At first I thought you were using the word figuratively or else joking. >> > Im now beginning to wonder if you mean it literally. >> > If so have you patented a new AOIP protocol? >> > If not do you give tuitions? in ESP/telepathy/Voodoo? I'll be happy to >> > pay >> >> Where I work, people do use voice still occasionally to communicate. > >I really dont understand what we are communicating (or not) about... > >Can you hear my accent? I certainly cant hear yours And if I call a Python list "books", is Python going to complain about my accent? Really? -- Steve Hayes from Tshwane, South Africa Web: http://www.khanya.org.za/stevesig.htm Blog: http://khanya.wordpress.com E-mail - see web page, or parse: shayes at dunelm full stop org full stop uk From alister.nospam.ware at ntlworld.com Fri Mar 6 07:34:52 2015 From: alister.nospam.ware at ntlworld.com (alister) Date: Fri, 6 Mar 2015 12:34:52 +0000 (UTC) Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] References: <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> <87twy34dst.fsf@elektro.pacujo.net> <726afahrhnim716av2dnckrsd9n5j5kukj@4ax.com> <21dafa533nrsmktshd35kdbd13ahgj50bf@4ax.com> <87fv9k2999.fsf@elektro.pacujo.net> <54f7599d$0$12988$c3e8da3$5496439d@news.astraweb.com> <8761ag36du.fsf@elektro.pacujo.net> <87mw3s10nl.fsf@elektro.pacujo.net> <9ccfd0c7-1310-44de-a493-6019a1773ae1@googlegroups.com> Message-ID: On Fri, 06 Mar 2015 08:31:40 +0000, Mark Lawrence wrote: > On 06/03/2015 08:00, Rustom Mody wrote: >> On Thursday, March 5, 2015 at 10:49:54 AM UTC+5:30, Marko Rauhamaa >> wrote: >>> Rustom Mody: >>> >>>> You keep talking of accent. >>>> At first I thought you were using the word figuratively or else >>>> joking. >>>> Im now beginning to wonder if you mean it literally. >>>> If so have you patented a new AOIP protocol? >>>> If not do you give tuitions? in ESP/telepathy/Voodoo? I'll be happy >>>> to pay >>> >>> Where I work, people do use voice still occasionally to communicate. >> >> I really dont understand what we are communicating (or not) about... >> >> Can you hear my accent? I certainly cant hear yours If you are talking >> of accent (aural/physical just to be clear) of your co-workers how is >> that more on-topic or relevant to this list than the weather in >> Finland. >> [Yeah its been freakish weather out here for the last 10 days -- global >> warming? >> And is global warming on topic for this list?] >> Just to be clear -- I am going to be one of the tail-enders complaining >> about on/off-topicness. But someone or other will complain I guess. >> >> If on the other hand you are being slightly metaphorical and using >> 'accent' >> to talk of (say) Mark's britishisms? then please disambiguate for >> better communication. >> >> But more to the point its still not clear (to me) whether you are >> objecting to - to Mark - to British accent > > British accent, Christmas is early this year so ho, ho, ho. Nobody in > this country ever guesses where I was born and bred, they all think I'm > from the South West or the West Country. Irish, Scottish, Welsh, > English alone are different. Most foreigners wouldn't have a dog's > chance in hell of understanding a Geordie or a Glaswegian. Move 50 > miles and you can hear a completely different accent. British accent > indeed. > Foreigner? I can barely understand a Geordie accent & I am English. whilst I agree to a point with Marco that when talking to a forigner you should take care to speak clearly for them the suggestion that American pronunciation is what I find unacceptable. even though I can (and do) watch American TV shows reasonably easily some of their pronunciations seriously grate on my nerves :- Bouy - it is pounced Boy not bo-ey! chasis - it has a soft Ch not a hard Ch, Aluminium, Heck they don't even sell it correctly ;-) >> - to British spellings in software - to anyone/anywhere international, >> using non-international format >> >> >> ?Personally I find Mark's britishisms sometimes funny eg I found this >> https://groups.google.com/d/msg/comp.lang.python/EfloMHB3DjQ/ ZdY3Vn_6rpsJ >> hilarious even though I could not decipher more than 70% of the >> british accent. >> Sometimes though I find it irrelevant/unnecessary/undecipherable. >> >> Personally I am not going to object to him nor am I going to object to >> anyone objecting to him. >> >> > Anybody objecting about me will be accused by me of discrimination > against autistic people. Now there is a not very subtle hint that might > penetrate one or two of the thicker skins on the thicker heads that > participate here. Thankfully the numbers of such people are extremely > small or we could have had WWIII. Which could have happened when Global > Crossing bought Racal Telecommunications and tried to stop us Brits > using our kettles to make our cuppas. Now that is seriously brain dead. > And they turned out to be a bit naughty with the books :( -- "All my life I wanted to be someone; I guess I should have been more specific." -- Jane Wagner From random832 at fastmail.us Fri Mar 6 08:33:00 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Fri, 06 Mar 2015 08:33:00 -0500 Subject: Newbie question about text encoding In-Reply-To: References: <201502241524.t1OFO09k022270@fido.openend.se> <201502241620.t1OGKf4n002146@fido.openend.se> <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <01dd9b83-db3e-4e7d-9022-dc6af75eb570@googlegroups.com> Message-ID: <1425648780.3358976.236451377.1ED1534A@webmail.messagingengine.com> On Fri, Mar 6, 2015, at 04:06, Rustom Mody wrote: > Also: > Can a programmer who is away from UTF-16 in one part of the system (say > by using python3) > assume he is safe all over? The most common failure of UTF-16 support, supposedly, is in programs misusing the number of code units (for length or random access) as a proxy for the number of characters. However, when do you _really_ want the number of characters? You may want to use it for, for example, the number of columns in a 'monospace' font, which you've already screwed up because you haven't accounted for double-wide characters or combining marks. Or you may want the position that pressing an arrow key or backspace or forward-delete a number of times will reach, which has its own rules in e.g. Indic languages (and also fails on Latin with combining marks). From rosuav at gmail.com Fri Mar 6 08:39:26 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 7 Mar 2015 00:39:26 +1100 Subject: Newbie question about text encoding In-Reply-To: <1425648780.3358976.236451377.1ED1534A@webmail.messagingengine.com> References: <201502241524.t1OFO09k022270@fido.openend.se> <201502241620.t1OGKf4n002146@fido.openend.se> <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <01dd9b83-db3e-4e7d-9022-dc6af75eb570@googlegroups.com> <1425648780.3358976.236451377.1ED1534A@webmail.messagingengine.com> Message-ID: On Sat, Mar 7, 2015 at 12:33 AM, wrote: > However, when do you _really_ want the number of characters? You may > want to use it for, for example, the number of columns in a 'monospace' > font, which you've already screwed up because you haven't accounted for > double-wide characters or combining marks. Or you may want the position > that pressing an arrow key or backspace or forward-delete a number of > times will reach, which has its own rules in e.g. Indic languages (and > also fails on Latin with combining marks). Number of code points is the most logical way to length-limit something. If you want to allow users to set their display names but not to make arbitrarily long ones, limiting them to X code points is the safest way (and preferably do an NFC or NFD normalization before counting, for consistency); this means you disallow pathological cases where every base character has innumerable combining marks added. ChrisA From fomcl at yahoo.com Fri Mar 6 08:48:56 2015 From: fomcl at yahoo.com (Albert-Jan Roskam) Date: Fri, 6 Mar 2015 13:48:56 +0000 (UTC) Subject: io.open vs. codecs.open In-Reply-To: <54f76359$0$13012$c3e8da3$5496439d@news.astraweb.com> References: <54f76359$0$13012$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1523225442.1568000.1425649736930.JavaMail.yahoo@mail.yahoo.com> ----- Original Message ----- > From: Steven D'Aprano > To: python-list at python.org > Cc: > Sent: Wednesday, March 4, 2015 8:56 PM > Subject: Re: io.open vs. codecs.open > > Albert-Jan Roskam wrote: > >> Hi, >> >> Is there a (use case) difference between codecs.open and io.open? What is >> the difference? A small difference that I just discovered is that >> codecs.open(somefile).read() returns a bytestring if no encoding is >> specified*), but a unicode string if an encoding is specified. io.open >> always returns a unicode string. > > What version of Python are you using? Python 2.7 and 3.4. > In Python 3, io.open is used as the built-in open. I believe this is > guaranteed, and not just an implementation detail. > > The signatures and capabilities are quite different: > > codecs.open: > > open(filename, mode='rb', encoding=None, errors='strict', > buffering=1) > > io.open: > > open(file, mode='r', buffering=-1, encoding=None, > errors=None, newline=None, closefd=True, opener=None) Thanks. I didn't realize that closefd was also available in Python 2. I had only seen it in Python 3 open() > > io.open does *not* always produce Unicode strings. If you pass 'rb' as > the > mode, the file is opened in binary mode, not text mode, and the read() > method will return bytes. So, in recent versions of Python 2 (Python 2.7.x, 2.6) I can basically ditch codecs.open() and the standard open()? Given that standard open() has no encoding parameter, it is only really safe for use with binary data (binary mode). > As usual, help() in the interactive interpreter is your friend. > help(codecs.open) and help(io.open) will explain the many differences > between them, including that codecs.open always opens the file in binary > mode. > > As for use-cases, I think that codecs.open is mostly a left-over from the > Python 2 days when the built-in open had a much simpler interface and fewer > capabilities. In Python 2, built-in open doesn't take an encoding argument, > so if you want to use something other than binary mode or the default > encoding, you were supposed to use codecs.open. > > In Python 2.6, the io module was added to Python 2 to aid in porting to > Python 3. The docs say: > > New in version 2.6. > > The io module provides the Python interfaces to stream handling. > Under Python 2.x, this is proposed as an alternative to the > built-in file object, but in Python 3.x it is the default > interface to access files and streams. > > https://docs.python.org/2/library/io.html > > > To summarise: > > * In Python 2, if you want to supply an encoding to open, use codecs.open > (before 2.6) or io.open (2.6 and later); > > * If you want the enhanced capabilities of Python 3 open, use io.open; > > * In Python 3, io.open is the same thing as built-in open; > > * And codecs.open is (I think) mostly there for backwards compatibility. > > > > > -- > Steven > > -- > https://mail.python.org/mailman/listinfo/python-list > From random832 at fastmail.us Fri Mar 6 09:03:11 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Fri, 06 Mar 2015 09:03:11 -0500 Subject: Newbie question about text encoding In-Reply-To: References: <201502241524.t1OFO09k022270@fido.openend.se> <201502241620.t1OGKf4n002146@fido.openend.se> <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <01dd9b83-db3e-4e7d-9022-dc6af75eb570@googlegroups.com> <1425648780.3358976.236451377.1ED1534A@webmail.messagingengine.com> Message-ID: <1425650591.3368169.236462481.4CA83873@webmail.messagingengine.com> On Fri, Mar 6, 2015, at 08:39, Chris Angelico wrote: > Number of code points is the most logical way to length-limit > something. If you want to allow users to set their display names but > not to make arbitrarily long ones, limiting them to X code points is > the safest way (and preferably do an NFC or NFD normalization before > counting, for consistency); Why are you length-limiting it? Storage space? Limit it in whatever encoding they're stored in. Why are combining marks "pathological" but surrogate characters not? Display space? Limit it by columns. If you're going to allow a Japanese user's name to be twice as wide, you've got a problem when you go to display it. > this means you disallow pathological cases > where every base character has innumerable combining marks added. No it doesn't. If you limit it to, say, fifty, someone can still post two base characters with twenty combining marks each. If you actually want to disallow this, you've got to do more work. You've disallowed some of the pathological cases, some of the time, by coincidence. And limiting the number of UTF-8 bytes, or the number of UTF-16 code points, will accomplish this just as well. Now, if you intend to _silently truncate_ it to the desired length, you certainly don't want to leave half a character in, of course. But who's to say the base character plus first few combining marks aren't also "half a character"? If you're _splitting_ a string, rather than merely truncating it, you probably don't want those combining marks at the beginning of part two. From rosuav at gmail.com Fri Mar 6 09:11:20 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 7 Mar 2015 01:11:20 +1100 Subject: Newbie question about text encoding In-Reply-To: <1425650591.3368169.236462481.4CA83873@webmail.messagingengine.com> References: <201502241524.t1OFO09k022270@fido.openend.se> <201502241620.t1OGKf4n002146@fido.openend.se> <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <01dd9b83-db3e-4e7d-9022-dc6af75eb570@googlegroups.com> <1425648780.3358976.236451377.1ED1534A@webmail.messagingengine.com> <1425650591.3368169.236462481.4CA83873@webmail.messagingengine.com> Message-ID: On Sat, Mar 7, 2015 at 1:03 AM, wrote: > On Fri, Mar 6, 2015, at 08:39, Chris Angelico wrote: >> Number of code points is the most logical way to length-limit >> something. If you want to allow users to set their display names but >> not to make arbitrarily long ones, limiting them to X code points is >> the safest way (and preferably do an NFC or NFD normalization before >> counting, for consistency); > > Why are you length-limiting it? Storage space? Limit it in whatever > encoding they're stored in. Why are combining marks "pathological" but > surrogate characters not? Display space? Limit it by columns. If you're > going to allow a Japanese user's name to be twice as wide, you've got a > problem when you go to display it. To prevent people from putting three paragraphs of lipsum in and calling it a username. >> this means you disallow pathological cases >> where every base character has innumerable combining marks added. > > No it doesn't. If you limit it to, say, fifty, someone can still post > two base characters with twenty combining marks each. If you actually > want to disallow this, you've got to do more work. You've disallowed > some of the pathological cases, some of the time, by coincidence. And > limiting the number of UTF-8 bytes, or the number of UTF-16 code points, > will accomplish this just as well. They can, but then they're limited to two base characters. They can't have fifty base characters with twenty combining marks each. That's the point. > Now, if you intend to _silently truncate_ it to the desired length, you > certainly don't want to leave half a character in, of course. But who's > to say the base character plus first few combining marks aren't also > "half a character"? If you're _splitting_ a string, rather than merely > truncating it, you probably don't want those combining marks at the > beginning of part two. So you truncate to the desired length, then if the first character of the trimmed-off section is a combining mark (based on its Unicode character types), you keep trimming until you've removed a character which isn't. Then, if you no longer have any content whatsoever, reject the name. Simple. ChrisA From random832 at fastmail.us Fri Mar 6 09:27:42 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Fri, 06 Mar 2015 09:27:42 -0500 Subject: Newbie question about text encoding In-Reply-To: References: <201502241524.t1OFO09k022270@fido.openend.se> <201502241620.t1OGKf4n002146@fido.openend.se> <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <01dd9b83-db3e-4e7d-9022-dc6af75eb570@googlegroups.com> <1425648780.3358976.236451377.1ED1534A@webmail.messagingengine.com> <1425650591.3368169.236462481.4CA83873@webmail.messagingengine.com> Message-ID: <1425652062.3374164.236476717.59518CD2@webmail.messagingengine.com> On Fri, Mar 6, 2015, at 09:11, Chris Angelico wrote: > To prevent people from putting three paragraphs of lipsum in and > calling it a username. Limiting by UTF-8 bytes or UTF-16 units works just as well for that. > So you truncate to the desired length, then if the first character of > the trimmed-off section is a combining mark (based on its Unicode > character types), you keep trimming until you've removed a character > which isn't. Then, if you no longer have any content whatsoever, > reject the name. Simple. My entire point was that UTF-32 doesn't save you from that, so it cannot be called a deficiency of UTF-16. My point is there are very few problems to which "count of Unicode code points" is the only right answer - that UTF-32 is good enough for but that are meaningfully impacted by a naive usage of UTF-16, to the point where UTF-16 is something you have to be "safe" from. From steve+comp.lang.python at pearwood.info Fri Mar 6 09:50:08 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 07 Mar 2015 01:50:08 +1100 Subject: Newbie question about text encoding References: <201502241620.t1OGKf4n002146@fido.openend.se> <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <01dd9b83-db3e-4e7d-9022-dc6af75eb570@googlegroups.com> Message-ID: <54f9bea1$0$12994$c3e8da3$5496439d@news.astraweb.com> Rustom Mody wrote: > On Friday, March 6, 2015 at 10:50:35 AM UTC+5:30, Chris Angelico wrote: [snip example of an analogous situation with NULs] > Strawman. Sigh. If I had a dollar for every time somebody cried "Strawman!" when what they really should say is "Yes, that's a good argument, I'm afraid I can't argue against it, at least not without considerable thought", I'd be a wealthy man... > Lets please stick to UTF-16 shall we? > > Now tell me: > - Is it broken or not? The UTF-16 standard is not broken. It is a perfectly adequate variable-width encoding, and considerably better than most other variable-width encodings. However, many implementations of UTF-16 are faulty, and assume a fixed-width. *That* is broken, not UTF-16. (The difference between specification and implementation is critical.) > - Is it widely used or not? It's quite widely used. > - Should programmers be careful of it or not? Programmers should be aware whether or not any specific language uses UTF-16 and whether the implementation is buggy. That will help them decide whether or not to use that language. > - Should programmers be warned about it or not? I'm in favour of people having more knowledge rather than less. I don't believe that ignorance is bliss, except perhaps in the case that a giant asteroid the size of Texas is heading straight for us. Programmers should be aware of the limitations or bugs in any UTF-16 implementation they are likely to run into. Hence my general recommendation: - For transmission over networks or storage on permanent media (e.g. the content of text files), use UTF-8. It is well-implemented by nearly all languages that support Unicode, as far as I know. - If you are designing your own language, your implementation of Unicode strings should use something like Python's FSR, or UTF-8 with tweaks to make string indexing O(1) rather than O(N), or correctly-implemented UTF-16, or even UTF-32 if you have the memory. (Choices, choices.) If, in 2015, you design your Unicode implementation as if UTF-16 is a fixed 2-byte per code point format, you fail. - If you are using an existing language, be aware of any bugs and limitations in its Unicode implementation. You may or may not be able to work around them, but at least you can decide whether or not you wish to try. - If you are writing your own file system layer, it's 2015 fer fecks sake, file names should be Unicode strings, not bytes! (That's one part of the Unix model that needs to die.) You can use UTF-8 or UTF-16 in the file system, whichever you please, but again remember that both are variable-width formats. -- Steven From rosuav at gmail.com Fri Mar 6 10:27:22 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 7 Mar 2015 02:27:22 +1100 Subject: Newbie question about text encoding In-Reply-To: <54f9bea1$0$12994$c3e8da3$5496439d@news.astraweb.com> References: <201502241620.t1OGKf4n002146@fido.openend.se> <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <01dd9b83-db3e-4e7d-9022-dc6af75eb570@googlegroups.com> <54f9bea1$0$12994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Mar 7, 2015 at 1:50 AM, Steven D'Aprano wrote: > Rustom Mody wrote: > >> On Friday, March 6, 2015 at 10:50:35 AM UTC+5:30, Chris Angelico wrote: > > [snip example of an analogous situation with NULs] > >> Strawman. > > Sigh. If I had a dollar for every time somebody cried "Strawman!" when what > they really should say is "Yes, that's a good argument, I'm afraid I can't > argue against it, at least not without considerable thought", I'd be a > wealthy man... If I had a dollar for every time anyone said "If I had for every time...", I'd go meta all day long and profit from it... :) > - If you are writing your own file system layer, it's 2015 fer fecks sake, > file names should be Unicode strings, not bytes! (That's one part of the > Unix model that needs to die.) You can use UTF-8 or UTF-16 in the file > system, whichever you please, but again remember that both are > variable-width formats. I agree that that part of the Unix model needs to change, but there are two viable ways to move forward: 1) Keep file names as bytes, but mandate that they be valid UTF-8 streams, and recommend that they be decoded UTF-8 for display to a human 2) Change the entire protocol stack from the file system upwards so that file names become Unicode strings. Trouble with #2 is that file names need to be passed around somehow, which means bytes in memory. So ultimately, #2 really means "keep file names as bytes, and mandate an encoding all the way up the stack"... so it's a massive documentation change that really comes down to the same thing as #1. This is one area where, as I understand it, Mac OS got it right. It's time for other Unix variants to adopt the same policy. The bulk of file names will be ASCII-only anyway, so requiring UTF-8 won't affect them; a lot of others are already UTF-8; so all we need is a transition scheme for the remaining ones. If there's a known FS encoding, it ought to be possible to have a file system conversion tool that goes through everything, decodes, re-encodes UTF-8, and then flags the file system as UTF-8 compliant. All that'd be left would be the file names that are broken already - ones that don't decode in the FS encoding - and there's nothing to be done with them but wrap them up into something probably-meaningless-but reversible. When can we start doing this? ext5? ChrisA From invalid at invalid.invalid Fri Mar 6 10:34:30 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 6 Mar 2015 15:34:30 +0000 (UTC) Subject: Is nan in (nan,) correct? References: Message-ID: On 2015-03-06, Chris Angelico wrote: > On Fri, Mar 6, 2015 at 8:50 PM, Rustom Mody wrote: >> In a language like python with decent exceptions we do not need nans. > > Not so. I could perhaps accept that we don't need signalling NaNs, as > they can be replaced with exceptions, but quiet NaNs are by definition > _not_ exceptions. And quiet NaNs are very, very useful. -- Grant Edwards grant.b.edwards Yow! A can of ASPARAGUS, at 73 pigeons, some LIVE ammo, gmail.com and a FROZEN DAQUIRI!! From gheskett at wdtv.com Fri Mar 6 11:14:06 2015 From: gheskett at wdtv.com (Gene Heskett) Date: Fri, 6 Mar 2015 11:14:06 -0500 Subject: Speeding up permutations generation In-Reply-To: <54F98DFA.4090503@davea.name> References: <201503060532.03842.gheskett@wdtv.com> <54F98DFA.4090503@davea.name> Message-ID: <201503061114.06957.gheskett@wdtv.com> On Friday 06 March 2015 06:22:34 Dave Angel wrote: > On 03/06/2015 05:32 AM, Gene Heskett wrote: > > On Friday 06 March 2015 03:24:48 Abhiram R wrote: > >>> A list of 100 elements has approximately 9.33 x 10**157 > >>> permutations. If you could somehow generate one permutation every > >>> yoctosecond, exhausting them would still take more than a hundred > >>> orders of magnitude longer than the age of the universe. > >>> -- > >>> https://mail.python.org/mailman/listinfo/python-list > >> > >> ?True that :D I may have exaggerated on the number. Let's consider > >> something more practically manageable? => 50 elements with a 50! > >> permutation. > >> Is there a solution now? > > > > Yes, but its now only 8.881784197e+84 elements so it is still not a > > practical target. Doing all elements of a matrix is generally equ > > to n!, and 50 raised to the 50th power is still a number that will > > probably use up this suns remaining lifetime doing it in assembly. > > Sorry, but 50! is not even close to 50**50. The latter is 85 digits > as you say, but 50! is "only" 64. > > > 30414093201713378043612608166064768844377641568960512000000000000L What utility output that as an L ? But you are right, new wheezy install with TBE desktop and kcalc has been played with. I used the wrong button. It seems every new and streamlined version is progressively stripped of some function I have formerly found useful, Grrrrrr. Not related to this, but now the binary bit display has been excised. Handier than bottled beer when checking/designing address decoders. > Still an enormous number of course, so an exhaustive visit to all > those permutations is still impossible on a conventional computer. +5 > > -- > DaveA 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 ian.g.kelly at gmail.com Fri Mar 6 11:17:10 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 6 Mar 2015 09:17:10 -0700 Subject: HELP!! How to ask a girl out with a simple witty Python code?? In-Reply-To: References: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> <2906370c-58c7-4d8b-8db3-2ea3773b9578@googlegroups.com> <54f8d56a$0$12984$c3e8da3$5496439d@news.astraweb.com> <54f916b2$0$12980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 6, 2015 at 4:53 AM, alister wrote: > I have not seen one female poster on this site claim to be offended by > the comment or even consider it to be a slur. > > I doubt that the original poster of the comment intended it to be either > & most people reading it would have known that (regardless of their > gender) > > one thing i personally find offensive is when someone raises an issue on > someone else's behalf because they THINK they MIGHT get offended without > bothering to check. "Offended" is a rather vacuous term. It describes a distraught emotional state without any attempt to reason about what actual problem might exist. Too often somebody simply says "I'm offended by X" and then a lot of people kowtow to that statement as if it in itself were a reason to check behavior. But that doesn't make it unimportant to measure the kinds of messages that our actions send, and that's not what's going on here. Ben has clearly laid out how the comment creates an unwelcoming environment to women and so marginalizes them. That's a problem even if no women are speaking up about the comment, because a) there may be some who find the comment troubling but are unwilling to speak up about it ("suffering in silence"), and b) it doesn't even matter if somebody says that they don't mind being insulted; it still creates a problem and it's still not socially acceptable to insult them. > I am not female so this particular instance does not relate to me but an > example from a few years ago was when a popular UK soap made an extreme > effort not to show a cross or Christmas tree during a church wedding in > case it "offended not-Christians". > > I am a non-Christian & found that decision offensive. I agree that example sounds idiotic. Where is the problem with depicting Christian paraphernalia in a clearly Christian setting? There is a great difference between showing Christian imagery and showing a world that is exclusionary of or hostile to non-Christians. From rustompmody at gmail.com Fri Mar 6 11:20:58 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 6 Mar 2015 08:20:58 -0800 (PST) Subject: Newbie question about text encoding In-Reply-To: <54f9bea1$0$12994$c3e8da3$5496439d@news.astraweb.com> References: <201502241620.t1OGKf4n002146@fido.openend.se> <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <01dd9b83-db3e-4e7d-9022-dc6af75eb570@googlegroups.com> <54f9bea1$0$12994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Friday, March 6, 2015 at 8:20:22 PM UTC+5:30, Steven D'Aprano wrote: > Rustom Mody wrote: > > > On Friday, March 6, 2015 at 10:50:35 AM UTC+5:30, Chris Angelico wrote: > > [snip example of an analogous situation with NULs] > > > Strawman. > > Sigh. If I had a dollar for every time somebody cried "Strawman!" when what > they really should say is "Yes, that's a good argument, I'm afraid I can't > argue against it, at least not without considerable thought", I'd be a > wealthy man... Missed my addition? Here it is again ? grammar slightly corrected. =========== Ah well if you insist on pursuing the nul-char example... - No, the unicode consortium (or ASCII equivalent) is not wrong in allocating codepoint 0 - No, the code that "can't cope with a perfectly normal character" is not wrong - It is C that is wrong for designing a buggy string data structure that cannot contain a valid char. =========== In fact Chris' nul-char example is so strongly supporting my argument ? bugginess of UTF-16 ? it is perhaps too strong even for me. To elaborate: Take the buggy-plane analogy I gave in http://blog.languager.org/2015/03/whimsical-unicode.html If a plane model crashes once in 10,000 flights compared to others that crash once in one million flights we can call it bug-prone though not strictly buggy ? it does fly 9999 times safely! OTOH if a plane is guaranteed to crash we can all it a buggy plane. C's string is not bug-prone its plain buggy as it cannot represent strings with nulls. I would not go that far for UTF-16. It is bug-inviting but it can also be implemented correctly > > > > Lets please stick to UTF-16 shall we? > > > > Now tell me: > > - Is it broken or not? > > The UTF-16 standard is not broken. It is a perfectly adequate variable-width > encoding, and considerably better than most other variable-width encodings. > > However, many implementations of UTF-16 are faulty, and assume a > fixed-width. *That* is broken, not UTF-16. > > (The difference between specification and implementation is critical.) > > > > - Is it widely used or not? > > It's quite widely used. > > > > - Should programmers be careful of it or not? > > Programmers should be aware whether or not any specific language uses UTF-16 > and whether the implementation is buggy. That will help them decide whether > or not to use that language. > > > > - Should programmers be warned about it or not? > > I'm in favour of people having more knowledge rather than less. I don't > believe that ignorance is bliss, except perhaps in the case that a giant > asteroid the size of Texas is heading straight for us. > > Programmers should be aware of the limitations or bugs in any UTF-16 > implementation they are likely to run into. Hence my general > recommendation: > > - For transmission over networks or storage on permanent media (e.g. the > content of text files), use UTF-8. It is well-implemented by nearly all > languages that support Unicode, as far as I know. > > - If you are designing your own language, your implementation of Unicode > strings should use something like Python's FSR, or UTF-8 with tweaks to > make string indexing O(1) rather than O(N), or correctly-implemented > UTF-16, or even UTF-32 if you have the memory. (Choices, choices.) FSR is possible in python for very specific pythonic reasons - dynamicness - immutable strings Drop either and FSR is impossible > If, in 2015, you design your Unicode implementation as if UTF-16 is a fixed > 2-byte per code point format, you fail. Seems obvious enough. So lets see... Here's a 2-line python program -- runs well enough when run as a command. Program: ========= pp = "?" print (pp) ========= Try open it in idle3 and you get (at least I get): $ idle3 ff.py Traceback (most recent call last): File "/usr/bin/idle3", line 5, in main() File "/usr/lib/python3.4/idlelib/PyShell.py", line 1562, in main if flist.open(filename) is None: File "/usr/lib/python3.4/idlelib/FileList.py", line 36, in open edit = self.EditorWindow(self, filename, key) File "/usr/lib/python3.4/idlelib/PyShell.py", line 126, in __init__ EditorWindow.__init__(self, *args) File "/usr/lib/python3.4/idlelib/EditorWindow.py", line 294, in __init__ if io.loadfile(filename): File "/usr/lib/python3.4/idlelib/IOBinding.py", line 236, in loadfile self.text.insert("1.0", chars) File "/usr/lib/python3.4/idlelib/Percolator.py", line 25, in insert self.top.insert(index, chars, tags) File "/usr/lib/python3.4/idlelib/UndoDelegator.py", line 81, in insert self.addcmd(InsertCommand(index, chars, tags)) File "/usr/lib/python3.4/idlelib/UndoDelegator.py", line 116, in addcmd cmd.do(self.delegate) File "/usr/lib/python3.4/idlelib/UndoDelegator.py", line 219, in do text.insert(self.index1, self.chars, self.tags) File "/usr/lib/python3.4/idlelib/ColorDelegator.py", line 82, in insert self.delegate.insert(index, chars, tags) File "/usr/lib/python3.4/idlelib/WidgetRedirector.py", line 148, in __call__ return self.tk_call(self.orig_and_operation + args) _tkinter.TclError: character U+1f4a9 is above the range (U+0000-U+FFFF) allowed by Tcl So who/what is broken? > > - If you are using an existing language, be aware of any bugs and > limitations in its Unicode implementation. You may or may not be able to > work around them, but at least you can decide whether or not you wish to > try. > > - If you are writing your own file system layer, it's 2015 fer fecks sake, > file names should be Unicode strings, not bytes! (That's one part of the > Unix model that needs to die.) You can use UTF-8 or UTF-16 in the file > system, whichever you please, but again remember that both are > variable-width formats. Correct. Windows is broken for using UTF-16 Linux is broken for conflating UTF-8 and byte string. Lot of breakage out here dont you think? May be related to the equation UTF-16 = UCS-2 + Duct-tape ?? From llanitedave at birdandflower.com Fri Mar 6 11:23:30 2015 From: llanitedave at birdandflower.com (llanitedave) Date: Fri, 6 Mar 2015 08:23:30 -0800 (PST) Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] In-Reply-To: <87k2yu5tos.fsf@elektro.pacujo.net> References: <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> <87twy34dst.fsf@elektro.pacujo.net> <726afahrhnim716av2dnckrsd9n5j5kukj@4ax.com> <21dafa533nrsmktshd35kdbd13ahgj50bf@4ax.com> <87fv9k2999.fsf@elektro.pacujo.net> <54f7599d$0$12988$c3e8da3$5496439d@news.astraweb.com> <8761ag36du.fsf@elektro.pacujo.net> <87mw3s10nl.fsf@elektro.pacujo.net> <9ccfd0c7-1310-44de-a493-6019a1773ae1@googlegroups.com> <87k2yu5tos.fsf@elektro.pacujo.net> Message-ID: On Friday, March 6, 2015 at 2:03:42 AM UTC-8, Marko Rauhamaa wrote: > Rustom Mody : > > > I really dont understand what we are communicating (or not) about... > > > > Can you hear my accent? > > If we met at a Python conference, I would hear it and hopefully even > understand it. > > > But more to the point its still not clear (to me) whether you are objecting to > > - to Mark > > - to British accent > > - to British spellings in software > > - to anyone/anywhere international, using non-international format > > I'm objecting (mildly) to British spellings in source code and technical > documentation. > > I'm objecting (more strongly) to local English accents in settings > including but not limited to: > > - conference speeches with international audiences > > - group discussions with international participants > > - teleconferences with international participants > > In my experience, it is harder to understand most British English > accents than, say, a run-of-the-mill Chinese engineer trying to speak > English. It has to do with pronunciation, speed and eloquence (too much > of it with native speakers). > > > Marko It's obvious that's what's needed here is a PEP requiring that the International Phonetic Alphabet be used for all Python identifiers and keywords. From llanitedave at birdandflower.com Fri Mar 6 11:25:40 2015 From: llanitedave at birdandflower.com (llanitedave) Date: Fri, 6 Mar 2015 08:25:40 -0800 (PST) Subject: HELP!! How to ask a girl out with a simple witty Python code?? In-Reply-To: References: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> Message-ID: On Wednesday, March 4, 2015 at 6:50:32 PM UTC-8, sohca... at gmail.com wrote: > On Wednesday, March 4, 2015 at 5:34:16 PM UTC-8, Xrrific wrote: > > Guys, please Help!!! > > > > I am trying to impress a girl who is learning python and want ask her out at the same time. > > > > Could you please come up with something witty incorporating a simple python line like If...then... but..etc. > > > > You will make me a very happy man!!! > > > > Thank you very much!!! > > You're asking a bunch of nerds for dating advice? Girls can be nerds too, ya know... From steve+comp.lang.python at pearwood.info Fri Mar 6 11:26:02 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 07 Mar 2015 03:26:02 +1100 Subject: Newbie question about text encoding References: <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <01dd9b83-db3e-4e7d-9022-dc6af75eb570@googlegroups.com> <1425648780.3358976.236451377.1ED1534A@webmail.messagingengine.com> <1425650591.3368169.236462481.4CA83873@webmail.messagingengine.com> Message-ID: <54f9d51b$0$13014$c3e8da3$5496439d@news.astraweb.com> random832 at fastmail.us wrote: > My point is there are very few > problems to which "count of Unicode code points" is the only right > answer - that UTF-32 is good enough for but that are meaningfully > impacted by a naive usage of UTF-16, to the point where UTF-16 is > something you have to be "safe" from. I'm not sure why you care about the "count of Unicode code points", although that *is* a problem. Not for end-user reasons like "how long is my password?", but because it makes your job as a programmer harder. [steve at ando ~]$ python2.7 -c "print (len(u'\U00004444:\U00014445'))" 4 [steve at ando ~]$ python3.3 -c "print (len(u'\U00004444:\U00014445'))" 3 It's hard to reason about your code when something as fundamental as the length of a string is implementation-dependent. (By the way, the right answer should be 3, not 4.) But an even more important problem is that broken-UTF-16 lets you create invalid, impossible Unicode strings *by accident*. Naturally you can create broken Unicode if you assemble strings of surrogates yourself, but broken-UTF-16 means it can happen from otherwise innocuous operations like reversing a string: py> s = u'\U00004444:\U00014445' # Python 2.7 narrow build py> s[::-1] u'\udc45\ud811:\u4444' It's hard for me to demonstrate that the reversed string is broken because the shell I am using does an amazingly good job of handling broken Unicode. Even if I print it, the shell just prints missing-character glyphs instead of crashing (fortunately for me!). But the first two code points are in illegal order: \udc45 is a high surrogate, and must follow a low surrogate; \ud811 is a low surrogate, and must precede a high surrogate; I'm not convinced you should be allowed to create Unicode strings containing mismatched surrogates like this deliberately, but you certainly shouldn't be able to do so by accident. -- Steven From wolfgang.maier at biologie.uni-freiburg.de Fri Mar 6 11:27:52 2015 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Fri, 06 Mar 2015 17:27:52 +0100 Subject: Speeding up permutations generation In-Reply-To: <201503061114.06957.gheskett@wdtv.com> References: <201503060532.03842.gheskett@wdtv.com> <54F98DFA.4090503@davea.name> <201503061114.06957.gheskett@wdtv.com> Message-ID: On 03/06/2015 05:14 PM, Gene Heskett wrote: > > > On Friday 06 March 2015 06:22:34 Dave Angel wrote: >> >> 30414093201713378043612608166064768844377641568960512000000000000L > > What utility output that as an L ? > One called the python interactive interpreter used by many people on this list (though it is a shame they haven't switched to python3 yet) :) Python 2.7.6 (default, Mar 22 2014, 22:59:56) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from math import factorial >>> factorial(50) 30414093201713378043612608166064768844377641568960512000000000000L Wolfgang From davea at davea.name Fri Mar 6 11:30:08 2015 From: davea at davea.name (Dave Angel) Date: Fri, 06 Mar 2015 11:30:08 -0500 Subject: Speeding up permutations generation In-Reply-To: <201503061114.06957.gheskett@wdtv.com> References: <201503060532.03842.gheskett@wdtv.com> <54F98DFA.4090503@davea.name> <201503061114.06957.gheskett@wdtv.com> Message-ID: <54F9D610.5050002@davea.name> On 03/06/2015 11:14 AM, Gene Heskett wrote: > > > On Friday 06 March 2015 06:22:34 Dave Angel wrote: >> >> Sorry, but 50! is not even close to 50**50. The latter is 85 digits >> as you say, but 50! is "only" 64. >> >> >> 30414093201713378043612608166064768844377641568960512000000000000L > > What utility output that as an L ? > Python 2.7 interpreter, after calculating factorial with the obvious loop. Basically, it's using repr() on the expression, so it flags the integer as a long, rather than an int. I debated not including it, but this way I was sure of getting the right number of zeroes. My copy/paste is notorious for missing a character or two at each end. -- DaveA From breamoreboy at yahoo.co.uk Fri Mar 6 11:35:25 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 06 Mar 2015 16:35:25 +0000 Subject: HELP!! How to ask a girl out with a simple witty Python code?? In-Reply-To: References: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> <2906370c-58c7-4d8b-8db3-2ea3773b9578@googlegroups.com> <54f8d56a$0$12984$c3e8da3$5496439d@news.astraweb.com> <54f916b2$0$12980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 06/03/2015 11:53, alister wrote: > On Fri, 06 Mar 2015 14:23:22 +1100, Ben Finney wrote: > >> >> No. I'm saying that it's clear the person saying ?get their panties all >> up in a bunch? fully intends to convey specifically *female* underwear, >> and thereby to use implied femininity as an insult. >> >> Yes, of course I know some people who aren't female wear panties. Yes, >> of course I know some women wear underwear that isn't panties. Don't try >> to change the topic with absurd logical extremes that I didn't raise. >> >> I'm talking about the implication of the comment as a gendered insult. >> >>> It's only gender specific if you accept the sexist gendered stereotype >>> that all women are by definition thin-skinned and excessively >>> sensitive. >> >> Bullshit. I said nothing about the sensitivity of anyone. Individual >> women you may know ? even *all* women, everywhere ? could be as tough as >> nails, and it doesn't address the point I'm raising. >> >> Whether any particular woman is targeted or not, the comment I'm >> responding to invokes female gender as an implied insult. That's >> unwelcoming to women, and I don't want such unwelcoming attitudes in >> this community. > > I have not seen one female poster on this site claim to be offended by > the comment or even consider it to be a slur. > > I doubt that the original poster of the comment intended it to be either > & most people reading it would have known that (regardless of their > gender) > > one thing i personally find offensive is when someone raises an issue on > someone else's behalf because they THINK they MIGHT get offended without > bothering to check. > > I am not female so this particular instance does not relate to me but an > example from a few years ago was when a popular UK soap made an extreme > effort not to show a cross or Christmas tree during a church wedding in > case it "offended not-Christians". > > I am a non-Christian & found that decision offensive. > When a UK TV station showed the Dam Busters film some years ago and edited out the part about the burial of Guy Gibson's dog, I wasn't offended, I was downright livid. How dare they distort history in an attempt to avoid offending people. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From steve+comp.lang.python at pearwood.info Fri Mar 6 11:43:37 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 07 Mar 2015 03:43:37 +1100 Subject: Is nan in (nan,) correct? References: Message-ID: <54f9d93a$0$12981$c3e8da3$5496439d@news.astraweb.com> Rustom Mody wrote: > On Friday, March 6, 2015 at 3:57:12 AM UTC+5:30, rand... at fastmail.us > wrote: >> It's been brought up on Stack Overflow that the "in" operator (on >> tuples, and by my testing on dict and list, as well as dict lookup) uses >> object identity as a shortcut, and returns true immediately if the >> object being tested *is* an element of the container. However, the >> contains operation does not specify whether object identity or equality >> is to be used. In effect, the built-in container types use a hybrid >> test: "a is b or a == b". >> >> My question is, is this a *correct* implementation of the operator, or >> are objects "supposed to" use a basis of equality for these tests? > > nan is an illegal or bogus value. NANs *represent* bogus values, they aren't bogus themselves. > As usual legalizing the illegal is always fraught with increasing > conundrums. > > The most (to me) classic instance of this is denotational semantics. > In DS one tries to give semantics to programs by mapping programs to > math-functions across some domains > > However some programs crash. What should be the semantics of such a > program. We say its a partial function ? undefined at the crash-points. > But partial functions are not nearly as tractable (to mathematicians!) as > total functions. > So we invent a bogus value ? (called bottom) and totalize all functions > by mapping to this. > > Very nice? > > So nice in fact that we wish to add ? to our programming language > > And now all hell breaks loose because the question x == ? is the halting > problem. Oh nonsense. x == ? is easily performed with the equivalent of: type(x) == BottomType and bit_representation(x) == bit_representation(?) > And people love this problem so much they keep replicating it: > > - C and null (or Pascal/Lisp and Nil) > [Hoare's billion dollar mistake > [https://en.wikipedia.org/wiki/Tony_Hoare#Apologies_and_retractions ] > - nul in SQL ? Should two nuls compare as same or different? > There are good (and different!) reasons for both answers > - Python and None > - Floats and nans This is a random grab-bag of unrelated "problems" that differ in their causes and their consequences. The only thing they have in common is that Null/Nil/Nul/None/NAN all begin with N, and are all "special" in some sense. > My own thoughts on this (not very well thought out, I admit) > The letter of the IEEE standard talks of nans and their details > The spirit of the standard is that nans capture exception-al computations > ie nan represents an exception > > In a language like python with decent exceptions we do not need nans. Then you are missing the most important use-case for NANs. Really, do you think that the designers of IEEE-754 actually didn't think of this? Long before high-level languages like Python started using exceptions, low-level languages had "traps" that did more or less the same thing. If all you want is merely to interrupt your calculation the first time an error occurs, then you just trap the error condition and you're done. But IEEE-754 supports *not* interrupting the calculation, but allowing the error condition to propagate all the way to the end of the calculation. Instead of peppering your calculation with dozens of checks ("Look Before You Leap") to avoid triggering a trap, you just perform the calculation, and then at the end inspect the result and if it is a NAN you can decide how to handle it ("Easier To Ask Forgiveness Than Permission"). The whole point of NANs is to avoid traps (exceptions, signals, or whatever you want to call this interruption) from being triggered. To replace NANs with exceptions is to miss their whole reason for existence! And for those who do want an immediate exception, the standard supports that too, with *signalling NANs*, which are supposed to trap on just about every operation. A proper IEEE-754 system will allow you to decide which operations should trap immediately and which don't, it's not a global all-or-nothing prospect. Alas, although many (most? all?) FPUs these days support these features, hardly any high-level language does. You typically cannot even control these features from C, but have to drop down to assembly. The fine control that IEEE-754 offers is under-utilized because the language designers don't support it. -- Steven From rosuav at gmail.com Fri Mar 6 11:45:35 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 7 Mar 2015 03:45:35 +1100 Subject: Newbie question about text encoding In-Reply-To: References: <201502241620.t1OGKf4n002146@fido.openend.se> <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <01dd9b83-db3e-4e7d-9022-dc6af75eb570@googlegroups.com> <54f9bea1$0$12994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Mar 7, 2015 at 3:20 AM, Rustom Mody wrote: > C's string is not bug-prone its plain buggy as it cannot represent strings > with nulls. > > I would not go that far for UTF-16. > It is bug-inviting but it can also be implemented correctly C's standard library string handling functions are restricted in that they handle a 255-byte alphabet. They do not handle Unicode, they do not handle NUL, that is simply how they are. But I never said I was talking about the C standard library. If you type a text string into a GUI entry field, or encode it quoted-printable and pass it to a web server, or whatever, you shouldn't know or care about what language the program is written in; and if that program barfs on a NUL, that's a limitation. That limitation might be caused by its naive use of strcpy() when it should have used memcpy(), but that's not your problem. It's exactly the same here: if your program chokes on an SMP character, I don't care what your program was written in or what library functions your program called on. All I care is that your program - repeated for emphasis, *your* program - failed on that input. It's up to you to choose your underlying functions appropriately. >> - If you are designing your own language, your implementation of Unicode >> strings should use something like Python's FSR, or UTF-8 with tweaks to >> make string indexing O(1) rather than O(N), or correctly-implemented >> UTF-16, or even UTF-32 if you have the memory. (Choices, choices.) > > FSR is possible in python for very specific pythonic reasons > - dynamicness > - immutable strings > > Drop either and FSR is impossible I don't know what you mean by "dynamicness". What you do need is a Unicode string type, such that the application program isn't aware of the underlying bytes, but simply treats this string as a sequence of code points. The immutability isn't technically a requirement, but it does make the FSR much more manageable; in a language with mutable strings, it's probably more efficient to use UTF-32 for simplicity, but it's up to the language designer to figure that out. (It might be best to use something like the FSR, but where strings are never narrowed after being widened, so it'd be possible for an ASCII-only string to be stored UTF-32. That has consequences for comparisons, but might give a reasonable hybrid of storage and mutation performance.) > _tkinter.TclError: character U+1f4a9 is above the range (U+0000-U+FFFF) allowed by Tcl > > So who/what is broken? The exception is pretty clear on that point. Tcl can't handle SMP characters. So it's Tcl that's broken. Unless there's evidence to the contrary, that's what I would expect to be the case. > Correct. > Windows is broken for using UTF-16 > Linux is broken for conflating UTF-8 and byte string. > > Lot of breakage out here dont you think? > May be related to the equation > > UTF-16 = UCS-2 + Duct-tape UTF-16 is an encoding that was designed to be backward-compatible with UCS-2, just as UTF-8 was designed to be compatible with ASCII. Call it what you will, but backward compatibility is pretty important. Look at things like DES3 - if you use the same key three times, it's compatible with DES. Linux isn't "broken" for conflating UTF-8 and byte strings. Linux is flawed in that it defines file names to be byte strings, which means that every file system could be different in what it actually uses as the encoding. Since file names exist for the benefit of humans, they should be treated as text, so we should work with them as text. But for reasons of backward compatibility, Linux hasn't yet changed. Windows isn't broken for using UTF-16. I think it's a poor trade-off, given that so many file names are ASCII-only; and, of course, if any program treats a Windows file name as UCS-2, then that program is broken. But UTF-16 is not itself broken, any more than UTF-7 is. And UTF-7 is a lot harder to work with. ChrisA From rustompmody at gmail.com Fri Mar 6 11:49:05 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 6 Mar 2015 08:49:05 -0800 (PST) Subject: HELP!! How to ask a girl out with a simple witty Python code?? In-Reply-To: References: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> <2906370c-58c7-4d8b-8db3-2ea3773b9578@googlegroups.com> <54f8d56a$0$12984$c3e8da3$5496439d@news.astraweb.com> <54f916b2$0$12980$c3e8da3$5496439d@news.astraweb.com> <85385izu51.fsf@benfinney.id.au> Message-ID: On Friday, March 6, 2015 at 9:08:07 AM UTC+5:30, Chris Angelico wrote: > Allow me to summarize this subthread: > > * sohcahtoa makes a comment implying that this list is full of nerds > who know nothing about dating. Gender-nonspecific and most likely > self-deprecating as much as insulting. > * I responded with a reference to a nerdy movie ("Real Genius", and if > you haven't seen it, go grab it - it's funny), which perhaps was not > recognized, leading to the post in which: > * sohcahtoa misunderstands me and thinks I was offended at his post > (which I wasn't), and gets his hackles up, thinking the original > nerd-dating-advice comment shouldn't have been offensive > * Two people then go back and forth about whether or not the previous > three posts were offensive. > Nice summary of the ridiculous Except you missed the subject of the thread From gheskett at wdtv.com Fri Mar 6 11:51:57 2015 From: gheskett at wdtv.com (Gene Heskett) Date: Fri, 6 Mar 2015 11:51:57 -0500 Subject: Speeding up permutations generation In-Reply-To: <54F9D610.5050002@davea.name> References: <201503061114.06957.gheskett@wdtv.com> <54F9D610.5050002@davea.name> Message-ID: <201503061151.57112.gheskett@wdtv.com> On Friday 06 March 2015 11:30:08 Dave Angel wrote: > On 03/06/2015 11:14 AM, Gene Heskett wrote: > > On Friday 06 March 2015 06:22:34 Dave Angel wrote: > >> Sorry, but 50! is not even close to 50**50. The latter is 85 > >> digits as you say, but 50! is "only" 64. > >> > >> > >> 30414093201713378043612608166064768844377641568960512000000000000L > > > > What utility output that as an L ? > > Python 2.7 interpreter, after calculating factorial with the obvious > loop. Basically, it's using repr() on the expression, so it flags the > integer as a long, rather than an int. > > I debated not including it, but this way I was sure of getting the > right number of zeroes. My copy/paste is notorious for missing a > character or two at each end. Chuckle, so is mine Dave. Mouse, holding breath cuz I have a finger on a button, is turning blue and finally exhales in desperation sort of thing I guess. Particularly against the left margin of a string. I can't see a single reason why a drag the mouse copy has to die if the mouse moves .0000001" past the left margin. But I didn't write it so I've no clue why it doesn't just take the whole damned highlighted string & be done with it. > -- > DaveA 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+comp.lang.python at pearwood.info Fri Mar 6 11:59:07 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 07 Mar 2015 03:59:07 +1100 Subject: Is nan in (nan,) correct? References: <87443f8f-3bd8-4b88-84c1-d20a2fc8cc19@googlegroups.com> Message-ID: <54f9dcdc$0$12987$c3e8da3$5496439d@news.astraweb.com> Rustom Mody wrote: > On Friday, March 6, 2015 at 3:31:58 PM UTC+5:30, Chris Angelico wrote: >> On Fri, Mar 6, 2015 at 8:50 PM, Rustom Mody wrote: >> > In a language like python with decent exceptions we do not need nans. >> >> Not so. I could perhaps accept that we don't need signalling NaNs, as >> they can be replaced with exceptions, but quiet NaNs are by definition >> _not_ exceptions. > > My impression (maybe I am wrong): > "Catch an exception and ignore it" is a way of converting signalling to > quiet With the added advantage of being able to tweak the specs of what > happens when nan op normal to one's taste I don't understand what you are trying to say. Let's take a dirt-simple example: def inverse(x): return 1.0/x There's an exception there, waiting to bite. If I include inverse() in some complex calculation: def function(x, y): return atan2(inverse(3*x*y)+1, inverse(1 - x**2 + 3*x - 0.2)**3) values = [function(1.5*x, y+2) for x, y in zip(xx, yy)] and I just wish to skip over the failed calculations, I can't just "ignore" exceptions: # This doesn't work! def inverse(x): try: return 1.0/x except ZeroDivisionError: pass I have to return something that acts like a number but isn't a number. Something which, once it enters a calculation, should propagate through it. But not necessarily something which once it enters can never be removed! It may be that some calculations can "cancel out" these "errors" (indeed, the atan2 function is one of those -- it can return non-NANs from at least some NAN arguments). So what should I return? It cannot be a number, but it has to act like a number. Ideally, it should carry diagnostic information so I can see what the failure was, for debugging, although I may not bother to do so that information should at least be available for use. I have just re-invented NANs. -- Steven From steve+comp.lang.python at pearwood.info Fri Mar 6 12:03:46 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 07 Mar 2015 04:03:46 +1100 Subject: HELP!! How to ask a girl out with a simple witty Python code?? References: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> <2906370c-58c7-4d8b-8db3-2ea3773b9578@googlegroups.com> <54f8d56a$0$12984$c3e8da3$5496439d@news.astraweb.com> <54f916b2$0$12980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <54f9ddf2$0$12987$c3e8da3$5496439d@news.astraweb.com> alister wrote: > I have not seen one female poster on this site claim to be offended by > the comment or even consider it to be a slur. In fairness to Ben, it must be recognised that there are very few women here, and that is a problem Ben (and I) would like to rectify. We just disagree on the root cause of that, and whether or not mild put-downs such as the one in question are part of the cause or not. (Well, I call it a "mild put-down". Ben may or may not agree that it is mild.) -- Steven From rustompmody at gmail.com Fri Mar 6 12:04:21 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 6 Mar 2015 09:04:21 -0800 (PST) Subject: Is nan in (nan,) correct? In-Reply-To: <54f9d93a$0$12981$c3e8da3$5496439d@news.astraweb.com> References: <54f9d93a$0$12981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Friday, March 6, 2015 at 10:13:55 PM UTC+5:30, Steven D'Aprano wrote: > Rustom Mody wrote: > > > On Friday, March 6, 2015 at 3:57:12 AM UTC+5:30, rand... at fastmail.us > > wrote: > >> It's been brought up on Stack Overflow that the "in" operator (on > >> tuples, and by my testing on dict and list, as well as dict lookup) uses > >> object identity as a shortcut, and returns true immediately if the > >> object being tested *is* an element of the container. However, the > >> contains operation does not specify whether object identity or equality > >> is to be used. In effect, the built-in container types use a hybrid > >> test: "a is b or a == b". > >> > >> My question is, is this a *correct* implementation of the operator, or > >> are objects "supposed to" use a basis of equality for these tests? > > > > nan is an illegal or bogus value. > > NANs *represent* bogus values, they aren't bogus themselves. > > > > As usual legalizing the illegal is always fraught with increasing > > conundrums. > > > > The most (to me) classic instance of this is denotational semantics. > > In DS one tries to give semantics to programs by mapping programs to > > math-functions across some domains > > > > However some programs crash. What should be the semantics of such a > > program. We say its a partial function ? undefined at the crash-points. > > But partial functions are not nearly as tractable (to mathematicians!) as > > total functions. > > So we invent a bogus value ? (called bottom) and totalize all functions > > by mapping to this. > > > > Very nice? > > > > So nice in fact that we wish to add ? to our programming language > > > > And now all hell breaks loose because the question x == ? is the halting > > problem. > > Oh nonsense. x == ? is easily performed with the equivalent of: > > type(x) == BottomType and bit_representation(x) == bit_representation(?) You dont grok your theory of computation very well do you? def foo(x): return x + x def bar(x): return x + x def baz(x): return 2*x One can imagine an implementation where id(foo) == id(bar) [I am assuming that id is a good enough approx to bit_representation] Can you imagine an implementation where id(bar) == id(baz) ? If you can I will just start increasing the gap between bar and baz and in that game we will be re-executing the details of the halting problem (and more generally the Rice theorem) Simpler for you to revise your Theory of computation I think From steve+comp.lang.python at pearwood.info Fri Mar 6 12:07:25 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 07 Mar 2015 04:07:25 +1100 Subject: Is nan in (nan,) correct? References: <54f90c53$0$12994$c3e8da3$5496439d@news.astraweb.com> <858ufazvff.fsf@benfinney.id.au> <54F91C70.6020303@stoneleaf.us> <85wq2uyffs.fsf@benfinney.id.au> Message-ID: <54f9decd$0$12987$c3e8da3$5496439d@news.astraweb.com> random832 at fastmail.us wrote: > On Thu, Mar 5, 2015, at 22:49, Chris Angelico wrote: >> I'm not sure it's just an optimization. Compare this post from >> python-dev, where Nick Coghlan discusses the same topic: >> >> https://mail.python.org/pipermail/python-dev/2014-July/135476.html > > If it is a bug for NaN to "infect" containers' behavior, we need to take > a serious look at sort(). Hmmm. No, I don't think so. I think that NANs are just weird and you either accept that they do weird things or you don't use them. Real numbers have a total ordering, so sorting a list of real numbers (or their closest equivalent in computer implementations) makes sense, and sure enough we can meaningfully sort a list of finite floats. Complex numbers do not define an ordering at all: given a complex number w, and another complex number z, asking whether w < z is meaningless. Ordering comparisons simply aren't defined for complex numbers at all, and trying to sort a list with more than one complex number will raise an exception. But NANs are weird. NANs are unordered like complex, but unlike complex the order comparisons are defined. They just always return False (except for not-equal, which always returns True): NAN < x returns False, for every x NAN > x also returns False, for every x If you think of NANs as members of a set with total ordering, like the real number line, then this doesn't make sense. But floats (as opposed to the Real Numbers) don't have total order. If you think of NANs as members of unorderable values like the complex plane, then you should get an exception, but they aren't members of an unorderable set, they're merely not ordered. There's nothing wrong with doing: if x < 1.2345: ... just because x happens to be a NAN. One shouldn't raise an exception (even though this is an exceptional case), because < and > operators are perfectly well-defined for NANs, unlike the case for complex values. But the consequence of this is that sort misbehaves. Sort algorithms depend on the values being sorted having a total order. If you sort a list containing objects with a partial order (like sets, or NANs), then the sort result is dependent on the initial order of the elements. If we really wanted to solve this problem, we could re-define sorting to use a separate method instead of __lt__, let's call it __sort_lt__. If __sort_lt__ doesn't exist, sorting will fall back on __lt__. That will allow sets to distinguish between the use of < for subset testing and the use of < for the purposes of sorting, and raise an exception or a warning. Likewise floats could define the method: def __sort_lt__(self, other): if isnan(self) or isnan(other): raise SomeException return type(self).__lt__(other) Another option would be to have a context manager which disables order comparisons for NANs: def sorted(it): L = list(it) with disabled_nan_comparisons(): L.sort() # raise if L contains a NAN return L sort of thing. But either solution is a pretty big change for a pretty rare issue. -- Steven From ian.g.kelly at gmail.com Fri Mar 6 12:13:25 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 6 Mar 2015 10:13:25 -0700 Subject: Speeding up permutations generation In-Reply-To: References: Message-ID: On Fri, Mar 6, 2015 at 1:24 AM, Abhiram R wrote: > >> >> A list of 100 elements has approximately 9.33 x 10**157 permutations. >> If you could somehow generate one permutation every yoctosecond, >> exhausting them would still take more than a hundred orders of >> magnitude longer than the age of the universe. >> -- >> https://mail.python.org/mailman/listinfo/python-list > > > True that :D I may have exaggerated on the number. Let's consider something > more practically manageable => 50 elements with a 50! permutation. > Is there a solution now? That's still infeasible, as others have pointed out. At one permutation every picosecond, you'll still need 9.6 x 10**44 years. If the size isn't that important to you and you just want a faster implementation of permutations, you could try reimplementing it yourself as a C extension. The stdlib implementation is already written in C though, so unless you have a better algorithm I doubt you'll find much room for optimization. From rosuav at gmail.com Fri Mar 6 12:16:44 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 7 Mar 2015 04:16:44 +1100 Subject: Is nan in (nan,) correct? In-Reply-To: References: <54f9d93a$0$12981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Mar 7, 2015 at 4:04 AM, Rustom Mody wrote: > You dont grok your theory of computation very well do you? > > def foo(x): return x + x > def bar(x): return x + x > def baz(x): return 2*x > > One can imagine an implementation where > id(foo) == id(bar) > [I am assuming that id is a good enough approx to bit_representation] > > Can you imagine an implementation where > id(bar) == id(baz) > ? No, I cannot imagine either. Those functions have different identities. They may be considered *equal* but they should not be *identical*. I can imagine a language in which they are considered indistinguishable and optimized down to one, but if you consider them to be the same function, then you've abolished all concept of identity. Also, I have no idea what any of this has to do with nans and container membership. ChrisA From rustompmody at gmail.com Fri Mar 6 12:36:56 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 6 Mar 2015 09:36:56 -0800 (PST) Subject: Is nan in (nan,) correct? In-Reply-To: References: <54f9d93a$0$12981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <794c8685-1aa5-4bc7-9178-d59dcca94bf0@googlegroups.com> On Friday, March 6, 2015 at 10:48:07 PM UTC+5:30, Chris Angelico wrote: > On Sat, Mar 7, 2015 at 4:04 AM, Rustom Mody wrote: > > You dont grok your theory of computation very well do you? > > > > def foo(x): return x + x > > def bar(x): return x + x > > def baz(x): return 2*x > > > > One can imagine an implementation where > > id(foo) == id(bar) > > [I am assuming that id is a good enough approx to bit_representation] > > > > Can you imagine an implementation where > > id(bar) == id(baz) > > ? > > No, I cannot imagine either. Those functions have different > identities. They may be considered *equal* but they should not be > *identical*. I can imagine a language in which they are considered > indistinguishable and optimized down to one, but if you consider them > to be the same function, then you've abolished all concept of > identity. Treat id as the python version of bit_representation. Now we have two things (worlds really) in-python entities like foo/bar/baz Their mathematical semantics -- the infinite sets of (domain,range) pairs that they are intended to capture. [Jargon note: The id-equal is called intensional-equality the math-equality is called extensional-equality] To get foo == bar one can imagine something like 1. Hash the dis of every function 2. If a new function being defined is hash-equal to an old one: If dis(new) == dis(old) make new_name point to old implementation To make bar == baz we need more and more heavy-duty theorem provers And will invariably hit halting-problem in some guise or other > > Also, I have no idea what any of this has to do with nans and > container membership. ? in semantics is the prototypical example of reifying an undefined entity. As are all the other examples nil/None/nul/nan. It buys a bigger problem for a smaller one -- Steven's (other thread) example of "Should I know whether an asteroid the size of Texas is earth bound?" To take a less apocalyptic example: I am holding a bomb in my hand. Is it good to know that? DOes it help any? Does the statement "We have a problem!!" make the 'problem' vanish? ?/nul/nil/nan are all 'bombs/problems' in some sense From rustompmody at gmail.com Fri Mar 6 13:04:47 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 6 Mar 2015 10:04:47 -0800 (PST) Subject: Is nan in (nan,) correct? In-Reply-To: <54f9dcdc$0$12987$c3e8da3$5496439d@news.astraweb.com> References: <87443f8f-3bd8-4b88-84c1-d20a2fc8cc19@googlegroups.com> <54f9dcdc$0$12987$c3e8da3$5496439d@news.astraweb.com> Message-ID: <6a78957e-d850-4189-923a-fa779a6a9463@googlegroups.com> On Friday, March 6, 2015 at 10:29:19 PM UTC+5:30, Steven D'Aprano wrote: > Rustom Mody wrote: > > > On Friday, March 6, 2015 at 3:31:58 PM UTC+5:30, Chris Angelico wrote: > >> On Fri, Mar 6, 2015 at 8:50 PM, Rustom Mody wrote: > >> > In a language like python with decent exceptions we do not need nans. > >> > >> Not so. I could perhaps accept that we don't need signalling NaNs, as > >> they can be replaced with exceptions, but quiet NaNs are by definition > >> _not_ exceptions. > > > > My impression (maybe I am wrong): > > "Catch an exception and ignore it" is a way of converting signalling to > > quiet With the added advantage of being able to tweak the specs of what > > happens when nan op normal to one's taste > > > I don't understand what you are trying to say. > > Let's take a dirt-simple example: > > def inverse(x): > return 1.0/x > > There's an exception there, waiting to bite. If I include inverse() in some > complex calculation: > > def function(x, y): > return atan2(inverse(3*x*y)+1, inverse(1 - x**2 + 3*x - 0.2)**3) > > values = [function(1.5*x, y+2) for x, y in zip(xx, yy)] > > and I just wish to skip over the failed calculations, I can't just "ignore" > exceptions: > > # This doesn't work! > def inverse(x): > try: > return 1.0/x > except ZeroDivisionError: > pass > > > I have to return something that acts like a number but isn't a number. > > Something which, once it enters a calculation, should propagate through it. > But not necessarily something which once it enters can never be removed! It > may be that some calculations can "cancel out" these "errors" (indeed, the > atan2 function is one of those -- it can return non-NANs from at least some > NAN arguments). So what should I return? It cannot be a number, but it has > to act like a number. Ideally, it should carry diagnostic information so I > can see what the failure was, for debugging, although I may not bother to > do so that information should at least be available for use. > > I have just re-invented NANs. Ok... Maybe so As I said I am not too sure about this However you have to give me a little fuller (if not more realistic) example [Your xx and yy are what?] And I have to see if I know how to tweak it nan-less And at least maintain hopefully improve the clarity, succinctness of the original! Not saying I will be able -- just that thats the claim From marko at pacujo.net Fri Mar 6 13:15:42 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 06 Mar 2015 20:15:42 +0200 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] References: <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> <87twy34dst.fsf@elektro.pacujo.net> <726afahrhnim716av2dnckrsd9n5j5kukj@4ax.com> <21dafa533nrsmktshd35kdbd13ahgj50bf@4ax.com> <87fv9k2999.fsf@elektro.pacujo.net> <54f7599d$0$12988$c3e8da3$5496439d@news.astraweb.com> <8761ag36du.fsf@elektro.pacujo.net> <87mw3s10nl.fsf@elektro.pacujo.net> <9ccfd0c7-1310-44de-a493-6019a1773ae1@googlegroups.com> <87k2yu5tos.fsf@elektro.pacujo.net> Message-ID: <87k2yuyott.fsf@elektro.pacujo.net> llanitedave : > It's obvious that's what's needed here is a PEP requiring that the > International Phonetic Alphabet be used for all Python identifiers and > keywords. You're onto something: ======================================================================== #!/?ju?z??/b?n/?nv ?pa?????n3 # -*- ?ko?d??: ?ju??ti???f-?8 -*- ??mpo?t lo??k?l d?f me?n(): t?a?: ?e?z ?V?lju??????() ?k?s?pt ?V?lju??????: t?a?: ?e?z ?A?O??????() ?fa?nli: ?e?z ?f __ne?m__ == "__me?n__": t?a?: me?n() ?k?s?pt ?V?lju??????: p??nt("H??lo?") ======================================================================== Marko From ethan at stoneleaf.us Fri Mar 6 13:16:10 2015 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 06 Mar 2015 10:16:10 -0800 Subject: Is nan in (nan,) correct? In-Reply-To: <6a78957e-d850-4189-923a-fa779a6a9463@googlegroups.com> References: <87443f8f-3bd8-4b88-84c1-d20a2fc8cc19@googlegroups.com> <54f9dcdc$0$12987$c3e8da3$5496439d@news.astraweb.com> <6a78957e-d850-4189-923a-fa779a6a9463@googlegroups.com> Message-ID: <54F9EEEA.1020204@stoneleaf.us> On 03/06/2015 10:04 AM, Rustom Mody wrote: > On Friday, March 6, 2015 at 10:29:19 PM UTC+5:30, Steven D'Aprano wrote: >> def inverse(x): >> return 1.0/x >> >> There's an exception there, waiting to bite. If I include inverse() in some >> complex calculation: >> >> def function(x, y): >> return atan2(inverse(3*x*y)+1, inverse(1 - x**2 + 3*x - 0.2)**3) >> >> values = [function(1.5*x, y+2) for x, y in zip(xx, yy)] > Ok... Maybe so > As I said I am not too sure about this > > However you have to give me a little fuller (if not more realistic) example > [Your xx and yy are what?] xx and yy are lists of floats, and for your test xx should have at least one zero in it. > And I have to see if I know how to tweak it nan-less > And at least maintain hopefully improve the clarity, succinctness of the original! Not saying I will be able -- just that thats the claim Good luck. :) -- ~Ethan~ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: OpenPGP digital signature URL: From auriocus at gmx.de Fri Mar 6 14:11:29 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Fri, 06 Mar 2015 20:11:29 +0100 Subject: Make standalone gui-enabled app for LINUX In-Reply-To: <0f6e6f37-60df-4683-8c2d-d4a0a34bf98b@googlegroups.com> References: <413fc3f5-38c3-4477-8495-366852e583e7@googlegroups.com> <0f6e6f37-60df-4683-8c2d-d4a0a34bf98b@googlegroups.com> Message-ID: Am 06.03.15 um 09:14 schrieb Mehdi: > On Friday, March 6, 2015 at 12:58:11 AM UTC+3:30, Christian Gollwitzer wrote: >> Use pyinstaller. It creates a "portable app", i.e. either single file or >> directory which can be run on (nearly) any system. However the resulting >> files can be awfully big. I use it with a relatively small program that >> depends on numpy/matplolib, and that pulls in ~100 MB worth of libraries. > > But i think pyinstaller doesn't work with python3. > Oops. you are right. I'm still using Python2. They announced "experimental python3 support" on the web page, though. Christian PS: Quoting fixed. From auriocus at gmx.de Fri Mar 6 14:26:41 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Fri, 06 Mar 2015 20:26:41 +0100 Subject: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices] In-Reply-To: <87k2yuyott.fsf@elektro.pacujo.net> References: <8761ak7kxm.fsf@elektro.pacujo.net> <87sido6491.fsf@elektro.pacujo.net> <6d6033b8-d228-4f5f-ac68-ae5b2a226431@googlegroups.com> <87d24regm6.fsf@elektro.pacujo.net> <54f4763c$0$12979$c3e8da3$5496439d@news.astraweb.com> <87twy34dst.fsf@elektro.pacujo.net> <726afahrhnim716av2dnckrsd9n5j5kukj@4ax.com> <21dafa533nrsmktshd35kdbd13ahgj50bf@4ax.com> <87fv9k2999.fsf@elektro.pacujo.net> <54f7599d$0$12988$c3e8da3$5496439d@news.astraweb.com> <8761ag36du.fsf@elektro.pacujo.net> <87mw3s10nl.fsf@elektro.pacujo.net> <9ccfd0c7-1310-44de-a493-6019a1773ae1@googlegroups.com> <87k2yu5tos.fsf@elektro.pacujo.net> <87k2yuyott.fsf@elektro.pacujo.net> Message-ID: Am 06.03.15 um 19:15 schrieb Marko Rauhamaa: > llanitedave : > >> It's obvious that's what's needed here is a PEP requiring that the >> International Phonetic Alphabet be used for all Python identifiers and >> keywords. > > You're onto something: ROFL!!! Though I'd prefer a few identifiers in a different way; I think you can drop many of the ?, e.g. > ======================================================================== > #!/?ju?z??/b?n/?nv ?pa?????n3 > # -*- ?ko?d??: ?ju??ti???f-?8 -*- > > ??mpo?t lo??k?l ?m?p??t ?l??kl British accent saves bytes!! SCNR > > d?f me?n(): > t?a?: > ?e?z ?V?lju??????() > ?k?s?pt ?V?lju??????: > t?a?: > ?e?z ?A?O??????() > ?fa?nli: > ?e?z > > ?f __ne?m__ == "__me?n__": > t?a?: > me?n() > ?k?s?pt ?V?lju??????: > p??nt("H??lo?") > ======================================================================== > > > Marko > From breamoreboy at yahoo.co.uk Fri Mar 6 15:03:07 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 06 Mar 2015 20:03:07 +0000 Subject: Odo: Shapeshifting for your data Message-ID: https://odo.readthedocs.org/en/latest/ I don't know if there is a need for shunting data around in this way but some of you may find this interesting. Now let's see how long it takes to go wonderfully off topic. I'll give it five minutes. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From sohcahtoa82 at gmail.com Fri Mar 6 15:05:20 2015 From: sohcahtoa82 at gmail.com (sohcahtoa82 at gmail.com) Date: Fri, 6 Mar 2015 12:05:20 -0800 (PST) Subject: Odo: Shapeshifting for your data In-Reply-To: References: Message-ID: On Friday, March 6, 2015 at 12:03:59 PM UTC-8, Mark Lawrence wrote: > https://odo.readthedocs.org/en/latest/ > > I don't know if there is a need for shunting data around in this way but > some of you may find this interesting. > > Now let's see how long it takes to go wonderfully off topic. I'll give > it five minutes. > > -- > My fellow Pythonistas, ask not what our language can do for you, ask > what you can do for our language. > > Mark Lawrence Five minutes? You have too much faith in this list. From stefan_ml at behnel.de Fri Mar 6 15:24:40 2015 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 06 Mar 2015 21:24:40 +0100 Subject: Speeding up permutations generation In-Reply-To: References: Message-ID: Ian Kelly schrieb am 06.03.2015 um 18:13: > On Fri, Mar 6, 2015 at 1:24 AM, Abhiram R wrote: >>> A list of 100 elements has approximately 9.33 x 10**157 permutations. >>> If you could somehow generate one permutation every yoctosecond, >>> exhausting them would still take more than a hundred orders of >>> magnitude longer than the age of the universe. >> >> True that :D I may have exaggerated on the number. Let's consider something >> more practically manageable => 50 elements with a 50! permutation. >> Is there a solution now? > > That's still infeasible, as others have pointed out. At one > permutation every picosecond, you'll still need 9.6 x 10**44 years. > > If the size isn't that important to you and you just want a faster > implementation of permutations, you could try reimplementing it > yourself as a C extension. The stdlib implementation is already > written in C though, so unless you have a better algorithm I doubt > you'll find much room for optimization. Well, one obvious "optimisation" in a case like this is to change the order in which permutations are returned. If processing all of them is infeasible, then being able to control which ones will be processed can be a crucial property of a "better" algorithm. Stefan From ginellobadellu at mail.com Fri Mar 6 15:36:24 2015 From: ginellobadellu at mail.com (SODOMIZZATO A 14 ANNI DA PEDERASTA DANIELE MINOTTI) Date: Fri, 6 Mar 2015 12:36:24 -0800 (PST) Subject: -- redacted -- Message-ID: <42d29010-e0f9-4748-8684-62c8619f3d77@googlegroups.com> -- redacted -- From emile at fenx.com Fri Mar 6 16:36:40 2015 From: emile at fenx.com (Emile van Sebille) Date: Fri, 06 Mar 2015 13:36:40 -0800 Subject: http: connection reset by peer In-Reply-To: References: <54F6A722.1000706@stoneleaf.us> <54F8A259.7040808@stoneleaf.us> Message-ID: On 3/5/2015 12:18 PM, Chris Angelico wrote: > On Fri, Mar 6, 2015 at 5:37 AM, Ethan Furman wrote: >> After mucking about with it with no results, I went on to another job -- when I came back to this one it was working. > > Huh. Well, if it recurs, see what you can find out about it... > otherwise, problem solved! Well, no remaining symptoms. I don't consider a problem solved if I fail to understand the context. Emile From jv92109 at gmail.com Fri Mar 6 16:55:13 2015 From: jv92109 at gmail.com (Jason Venneri) Date: Fri, 6 Mar 2015 13:55:13 -0800 (PST) Subject: Append a file Message-ID: Hello, I'm using the urllib.urlretrieve command to retrieve a couple of lines of data. I want to combine the two results into one file not two. Any suggestions? Sample urllib.urlretrieve('http://www.airplanes.com/data/boeing1.html','B747A.txt') urllib.urlretrieve('http://www.airplanes.com/data/boeing2.html','B747B.txt') I would like one file say B747C that contains the data from B747A and B747B in a file named B747C From sohcahtoa82 at gmail.com Fri Mar 6 17:05:31 2015 From: sohcahtoa82 at gmail.com (sohcahtoa82 at gmail.com) Date: Fri, 6 Mar 2015 14:05:31 -0800 (PST) Subject: Append a file In-Reply-To: References: Message-ID: <53fba4b4-d751-4e57-9da3-7fa1aa3ed8f1@googlegroups.com> On Friday, March 6, 2015 at 1:55:31 PM UTC-8, Jason Venneri wrote: > Hello, I'm using the urllib.urlretrieve command to retrieve a couple of lines of data. I want to combine the two results into one file not two. > > Any suggestions? > > Sample > urllib.urlretrieve('http://www.airplanes.com/data/boeing1.html','B747A.txt') > urllib.urlretrieve('http://www.airplanes.com/data/boeing2.html','B747B.txt') > > I would like one file say B747C that contains the data from B747A and B747B in a file named B747C What have you tried so far? Generally on this mailing list, we'll help you find what you're doing wrong, but we won't write your script for you. I'll give you one hint though, you should probably try urllib.urlopen, then write the file yourself. From invalid at invalid.invalid Fri Mar 6 17:12:25 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 6 Mar 2015 22:12:25 +0000 (UTC) Subject: http: connection reset by peer References: <54F6A722.1000706@stoneleaf.us> <54F8A259.7040808@stoneleaf.us> Message-ID: On 2015-03-06, Emile van Sebille wrote: > On 3/5/2015 12:18 PM, Chris Angelico wrote: >> On Fri, Mar 6, 2015 at 5:37 AM, Ethan Furman wrote: > >>> After mucking about with it with no results, I went on to another job >>> -- when I came back to this one it was working. >> >> Huh. Well, if it recurs, see what you can find out about it... >> otherwise, problem solved! > > Well, no remaining symptoms. I don't consider a problem solved if I > fail to understand the context. In cases like that, I don't call the problem solved. I prefer to say that the problem "went away". :) -- Grant Edwards grant.b.edwards Yow! I think I am an at overnight sensation right gmail.com now!! From rosuav at gmail.com Fri Mar 6 17:51:27 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 7 Mar 2015 09:51:27 +1100 Subject: http: connection reset by peer In-Reply-To: References: <54F6A722.1000706@stoneleaf.us> <54F8A259.7040808@stoneleaf.us> Message-ID: On Sat, Mar 7, 2015 at 9:12 AM, Grant Edwards wrote: > On 2015-03-06, Emile van Sebille wrote: >> On 3/5/2015 12:18 PM, Chris Angelico wrote: >>> On Fri, Mar 6, 2015 at 5:37 AM, Ethan Furman wrote: >> >>>> After mucking about with it with no results, I went on to another job >>>> -- when I came back to this one it was working. >>> >>> Huh. Well, if it recurs, see what you can find out about it... >>> otherwise, problem solved! >> >> Well, no remaining symptoms. I don't consider a problem solved if I >> fail to understand the context. > > In cases like that, I don't call the problem solved. I prefer to say > that the problem "went away". :) It's like with Mythbusters. They ask JD Nelson to help them to make something 'go away'. ChrisA From ben+python at benfinney.id.au Fri Mar 6 18:22:48 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 07 Mar 2015 10:22:48 +1100 Subject: HELP!! How to ask a girl out with a simple witty Python code?? References: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> <2906370c-58c7-4d8b-8db3-2ea3773b9578@googlegroups.com> <54f8d56a$0$12984$c3e8da3$5496439d@news.astraweb.com> <54f916b2$0$12980$c3e8da3$5496439d@news.astraweb.com> <54f9ddf2$0$12987$c3e8da3$5496439d@news.astraweb.com> Message-ID: <85egp1yalz.fsf@benfinney.id.au> Steven D'Aprano writes: > (Well, I call it a "mild put-down". Ben may or may not agree that it is > mild.) I agree that the put-down is mild, in that the person uttering it probably doesn't expect it to be more than a mild insult to the person they were addressing. That's quite orthogonal to the fact that invoking gender as an insult is strongly undermining the goal of making our community welcoming to all genders. That effect on third parties is completely unrelated to the intended magnitude of the insult. I'm glad we have common cause. Let's keep calling out harmful crap when we see it. -- \ ?Airports are ugly. Some are very ugly. Some attain a degree of | `\ ugliness that can only be the result of a special effort.? | _o__) ?Douglas Adams, _The Long Dark Tea-Time of the Soul_, 1988 | Ben Finney From steve+comp.lang.python at pearwood.info Fri Mar 6 18:33:49 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 07 Mar 2015 10:33:49 +1100 Subject: Is nan in (nan,) correct? References: <54f9d93a$0$12981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <54fa395e$0$13008$c3e8da3$5496439d@news.astraweb.com> Rustom Mody wrote: > On Friday, March 6, 2015 at 10:13:55 PM UTC+5:30, Steven D'Aprano wrote: >> Rustom Mody wrote: >> >> > On Friday, March 6, 2015 at 3:57:12 AM UTC+5:30, rand... at fastmail.us >> > wrote: >> >> It's been brought up on Stack Overflow that the "in" operator (on >> >> tuples, and by my testing on dict and list, as well as dict lookup) >> >> uses object identity as a shortcut, and returns true immediately if >> >> the object being tested *is* an element of the container. However, the >> >> contains operation does not specify whether object identity or >> >> equality is to be used. In effect, the built-in container types use a >> >> hybrid test: "a is b or a == b". >> >> >> >> My question is, is this a *correct* implementation of the operator, or >> >> are objects "supposed to" use a basis of equality for these tests? >> > >> > nan is an illegal or bogus value. >> >> NANs *represent* bogus values, they aren't bogus themselves. >> >> >> > As usual legalizing the illegal is always fraught with increasing >> > conundrums. >> > >> > The most (to me) classic instance of this is denotational semantics. >> > In DS one tries to give semantics to programs by mapping programs to >> > math-functions across some domains >> > >> > However some programs crash. What should be the semantics of such a >> > program. We say its a partial function ? undefined at the crash-points. >> > But partial functions are not nearly as tractable (to mathematicians!) >> > as total functions. >> > So we invent a bogus value ? (called bottom) and totalize all >> > functions by mapping to this. >> > >> > Very nice? >> > >> > So nice in fact that we wish to add ? to our programming language >> > >> > And now all hell breaks loose because the question x == ? is the >> > halting problem. >> >> Oh nonsense. x == ? is easily performed with the equivalent of: >> >> type(x) == BottomType and bit_representation(x) == bit_representation(?) > > You dont grok your theory of computation very well do you? > > def foo(x): return x + x > def bar(x): return x + x > def baz(x): return 2*x > > One can imagine an implementation where > id(foo) == id(bar) > [I am assuming that id is a good enough approx to bit_representation] > > Can you imagine an implementation where > id(bar) == id(baz) > ? Not necessarily if x are floats. But I'll grant you that 2*x and x+x are computationally equivalent if x is an int. I'll also grant you that there are other functions which are computationally equivalent to x+x but immeasurably more complex, and that for the compiler to recognise all such functions is equivalent to the halting problem. What does this have to do with the ability to perform an equality test against some ? value? Your argument is analogous to this: "Somewhere, out in the immensity of space, floats an infinite number of haystacks. Inside just one of those haystacks is a single tiny needle. Since it is impossible to locate that needle, it is likewise impossible to locate this needle I hold between my fingers!" You have made a claim that None is a reinvention of the ? (bottom) pattern, and that it is impossible to evaluate x == ? due to the Halting Problem. Let's put that to the test: [steve at ando ~]$ python -c "x = 23; print x == None" False I was hoping to have time to make a cup of tea while Python tried to solve the Halting Problem, possibly even to go to the market, do some shopping, do my house work, watch a movie, and catch a good night's sleep, but it only took a small fraction of a second for x == None to complete. I can draw only two possible conclusions: (1) The halting problem, and therefore Godel's Incompleteness Theorem as well, are disproven and the very fundamentals of mathematics and logic are overturned; or (2) You are mistaken that evaluating x == ? is equivalent to solving the Halting Problem. If I were a betting man, I know where I would put my money. -- Steven From dchichkov at gmail.com Fri Mar 6 20:08:08 2015 From: dchichkov at gmail.com (Dmitry Chichkov) Date: Fri, 6 Mar 2015 17:08:08 -0800 (PST) Subject: A strange statement in the bisect documentation? Message-ID: <9152f2c7-91c8-4898-a61d-c0b3b6358953@googlegroups.com> I was looking over documentation of the bisect module and encountered the following very strange statement there: >From https://docs.python.org/2/library/bisect.html ...it does not make sense for the bisect() functions to have key or reversed arguments because that would lead to an inefficient design (successive calls to bisect functions would not "remember" all of the previous key lookups). Instead, it is better to search a list of precomputed keys to find the index of the record in question... Is that right that the documentation encourages to use O(N) algorithm [by making a copy of all keys] instead of using O(log(N)) bisect with kay=attrgetter? And claims that O(N) is more efficient than O(log(N))? Thanks From steve+comp.lang.python at pearwood.info Fri Mar 6 21:24:11 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 07 Mar 2015 13:24:11 +1100 Subject: A strange statement in the bisect documentation? References: <9152f2c7-91c8-4898-a61d-c0b3b6358953@googlegroups.com> Message-ID: <54fa614c$0$13014$c3e8da3$5496439d@news.astraweb.com> Dmitry Chichkov wrote: > I was looking over documentation of the bisect module and encountered the > following very strange statement there: > > From https://docs.python.org/2/library/bisect.html > > ...it does not make sense for the bisect() functions to have key or > reversed arguments because that would lead to an inefficient design > (successive calls to bisect functions would not "remember" all of the > previous key lookups). > > Instead, it is better to search a list of precomputed keys to find the > index of the record in question... > > > Is that right that the documentation encourages to use O(N) algorithm [by > making a copy of all keys] instead of using O(log(N)) bisect with > kay=attrgetter? And claims that O(N) is more efficient than O(log(N))? Apparently :-) The documentation may not be completely clear, but what it is arguing is this: If you are making repeated bisect calls, then using a key function is inefficient because the key gets lost after each call and has to be recalculated over and over again. A concrete example: data = [i/100 for i in range(1, 7000001, 7)] data.sort(key=str) for x in many_x_values: bisect.insort(data, x, key=str) # Pretend this works. The first time you call insort, the key function (str in this case) will be called O(log N) times. The second time you call insort, the key function must be called again, even for the same data points, because the keys str(x) are thrown away and lost after each call to insort. After M calls to insort, there will have been on average M*(log(N)+1) calls to the key function. (The +1 is because the x gets str'ed as well, and there are M loops.) As an alternative, suppose we do this: data = [i/100 for i in range(1, 7000001, 7)] data.sort(key=str) keyed_data = [str(x) for x in data] for x in many_x_values: key = str(x) pos = bisect.bisect(keyed_data, key) keyed_data.insert(pos, key) data.insert(pos, x) This costs N calls to str in preparing the keyed_data list, plus M calls to str in the loop. The documentation suggests that we consider this will be cheaper in the long run, in other words: N + M < M*(log(N) + 1) N + M < M + M*log(N) That's true whenever N < M*log(N). The documentation assumes we should care about large N and large M. As they say, "everything is fast for small N": if you are doing three bisections on a list with ten items, then *who cares* how you do it, it's going to be quite fast. So let's say you have a list of 10000 items, that is N = 10000. Then it is faster to build a second keyed_list when: 10000 < M*log(10000) = M*13 # approximately i.e. M > 770 give or take. That's a fairly small number, and it's only about 8% of the size of N. So the general perspective is: If you have a list of N items, and you call bisect more than about (10% of N) times, it will likely be faster to pre-prepare a keyed list than call a key function repeatedly for each call to bisect. If you call bisect less than (10% of N) times, then it doesn't matter, because that's comparatively a small number and will be fast enough either way. Is the documentation correct? I don't know. I don't have an opinion on this. I recommend that you fork the bisect module, call it mybisect, add a key function parameter, and compare the speed of the two versions, with or without a key function. Remember: - Recent versions of bisect have a C accelerated version. Make sure you disable that, so you are comparing the speed of Python versus Python not Python versus C. - Nobody will care about small lists. I suggest that you start with at least ten thousand items, and move up to ten billion or so. For each N in (10**4, 10**5, ... 10**10) find out how many calls to insort or bisect does it take before the key function version becomes slower. Or possibly faster. - Is there are difference between fast key functions like str, and slow ones that have to do a lot of processing? -- Steven From rustompmody at gmail.com Fri Mar 6 21:37:39 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 6 Mar 2015 18:37:39 -0800 (PST) Subject: Is nan in (nan,) correct? In-Reply-To: <54fa395e$0$13008$c3e8da3$5496439d@news.astraweb.com> References: <54f9d93a$0$12981$c3e8da3$5496439d@news.astraweb.com> <54fa395e$0$13008$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Saturday, March 7, 2015 at 5:04:02 AM UTC+5:30, Steven D'Aprano wrote: > Rustom Mody wrote: > > > On Friday, March 6, 2015 at 10:13:55 PM UTC+5:30, Steven D'Aprano wrote: > >> Rustom Mody wrote: > >> > >> > On Friday, March 6, 2015 at 3:57:12 AM UTC+5:30, rand... at fastmail.us > >> > wrote: > >> >> It's been brought up on Stack Overflow that the "in" operator (on > >> >> tuples, and by my testing on dict and list, as well as dict lookup) > >> >> uses object identity as a shortcut, and returns true immediately if > >> >> the object being tested *is* an element of the container. However, the > >> >> contains operation does not specify whether object identity or > >> >> equality is to be used. In effect, the built-in container types use a > >> >> hybrid test: "a is b or a == b". > >> >> > >> >> My question is, is this a *correct* implementation of the operator, or > >> >> are objects "supposed to" use a basis of equality for these tests? > >> > > >> > nan is an illegal or bogus value. > >> > >> NANs *represent* bogus values, they aren't bogus themselves. > >> > >> > >> > As usual legalizing the illegal is always fraught with increasing > >> > conundrums. > >> > > >> > The most (to me) classic instance of this is denotational semantics. > >> > In DS one tries to give semantics to programs by mapping programs to > >> > math-functions across some domains > >> > > >> > However some programs crash. What should be the semantics of such a > >> > program. We say its a partial function ? undefined at the crash-points. > >> > But partial functions are not nearly as tractable (to mathematicians!) > >> > as total functions. > >> > So we invent a bogus value ? (called bottom) and totalize all > >> > functions by mapping to this. > >> > > >> > Very nice? > >> > > >> > So nice in fact that we wish to add ? to our programming language > >> > > >> > And now all hell breaks loose because the question x == ? is the > >> > halting problem. > >> > >> Oh nonsense. x == ? is easily performed with the equivalent of: > >> > >> type(x) == BottomType and bit_representation(x) == bit_representation(?) > > > > You dont grok your theory of computation very well do you? > > > > def foo(x): return x + x > > def bar(x): return x + x > > def baz(x): return 2*x > > > > One can imagine an implementation where > > id(foo) == id(bar) > > [I am assuming that id is a good enough approx to bit_representation] > > > > Can you imagine an implementation where > > id(bar) == id(baz) > > ? > > Not necessarily if x are floats. But I'll grant you that 2*x and x+x are > computationally equivalent if x is an int. I'll also grant you that there > are other functions which are computationally equivalent to x+x but > immeasurably more complex, and that for the compiler to recognise all such > functions is equivalent to the halting problem. Good so far > > What does this have to do with the ability to perform an equality test > against some ? value? What do you understand by ? value? > > Your argument is analogous to this: > > "Somewhere, out in the immensity of space, floats an infinite number of > haystacks. Inside just one of those haystacks is a single tiny needle. > Since it is impossible to locate that needle, it is likewise impossible to > locate this needle I hold between my fingers!" Straw... er Hayman! > > You have made a claim that None is a reinvention of the ? (bottom) pattern, Ok > and that it is impossible to evaluate x == ? due to the Halting Problem. That depends on how you answer my question above: What do mean by ? value? > Let's put that to the test: > > [steve at ando ~]$ python -c "x = 23; print x == None" > False > > > I was hoping to have time to make a cup of tea while Python tried to solve > the Halting Problem, possibly even to go to the market, do some shopping, > do my house work, watch a movie, and catch a good night's sleep, but it > only took a small fraction of a second for x == None to complete. You dont know the difference between analogy and identity? > > I can draw only two possible conclusions: > > (1) The halting problem, and therefore Godel's Incompleteness Theorem as > well, are disproven and the very fundamentals of mathematics and logic are > overturned; or > > (2) You are mistaken that evaluating x == ? is equivalent to solving the > Halting Problem. > > > If I were a betting man, I know where I would put my money. > I'd put my money on (some variation of) "Syntax Error" python3: >>> x = 1 >>> x == ? File "", line 1 x == ? ^ SyntaxError: invalid character in identifier python2 >>> x = 1 >>> x == ? File "", line 1 x == ? ^ SyntaxError: invalid syntax Which is to say ? does not exist in python. So until you say what *you* mean by ? we cannot evaluate where the rheostat sits between "You/I are wrong" ? "You/I are confused" ? "You/I are not even wrong" From hayesstw at telkomsa.net Fri Mar 6 23:42:31 2015 From: hayesstw at telkomsa.net (Steve Hayes) Date: Sat, 07 Mar 2015 06:42:31 +0200 Subject: Odo: Shapeshifting for your data References: Message-ID: On Fri, 06 Mar 2015 20:03:07 +0000, Mark Lawrence wrote: >https://odo.readthedocs.org/en/latest/ > >I don't know if there is a need for shunting data around in this way but >some of you may find this interesting. That looks very interesting indeed. What wasn't clear is whether odo is something you have to download somewhere. -- Steve Hayes from Tshwane, South Africa Web: http://www.khanya.org.za/stevesig.htm Blog: http://khanya.wordpress.com E-mail - see web page, or parse: shayes at dunelm full stop org full stop uk From breamoreboy at yahoo.co.uk Fri Mar 6 23:49:26 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 07 Mar 2015 04:49:26 +0000 Subject: Odo: Shapeshifting for your data In-Reply-To: References: Message-ID: On 07/03/2015 04:42, Steve Hayes wrote: > On Fri, 06 Mar 2015 20:03:07 +0000, Mark Lawrence > wrote: > >> https://odo.readthedocs.org/en/latest/ >> >> I don't know if there is a need for shunting data around in this way but >> some of you may find this interesting. > > That looks very interesting indeed. > > What wasn't clear is whether odo is something you have to download > somewhere. > https://pypi.python.org/pypi/odo/0.3.0 -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From greg.ewing at canterbury.ac.nz Sat Mar 7 00:06:36 2015 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 07 Mar 2015 18:06:36 +1300 Subject: HELP!! How to ask a girl out with a simple witty Python code?? In-Reply-To: References: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> <2906370c-58c7-4d8b-8db3-2ea3773b9578@googlegroups.com> <54f8d56a$0$12984$c3e8da3$5496439d@news.astraweb.com> <54f916b2$0$12980$c3e8da3$5496439d@news.astraweb.com> Message-ID: alister wrote: > a popular UK soap made an extreme > effort not to show a cross or Christmas tree during a church wedding in > case it "offended not-Christians". In today's climate, when offending certain varieties of non-Christian can get you blown up or shot, it might not be quite as silly as it sounds. -- Greg From rustompmody at gmail.com Sat Mar 7 00:27:04 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 6 Mar 2015 21:27:04 -0800 (PST) Subject: HELP!! How to ask a girl out with a simple witty Python code?? In-Reply-To: References: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> <2906370c-58c7-4d8b-8db3-2ea3773b9578@googlegroups.com> <54f8d56a$0$12984$c3e8da3$5496439d@news.astraweb.com> <54f916b2$0$12980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Saturday, March 7, 2015 at 10:36:54 AM UTC+5:30, Gregory Ewing wrote: > alister wrote: > > a popular UK soap made an extreme > > effort not to show a cross or Christmas tree during a church wedding in > > case it "offended not-Christians". > > In today's climate, when offending certain varieties > of non-Christian can get you blown up or shot, it might > not be quite as silly as it sounds. > > -- > Greg Best we know, stupidity and geography dont correlate. Likewise stupidity and religious affiliation: http://rmitz.org/freebsd.daemon.html From jsf80238 at gmail.com Sat Mar 7 00:37:18 2015 From: jsf80238 at gmail.com (Jason Friedman) Date: Fri, 6 Mar 2015 22:37:18 -0700 Subject: Append a file In-Reply-To: References: Message-ID: On Fri, Mar 6, 2015 at 2:55 PM, Jason Venneri wrote: > Hello, I'm using the urllib.urlretrieve command to retrieve a couple of lines of data. I want to combine the two results into one file not two. > > Any suggestions? > > Sample > urllib.urlretrieve('http://www.airplanes.com/data/boeing1.html','B747A.txt') > urllib.urlretrieve('http://www.airplanes.com/data/boeing2.html','B747B.txt') > > I would like one file say B747C that contains the data from B747A and B747B in a file named B747C >>> f = open("B747C.txt", "w") >>> look_for = "Aircraft," >>> for line in open("B747A.txt"): ... if look_for in line: ... f.write(line) ... >>> for line in open("B747B.txt"): ... if look_for in line: ... f.write(line) ... >>> f.close() Seems like you are using Python 2, you ought to consider Python 3. The requests module (http://docs.python-requests.org/en/latest/user/install/) makes this kind of work easier. From tjreedy at udel.edu Sat Mar 7 01:11:01 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 07 Mar 2015 01:11:01 -0500 Subject: Newbie question about text encoding In-Reply-To: References: <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <01dd9b83-db3e-4e7d-9022-dc6af75eb570@googlegroups.com> <54f9bea1$0$12994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/6/2015 11:20 AM, Rustom Mody wrote: > ========= > pp = "?" > print (pp) > ========= > Try open it in idle3 and you get (at least I get): > > $ idle3 ff.py > Traceback (most recent call last): > File "/usr/bin/idle3", line 5, in > main() > File "/usr/lib/python3.4/idlelib/PyShell.py", line 1562, in main > if flist.open(filename) is None: > File "/usr/lib/python3.4/idlelib/FileList.py", line 36, in open > edit = self.EditorWindow(self, filename, key) > File "/usr/lib/python3.4/idlelib/PyShell.py", line 126, in __init__ > EditorWindow.__init__(self, *args) > File "/usr/lib/python3.4/idlelib/EditorWindow.py", line 294, in __init__ > if io.loadfile(filename): > File "/usr/lib/python3.4/idlelib/IOBinding.py", line 236, in loadfile > self.text.insert("1.0", chars) > File "/usr/lib/python3.4/idlelib/Percolator.py", line 25, in insert > self.top.insert(index, chars, tags) > File "/usr/lib/python3.4/idlelib/UndoDelegator.py", line 81, in insert > self.addcmd(InsertCommand(index, chars, tags)) > File "/usr/lib/python3.4/idlelib/UndoDelegator.py", line 116, in addcmd > cmd.do(self.delegate) > File "/usr/lib/python3.4/idlelib/UndoDelegator.py", line 219, in do > text.insert(self.index1, self.chars, self.tags) > File "/usr/lib/python3.4/idlelib/ColorDelegator.py", line 82, in insert > self.delegate.insert(index, chars, tags) > File "/usr/lib/python3.4/idlelib/WidgetRedirector.py", line 148, in __call__ > return self.tk_call(self.orig_and_operation + args) > _tkinter.TclError: character U+1f4a9 is above the range (U+0000-U+FFFF) allowed by Tcl > > So who/what is broken? tcl The possible workaround is for Idle to translate "?" to "\U0001f4a9" (10 chars) before sending it to tk. But some perspective. In the console interpreter: >>> print("\U0001f4a9") Traceback (most recent call last): File "", line 1, in File "C:\Programs\Python34\lib\encodings\cp437.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_map)[0] UnicodeEncodeError: 'charmap' codec can't encode character '\U0001f4a9' in posit ion 0: character maps to So what is broken? Windows Command Prompt. More perspective. tk/Idle *will* print *something* for every BMP char. Command Prompt will not. It does not even do ucs-2 correctly. So which is more broken? Windows Command Prompt. Who has perhaps 1,000,000 times more resources, Microsoft? or the tcl/tk group? I think we all know. -- Terry Jan Reedy From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Sat Mar 7 02:13:26 2015 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Sat, 07 Mar 2015 08:13:26 +0100 Subject: Python Worst Practices In-Reply-To: References: <85bnkh5z96.fsf@benfinney.id.au> <85zj814jmb.fsf@benfinney.id.au> Message-ID: Am 26.02.2015 01:37 schrieb Chris Angelico: > My bad. I was talking in a context of Python programming, specifically > with APIs where you would use some kind of true/false flag as either a > function parameter or a return value. Oh. Then take subprocess.Popen.wait()... :-P Thomas From lakshmipathi.g at gmail.com Sat Mar 7 04:15:41 2015 From: lakshmipathi.g at gmail.com (Lakshmipathi.G) Date: Sat, 7 Mar 2015 14:45:41 +0530 Subject: Adding a 'struct' into new python type Message-ID: Hi, I'm following this example : http://nedbatchelder.com/text/whirlext.html#h_making_a_type and trying to add new data into 'CountDict' type Adding a simple 'char' works well. typedef struct { PyObject_HEAD PyObject * dict; int count; char c; //add this and placed an entry into PyMemberDef as T_CHAR. } CountDict; I can access 'c' from python code,no issues so far. Now I want to added 'struct type' into this 'CountDict' type. struct test { int x; }; typedef struct { PyObject_HEAD PyObject * dict; int count; char c; struct test t1; //?? how to add this } CountDict; How to do achieve this? (Due to legacy code dependency, I can't use ctype/cpython etc). thanks for any help/pointers. ---- Cheers, Lakshmipathi.G FOSS Programmer. www.giis.co.in/readme.html From daiyueweng at gmail.com Sat Mar 7 05:42:24 2015 From: daiyueweng at gmail.com (Daiyue Weng) Date: Sat, 7 Mar 2015 02:42:24 -0800 (PST) Subject: Python 3.4 and 2.7 installation no Script folder and no pip installed Message-ID: Hi, I was doing a fresh installation for Python 2.7.9 (32 bit) and 3.4.3 (32 bit) (downloaded from PSF) on Win7 X64 today, and I found that there is no 'Script' folder in 'Python27' and 'Python34' folder as first child level folder, but there is one in Tools. However, I couldn't find pip within that 'Script' folder, although pip should be installed with Python by default. The other I was doing the same installation for my other PC and laptop, there was 'Script' folder (as first level child folder in 'Python27' and 'Python34') containing pip. So what is going on? how to install pip and maybe other useful scripts this way? 'C:\Pythonxy\Lib\site-packages' contains nothing but a README file. I tried 'python -m ensurepip' in 'C:\Python34'. I got the following errors: Ignoring indexes: https://pypi.python.org/simple Collecting setuptools Exception: Traceback (most recent call last): File "C:\Users\daiyue\AppData\Local\Temp\tmppvmc8dv1\pip-6.0.8-py2.py3-none- any.whl\pip\basecommand.py", line 232, in main status = self.run(options, args) File "C:\Users\daiyue\AppData\Local\Temp\tmppvmc8dv1\pip-6.0.8-py2.py3-none- any.whl\pip\commands\install.py", line 339, in run requirement_set.prepare_files(finder) File "C:\Users\daiyue\AppData\Local\Temp\tmppvmc8dv1\pip-6.0.8-py2.py3-none- any.whl\pip\req\req_set.py", line 333, in prepare_files upgrade=self.upgrade, File "C:\Users\daiyue\AppData\Local\Temp\tmppvmc8dv1\pip-6.0.8-py2.py3-none- any.whl\pip\index.py", line 326, in find_requirement file_locations, url_locations = self._sort_locations(locations) File "C:\Users\daiyue\AppData\Local\Temp\tmppvmc8dv1\pip-6.0.8-py2.py3-none- any.whl\pip\index.py", line 158, in _sort_locations sort_path(os.path.join(path, item)) File "C:\Users\daiyue\AppData\Local\Temp\tmppvmc8dv1\pip-6.0.8-py2.py3-none- any.whl\pip\index.py", line 139, in sort_path if mimetypes.guess_type(url, strict=False)[0] == 'text/html': File "C:\Python34\lib\mimetypes.py", line 287, in guess_type init() File "C:\Python34\lib\mimetypes.py", line 348, in init db.read_windows_registry() File "C:\Python34\lib\mimetypes.py", line 255, in read_windows_registry with _winreg.OpenKey(hkcr, subkeyname) as subkey: TypeError: OpenKey() argument 2 must be str without null characters or None, not str I have also tried out 64bit Python installation, but got the same result. So how to fix this? cheers From steve+comp.lang.python at pearwood.info Sat Mar 7 06:09:35 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 07 Mar 2015 22:09:35 +1100 Subject: Newbie question about text encoding References: <201502241524.t1OFO09k022270@fido.openend.se> <201502241620.t1OGKf4n002146@fido.openend.se> <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> Message-ID: <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> Rustom Mody wrote: > On Thursday, March 5, 2015 at 7:36:32 PM UTC+5:30, Steven D'Aprano wrote: [...] >> Chris is suggesting that going from BMP to all of Unicode is not the hard >> part. Going from ASCII to the BMP part of Unicode is the hard part. If >> you can do that, you can go the rest of the way easily. > > Depends where the going is starting from. > I specifically names Java, Javascript, Windows... among others. > Here's some quotes from the supplementary chars doc of Java > http://www.oracle.com/technetwork/articles/javase/supplementary-142654.html > > | Supplementary characters are characters in the Unicode standard whose > | code points are above U+FFFF, and which therefore cannot be described as > | single 16-bit entities such as the char data type in the Java > | programming language. Such characters are generally rare, but some are > | used, for example, as part of Chinese and Japanese personal names, and > | so support for them is commonly required for government applications in > | East Asian countries... > > | The introduction of supplementary characters unfortunately makes the > | character model quite a bit more complicated. > > | Unicode was originally designed as a fixed-width 16-bit character > | encoding. The primitive data type char in the Java programming language > | was intended to take advantage of this design by providing a simple data > | type that could hold > | any character.... Version 5.0 of the J2SE is required to support > | version 4.0 of the Unicode standard, so it has to support supplementary > | characters. > > My conclusion: Early adopters of unicode -- Windows and Java -- were > punished > for their early adoption. You can blame the unicode consortium, you can > blame the babel of human languages, particularly that some use characters > and some only (the equivalent of) what we call words. I see you are blaming everyone except the people actually to blame. It is 2015. Unicode 2.0 introduced the SMPs in 1996, almost twenty years ago, the same year as 1.0 release of Java. Java has had eight major new releases since then. Oracle, and Sun before them, are/were serious, tier-1, world-class major IT companies. Why haven't they done something about introducing proper support for Unicode in Java? It's not hard -- if Python can do it using nothing but volunteers, Oracle can do it. They could even do it in a backwards-compatible way, by leaving the existing APIs in place and adding new APIs. As for Microsoft, as a member of the Unicode Consortium they have no excuse. But I think you exaggerate the lack of support for SMPs in Windows. Some parts of Windows have no SMP support, but they tend to be the oldest and less important (to Microsoft) parts, like the command prompt. Anyone have Powershell and like to see how well it supports SMP? This Stackoverflow question suggests that post-Windows 2000, the Windows file system has proper support for code points in the supplementary planes: http://stackoverflow.com/questions/7870014/how-does-windows-wchar-t-handle-unicode-characters-outside-the-basic-multilingua Or maybe not. > Or you can skip the blame-game and simply note the fact that large > segments of extant code-bases are currently in bug-prone or plain buggy > state. > > This includes not just bug-prone-system code such as Java and Windows but > seemingly working code such as python 3. What Unicode bugs do you think Python 3.3 and above have? >> I mostly agree with Chris. Supporting *just* the BMP is non-trivial in >> UTF-8 and UTF-32, since that goes against the grain of the system. You >> would have to program in artificial restrictions that otherwise don't >> exist. > > Yes UTF-8 and UTF-32 make most of the objections to unicode 7.0 > irrelevant. Glad you agree about that much at least. [...] >> Conclusion: faulty implementations of UTF-16 which incorrectly handle >> surrogate pairs should be replaced by non-faulty implementations, or >> changed to UTF-8 or UTF-32; incomplete Unicode implementations which >> assume that Unicode is 16-bit only (e.g. UCS-2) are obsolete and should >> be upgraded. > > Imagine for a moment a thought experiment -- we are not on a python but a > java forum and please rewrite the above para. There is no need to re-write it. If Java's only implementation of Unicode assumes that code points are 16 bits only, then Java needs a new Unicode implementation. (I assume that the existing one cannot be changed for backwards-compatibility reasons.) > Are you addressing the vanilla java programmer? Language implementer? > Designer? The Java-funders -- earlier Sun, now Oracle? The last three should be considered the same people. The vanilla Java programmer is not responsible for the short-comings of Java's implementation. [...] >> > In practice, standards change. >> > However if a standard changes so frequently that that users have to >> > play catching cook and keep asking: "Which version?" they are justified >> > in asking "Are the standard-makers doing due diligence?" >> >> Since Unicode has stability guarantees, and the encodings have not >> changed in twenty years and will not change in the future, this argument >> is bogus. Updating to a new version of the standard means, to a first >> approximation, merely allocating some new code points which had >> previously been undefined but are now defined. >> >> (Code points can be flagged deprecated, but they will never be removed.) > > Its not about new code points; its about "Fits in 2 bytes" to "Does not > fit in 2 bytes" I quote you again: "if a standard changes so frequently..." The move to more than 16 bits happened once. It happened almost 20 years ago. In what way does this count as frequent changes? > If you call that argument bogus I call you a non computer scientist. I am not a computer scientist, and the argument remains bogus. Unicode does not change "frequently", and changes are backward-compatible. > [Essentially this is my issue with the consortium it seems to be working > [like a bunch of linguists not computer scientists] That's rather like complaining that some computer game looks like it was designed by games players instead of theoreticians. "Why, people have FUN playing this, almost like it was designed by professionals who think about gaming!!!" Unicode is a standard intended for the handling of human languages. It is intended as a real-life working standard, not some theoretical toy for academics to experiment with. It is designed to be used, not to have papers written about it. The character set part of it has effectively been designed by linguists, and that is a good thing. But the encoding side of things has been designed by practising computer programmers such as Rob Pike and Ken Thompson. You might have heard of them. > Here is Roy's Smith post that first started me thinking that something may > be wrong with SMP > https://groups.google.com/d/msg/comp.lang.python/loYWMJnPtos/GHMC0cX_hfgJ There are plenty of things wrong with some implementations of Unicode, those that assume all code points are two bytes. There may be a few things wrong with the current Unicode standard, such as missing characters, characters given the wrong name, and so forth. But there's nothing wrong with the design of the SMP. It allows the great majority of text, probably 99% or more, to use two bytes (UTF-16) or no more than three bytes (UTF-8), while only relatively specialised uses need four bytes for some code points. > Some parts are here some earlier and from my memory. > If details wrong please correct: > - 200 million records > - Containing 4 strings with SMP characters > - System made with python and mysql. SMP works with python, breaks mysql. > So whole system broke due to those 4 in 200,000,000 records No, they broke because MySQL has buggy Unicode handling. Bugs are not unusual. I used to have a version of Apple's Hypercard which would lock up the whole operating system if you tried to display the string "0^0" in a message dialog. Given that classic Mac OS was not a proper multi-tasking OS like Unix or OS-X or even Windows, this was a real pain. My conclusion from that is that that version of Hypercard was buggy. What is your conclusion? > I know enough (or not enough) of unicode to be chary of statistical > conclusions from the above. > My conclusion is essentially an 'existence-proof': > > SMP-chars can break systems. Oh come on. How about this instead? X can break systems, for every conceivable value of X. > The breakage is costly-fied by the combination > - layman statistical assumptions > - BMP ? SMP exercises different code-paths > > It is necessary but not sufficient to test print "hello world" in ASCII, > BMP, SMP. You also have to write the hello world in the database -- mysql > Read it from the webform -- javascript > etc etc Yes. This is called "integration testing". That's what professionals do. > You could also choose do with "astral crap" (Roy's words) what we all do > with crap -- throw it out as early as possible. And when Roy's customers demand that his product support emoji, or complain that they cannot spell their own name because of his parochial and ignorant idea of "crap", perhaps he will consider doing what he should have done from the beginning: Stop using MySQL, which is a joke of a database[1], and use Postgres which does not have this problem. [1] So I have been told. -- Steven From rosuav at gmail.com Sat Mar 7 06:33:58 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 7 Mar 2015 22:33:58 +1100 Subject: Newbie question about text encoding In-Reply-To: <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> References: <201502241524.t1OFO09k022270@fido.openend.se> <201502241620.t1OGKf4n002146@fido.openend.se> <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Mar 7, 2015 at 10:09 PM, Steven D'Aprano wrote: > Stop using MySQL, which is a joke of a database[1], and use Postgres which > does not have this problem. I agree with the recommendation, though to be fair to MySQL, it is now possible to store full Unicode. Though personally, I think the whole "UTF8MB3 vs UTF8MB4" split is an embarrassment and should be abolished *immediately* - not "we may change the meaning of UTF8 to be an alias for UTF8MB4 in the future", just completely abolish the distinction right now. (And deprecate the longer words.) There should be no reason to build any kind of "UTF-8 but limited to three bytes" encoding for anything. Ever. But at least you can, if you configure things correctly, store any Unicode character in your TEXT field. ChrisA From marko at pacujo.net Sat Mar 7 06:53:10 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 07 Mar 2015 13:53:10 +0200 Subject: Newbie question about text encoding References: <201502241620.t1OGKf4n002146@fido.openend.se> <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87twxxxbvd.fsf@elektro.pacujo.net> Steven D'Aprano : > Rustom Mody wrote: >> My conclusion: Early adopters of unicode -- Windows and Java -- were >> punished for their early adoption. You can blame the unicode >> consortium, you can blame the babel of human languages, particularly >> that some use characters and some only (the equivalent of) what we >> call words. > > I see you are blaming everyone except the people actually to blame. I don't think you need to blame anybody. I think the UCS-2 mistake was both deplorable and very understandable. At the time it looked like the magic bullet to get out of the 8-bit mess. While 16-bit wide wchar_t's looked like a hugely expensive price, it was deemed forward-looking to pay it anyway to resolve the character set problem once and for all. Linux was lucky to join the fray late enough to benefit from the bad UCS-2 experience. That said, UTF-8 does suffer badly from its not being a bijective mapping. (Linux didn't quite dodge the bullet with pthreads, threads being another sad fad of the 1990's. The hippies that cooked up the fork system call should be awarded the next Millennium Prize. That foresight or stroke of luck has withstood the challenge of half a century.) > But there's nothing wrong with the design of the SMP. It allows the > great majority of text, probably 99% or more, to use two bytes > (UTF-16) or no more than three bytes (UTF-8), while only relatively > specialised uses need four bytes for some code points. The main dream was a fixed-width encoding scheme. People thought 16 bits would be enough. The dream is so precious and true to us in the West that people don't want to give it up. It may yet be that UTF-32 replaces all previous schemes since it has all the benefits of ASCII and only one drawback: redundancy. Maybe one day we'll declare the byte 32 bits wide and be done with it. In some many other aspects, 32-bit "bytes" are the de-facto reality already. Even C coders routinely use 32 bits to express boolean values. > And when Roy's customers demand that his product support emoji, or > complain that they cannot spell their own name because of his > parochial and ignorant idea of "crap", perhaps he will consider doing > what he should have done from the beginning: That's a recurring theme: Why didn't we do IPv6 from the get-go? Why didn't we do multi-user from the get-go? Why didn't we do localization from the get-go? There comes a point when you have to release to start making money. You then suffer the consequences until your company goes bankrupt. Marko From rosuav at gmail.com Sat Mar 7 07:02:57 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 7 Mar 2015 23:02:57 +1100 Subject: Newbie question about text encoding In-Reply-To: <87twxxxbvd.fsf@elektro.pacujo.net> References: <201502241620.t1OGKf4n002146@fido.openend.se> <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> Message-ID: On Sat, Mar 7, 2015 at 10:53 PM, Marko Rauhamaa wrote: > The main dream was a fixed-width encoding scheme. People thought 16 bits > would be enough. The dream is so precious and true to us in the West > that people don't want to give it up. So... use Pike, or Python 3.3+? ChrisA From daiyueweng at gmail.com Sat Mar 7 07:55:24 2015 From: daiyueweng at gmail.com (Daiyue Weng) Date: Sat, 7 Mar 2015 12:55:24 +0000 Subject: Python 3.4 and 2.7 installation no Script folder and pip installation failed Message-ID: Hi, I was doing a fresh installation for Python 2.7.9 (32 bit) and 3.4.3 (32 bit) (downloaded from PSF) on Win7 X64 today, and I found that there is no 'Script' folder in 'Python27' and 'Python34' folder as first child level folder, but there is one in Tools. However, I couldn't find pip within that 'Script' folder, although pip should be installed with Python by default. The other I was doing the same installation for my other PC and laptop, there was 'Script' folder (as first level child folder in 'Python27' and 'Python34') containing pip. So what is going on? how to install pip and maybe other useful scripts this way? 'C:\Pythonxy\Lib\site-packages' contains nothing but a README file. I tried 'python -m ensurepip' in 'C:\Python34'. I got the following errors: Ignoring indexes: https://pypi.python.org/simple Collecting setuptools Exception: Traceback (most recent call last): File "C:\Users\daiyue\AppData\Local\Temp\tmppvmc8dv1\pip-6. 0.8-py2.py3-none- any.whl\pip\basecommand.py", line 232, in main status = self.run(options, args) File "C:\Users\daiyue\AppData\Local\Temp\tmppvmc8dv1\pip-6. 0.8-py2.py3-none- any.whl\pip\commands\install.py", line 339, in run requirement_set.prepare_files(finder) File "C:\Users\daiyue\AppData\Local\Temp\tmppvmc8dv1\pip-6. 0.8-py2.py3-none- any.whl\pip\req\req_set.py", line 333, in prepare_files upgrade=self.upgrade, File "C:\Users\daiyue\AppData\Local\Temp\tmppvmc8dv1\pip-6. 0.8-py2.py3-none- any.whl\pip\index.py", line 326, in find_requirement file_locations, url_locations = self._sort_locations(locations) File "C:\Users\daiyue\AppData\Local\Temp\tmppvmc8dv1\pip-6. 0.8-py2.py3-none- any.whl\pip\index.py", line 158, in _sort_locations sort_path(os.path.join(path, item)) File "C:\Users\daiyue\AppData\Local\Temp\tmppvmc8dv1\pip-6. 0.8-py2.py3-none- any.whl\pip\index.py", line 139, in sort_path if mimetypes.guess_type(url, strict=False)[0] == 'text/html': File "C:\Python34\lib\mimetypes.py", line 287, in guess_type init() File "C:\Python34\lib\mimetypes.py", line 348, in init db.read_windows_registry() File "C:\Python34\lib\mimetypes.py", line 255, in read_windows_registry with _winreg.OpenKey(hkcr, subkeyname) as subkey: TypeError: OpenKey() argument 2 must be str without null characters or None, not str I have also tried out 64bit Python installation, but got the same result. So how to fix this? cheers -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Sat Mar 7 09:07:12 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 07 Mar 2015 14:07:12 +0000 Subject: Newbie question about text encoding In-Reply-To: References: <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> Message-ID: On 07/03/2015 12:02, Chris Angelico wrote: > On Sat, Mar 7, 2015 at 10:53 PM, Marko Rauhamaa wrote: >> The main dream was a fixed-width encoding scheme. People thought 16 bits >> would be enough. The dream is so precious and true to us in the West >> that people don't want to give it up. > > So... use Pike, or Python 3.3+? > > ChrisA > Cue obligatory cobblers from our RUE. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Sat Mar 7 09:13:41 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 07 Mar 2015 14:13:41 +0000 Subject: Newbie question about text encoding In-Reply-To: <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> References: <201502241620.t1OGKf4n002146@fido.openend.se> <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 07/03/2015 11:09, Steven D'Aprano wrote: > Rustom Mody wrote: > >> >> This includes not just bug-prone-system code such as Java and Windows but >> seemingly working code such as python 3. > > What Unicode bugs do you think Python 3.3 and above have? > Methinks somebody has been drinking too much loony juice. Either that or taking too much notice of our RUE. Not that I've done a proper analysis, but to my knowledge there's nothing like the number of issues on the bug tracker for Unicode bugs for Python 3 compared to Python 2. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From marfig at gmail.com Sat Mar 7 10:11:46 2015 From: marfig at gmail.com (Mario Figueiredo) Date: Sat, 07 Mar 2015 16:11:46 +0100 Subject: Python Worst Practices References: <7053A277-9687-49B0-9FDB-CB4DB3E76DEC@gmail.com> <54F0E38D.40006@davea.name> <54f274bb$0$13011$c3e8da3$5496439d@news.astraweb.com> <54F95032.9010000@wielicki.name> Message-ID: On Fri, 6 Mar 2015 21:09:24 +1100, Chris Angelico wrote: > >there was a time (maybe times, I don't remember) when >Microsoft tried hard to require "managed code" everywhere (aka ".NET >runtime only"), and the push-back was so strong that they had to >abandon the requirement. But somehow, people accept rules about phone >apps that they wouldn't accept about desktop apps... crazy stuff. > I think the Apple mobile ecosystem was just a special case. Due to the popularity and lack of competition it enjoyed in the yearly years (really a byproduct of the fact they basically created the computing platform) it became possible for Apple to impose those absurd rules to quite a degree of success. No doubt with the help of the genius invention of curated app stores. But history is bound to repeat itself. Just like with the desktop market when Apple enjoyed sudden growth in the 80s and the early 90s, it was its all-around closed architecture that enventually removed it from mainstream computing. And we are already witnessing the same happening to its mobile sector. Perhaps just not with the dramatic results of its desktop counterpart, due to the fact Apple introduced mobile computing to an already established and massified computing marketplace and was so able to create a larger share. But an all-around closed architecture is still one of the things that is putting Apple behind. I think that open systems eventually dominate over closed ones as soon as they become available. The mobile market, still in its infancy, allows for some walled gardens. But they will just wither and die. From steve+comp.lang.python at pearwood.info Sat Mar 7 10:40:35 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 08 Mar 2015 02:40:35 +1100 Subject: Newbie question about text encoding References: <201502241620.t1OGKf4n002146@fido.openend.se> <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> Message-ID: <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> Marko Rauhamaa wrote: > That said, UTF-8 does suffer badly from its not being > a bijective mapping. Can you explain? As far as I am aware, every code point has one and only one valid UTF-8 encoding, and every UTF-8 encoding has one and only one valid code point. There are *invalid* UTF-8 encodings, such as CESU-8, which is sometimes mislabelled as UTF-8 (Oracle, I'm looking at you.) It violates the rule that valid UTF-8 encodings are the shortest possible. E.g. SMP code points should be encoded to four bytes using UTF-8: py> u'\U0010FF01'.encode('utf-8') # U+10FF01 '\xf4\x8f\xbc\x81' But in CESU-8, the code point is first interpreted as a UTF-16 surrogate pair: py> u'\U0010FF01'.encode('utf-16be') '\xdb\xff\xdf\x01' then each surrogate pair is treated as a 16-bit code unit and individually encoded to three bytes using UTF-8: py> u'\udbff'.encode('utf-8') '\xed\xaf\xbf' py> u'\udf01'.encode('utf-8') '\xed\xbc\x81' giving six bytes in total: '\xed\xaf\xbf\xed\xbc\x81' This is not UTF-8! But some software mislabels it as UTF-8. -- Steven From marko at pacujo.net Sat Mar 7 10:48:40 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 07 Mar 2015 17:48:40 +0200 Subject: Newbie question about text encoding References: <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87twxw4xlz.fsf@elektro.pacujo.net> Steven D'Aprano : > Marko Rauhamaa wrote: > >> That said, UTF-8 does suffer badly from its not being >> a bijective mapping. > > Can you explain? In Python terms, there are bytes objects b that don't satisfy: b.decode('utf-8').encode('utf-8') == b Marko From jason.swails at gmail.com Sat Mar 7 10:53:05 2015 From: jason.swails at gmail.com (Jason Swails) Date: Sat, 7 Mar 2015 10:53:05 -0500 Subject: Adding a 'struct' into new python type In-Reply-To: References: Message-ID: On Sat, Mar 7, 2015 at 4:15 AM, Lakshmipathi.G wrote: > Hi, > > I'm following this example : > http://nedbatchelder.com/text/whirlext.html#h_making_a_type and trying > to add > new data into 'CountDict' type > > Adding a simple 'char' works well. > > typedef struct { > PyObject_HEAD > PyObject * dict; > int count; > char c; //add this and placed an entry into PyMemberDef as T_CHAR. > } CountDict; > > I can access 'c' from python code,no issues so far. > > Now I want to added 'struct type' into this 'CountDict' type. > struct test { > int x; > }; > > typedef struct { > PyObject_HEAD > PyObject * dict; > int count; > char c; > struct test t1; //?? how to add this > } CountDict; > ?? > ? > ?? > > ?? > How to do achieve this? (Due to legacy code dependency, I can't use > ?? > ctype/cpython etc). > ?? > thanks for any help/pointers. > ?The way *I* would do this is turn struct test into another Python object. Then instead of defining it in CountDict as type "struct test", define it as the PyStructTest that you assigned it to when you turned it into a Python class. For example, in that website you linked to, CountDict was turned into a CountDictType Python type. So do something similar to "test" in which you turn it into a PyStructTest type in the same way. Then declare it as a PyStructTest pointer instead of a struct test. I'm not sure you can get around an approach like this. I believe that in order to access data from Python, it needs to be a Python type. The struct-to-Python-type conversion *knows* how to translate basic types, like char, double, float, int, and long into their Python equivalents; but it can't handle something as potentially complicated as an arbitrary struct. Of course, if all you want to do is access t1 from C, then I think what you have is fine. ?Good luck, Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: From polyvertex at gmail.com Sat Mar 7 10:55:24 2015 From: polyvertex at gmail.com (polyvertex at gmail.com) Date: Sat, 7 Mar 2015 07:55:24 -0800 (PST) Subject: MSVC2013 Message-ID: <7ec7c58b-f021-4a21-bd26-a2c9030c6ba9@googlegroups.com> Out of curiosity, is there any plan to use a more recent version of Visual Studio (i.e.: 2013) to compile the official Python3 distribution for Windows? Is it in discussion? Maybe waiting for the 2015 version? I'm working on a C++ software that embeds Python3, currently compiled with MSVC2010 and would like to upgrade to MSVC2013, but it appears that, while being feasible, Python3 won't compile out of the box with that configuration. I would like to avoid that hassle if possible... Cheers, From johnnybureddu at gmx.com Sat Mar 7 10:56:15 2015 From: johnnybureddu at gmx.com (REVOLUCION!) Date: Sat, 7 Mar 2015 07:56:15 -0800 (PST) Subject: -- redacted -- In-Reply-To: <4f5ceab4-d175-4b96-829b-8c8fab7f77f0@googlegroups.com> References: <4f5ceab4-d175-4b96-829b-8c8fab7f77f0@googlegroups.com> Message-ID: <7f6a5584-a81d-468e-a26f-96aa9c4e12da@googlegroups.com> -- redacted -- From johnnybureddu at gmx.com Sat Mar 7 10:56:47 2015 From: johnnybureddu at gmx.com (REVOLUCION!) Date: Sat, 7 Mar 2015 07:56:47 -0800 (PST) Subject: -- redacted -- In-Reply-To: References: Message-ID: <0d41b2b5-2326-4ca4-9279-ce209039a592@googlegroups.com> -- redacted -- From marfig at gmail.com Sat Mar 7 10:59:13 2015 From: marfig at gmail.com (Mario Figueiredo) Date: Sat, 07 Mar 2015 16:59:13 +0100 Subject: [Python 3.4] Rationale for readonly slice data attributes References: Message-ID: On Thu, 5 Mar 2015 23:36:47 -0700, Ian Kelly wrote: > >I'm not following what it is that you want to accomplish in this >example by modifying the slice object. Yeah. That code doesn't show anything. It was just meant to illustrate what I was doing, not how. But in retrospect it just made my post more confusing to follow. > >Immutable types are often desirable because they're easier to reason >about, especially when concurrency enters the picture. As an example, >suppose I'm iterating over a view constructed by slicing some >collection. What should happen if the slice is suddenly altered in >mid-iteration? Because slice objects are immutable, this is a question >that doesn't even need an answer. But that doesn't break the consenting adults principle? I mean the class slice is a typical API structure. May be inspected inside a __getitem__ method override (note: I can provide a real-life example of the need to inspect and act upon slide object instances, but I suspect you know of it already). As an API structure I would expect it to let me operate as I see fit. Including changing its state. The only exception would be an actual and plausible requirement for data to stay immutable. > >slice is about as light-weight a class as they come. If you need to >modify a slice, is there any reason you can't just construct a new >one? > It's what I did. Like I said it's not a big deal. Other solutions abound. I am just curious at what actually makes it a requirement that slice data members are made readonly. That is my question. In OOP I'm not just going to code readonly properties because I can. I will do it because I `must`. And I don't see why slice must have readonly properties. There's not many reasons why I actually need a readonly property. Maintaining an object internal consistency might be one of those. But slice is basically just a struct and it has no other features. From johnnybureddu at gmx.com Sat Mar 7 11:00:46 2015 From: johnnybureddu at gmx.com (REVOLUCION!) Date: Sat, 7 Mar 2015 08:00:46 -0800 (PST) Subject: -- redacted -- In-Reply-To: <360baff8-8111-49df-bde7-97df7e53ed17@googlegroups.com> References: <360baff8-8111-49df-bde7-97df7e53ed17@googlegroups.com> Message-ID: <77d288a7-53bb-44c0-a488-dcbec14bda4c@googlegroups.com> -- redacted -- From rosuav at gmail.com Sat Mar 7 11:17:57 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 8 Mar 2015 03:17:57 +1100 Subject: Newbie question about text encoding In-Reply-To: <87twxw4xlz.fsf@elektro.pacujo.net> References: <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> Message-ID: On Sun, Mar 8, 2015 at 2:48 AM, Marko Rauhamaa wrote: > Steven D'Aprano : > >> Marko Rauhamaa wrote: >> >>> That said, UTF-8 does suffer badly from its not being >>> a bijective mapping. >> >> Can you explain? > > In Python terms, there are bytes objects b that don't satisfy: > > b.decode('utf-8').encode('utf-8') == b Please provide an example; that sounds like a bug. If there is any invalid UTF-8 stream which decodes without an error, it is actually a security bug, and should be fixed pronto in all affected and supported versions. ChrisA From rosuav at gmail.com Sat Mar 7 11:25:20 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 8 Mar 2015 03:25:20 +1100 Subject: MSVC2013 In-Reply-To: <7ec7c58b-f021-4a21-bd26-a2c9030c6ba9@googlegroups.com> References: <7ec7c58b-f021-4a21-bd26-a2c9030c6ba9@googlegroups.com> Message-ID: On Sun, Mar 8, 2015 at 2:55 AM, wrote: > Out of curiosity, is there any plan to use a more recent version of Visual Studio (i.e.: 2013) to compile the official Python3 distribution for Windows? > Is it in discussion? Maybe waiting for the 2015 version? > > I'm working on a C++ software that embeds Python3, currently compiled with MSVC2010 and would like to upgrade to MSVC2013, but it appears that, while being feasible, Python3 won't compile out of the box with that configuration. I would like to avoid that hassle if possible... There's something in the works with the very newest VS that will guarantee forward compatibility, which will be awesome. If that compiler is stable in time for the Python 3.5 release, then it will be used... but you'll be able to use any future version of VS to build extensions with, and they'll "just work". I don't know the full details, as it's still all in alpha at the moment, but yes, there are definitely plans to compile the newer Python 3.x versions on the newer compiler. Steve Dower of Microsoft is working closely with the python-dev group to make sure that this works. As a general rule, the official Windows builds of CPython are made with the latest stable VS as of their initial release. Unfortunately, that means that Python 2.7 is built using the compiler that was current when 2.7.0 came out, which is no longer supported; there have been some discussions about what to do about that. But for CPython 3.x, the compilers have all been supported for at least as long as the Python versions, so it's safe. You just have to wait until (closer to) the actual release to see which version to use. ChrisA From marko at pacujo.net Sat Mar 7 11:25:43 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 07 Mar 2015 18:25:43 +0200 Subject: Newbie question about text encoding References: <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> Message-ID: <87k2ysydtk.fsf@elektro.pacujo.net> Chris Angelico : > On Sun, Mar 8, 2015 at 2:48 AM, Marko Rauhamaa wrote: >> Steven D'Aprano : >> >>> Marko Rauhamaa wrote: >>> >>>> That said, UTF-8 does suffer badly from its not being >>>> a bijective mapping. >>> >>> Can you explain? >> >> In Python terms, there are bytes objects b that don't satisfy: >> >> b.decode('utf-8').encode('utf-8') == b > > Please provide an example; that sounds like a bug. If there is any > invalid UTF-8 stream which decodes without an error, it is actually a > security bug, and should be fixed pronto in all affected and supported > versions. Here's an example: b = b'\x80' Yes, it generates an exception. IOW, UTF-8 is not a bijective mapping from str objects to bytes objects. Marko From breamoreboy at yahoo.co.uk Sat Mar 7 11:35:12 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 07 Mar 2015 16:35:12 +0000 Subject: MSVC2013 In-Reply-To: <7ec7c58b-f021-4a21-bd26-a2c9030c6ba9@googlegroups.com> References: <7ec7c58b-f021-4a21-bd26-a2c9030c6ba9@googlegroups.com> Message-ID: On 07/03/2015 15:55, polyvertex at gmail.com wrote: > Out of curiosity, is there any plan to use a more recent version of Visual Studio (i.e.: 2013) to compile the official Python3 distribution for Windows? > Is it in discussion? Maybe waiting for the 2015 version? > > I'm working on a C++ software that embeds Python3, currently compiled with MSVC2010 and would like to upgrade to MSVC2013, but it appears that, while being feasible, Python3 won't compile out of the box with that configuration. I would like to avoid that hassle if possible... > > Cheers, > I'm building Python 3.5 every day with 2013 no problems at all, thanks mainly to the work on the build system by Zach Ware and Steve Dower. If 2015 is stable that will be used for 3.5 else we'll stick with 2013. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Sat Mar 7 11:40:08 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 07 Mar 2015 16:40:08 +0000 Subject: Newbie question about text encoding In-Reply-To: <87k2ysydtk.fsf@elektro.pacujo.net> References: <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <87k2ysydtk.fsf@elektro.pacujo.net> Message-ID: On 07/03/2015 16:25, Marko Rauhamaa wrote: > Chris Angelico : > >> On Sun, Mar 8, 2015 at 2:48 AM, Marko Rauhamaa wrote: >>> Steven D'Aprano : >>> >>>> Marko Rauhamaa wrote: >>>> >>>>> That said, UTF-8 does suffer badly from its not being >>>>> a bijective mapping. >>>> >>>> Can you explain? >>> >>> In Python terms, there are bytes objects b that don't satisfy: >>> >>> b.decode('utf-8').encode('utf-8') == b >> >> Please provide an example; that sounds like a bug. If there is any >> invalid UTF-8 stream which decodes without an error, it is actually a >> security bug, and should be fixed pronto in all affected and supported >> versions. > > Here's an example: > > b = b'\x80' > > Yes, it generates an exception. IOW, UTF-8 is not a bijective mapping > from str objects to bytes objects. > Python 2 might, Python 3 doesn't. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rosuav at gmail.com Sat Mar 7 11:41:28 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 8 Mar 2015 03:41:28 +1100 Subject: Newbie question about text encoding In-Reply-To: <87k2ysydtk.fsf@elektro.pacujo.net> References: <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <87k2ysydtk.fsf@elektro.pacujo.net> Message-ID: On Sun, Mar 8, 2015 at 3:25 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> On Sun, Mar 8, 2015 at 2:48 AM, Marko Rauhamaa wrote: >>> Steven D'Aprano : >>> >>>> Marko Rauhamaa wrote: >>>> >>>>> That said, UTF-8 does suffer badly from its not being >>>>> a bijective mapping. >>>> >>>> Can you explain? >>> >>> In Python terms, there are bytes objects b that don't satisfy: >>> >>> b.decode('utf-8').encode('utf-8') == b >> >> Please provide an example; that sounds like a bug. If there is any >> invalid UTF-8 stream which decodes without an error, it is actually a >> security bug, and should be fixed pronto in all affected and supported >> versions. > > Here's an example: > > b = b'\x80' > > Yes, it generates an exception. IOW, UTF-8 is not a bijective mapping > from str objects to bytes objects. That's not the same as what you said. All you've proven is that there are bit patterns which are not UTF-8 streams... which is a very deliberate feature. How does UTF-8 *suffer* from this? It benefits hugely! ChrisA From rxjwg98 at gmail.com Sat Mar 7 11:44:13 2015 From: rxjwg98 at gmail.com (fl) Date: Sat, 7 Mar 2015 08:44:13 -0800 (PST) Subject: Question about 'x' in pymc.invlogit(a+b*x) Message-ID: Hi, I once learnt Python for a few weeks. Now, I try to using a Python package pymc. It has the following example code: import pymc import numpy as np n = 5*np.ones(4,dtype=int) x = np.array([-.86,-.3,-.05,.73]) alpha = pymc.Normal('alpha',mu=0,tau=.01) beta = pymc.Normal('beta',mu=0,tau=.01) @pymc.deterministic def theta(a=alpha, b=beta): """theta = logit^{-1}(a+b)""" return pymc.invlogit(a+b*x) d = pymc.Binomial('d', n=n, p=theta, value=np.array([0.,1.,3.,5.]),\ observed=True) I don't understand the 'x' in pymc.invlogit(a+b*x). Could you help me on it? Thanks. From marko at pacujo.net Sat Mar 7 11:48:24 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 07 Mar 2015 18:48:24 +0200 Subject: Newbie question about text encoding References: <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <87k2ysydtk.fsf@elektro.pacujo.net> Message-ID: <87fv9gycrr.fsf@elektro.pacujo.net> Mark Lawrence : > On 07/03/2015 16:25, Marko Rauhamaa wrote: >> Here's an example: >> >> b = b'\x80' >> >> Yes, it generates an exception. IOW, UTF-8 is not a bijective mapping >> from str objects to bytes objects. > > Python 2 might, Python 3 doesn't. Python 3.3.2 (default, Dec 4 2014, 12:49:00) [GCC 4.8.3 20140911 (Red Hat 4.8.3-7)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> b'\x80'.decode('utf-8') Traceback (most recent call last): File "", line 1, in UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte Marko From rosuav at gmail.com Sat Mar 7 11:53:09 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 8 Mar 2015 03:53:09 +1100 Subject: Newbie question about text encoding In-Reply-To: References: <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <87k2ysydtk.fsf@elektro.pacujo.net> Message-ID: On Sun, Mar 8, 2015 at 3:40 AM, Mark Lawrence wrote: >> Here's an example: >> >> b = b'\x80' >> >> Yes, it generates an exception. IOW, UTF-8 is not a bijective mapping >> from str objects to bytes objects. >> > > Python 2 might, Python 3 doesn't. He was talking about this line of code: b.decode('utf-8').encode('utf-8') == b With the above assignment, that does indeed throw an error - which is correct behaviour. Challenge: Figure out a byte-string input that will make this function return True. def is_utf8_broken(b): return b.decode('utf-8').encode('utf-8') != b Correct responses for this function are either False or raising an exception. ChrisA From marko at pacujo.net Sat Mar 7 11:54:14 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 07 Mar 2015 18:54:14 +0200 Subject: Newbie question about text encoding References: <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <87k2ysydtk.fsf@elektro.pacujo.net> Message-ID: <87bnk4yci1.fsf@elektro.pacujo.net> Chris Angelico : > On Sun, Mar 8, 2015 at 3:25 AM, Marko Rauhamaa wrote: >>>>> Marko Rauhamaa wrote: >>>>>> That said, UTF-8 does suffer badly from its not being >>>>>> a bijective mapping. >>>>> >> Here's an example: >> >> b = b'\x80' >> >> Yes, it generates an exception. IOW, UTF-8 is not a bijective mapping >> from str objects to bytes objects. > > That's not the same as what you said. Except that it's precisely what I said. > All you've proven is that there are bit patterns which are not UTF-8 > streams... And that causes problems. > which is a very deliberate feature. Well, nobody desired it. It was just something that had to give. I believe you *could* have defined it as a bijective mapping but then you would have lost the sorting order correspondence. > How does UTF-8 *suffer* from this? It benefits hugely! You can't operate on file names and text files using Python strings. Or at least, you will need to add (nontrivial) exception catching logic. Marko From rosuav at gmail.com Sat Mar 7 11:58:09 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 8 Mar 2015 03:58:09 +1100 Subject: Newbie question about text encoding In-Reply-To: <87bnk4yci1.fsf@elektro.pacujo.net> References: <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <87k2ysydtk.fsf@elektro.pacujo.net> <87bnk4yci1.fsf@elektro.pacujo.net> Message-ID: On Sun, Mar 8, 2015 at 3:54 AM, Marko Rauhamaa wrote: >> All you've proven is that there are bit patterns which are not UTF-8 >> streams... > > And that causes problems. Demonstrate. ChrisA From rosuav at gmail.com Sat Mar 7 12:00:44 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 8 Mar 2015 04:00:44 +1100 Subject: Newbie question about text encoding In-Reply-To: <87bnk4yci1.fsf@elektro.pacujo.net> References: <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <87k2ysydtk.fsf@elektro.pacujo.net> <87bnk4yci1.fsf@elektro.pacujo.net> Message-ID: On Sun, Mar 8, 2015 at 3:54 AM, Marko Rauhamaa wrote: > You can't operate on file names and text files using Python strings. Or > at least, you will need to add (nontrivial) exception catching logic. You can't operate on a JPG file using a Unicode string, nor an array of integers. What of it? You can't operate on an array of integers using a dictionary, either. So? How is this a failing of UTF-8? If you really REALLY can't use the bytes() type to work with something that is, yaknow, bytes, then you could use an alternative encoding that has a value for every byte. It's still not Unicode text, so it doesn't much matter which encoding you use. But it's much better to use the bytes type to work with bytes. It is not text, so don't treat it as text. ChrisA From breamoreboy at yahoo.co.uk Sat Mar 7 12:02:35 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 07 Mar 2015 17:02:35 +0000 Subject: Newbie question about text encoding In-Reply-To: <87fv9gycrr.fsf@elektro.pacujo.net> References: <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <87k2ysydtk.fsf@elektro.pacujo.net> <87fv9gycrr.fsf@elektro.pacujo.net> Message-ID: On 07/03/2015 16:48, Marko Rauhamaa wrote: > Mark Lawrence : > >> On 07/03/2015 16:25, Marko Rauhamaa wrote: >>> Here's an example: >>> >>> b = b'\x80' >>> >>> Yes, it generates an exception. IOW, UTF-8 is not a bijective mapping >>> from str objects to bytes objects. >> >> Python 2 might, Python 3 doesn't. > > Python 3.3.2 (default, Dec 4 2014, 12:49:00) > [GCC 4.8.3 20140911 (Red Hat 4.8.3-7)] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> b'\x80'.decode('utf-8') > Traceback (most recent call last): > File "", line 1, in > UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: > invalid start byte > > > Marko > It would clearly help if you were to type in the correct UK English accent. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From marko at pacujo.net Sat Mar 7 12:14:28 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 07 Mar 2015 19:14:28 +0200 Subject: Newbie question about text encoding References: <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <87k2ysydtk.fsf@elektro.pacujo.net> <87bnk4yci1.fsf@elektro.pacujo.net> Message-ID: <877fusybkb.fsf@elektro.pacujo.net> Chris Angelico : > If you really REALLY can't use the bytes() type to work with something > that is, yaknow, bytes, then you could use an alternative encoding > that has a value for every byte. It's still not Unicode text, so it > doesn't much matter which encoding you use. But it's much better to > use the bytes type to work with bytes. It is not text, so don't treat > it as text. See: $ mkdir /tmp/xyz $ touch /tmp/xyz/$'\x80' $ python3 Python 3.3.2 (default, Dec 4 2014, 12:49:00) [GCC 4.8.3 20140911 (Red Hat 4.8.3-7)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> os.listdir('/tmp/xyz') ['\udc80'] >>> open(os.listdir('/tmp/xyz')[0]) Traceback (most recent call last): File "", line 1, in FileNotFoundError: [Errno 2] No such file or directory: '\udc80' File names encoded with Latin-X are quite commonplace even in UTF-8 locales. Marko From marko at pacujo.net Sat Mar 7 12:16:44 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 07 Mar 2015 19:16:44 +0200 Subject: Newbie question about text encoding References: <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <87k2ysydtk.fsf@elektro.pacujo.net> <87fv9gycrr.fsf@elektro.pacujo.net> Message-ID: <87385gybgj.fsf@elektro.pacujo.net> Mark Lawrence : > It would clearly help if you were to type in the correct UK English > accent. Your ad-hominem-to-contribution ratio is alarmingly high. Marko From rosuav at gmail.com Sat Mar 7 12:26:58 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 8 Mar 2015 04:26:58 +1100 Subject: Newbie question about text encoding In-Reply-To: <877fusybkb.fsf@elektro.pacujo.net> References: <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <87k2ysydtk.fsf@elektro.pacujo.net> <87bnk4yci1.fsf@elektro.pacujo.net> <877fusybkb.fsf@elektro.pacujo.net> Message-ID: On Sun, Mar 8, 2015 at 4:14 AM, Marko Rauhamaa wrote: > See: > > $ mkdir /tmp/xyz > $ touch /tmp/xyz/ > \x80' > $ python3 > Python 3.3.2 (default, Dec 4 2014, 12:49:00) > [GCC 4.8.3 20140911 (Red Hat 4.8.3-7)] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> import os > >>> os.listdir('/tmp/xyz') > ['\udc80'] > >>> open(os.listdir('/tmp/xyz')[0]) > Traceback (most recent call last): > File "", line 1, in > FileNotFoundError: [Errno 2] No such file or directory: '\udc80' > > File names encoded with Latin-X are quite commonplace even in UTF-8 > locales. That is not a problem with UTF-8, though. I don't understand how you're blaming UTF-8 for that. There are two things happening here: 1) The underlying file system is not UTF-8, and you can't depend on that, ergo the decode to Unicode has to have some special handling of failing bytes. 2) You forgot to put the path on that, so it failed to find the file. Here's my version of your demo: >>> open("/tmp/xyz/"+os.listdir('/tmp/xyz')[0]) <_io.TextIOWrapper name='/tmp/xyz/\udc80' mode='r' encoding='UTF-8'> Looks fine to me. Alternatively, if you pass a byte string to os.listdir, you get back a list of byte string file names: >>> os.listdir(b"/tmp/xyz") [b'\x80'] >>> open(b"/tmp/xyz/"+os.listdir(b'/tmp/xyz')[0]) <_io.TextIOWrapper name=b'/tmp/xyz/\x80' mode='r' encoding='UTF-8'> Either way works. You can use bytes or text, and if you use text, there is a way to smuggle bytes through it. None of this has anything to do with UTF-8 as an encoding. (Note that the "encoding='UTF-8'" note in the response has to do with the presumed encoding of the file contents, not of the file name. As an empty file, it can be considered to be a stream of zero Unicode characters, encoded UTF-8, so that's valid.) ChrisA From marko at pacujo.net Sat Mar 7 12:50:20 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 07 Mar 2015 19:50:20 +0200 Subject: Newbie question about text encoding References: <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <87k2ysydtk.fsf@elektro.pacujo.net> <87bnk4yci1.fsf@elektro.pacujo.net> <877fusybkb.fsf@elektro.pacujo.net> Message-ID: <87y4n8wvc3.fsf@elektro.pacujo.net> Chris Angelico : > On Sun, Mar 8, 2015 at 4:14 AM, Marko Rauhamaa wrote: >> File names encoded with Latin-X are quite commonplace even in UTF-8 >> locales. > > That is not a problem with UTF-8, though. I don't understand how > you're blaming UTF-8 for that. I'm saying it creates practical problems. There's a snake in the paradise. > There are two things happening here: > > 1) The underlying file system is not UTF-8, and you can't depend on > that, Correct. Linux pathnames are octet strings regardless of the locale. That's why Linux developers should refer to filenames using bytes. Unfortunately, Python itself violates that principle by having os.listdir() return str objects (to mention one example). > 2) You forgot to put the path on that, so it failed to find the file. > Here's my version of your demo: > >>>> open("/tmp/xyz/"+os.listdir('/tmp/xyz')[0]) > <_io.TextIOWrapper name='/tmp/xyz/\udc80' mode='r' encoding='UTF-8'> > > Looks fine to me. I stand corrected. Then we have: >>> os.listdir()[0].encode('utf-8') Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'utf-8' codec can't encode character '\udc80' in position 0: surrogates not allowed Marko From rosuav at gmail.com Sat Mar 7 12:59:56 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 8 Mar 2015 04:59:56 +1100 Subject: Newbie question about text encoding In-Reply-To: <87y4n8wvc3.fsf@elektro.pacujo.net> References: <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <87k2ysydtk.fsf@elektro.pacujo.net> <87bnk4yci1.fsf@elektro.pacujo.net> <877fusybkb.fsf@elektro.pacujo.net> <87y4n8wvc3.fsf@elektro.pacujo.net> Message-ID: On Sun, Mar 8, 2015 at 4:50 AM, Marko Rauhamaa wrote: >> There are two things happening here: >> >> 1) The underlying file system is not UTF-8, and you can't depend on >> that, > > Correct. Linux pathnames are octet strings regardless of the locale. > > That's why Linux developers should refer to filenames using bytes. > Unfortunately, Python itself violates that principle by having > os.listdir() return str objects (to mention one example). Only because you gave it a str with the path name. If you want to refer to file names using bytes, then be consistent and refer to ALL file names using bytes. As I demonstrated, that works just fine. >> 2) You forgot to put the path on that, so it failed to find the file. >> Here's my version of your demo: >> >>>>> open("/tmp/xyz/"+os.listdir('/tmp/xyz')[0]) >> <_io.TextIOWrapper name='/tmp/xyz/\udc80' mode='r' encoding='UTF-8'> >> >> Looks fine to me. > > I stand corrected. > > Then we have: > > >>> os.listdir()[0].encode('utf-8') > Traceback (most recent call last): > File "", line 1, in > UnicodeEncodeError: 'utf-8' codec can't encode character '\udc80' in > position 0: surrogates not allowed So? ChrisA From dan at tombstonezero.net Sat Mar 7 13:02:50 2015 From: dan at tombstonezero.net (Dan Sommers) Date: Sat, 7 Mar 2015 18:02:50 +0000 (UTC) Subject: Newbie question about text encoding References: <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <87k2ysydtk.fsf@elektro.pacujo.net> <87bnk4yci1.fsf@elektro.pacujo.net> <877fusybkb.fsf@elektro.pacujo.net> <87y4n8wvc3.fsf@elektro.pacujo.net> Message-ID: On Sun, 08 Mar 2015 04:59:56 +1100, Chris Angelico wrote: > On Sun, Mar 8, 2015 at 4:50 AM, Marko Rauhamaa wrote: >> Correct. Linux pathnames are octet strings regardless of the locale. >> >> That's why Linux developers should refer to filenames using bytes. >> Unfortunately, Python itself violates that principle by having >> os.listdir() return str objects (to mention one example). > > Only because you gave it a str with the path name. If you want to > refer to file names using bytes, then be consistent and refer to ALL > file names using bytes. As I demonstrated, that works just fine. Python 3.4.2 (default, Oct 8 2014, 10:45:20) [GCC 4.9.1] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> type(os.listdir(os.curdir)[0]) From rosuav at gmail.com Sat Mar 7 13:13:09 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 8 Mar 2015 05:13:09 +1100 Subject: Newbie question about text encoding In-Reply-To: References: <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <87k2ysydtk.fsf@elektro.pacujo.net> <87bnk4yci1.fsf@elektro.pacujo.net> <877fusybkb.fsf@elektro.pacujo.net> <87y4n8wvc3.fsf@elektro.pacujo.net> Message-ID: On Sun, Mar 8, 2015 at 5:02 AM, Dan Sommers wrote: > On Sun, 08 Mar 2015 04:59:56 +1100, Chris Angelico wrote: > >> On Sun, Mar 8, 2015 at 4:50 AM, Marko Rauhamaa wrote: > >>> Correct. Linux pathnames are octet strings regardless of the locale. >>> >>> That's why Linux developers should refer to filenames using bytes. >>> Unfortunately, Python itself violates that principle by having >>> os.listdir() return str objects (to mention one example). >> >> Only because you gave it a str with the path name. If you want to >> refer to file names using bytes, then be consistent and refer to ALL >> file names using bytes. As I demonstrated, that works just fine. > > Python 3.4.2 (default, Oct 8 2014, 10:45:20) > [GCC 4.9.1] on linux > Type "help", "copyright", "credits" or "license" for more information. >>>> import os >>>> type(os.listdir(os.curdir)[0]) > Help on module os: DESCRIPTION This exports: - os.curdir is a string representing the current directory ('.' or ':') - os.pardir is a string representing the parent directory ('..' or '::') Explicitly documented as strings. If you want to work with strings, work with strings. If you want to work with bytes, don't use os.curdir, use bytes instead. Personally, I'm happy using strings, but if you want to go down the path of using bytes, you simply have to be consistent, and that probably means being platform-dependent anyway, so just use b"." for the current directory. Normally, using Unicode strings for file names will work just fine. Any name that you craft yourself will be correctly encoded for the target file system (or UTF-8 if you can't know), and any that you get back from os.listdir or equivalent will be usable in file name contexts. What else can you do with a file name that isn't encoded the way you expect it to be? Unless you have some out-of-band encoding information, you can't do anything meaningful with the stream of bytes, other than keeping it exactly as it is. ChrisA From tjreedy at udel.edu Sat Mar 7 13:13:59 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 07 Mar 2015 13:13:59 -0500 Subject: Question about 'x' in pymc.invlogit(a+b*x) In-Reply-To: References: Message-ID: On 3/7/2015 11:44 AM, fl wrote: > Hi, > > I once learnt Python for a few weeks. Now, I try to using a Python package > pymc. It has the following example code: > > > > > import pymc > import numpy as np > n = 5*np.ones(4,dtype=int) > x = np.array([-.86,-.3,-.05,.73]) x is defined here as a module ('global') name > alpha = pymc.Normal('alpha',mu=0,tau=.01) > beta = pymc.Normal('beta',mu=0,tau=.01) > @pymc.deterministic > def theta(a=alpha, b=beta): > """theta = logit^{-1}(a+b)""" > return pymc.invlogit(a+b*x) x is used here. Names in functions can be resolved in the local, (nonlocal, when present, but not here), global, and builtin namespaces, in that order. They are resolved when the function is called. > d = pymc.Binomial('d', n=n, p=theta, value=np.array([0.,1.,3.,5.]),\ > observed=True) > I don't understand the 'x' in pymc.invlogit(a+b*x). Could you help me on it? See comments, and contemplate this simplified example >>> def f(a): return a+b >>> b = 3 >>> f(4) 7 -- Terry Jan Reedy From breamoreboy at yahoo.co.uk Sat Mar 7 13:18:44 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 07 Mar 2015 18:18:44 +0000 Subject: Newbie question about text encoding In-Reply-To: <87385gybgj.fsf@elektro.pacujo.net> References: <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <87k2ysydtk.fsf@elektro.pacujo.net> <87fv9gycrr.fsf@elektro.pacujo.net> <87385gybgj.fsf@elektro.pacujo.net> Message-ID: On 07/03/2015 17:16, Marko Rauhamaa wrote: > Mark Lawrence : > >> It would clearly help if you were to type in the correct UK English >> accent. > > Your ad-hominem-to-contribution ratio is alarmingly high. > > > Marko > You've been a PITA ever since you first joined this list, what about it? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From dan at tombstonezero.net Sat Mar 7 13:34:27 2015 From: dan at tombstonezero.net (Dan Sommers) Date: Sat, 7 Mar 2015 18:34:27 +0000 (UTC) Subject: Newbie question about text encoding References: <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <87k2ysydtk.fsf@elektro.pacujo.net> <87bnk4yci1.fsf@elektro.pacujo.net> <877fusybkb.fsf@elektro.pacujo.net> <87y4n8wvc3.fsf@elektro.pacujo.net> Message-ID: On Sun, 08 Mar 2015 05:13:09 +1100, Chris Angelico wrote: > On Sun, Mar 8, 2015 at 5:02 AM, Dan Sommers wrote: >> On Sun, 08 Mar 2015 04:59:56 +1100, Chris Angelico wrote: >> >>> On Sun, Mar 8, 2015 at 4:50 AM, Marko Rauhamaa wrote: >> >>>> Correct. Linux pathnames are octet strings regardless of the locale. >>>> >>>> That's why Linux developers should refer to filenames using bytes. >>>> Unfortunately, Python itself violates that principle by having >>>> os.listdir() return str objects (to mention one example). >>> >>> Only because you gave it a str with the path name. If you want to >>> refer to file names using bytes, then be consistent and refer to ALL >>> file names using bytes. As I demonstrated, that works just fine. >> >> Python 3.4.2 (default, Oct 8 2014, 10:45:20) >> [GCC 4.9.1] on linux >> Type "help", "copyright", "credits" or "license" for more information. >>>>> import os >>>>> type(os.listdir(os.curdir)[0]) >> > > Help on module os: > > DESCRIPTION > This exports: > - os.curdir is a string representing the current directory ('.' or ':') > - os.pardir is a string representing the parent directory ('..' or '::') > > Explicitly documented as strings. If you want to work with strings, > work with strings. If you want to work with bytes, don't use > os.curdir, use bytes instead. Personally, I'm happy using strings, but > if you want to go down the path of using bytes, you simply have to be > consistent, and that probably means being platform-dependent anyway, > so just use b"." for the current directory. I think we're all agreeing: not all file systems are the same, and Python doesn't smooth out all of the bumps, even for something that seems as simple as displaying the names of files in a directory. And that's *after* we've agreed that filesystems contain files in hierarchical directories. Dan From rosuav at gmail.com Sat Mar 7 13:44:03 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 8 Mar 2015 05:44:03 +1100 Subject: Newbie question about text encoding In-Reply-To: References: <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <87k2ysydtk.fsf@elektro.pacujo.net> <87bnk4yci1.fsf@elektro.pacujo.net> <877fusybkb.fsf@elektro.pacujo.net> <87y4n8wvc3.fsf@elektro.pacujo.net> Message-ID: On Sun, Mar 8, 2015 at 5:34 AM, Dan Sommers wrote: > I think we're all agreeing: not all file systems are the same, and > Python doesn't smooth out all of the bumps, even for something that > seems as simple as displaying the names of files in a directory. And > that's *after* we've agreed that filesystems contain files in > hierarchical directories. I think you and I are in agreement. No idea about Marko, I'm still not entirely sure what he's saying. Python can't smooth out all of the bumps in file systems, any more than Unicode can smooth out the bumps in natural language, or TCP can smooth out the bumps in IP. The abstraction layers help, but every now and then they leak, and you have to cope with the underlying mess. ChrisA From breamoreboy at yahoo.co.uk Sat Mar 7 14:00:47 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 07 Mar 2015 19:00:47 +0000 Subject: Newbie question about text encoding In-Reply-To: References: <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <87k2ysydtk.fsf@elektro.pacujo.net> <87bnk4yci1.fsf@elektro.pacujo.net> <877fusybkb.fsf@elektro.pacujo.net> <87y4n8wvc3.fsf@elektro.pacujo.net> Message-ID: On 07/03/2015 18:34, Dan Sommers wrote: > On Sun, 08 Mar 2015 05:13:09 +1100, Chris Angelico wrote: > >> On Sun, Mar 8, 2015 at 5:02 AM, Dan Sommers wrote: >>> On Sun, 08 Mar 2015 04:59:56 +1100, Chris Angelico wrote: >>> >>>> On Sun, Mar 8, 2015 at 4:50 AM, Marko Rauhamaa wrote: >>> >>>>> Correct. Linux pathnames are octet strings regardless of the locale. >>>>> >>>>> That's why Linux developers should refer to filenames using bytes. >>>>> Unfortunately, Python itself violates that principle by having >>>>> os.listdir() return str objects (to mention one example). >>>> >>>> Only because you gave it a str with the path name. If you want to >>>> refer to file names using bytes, then be consistent and refer to ALL >>>> file names using bytes. As I demonstrated, that works just fine. >>> >>> Python 3.4.2 (default, Oct 8 2014, 10:45:20) >>> [GCC 4.9.1] on linux >>> Type "help", "copyright", "credits" or "license" for more information. >>>>>> import os >>>>>> type(os.listdir(os.curdir)[0]) >>> >> >> Help on module os: >> >> DESCRIPTION >> This exports: >> - os.curdir is a string representing the current directory ('.' or ':') >> - os.pardir is a string representing the parent directory ('..' or '::') >> >> Explicitly documented as strings. If you want to work with strings, >> work with strings. If you want to work with bytes, don't use >> os.curdir, use bytes instead. Personally, I'm happy using strings, but >> if you want to go down the path of using bytes, you simply have to be >> consistent, and that probably means being platform-dependent anyway, >> so just use b"." for the current directory. > > I think we're all agreeing: not all file systems are the same, and > Python doesn't smooth out all of the bumps, even for something that > seems as simple as displaying the names of files in a directory. And > that's *after* we've agreed that filesystems contain files in > hierarchical directories. > > Dan > Isn't pathlib https://docs.python.org/3/library/pathlib.html#module-pathlib effectively a more recent attempt at smoothing or even removing (some of) the bumps? Has anybody here got experience of it as I've never used it? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From marko at pacujo.net Sat Mar 7 14:01:27 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 07 Mar 2015 21:01:27 +0200 Subject: Newbie question about text encoding References: <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <87k2ysydtk.fsf@elektro.pacujo.net> <87bnk4yci1.fsf@elektro.pacujo.net> <877fusybkb.fsf@elektro.pacujo.net> <87y4n8wvc3.fsf@elektro.pacujo.net> Message-ID: <87twxwws1k.fsf@elektro.pacujo.net> Dan Sommers : > I think we're all agreeing: not all file systems are the same, and > Python doesn't smooth out all of the bumps, even for something that > seems as simple as displaying the names of files in a directory. And > that's *after* we've agreed that filesystems contain files in > hierarchical directories. A whole new set of problems took root with Unicode. There were gains but there were losses, too. Python is not alone in the conceptual difficulties. Guile 2's (readdir) simply converts bad UTF-8 in a filename into a question mark: scheme@(guile-user) [1]> (readdir s) $3 = "?" scheme@(guile-user) [4]> (equal? $3 "?") $4 = #t So does lxterminal: $ ls ? even though it's all bytes on the inside: $ [ $(ls) = "?" ] $ echo $? 1 Scripts that make use of standard text utilities must now be very careful: $ ls | egrep "^.$" | wc -l 0 You are well advised to sprinkle LANG=C in your scripts: $ ls | LANG=C egrep "^.$" | wc -l 1 Nasty locale-related bugs plague installation scripts, whose writers are not accustomed to running their tests in myriads of locales. The topic is of course larger than just Unicode. Marko From fomcl at yahoo.com Sat Mar 7 14:03:34 2015 From: fomcl at yahoo.com (Albert-Jan Roskam) Date: Sat, 7 Mar 2015 19:03:34 +0000 (UTC) Subject: Newbie question about text encoding In-Reply-To: References: Message-ID: <112110016.96136.1425755014276.JavaMail.yahoo@mail.yahoo.com> --- Original Message ----- > From: Chris Angelico > To: > Cc: "python-list at python.org" > Sent: Saturday, March 7, 2015 6:26 PM > Subject: Re: Newbie question about text encoding > > On Sun, Mar 8, 2015 at 4:14 AM, Marko Rauhamaa wrote: >> See: >> >> $ mkdir /tmp/xyz >> $ touch /tmp/xyz/ >> \x80' >> $ python3 >> Python 3.3.2 (default, Dec 4 2014, 12:49:00) >> [GCC 4.8.3 20140911 (Red Hat 4.8.3-7)] on linux >> Type "help", "copyright", "credits" or > "license" for more information. >> >>> import os >> >>> os.listdir('/tmp/xyz') >> ['\udc80'] >> >>> open(os.listdir('/tmp/xyz')[0]) >> Traceback (most recent call last): >> File "", line 1, in >> FileNotFoundError: [Errno 2] No such file or directory: > '\udc80' >> >> File names encoded with Latin-X are quite commonplace even in UTF-8 >> locales. > > That is not a problem with UTF-8, though. I don't understand how > you're blaming UTF-8 for that. There are two things happening here: > > 1) The underlying file system is not UTF-8, and you can't depend on > that, ergo the decode to Unicode has to have some special handling of > failing bytes. > 2) You forgot to put the path on that, so it failed to find the file. > Here's my version of your demo: > >>>> open("/tmp/xyz/"+os.listdir('/tmp/xyz')[0]) > <_io.TextIOWrapper name='/tmp/xyz/\udc80' mode='r' > encoding='UTF-8'> > > Looks fine to me. > > Alternatively, if you pass a byte string to os.listdir, you get back a > list of byte string file names: > >>>> os.listdir(b"/tmp/xyz") > [b'\x80'] Nice, I did not know that. And glob.glob works the same way: it returns a list of ustrings when given a ustring, and returns bstrings when given a bstring. From markos at c2o.pro.br Sat Mar 7 14:15:59 2015 From: markos at c2o.pro.br (Markos) Date: Sat, 07 Mar 2015 16:15:59 -0300 Subject: Idle - ImportError: No module named numpy Message-ID: <54FB4E6F.2050504@c2o.pro.br> Hi, I'm beginning to study the numpy. When I open a terminal (Debian Squeeze) and run the python interpreter the command "import numpy as np" run without errors. But when I run the same command on idle3 the following error appears. >>> import numpy as np Traceback (most recent call last): File "", line 1, in import numpy as np ImportError: No module named numpy How configure idle to load the numpy module? Thanks, Markos From dan at tombstonezero.net Sat Mar 7 14:16:42 2015 From: dan at tombstonezero.net (Dan Sommers) Date: Sat, 7 Mar 2015 19:16:42 +0000 (UTC) Subject: Newbie question about text encoding References: <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <87k2ysydtk.fsf@elektro.pacujo.net> <87bnk4yci1.fsf@elektro.pacujo.net> <877fusybkb.fsf@elektro.pacujo.net> <87y4n8wvc3.fsf@elektro.pacujo.net> Message-ID: On Sat, 07 Mar 2015 19:00:47 +0000, Mark Lawrence wrote: > Isn't pathlib > https://docs.python.org/3/library/pathlib.html#module-pathlib > effectively a more recent attempt at smoothing or even removing (some > of) the bumps? Has anybody here got experience of it as I've never > used it? I almost said something about Common Lisp's PATHNAME type, but I didn't. An extremely quick reading of that page tells me that os.pathlib addresses *some* of the issues that PATHNAME addresses, but os.pathlib seems more limited in scope (e.g., os.pathlib doesn't account for filesystems with versioned files). I'll certainly have a closer look later. From markos at c2o.pro.br Sat Mar 7 16:54:38 2015 From: markos at c2o.pro.br (Markos) Date: Sat, 07 Mar 2015 18:54:38 -0300 Subject: How to install i1636 Message-ID: <54FB739E.6000407@c2o.pro.br> Please, How to install the ia636 library on Debian (Squeeze) with Python 2.6? Thank you, Markos From james.dekker at gmail.com Sat Mar 7 18:39:30 2015 From: james.dekker at gmail.com (James Dekker) Date: Sat, 7 Mar 2015 15:39:30 -0800 Subject: Installed Python 3 on Mac OS X Yosemite but its still Python 2.7 Message-ID: I am currently running OS X Yosemite (10.10.2) on my MacBook Pro... By default, Apple ships Python 2.7.6 on Yosemite. Just downloaded and ran this installer for Python 3: python-3.4.3-macosx10.6.pkg When I opened up my Terminal and typed in python, this is what came up: Python 2.7.6 (default, Sep 9 2014, 15:04:36) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwinType "help", "copyright", "credits" or "license" for more information.>>> Sorry, I am very new to Python... Question(s): (1) Does anyone know where the Python 3.4.3 interpreter was installed? (2) Do I need to uninstall Python 2.7.3 (if so, how do I go about doing this) before setting a global environmental variable such as PYTHON_HOME to the location of the installed Python 3.4.3? Thank for taking the time to read this... -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Sat Mar 7 20:45:54 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 08 Mar 2015 12:45:54 +1100 Subject: Newbie question about text encoding References: <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> Message-ID: <54fba9d4$0$12988$c3e8da3$5496439d@news.astraweb.com> Marko Rauhamaa wrote: > Steven D'Aprano : > >> Marko Rauhamaa wrote: >> >>> That said, UTF-8 does suffer badly from its not being >>> a bijective mapping. >> >> Can you explain? > > In Python terms, there are bytes objects b that don't satisfy: > > b.decode('utf-8').encode('utf-8') == b Are you talking about the fact that not all byte streams are valid UTF-8? That is, some byte objects b may raise an exception on b.decode('utf-8'). I don't see why that means UTF-8 "suffers badly" from this. Can you give an example of where you would expect to take an arbitrary byte-stream, decode it as UTF-8, and expect the results to be meaningful? For those cases where you do wish to take an arbitrary byte stream and round-trip it, Python now provides an error handler for that. py> import random py> b = bytes([random.randint(0, 255) for _ in range(10000)]) py> s = b.decode('utf-8') Traceback (most recent call last): File "", line 1, in UnicodeDecodeError: 'utf-8' codec can't decode byte 0x94 in position 0: invalid start byte py> s = b.decode('utf-8', errors='surrogateescape') py> s.encode('utf-8', errors='surrogateescape') == b True -- Steven From rustompmody at gmail.com Sun Mar 8 00:06:27 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 7 Mar 2015 21:06:27 -0800 (PST) Subject: Newbie question about text encoding In-Reply-To: References: <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <87k2ysydtk.fsf@elektro.pacujo.net> <87fv9gycrr.fsf@elektro.pacujo.net> <87385gybgj.fsf@elektro.pacujo.net> Message-ID: On Saturday, March 7, 2015 at 11:49:44 PM UTC+5:30, Mark Lawrence wrote: > On 07/03/2015 17:16, Marko Rauhamaa wrote: > > Mark Lawrence: > > > >> It would clearly help if you were to type in the correct UK English > >> accent. > > > > Your ad-hominem-to-contribution ratio is alarmingly high. > > > > > > Marko > > > > You've been a PITA ever since you first joined this list, what about it? > > -- > My fellow Pythonistas, ask not what our language can do for you, ask > what you can do for our language. Hi Mark Your UK accent above is funny [At least *I* find it so] The above however is crossing a line. Please desist. From invalid at invalid.invalid Sun Mar 8 00:19:51 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Sun, 8 Mar 2015 05:19:51 +0000 (UTC) Subject: HELP!! How to ask a girl out with a simple witty Python code?? References: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> <2906370c-58c7-4d8b-8db3-2ea3773b9578@googlegroups.com> <54f8d56a$0$12984$c3e8da3$5496439d@news.astraweb.com> <54f916b2$0$12980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2015-03-07, Gregory Ewing wrote: > alister wrote: > >> a popular UK soap made an extreme effort not to show a cross or >> Christmas tree during a church wedding in case it "offended >> not-Christians". > > In today's climate, when offending certain varieties > of non-Christian can get you blown up or shot, it might > not be quite as silly as it sounds. The same can happen if you offend certain varieties of Christians. -- Grant From rustompmody at gmail.com Sun Mar 8 00:25:32 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 7 Mar 2015 21:25:32 -0800 (PST) Subject: Newbie question about text encoding In-Reply-To: References: <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <01dd9b83-db3e-4e7d-9022-dc6af75eb570@googlegroups.com> <54f9bea1$0$12994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7d2480b3-8a39-40d7-aa95-4f1aae95a1f8@googlegroups.com> On Saturday, March 7, 2015 at 11:41:53 AM UTC+5:30, Terry Reedy wrote: > On 3/6/2015 11:20 AM, Rustom Mody wrote: > > > ========= > > pp = "?" > > print (pp) > > ========= > > Try open it in idle3 and you get (at least I get): > > > > $ idle3 ff.py > > Traceback (most recent call last): > > File "/usr/bin/idle3", line 5, in > > main() > > File "/usr/lib/python3.4/idlelib/PyShell.py", line 1562, in main > > if flist.open(filename) is None: > > File "/usr/lib/python3.4/idlelib/FileList.py", line 36, in open > > edit = self.EditorWindow(self, filename, key) > > File "/usr/lib/python3.4/idlelib/PyShell.py", line 126, in __init__ > > EditorWindow.__init__(self, *args) > > File "/usr/lib/python3.4/idlelib/EditorWindow.py", line 294, in __init__ > > if io.loadfile(filename): > > File "/usr/lib/python3.4/idlelib/IOBinding.py", line 236, in loadfile > > self.text.insert("1.0", chars) > > File "/usr/lib/python3.4/idlelib/Percolator.py", line 25, in insert > > self.top.insert(index, chars, tags) > > File "/usr/lib/python3.4/idlelib/UndoDelegator.py", line 81, in insert > > self.addcmd(InsertCommand(index, chars, tags)) > > File "/usr/lib/python3.4/idlelib/UndoDelegator.py", line 116, in addcmd > > cmd.do(self.delegate) > > File "/usr/lib/python3.4/idlelib/UndoDelegator.py", line 219, in do > > text.insert(self.index1, self.chars, self.tags) > > File "/usr/lib/python3.4/idlelib/ColorDelegator.py", line 82, in insert > > self.delegate.insert(index, chars, tags) > > File "/usr/lib/python3.4/idlelib/WidgetRedirector.py", line 148, in __call__ > > return self.tk_call(self.orig_and_operation + args) > > _tkinter.TclError: character U+1f4a9 is above the range (U+0000-U+FFFF) allowed by Tcl > > > > So who/what is broken? > > tcl > The possible workaround is for Idle to translate "?" to "\U0001f4a9" > (10 chars) before sending it to tk. > > But some perspective. In the console interpreter: > > >>> print("\U0001f4a9") > Traceback (most recent call last): > File "", line 1, in > File "C:\Programs\Python34\lib\encodings\cp437.py", line 19, in encode > return codecs.charmap_encode(input,self.errors,encoding_map)[0] > UnicodeEncodeError: 'charmap' codec can't encode character '\U0001f4a9' > in posit > ion 0: character maps to > > So what is broken? Windows Command Prompt. > > More perspective. tk/Idle *will* print *something* for every BMP char. > Command Prompt will not. It does not even do ucs-2 correctly. So > which is more broken? Windows Command Prompt. Who has perhaps > 1,000,000 times more resources, Microsoft? or the tcl/tk group? I think > we all know. Thanks Terry for the perspective. >From my side: No complaints about python or tcl (or idle -- its actually neater than emacs if only emacs was not burnt into my nervous system) Even unicode -- only marginal complaints. I wrote http://blog.languager.org/2015/02/universal-unicode.html precisely to say that unicode is a wonderful thing and one should be enthusiastic about it. [You got that better than anyone else who has spoken -- Thanks] Xah's pages are way more comprehensive than mine. But comprehensive can be a negative -- ultimately the unicode standard is the most comprehensive and correspondingly impenetrable without a compass. The only very minor complaint I would make is: If idle is unable to deal with SMP-chars and this is known and unlikely to change (until TK changes), why not put up a dialog of the sort: SMP char on line SMP support currently unimplemented -- Sorry instead of a backtrace? [As I said just a suggestion] From hamilton at nothere.com Sun Mar 8 01:54:02 2015 From: hamilton at nothere.com (hamilton) Date: Sat, 07 Mar 2015 23:54:02 -0700 Subject: HELP!! How to ask a girl out with a simple witty Python code?? In-Reply-To: References: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> <2906370c-58c7-4d8b-8db3-2ea3773b9578@googlegroups.com> <54f8d56a$0$12984$c3e8da3$5496439d@news.astraweb.com> <54f916b2$0$12980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/7/2015 10:19 PM, Grant Edwards wrote: > On 2015-03-07, Gregory Ewing wrote: >> alister wrote: >> >>> a popular UK soap made an extreme effort not to show a cross or >>> Christmas tree during a church wedding in case it "offended >>> not-Christians". >> >> In today's climate, when offending certain varieties >> of non-Christian can get you blown up or shot, it might >> not be quite as silly as it sounds. > > The same can happen if you offend certain varieties of Christians. Does Centennial Olympic Park sound familiar ? Christians and Republicans forgot what Jesus had to say. Which means they are NOT Christians. http://www.amazon.com/How-Republicans-Stole-Religion-Religious/dp/0385516045 > > -- > Grant > From marko at pacujo.net Sun Mar 8 03:20:33 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 08 Mar 2015 09:20:33 +0200 Subject: Newbie question about text encoding References: <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <54fba9d4$0$12988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87y4n8uf9a.fsf@elektro.pacujo.net> Steven D'Aprano : > For those cases where you do wish to take an arbitrary byte stream and > round-trip it, Python now provides an error handler for that. > > py> import random > py> b = bytes([random.randint(0, 255) for _ in range(10000)]) > py> s = b.decode('utf-8') > Traceback (most recent call last): > File "", line 1, in > UnicodeDecodeError: 'utf-8' codec can't decode byte 0x94 in position 0: > invalid start byte > py> s = b.decode('utf-8', errors='surrogateescape') > py> s.encode('utf-8', errors='surrogateescape') == b > True That is indeed a valid workaround. With it we achieve b.decode('utf-8', errors='surrogateescape'). \ encode('utf-8', errors='surrogateescape') == b for any bytes b. It goes to great lengths to address the Linux programmer's situation. However, * it's not UTF-8 but a variant of it, * it sacrifices the ordering correspondence of UTF-8: >>> '\udc80' > '?' True >>> '\udc80'.encode('utf-8', errors='surrogateescape') > \ ... '?'.encode('utf-8', errors='surrogateescape') False * it still isn't bijective between str and bytes: >>> '\udd00'.encode('utf-8', errors='surrogateescape') Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'utf-8' codec can't encode character '\udd00' in position 0: surrogates not allowed Marko From rustompmody at gmail.com Sun Mar 8 03:23:53 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 7 Mar 2015 23:23:53 -0800 (PST) Subject: Newbie question about text encoding In-Reply-To: <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> References: <201502241524.t1OFO09k022270@fido.openend.se> <201502241620.t1OGKf4n002146@fido.openend.se> <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7cdb210c-c152-41a6-8afa-a0c0028f454e@googlegroups.com> On Saturday, March 7, 2015 at 4:39:48 PM UTC+5:30, Steven D'Aprano wrote: > Rustom Mody wrote: > > This includes not just bug-prone-system code such as Java and Windows but > > seemingly working code such as python 3. > > What Unicode bugs do you think Python 3.3 and above have? Literal/Legalistic answer: https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2012-2135 [And already quoted at http://blog.languager.org/2015/03/whimsical-unicode.html ] An answer more in the spirit of what I am trying to say: Idle3, Roy's example and in general all systems that are python-centric but use components outside of python that are unicode-broken IOW I would expect people (at least people with good faith) reading my > bug-prone-system code...seemingly working code such as python 3... to interpret that NOT as "python 3 is seemingly working but actually broken" But as "Apps made with working system code (eg python3) can end up being broken because of other non-working system code - eg mysql, java, javascript, windows-shell, and ultimately windows, linux" From frank at chagford.com Sun Mar 8 03:30:25 2015 From: frank at chagford.com (Frank Millman) Date: Sun, 8 Mar 2015 09:30:25 +0200 Subject: Question about importlib Message-ID: Hi all It is well known that if you import a module more than once, the overhead for the subsequent imports is negligible. Does anyone happen to know if the same is true of the following? module_name, func_name = func_name.rsplit('.', 1) module = importlib.import_module(module_name) getattr(module, func_name)(caller, xml_elem) I have a situation where I want to call a function dynamically, by passing a string containing a path to the function. The same function could be called multiple times. I would hope that the overhead for the second and subsequent calls is also fairly minimal. Actually, as I write this, I realise that there is a more important question that had not occurred to me before. Is this a potential security risk? My intention is that the caller would only call functions within my own modules, but this could be used to call any arbitrary function. You cannot pass arbitrary arguments to the function. The arguments are the 'caller', which can only be an object within my application, and an xml element, from which the function can extract attributes using xml_elem.get(attr_name). Before posting this I ran some timing tests, and the overhead does indeed seem to be minimal - 0.0001 sec on a slow desktop machine. I think it is still worth posting, for any insights into either question. Thanks Frank Millman From rosuav at gmail.com Sun Mar 8 03:37:34 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 8 Mar 2015 18:37:34 +1100 Subject: Newbie question about text encoding In-Reply-To: <87y4n8uf9a.fsf@elektro.pacujo.net> References: <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <54fba9d4$0$12988$c3e8da3$5496439d@news.astraweb.com> <87y4n8uf9a.fsf@elektro.pacujo.net> Message-ID: On Sun, Mar 8, 2015 at 6:20 PM, Marko Rauhamaa wrote: > * it still isn't bijective between str and bytes: > > >>> '\udd00'.encode('utf-8', errors='surrogateescape') > Traceback (most recent call last): > File "", line 1, in > UnicodeEncodeError: 'utf-8' codec can't encode character > '\udd00' in position 0: surrogates not allowed Once again, you appear to be surprised that invalid data is failing. Why is this so strange? U+DD00 is not a valid character. It is quite correct to throw this error. ChrisA From rosuav at gmail.com Sun Mar 8 03:42:06 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 8 Mar 2015 18:42:06 +1100 Subject: Question about importlib In-Reply-To: References: Message-ID: On Sun, Mar 8, 2015 at 6:30 PM, Frank Millman wrote: > Actually, as I write this, I realise that there is a more important question > that had not occurred to me before. Is this a potential security risk? My > intention is that the caller would only call functions within my own > modules, but this could be used to call any arbitrary function. Here's an easy solution to both halves of your problem. It guarantees that arbitrary functions can't be called (or at least, that functions from arbitrary modules can't be called), and guarantees predictable performance: modules = { "some_module": some_module, "another_module": another_module, } module_name, func_name = func_name.rsplit('.', 1) module = modules.get(module_name) if module: getattr(module, func_name)(caller, xml_elem) else: cope with invalid choice of module You could programmatically populate the dictionary (eg from a list of acceptable module names) either with importlib or by pulling them from sys.modules. But whichever way you do it, you have an easy guarantee that arbitrary modules won't be imported, guaranteeing both security and performance in one stroke. ChrisA From frank at chagford.com Sun Mar 8 03:53:07 2015 From: frank at chagford.com (Frank Millman) Date: Sun, 8 Mar 2015 09:53:07 +0200 Subject: Question about importlib References: Message-ID: "Chris Angelico" wrote in message news:CAPTjJmrXp4MSO9f=xb_BRuPnRZ7XRKsKTkbFvo-e5N7Lr_MVVg at mail.gmail.com... > On Sun, Mar 8, 2015 at 6:30 PM, Frank Millman wrote: >> Actually, as I write this, I realise that there is a more important >> question >> that had not occurred to me before. Is this a potential security risk? My >> intention is that the caller would only call functions within my own >> modules, but this could be used to call any arbitrary function. > > Here's an easy solution to both halves of your problem. It guarantees > that arbitrary functions can't be called (or at least, that functions > from arbitrary modules can't be called), and guarantees predictable > performance: > > modules = { > "some_module": some_module, > "another_module": another_module, > } > > module_name, func_name = func_name.rsplit('.', 1) > module = modules.get(module_name) > if module: getattr(module, func_name)(caller, xml_elem) > else: cope with invalid choice of module > > You could programmatically populate the dictionary (eg from a list of > acceptable module names) either with importlib or by pulling them from > sys.modules. But whichever way you do it, you have an easy guarantee > that arbitrary modules won't be imported, guaranteeing both security > and performance in one stroke. That is a neat solution. Thanks, Chris Frank From steve+comp.lang.python at pearwood.info Sun Mar 8 04:01:19 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 08 Mar 2015 19:01:19 +1100 Subject: Newbie question about text encoding References: <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <54fba9d4$0$12988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <54fc01cf$0$12995$c3e8da3$5496439d@news.astraweb.com> Steven D'Aprano wrote: > Marko Rauhamaa wrote: > >> Steven D'Aprano : >> >>> Marko Rauhamaa wrote: >>> >>>> That said, UTF-8 does suffer badly from its not being >>>> a bijective mapping. >>> >>> Can you explain? >> >> In Python terms, there are bytes objects b that don't satisfy: >> >> b.decode('utf-8').encode('utf-8') == b > > Are you talking about the fact that not all byte streams are valid UTF-8? > That is, some byte objects b may raise an exception on b.decode('utf-8'). Eh, I should have read the rest of the thread before replying... > I don't see why that means UTF-8 "suffers badly" from this. Can you give > an example of where you would expect to take an arbitrary byte-stream, > decode it as UTF-8, and expect the results to be meaningful? File names on Unix-like systems. Unfortunately file names are a bit of a mess, but we're slowly converging on Unicode support for files. I reckon that by 2070, 2080 tops, we'll have that licked... The three major operating systems have different levels of support for Unicode file names: * Apple OS X: HFS+ stores file names in decomposed form, using UTF-16. I think this is the strictest Unicode support of all common file systems. Well done Apple. Decomposed in this sense means that single code points may be expanded where possible, e.g. ? U+00E9 LATIN SMALL LETTER E WITH ACUTE will be stored as two code points, U+0065 LATIN SMALL LETTER E + U+0301 COMBINING ACUTE ACCENT. * Windows: NTFS stores file names as sequences of 16-bit code units except 0x0000. (Additional restrictions also apply: e.g. in POSIX mode, / is also forbidden; in Win32 mode, / ? + etc. are forbidden.) The code units are interpreted as UTF-16 but the file system doesn't prevent you from creating file names with invalid sequences. * Linux: ext2/ext3 stores file names as arbitrary bytes except for / and nul. However most Linux distributions treat file names as if they were UTF-8 (displaying ? glyphs for undecodable bytes), and many Linux GUI file managers enforce the rule that file names are valid UTF-8. File systems on removable media (FAT32, UDF, ISO-9660 with or without extensions such as Joliet and Rock Ridge) have their own issues, but generally speaking don't support Unicode well or at all. So although the current situation is still a bit of a mess, there is a slow move towards file names which are valid Unicode. -- Steven From marko at pacujo.net Sun Mar 8 04:09:50 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 08 Mar 2015 10:09:50 +0200 Subject: Newbie question about text encoding References: <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <54fba9d4$0$12988$c3e8da3$5496439d@news.astraweb.com> <87y4n8uf9a.fsf@elektro.pacujo.net> Message-ID: <87twxvvrjl.fsf@elektro.pacujo.net> Chris Angelico : > Once again, you appear to be surprised that invalid data is failing. > Why is this so strange? U+DD00 is not a valid character. It is quite > correct to throw this error. '\udd00' is a valid str object: >>> '\udd00' '\udd00' >>> '\udd00'.encode('utf-32') b'\xff\xfe\x00\x00\x00\xdd\x00\x00' >>> '\udd00'.encode('utf-16') b'\xff\xfe\x00\xdd' I was simply stating that UTF-8 is not a bijection between unicode strings and octet strings (even forgetting Python). Enriching Unicode with 128 surrogates (U+DC80..U+DCFF) establishes a bijection, but not without side effects. Marko From rosuav at gmail.com Sun Mar 8 04:23:37 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 8 Mar 2015 19:23:37 +1100 Subject: Newbie question about text encoding In-Reply-To: <87twxvvrjl.fsf@elektro.pacujo.net> References: <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <54fba9d4$0$12988$c3e8da3$5496439d@news.astraweb.com> <87y4n8uf9a.fsf@elektro.pacujo.net> <87twxvvrjl.fsf@elektro.pacujo.net> Message-ID: On Sun, Mar 8, 2015 at 7:09 PM, Marko Rauhamaa wrote: > Chris Angelico : > >> Once again, you appear to be surprised that invalid data is failing. >> Why is this so strange? U+DD00 is not a valid character. It is quite >> correct to throw this error. > > '\udd00' is a valid str object: > > >>> '\udd00' > '\udd00' > >>> '\udd00'.encode('utf-32') > b'\xff\xfe\x00\x00\x00\xdd\x00\x00' > >>> '\udd00'.encode('utf-16') > b'\xff\xfe\x00\xdd' > > I was simply stating that UTF-8 is not a bijection between unicode > strings and octet strings (even forgetting Python). Enriching Unicode > with 128 surrogates (U+DC80..U+DCFF) establishes a bijection, but not > without side effects. But it's not a valid Unicode string, so a Unicode encoding can't be expected to cope with it. Mathematically, 0xC0 0x80 would represent U+0000, and some UTF-8 codecs generate and accept this (in order to allow U+0000 without ever yielding 0x00), but that doesn't mean that UTF-8 should allow that byte sequence. The only reason to craft some kind of Unicode string for any arbitrary sequence of bytes is the "smuggling" effect used for file name handling. There is no reason to support invalid Unicode codepoints. ChrisA From cs at zip.com.au Sun Mar 8 05:15:50 2015 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 8 Mar 2015 20:15:50 +1100 Subject: surprising exception text Message-ID: <20150308091550.GA26258@cskk.homeip.net> Gotta love this: TypeError: decoding with 'utf-8' codec failed (TypeError: '_io.BufferedReader' does not support the buffer interface) Not to worry:-) Cheers, Cameron Simpson The Design View editor of Visual InterDev 6.0 is currently incompatible with Compatibility Mode, and may not function correctly. - George Politis , 22apr1999, quoting http://msdn.microsoft.com/vstudio/technical/ie5.asp From monika786agrawal at gmail.com Sun Mar 8 07:52:37 2015 From: monika786agrawal at gmail.com (monika786agrawal at gmail.com) Date: Sun, 8 Mar 2015 04:52:37 -0700 (PDT) Subject: Become Microsoft Research Certified Message-ID: <05eb691e-3396-4976-b36e-fb7c080cf5c2@googlegroups.com> Microsoft Research India is excited to introduce MEC (short for "Massively Empowered Classrooms"), a research project designed to bring the highest quality classroom material to every undergraduate engineering student in India. Go to the website and get registered http://bit.ly/1BV3uI9 4 courses are currently being offered: Algorithms, Computer Networks, Data Structures and Theory of Computation. More courses may get added. Please check the home page for further course details. Based on the performance (completion of lessons, quizzes, forum participation), Microsoft Research will issue digital certificates to eligible students. To be eligible for digital certificate enter "monika20009 at ymail.com" in the referral code option of course signup page.Everything is free and available online. From breamoreboy at yahoo.co.uk Sun Mar 8 10:21:29 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 08 Mar 2015 14:21:29 +0000 Subject: surprising exception text In-Reply-To: <20150308091550.GA26258@cskk.homeip.net> References: <20150308091550.GA26258@cskk.homeip.net> Message-ID: On 08/03/2015 09:15, Cameron Simpson wrote: > Gotta love this: > > TypeError: decoding with 'utf-8' codec failed (TypeError: > '_io.BufferedReader' does not support the buffer interface) > > Not to worry:-) > > Cheers, > Cameron Simpson > What is the bug report number? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From lakshmipathi.g at gmail.com Sun Mar 8 12:51:27 2015 From: lakshmipathi.g at gmail.com (Lakshmipathi.G) Date: Sun, 8 Mar 2015 22:21:27 +0530 Subject: Adding a 'struct' into new python type In-Reply-To: References: Message-ID: Hi Jason, Thanks for the response. Okay, Will try to convert 'struct test' into new python object (say 'PyStructTest') and include it inside CountDictType as pyobject instead of 'struct'. Will post details here, If i encounter any issues. ---- Cheers, Lakshmipathi.G FOSS Programmer. www.giis.co.in/readme.html On Sat, Mar 7, 2015 at 9:23 PM, Jason Swails wrote: > > > On Sat, Mar 7, 2015 at 4:15 AM, Lakshmipathi.G > wrote: >> >> Hi, >> >> I'm following this example : >> http://nedbatchelder.com/text/whirlext.html#h_making_a_type and trying >> to add >> new data into 'CountDict' type >> >> Adding a simple 'char' works well. >> >> typedef struct { >> PyObject_HEAD >> PyObject * dict; >> int count; >> char c; //add this and placed an entry into PyMemberDef as T_CHAR. >> } CountDict; >> >> I can access 'c' from python code,no issues so far. >> >> Now I want to added 'struct type' into this 'CountDict' type. >> struct test { >> int x; >> }; >> >> typedef struct { >> PyObject_HEAD >> PyObject * dict; >> int count; >> char c; >> struct test t1; //?? how to add this >> } CountDict; >> >> >> >> How to do achieve this? (Due to legacy code dependency, I can't use >> ctype/cpython etc). >> thanks for any help/pointers. > > > The way *I* would do this is turn struct test into another Python object. > Then instead of defining it in CountDict as type "struct test", define it as > the PyStructTest that you assigned it to when you turned it into a Python > class. > > For example, in that website you linked to, CountDict was turned into a > CountDictType Python type. So do something similar to "test" in which you > turn it into a PyStructTest type in the same way. Then declare it as a > PyStructTest pointer instead of a struct test. > > I'm not sure you can get around an approach like this. I believe that in > order to access data from Python, it needs to be a Python type. The > struct-to-Python-type conversion *knows* how to translate basic types, like > char, double, float, int, and long into their Python equivalents; but it > can't handle something as potentially complicated as an arbitrary struct. > Of course, if all you want to do is access t1 from C, then I think what you > have is fine. > > Good luck, > Jason From polyvertex at gmail.com Sun Mar 8 13:57:45 2015 From: polyvertex at gmail.com (polyvertex at gmail.com) Date: Sun, 8 Mar 2015 10:57:45 -0700 (PDT) Subject: MSVC2013 In-Reply-To: References: <7ec7c58b-f021-4a21-bd26-a2c9030c6ba9@googlegroups.com> Message-ID: <51172c2b-5262-4d09-bee7-06ca3fdbddf4@googlegroups.com> On Saturday, March 7, 2015 at 5:36:07 PM UTC+1, Mark Lawrence wrote: > On 07/03/2015 15:55, polyvertex at gmail.com wrote: > > Out of curiosity, is there any plan to use a more recent version of Visual Studio (i.e.: 2013) to compile the official Python3 distribution for Windows? > > Is it in discussion? Maybe waiting for the 2015 version? > > > > I'm working on a C++ software that embeds Python3, currently compiled with MSVC2010 and would like to upgrade to MSVC2013, but it appears that, while being feasible, Python3 won't compile out of the box with that configuration. I would like to avoid that hassle if possible... > > > > Cheers, > > > > I'm building Python 3.5 every day with 2013 no problems at all, thanks > mainly to the work on the build system by Zach Ware and Steve Dower. If > 2015 is stable that will be used for 3.5 else we'll stick with 2013. > > -- > My fellow Pythonistas, ask not what our language can do for you, ask > what you can do for our language. > > Mark Lawrence For the record, I successfully compiled v3.5.0a1 (the latest 3.5 candidate as of today) with a fresh install of msvc2013. I ran the PCbuild/get_externals.bat script manually then opened the pcbuild.sln to launch a "Release/x64" build. Note that I had to launch the global build twice since the first one failed due to header not found during _tkinter build. Re-launching the global build without modifying any setting/property just did the job flawlessly. As a quick test, I copied the built binaries (python.exe, .dll and .pyd files) in a new directory, as well as the content of the Lib folder. Then I started an interpreter session and typed some random imports. It all worked like a charm. Thank you for your answers. From steve+comp.lang.python at pearwood.info Sun Mar 8 14:20:00 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 09 Mar 2015 05:20:00 +1100 Subject: surprising exception text References: <20150308091550.GA26258@cskk.homeip.net> Message-ID: <54fc92d0$0$13004$c3e8da3$5496439d@news.astraweb.com> Mark Lawrence wrote: > On 08/03/2015 09:15, Cameron Simpson wrote: >> Gotta love this: >> >> TypeError: decoding with 'utf-8' codec failed (TypeError: >> '_io.BufferedReader' does not support the buffer interface) >> >> Not to worry:-) >> >> Cheers, >> Cameron Simpson >> > > What is the bug report number? > Who said it was a bug? Cameron called it "surprising", not "wrong". -- Steven From steve+comp.lang.python at pearwood.info Sun Mar 8 14:25:02 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 09 Mar 2015 05:25:02 +1100 Subject: Newbie question about text encoding References: <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <54fba9d4$0$12988$c3e8da3$5496439d@news.astraweb.com> <87y4n8uf9a.fsf@elektro.pacujo.net> <87twxvvrjl.fsf@elektro.pacujo.net> Message-ID: <54fc9400$0$13009$c3e8da3$5496439d@news.astraweb.com> Marko Rauhamaa wrote: > Chris Angelico : > >> Once again, you appear to be surprised that invalid data is failing. >> Why is this so strange? U+DD00 is not a valid character. But it is a valid non-character code point. >> It is quite correct to throw this error. > > '\udd00' is a valid str object: Is it though? Perhaps the bug is not UTF-8's inability to encode lone surrogates, but that Python allows you to create lone surrogates in the first place. That's not a rhetorical question. It's a genuine question. > >>> '\udd00' > '\udd00' > >>> '\udd00'.encode('utf-32') > b'\xff\xfe\x00\x00\x00\xdd\x00\x00' > >>> '\udd00'.encode('utf-16') > b'\xff\xfe\x00\xdd' If you explicitly specify the endianness (say, utf-16-be or -le) then you don't get the BOMs. > I was simply stating that UTF-8 is not a bijection between unicode > strings and octet strings (even forgetting Python). Enriching Unicode > with 128 surrogates (U+DC80..U+DCFF) establishes a bijection, but not > without side effects. -- Steven From cfkaran2 at gmail.com Sun Mar 8 14:30:32 2015 From: cfkaran2 at gmail.com (Cem Karan) Date: Sun, 8 Mar 2015 14:30:32 -0400 Subject: Design thought for callbacks In-Reply-To: References: <33677AE8-B2FA-49F9-9304-C8D93784255D@gmail.com> <8A3659BC-9100-4A3A-9117-47227B3D290B@gmail.com> Message-ID: <5522439B-AEFA-400D-9B6F-00613528381F@gmail.com> Hi all, I apologize for taking so long to reply, but neither my work schedule nor the weather have been kind in the past week. That said, I've been thinking long and hard about what everyone has said, and have decided that it would be useful to write a wrap-up email that attempts to encapsulate everything everyone has said, as a record of sorts if nothing else. As such, this email is fairly long and involved. ======================= Analysis of the problem ======================= My original question was 'what is the least surprising/most pythonic way to write a callback API?' Through reading what everyone has said, I realized that I wasn't being specific enough, simply because callback APIs can be quite different. At the very least, the following questions need to be answered: 1) When a callback is registered, does it replace the prior callback? 2) If more than one callback can be registered, is there an ordering to them? 3) Can a callback be registered more than once? 4) When and how are callbacks deregistered? 5) Who is responsible for maintaining a strong reference to the callback? As far as I know, there isn't a standard method to indicate to the caller that one callback replaces another one except via well-written documentation. My personal feeling is that callbacks that replace other callbacks should be properties of the library. By implementing a setter, getter, and deleter for each callback, the library makes it obvious that there is one and only one callback active at a time. The only difficulty is making sure the user knows that the library retains the callback, but this is a documentation problem. I realized that ordering could be a problem when I read through the documentation to asyncio.call_soon(). It promises that callbacks will be called in the order in which they were registered. However, there are cases where the order doesn't matter. Registration in both of these cases is fairly simple; the former appends the callback to a list, while the latter adds it to a set. The list or set can be a property of the library, and registration is simply a matter of either inserting or adding. But this brings up point 3; if a callback can be registered at most once and ordering matters, then we need something that is both a sequence and a set. Subclassing either (or both) collections.abc.MutableSequence or collections.abc.MutableSet will lead to confusion due to unexpected violations of PEP 3119 (https://www.python.org/dev/peps/pep-3119/). Once again, the only option appears to be careful documentation. Registration is only half the problem. The other half is determining when a callback should be unregistered. Some callbacks are one-shots and are automatically unregistered as soon as they are called. Others will be called each time an event occurs until they are explicitly unregistered from the library. Which happens is another design choice that needs to be carefully documented. Finally, we come to the part that started my original question; who retains the callback. I had originally asked everyone if it would be surprising to store callbacks as weak references. The idea was that unless someone else maintained a strong reference to the callback, it would be garbage collected, which would save users from 'surprising' results such as the following: """ #! /usr/bin/env python class Callback_object(object): def __init__(self, msg): self._msg = msg def callback(self, stuff): print("From {0!s}: {1!s}".format(self._msg, stuff)) class Fake_library(object): def __init__(self): self._callbacks = list() def register_callback(self, callback): self._callbacks.append(callback) def execute_callbacks(self): for thing in self._callbacks: thing('Surprise!') if __name__ == "__main__": cbo = Callback_object("Evil Zombie") lib = Fake_library() lib.register_callback(cbo.callback) # Way later, after the user forgot all about the callback above cbo = Callback_object("Your Significant Other") lib.register_callback(cbo.callback) # And finally getting around to running all those callbacks. lib.execute_callbacks() """ However, as others pointed out using a weak reference could actually increase confusion rather than decrease it. The problem is that if there is a reference cycle elsewhere in the code, it is possible that the zombie object is still alive when it is supposed to be dead. This will likely be difficult to debug. In addition, different types of callables have different requirements in order to correctly store weak references to them. Both Ian Kelly and Fabio Zadrozny provided solutions to this, with Fabio providing a link to his code at http://pydev.blogspot.com.br/2015/02/design-for-client-side-applications-in.html. ==================================== Solution to my problem in particular ==================================== After considering all the comments above, I've decided to do the following for my API: - All callbacks will be strongly retained (no weakrefs). - Callbacks will be stored in a list, and the list will be exposed as a read-only property of the library. This will let users reorder callbacks as necessary, add them multiple times in a row, etc. I'm also hoping that by making it a list, it becomes obvious that the callback is strongly retained. - Finally, callbacks are not one-shots. This just happens to make sense for my code, but others may find other methods make more sense. Thanks again to everyone for providing so many comments on my question, and I apologize again for taking so long to wrap things up. Thanks, Cem Karan From steve+comp.lang.python at pearwood.info Sun Mar 8 14:30:45 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 09 Mar 2015 05:30:45 +1100 Subject: Newbie question about text encoding References: <201502241620.t1OGKf4n002146@fido.openend.se> <54ECB134.5090304@davea.name> <201502241945.t1OJjshO013092@fido.openend.se> <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <7cdb210c-c152-41a6-8afa-a0c0028f454e@googlegroups.com> Message-ID: <54fc9556$0$12994$c3e8da3$5496439d@news.astraweb.com> Rustom Mody wrote: > On Saturday, March 7, 2015 at 4:39:48 PM UTC+5:30, Steven D'Aprano wrote: >> Rustom Mody wrote: >> > This includes not just bug-prone-system code such as Java and Windows >> > but seemingly working code such as python 3. >> >> What Unicode bugs do you think Python 3.3 and above have? > > Literal/Legalistic answer: > https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2012-2135 Nice one :-) but not exactly in the spirit of what we're discussing (as you acknowledge below), so I won't discuss that. > [And already quoted at > http://blog.languager.org/2015/03/whimsical-unicode.html > ] > > An answer more in the spirit of what I am trying to say: > Idle3, Roy's example and in general all systems that are > python-centric but use components outside of python that are > unicode-broken > > IOW I would expect people (at least people with good faith) reading my > >> bug-prone-system code...seemingly working code such as python 3... > > to interpret that NOT as > > "python 3 is seemingly working but actually broken" Why not? That is the natural interpretation of the sentence, particularly in the context of your previous sentence: [quote] Or you can skip the blame-game and simply note the fact that large segments of extant code-bases are currently in bug-prone or plain buggy state. This includes not just bug-prone-system code such as Java and Windows but seemingly working code such as python 3. [end quote] The natural interpretation of this is that Python 3 is only *seemingly* working, but is also an example of a code base in "bug-prone or plain buggy state". If that's not your intended meaning, then rather than casting aspersions on my honesty ("good faith" indeed) you might accept that perhaps you didn't quite manage to get your message across. > But as > > "Apps made with working system code (eg python3) can end up being broken > because of other non-working system code - eg mysql, java, javascript, > windows-shell, and ultimately windows, linux" Don't forget viruses or other malware, cosmic rays, processor bugs, dry solder joints on the motherboard, faulty memory, and user-error. I'm not sure what point you think you are making. If you want to discuss the fact that complex systems have more interactions than simple systems, and therefore more ways for things to go wrong, I will agree. I'll agree that this is an issue with Python code that interacts with other systems which may or may not implement Unicode correctly. There are a few ways to interpret this: (1) You're making a general point about the complexity of modern computing. (2) You're making the point that dealing with text encodings in general, and Unicode in specific, is hard because of the interaction of programming language, database, file system, locale, etc. (3) You're implying that Python ought to fix this problem some how. (4) You're implying that *Unicode* specifically is uniquely problematic in this way. Or at least *unusual* to be problematic in this way. I will agree with 1 and 2; I'll say that 3 would be nice but in the absence of concrete proposals for how to fix it, it's just meaningless chatter. And I'll disagree strongly with 4. Unicode came into existence because legacy encodings suffer from similar problems, only worse. (One major advantage of Unicode over previous multi-byte encodings is that the UTF encodings are self-healing. A single corrupted byte will, *at worst*, cause a single corrupted code point.) In one sense, Unicode has solved these legacy encoding problems, in the sense that if you always use a correct implementation of Unicode then you won't *ever* suffer from problems like moji-bake, broken strings and so forth. In another sense, Unicode hasn't solved these legacy problems because we still have to deal with files using legacy encodings, as well as standards organisations, operating systems, developers, applications and users who continue to produce new content using legacy encodings, buggy or incorrect implementations of the standard, also viruses, cosmic rays, dry solder joints and user-error. How are these things Unicode's fault or responsibility? -- Steven From breamoreboy at yahoo.co.uk Sun Mar 8 14:50:50 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 08 Mar 2015 18:50:50 +0000 Subject: MSVC2013 In-Reply-To: <51172c2b-5262-4d09-bee7-06ca3fdbddf4@googlegroups.com> References: <7ec7c58b-f021-4a21-bd26-a2c9030c6ba9@googlegroups.com> <51172c2b-5262-4d09-bee7-06ca3fdbddf4@googlegroups.com> Message-ID: On 08/03/2015 17:57, polyvertex at gmail.com wrote: > On Saturday, March 7, 2015 at 5:36:07 PM UTC+1, Mark Lawrence wrote: >> On 07/03/2015 15:55, polyvertex at gmail.com wrote: >>> Out of curiosity, is there any plan to use a more recent version of Visual Studio (i.e.: 2013) to compile the official Python3 distribution for Windows? >>> Is it in discussion? Maybe waiting for the 2015 version? >>> >>> I'm working on a C++ software that embeds Python3, currently compiled with MSVC2010 and would like to upgrade to MSVC2013, but it appears that, while being feasible, Python3 won't compile out of the box with that configuration. I would like to avoid that hassle if possible... >>> >>> Cheers, >>> >> >> I'm building Python 3.5 every day with 2013 no problems at all, thanks >> mainly to the work on the build system by Zach Ware and Steve Dower. If >> 2015 is stable that will be used for 3.5 else we'll stick with 2013. >> >> -- >> My fellow Pythonistas, ask not what our language can do for you, ask >> what you can do for our language. >> >> Mark Lawrence > > For the record, I successfully compiled v3.5.0a1 (the latest 3.5 candidate as of today) with a fresh install of msvc2013. I ran the PCbuild/get_externals.bat script manually then opened the pcbuild.sln to launch a "Release/x64" build. > > Note that I had to launch the global build twice since the first one failed due to header not found during _tkinter build. Re-launching the global build without modifying any setting/property just did the job flawlessly. > http://bugs.python.org/issue23452 > As a quick test, I copied the built binaries (python.exe, .dll and .pyd files) in a new directory, as well as the content of the Lib folder. Then I started an interpreter session and typed some random imports. It all worked like a charm. > > Thank you for your answers. > No problem :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Sun Mar 8 14:52:53 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 08 Mar 2015 18:52:53 +0000 Subject: surprising exception text In-Reply-To: <54fc92d0$0$13004$c3e8da3$5496439d@news.astraweb.com> References: <20150308091550.GA26258@cskk.homeip.net> <54fc92d0$0$13004$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 08/03/2015 18:20, Steven D'Aprano wrote: > Mark Lawrence wrote: > >> On 08/03/2015 09:15, Cameron Simpson wrote: >>> Gotta love this: >>> >>> TypeError: decoding with 'utf-8' codec failed (TypeError: >>> '_io.BufferedReader' does not support the buffer interface) >>> >>> Not to worry:-) >>> >>> Cheers, >>> Cameron Simpson >>> >> >> What is the bug report number? >> > > > Who said it was a bug? Cameron called it "surprising", not "wrong". > s/bug/issue/ -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From info at parcheto.ch Sun Mar 8 15:24:12 2015 From: info at parcheto.ch (Michael Parchet) Date: Sun, 08 Mar 2015 20:24:12 +0100 Subject: Visual kalendar like korganizer or evolution calendaar (outlook calendar) a print priview and enventualy an adressbook Message-ID: <54FCA1DC.1030106@parcheto.ch> Hello, I am working with pyqt framework and i'm looking for a calendar (organizer) like korganizer, evolution or outlook calendar that is OS ind??pendent with recurrence event. writting in python with an UI framework (ex pyqt, pygtk, wkpython, tkinter or other ui framwork) Where could I find it ? I'm also loocking for a print preview and eventual an addressbook. Could your help me please ? Best regards mparchet From marko at pacujo.net Sun Mar 8 16:09:08 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 08 Mar 2015 22:09:08 +0200 Subject: Newbie question about text encoding References: <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <54fba9d4$0$12988$c3e8da3$5496439d@news.astraweb.com> <87y4n8uf9a.fsf@elektro.pacujo.net> <87twxvvrjl.fsf@elektro.pacujo.net> <54fc9400$0$13009$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87d24juu8r.fsf@elektro.pacujo.net> Steven D'Aprano : > Marko Rauhamaa wrote: >> '\udd00' is a valid str object: > > Is it though? Perhaps the bug is not UTF-8's inability to encode lone > surrogates, but that Python allows you to create lone surrogates in > the first place. That's not a rhetorical question. It's a genuine > question. The problem is that no matter how you shuffle surrogates, encoding schemes, coding points and the like, a wrinkle always remains. I'm reminded of number sets where you go from ? to ? to ? to ? to ?. But that's where the buck stops; traditional arithmetic functions are closed under ?. Unicode apparently hasn't found a similar closure. That's why I think that while UTF-8 is a fabulous way to bring Unicode to Linux, Linux should have taken the tack that Unicode is always an application-level interpretation with few operating system tie-ins. Unfortunately, the GNU world is busy trying to build a Unicode frosting everywhere. The illusion can never be complete but is convincing enough for application developers to forget to handle corner cases. To answer your question, I think every code point from 0 to 1114111 should be treated as valid and analogous. Thus Python is correct here: >>> len('\udd00') 1 >>> len('\ufeff') 1 The alternatives are far too messy to consider. Marko From ginellobadellu at mail.com Sun Mar 8 16:14:20 2015 From: ginellobadellu at mail.com (REVOLUCIOOON!) Date: Sun, 8 Mar 2015 13:14:20 -0700 (PDT) Subject: -- redacted -- In-Reply-To: <4f5ceab4-d175-4b96-829b-8c8fab7f77f0@googlegroups.com> References: <4f5ceab4-d175-4b96-829b-8c8fab7f77f0@googlegroups.com> Message-ID: -- redacted -- From ginellobadellu at mail.com Sun Mar 8 16:15:36 2015 From: ginellobadellu at mail.com (REVOLUCIOOON!) Date: Sun, 8 Mar 2015 13:15:36 -0700 (PDT) Subject: -- redacted -- Message-ID: <76d6b00b-d8fa-437a-9b0a-0c5e1170e67f@googlegroups.com> -- redacted -- From rosuav at gmail.com Sun Mar 8 16:55:44 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 Mar 2015 07:55:44 +1100 Subject: Newbie question about text encoding In-Reply-To: <54fc9400$0$13009$c3e8da3$5496439d@news.astraweb.com> References: <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <54fba9d4$0$12988$c3e8da3$5496439d@news.astraweb.com> <87y4n8uf9a.fsf@elektro.pacujo.net> <87twxvvrjl.fsf@elektro.pacujo.net> <54fc9400$0$13009$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Mar 9, 2015 at 5:25 AM, Steven D'Aprano wrote: > Marko Rauhamaa wrote: > >> Chris Angelico : >> >>> Once again, you appear to be surprised that invalid data is failing. >>> Why is this so strange? U+DD00 is not a valid character. > > But it is a valid non-character code point. > >>> It is quite correct to throw this error. >> >> '\udd00' is a valid str object: > > Is it though? Perhaps the bug is not UTF-8's inability to encode lone > surrogates, but that Python allows you to create lone surrogates in the > first place. That's not a rhetorical question. It's a genuine question. Ah, I see the confusion. Yes, it is plausible to permit the UTF-8-like encoding of surrogates; but it's illegal according to the RFC: https://tools.ietf.org/html/rfc3629 """ The definition of UTF-8 prohibits encoding character numbers between U+D800 and U+DFFF, which are reserved for use with the UTF-16 encoding form (as surrogate pairs) and do not directly represent characters. """ They're not valid characters, and the UTF-8 spec explicitly says that they must not be encoded. Python is fully spec-compliant in rejecting these. Some encoders [1] will permit them, but the resulting stream is invalid UTF-8, just as CESU-8 and Modified UTF-8 are (the latter being "UTF-8, only U+0000 is represented as C0 80"). ChrisA [1] eg http://pike.lysator.liu.se/generated/manual/modref/ex/predef_3A_3A/string_to_utf8.html optionally From rosuav at gmail.com Sun Mar 8 17:13:48 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 Mar 2015 08:13:48 +1100 Subject: Newbie question about text encoding In-Reply-To: <54fc9400$0$13009$c3e8da3$5496439d@news.astraweb.com> References: <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <54fba9d4$0$12988$c3e8da3$5496439d@news.astraweb.com> <87y4n8uf9a.fsf@elektro.pacujo.net> <87twxvvrjl.fsf@elektro.pacujo.net> <54fc9400$0$13009$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Mar 9, 2015 at 5:25 AM, Steven D'Aprano wrote: > Perhaps the bug is not UTF-8's inability to encode lone > surrogates, but that Python allows you to create lone surrogates in the > first place. That's not a rhetorical question. It's a genuine question. As to the notion of rejecting the construction of strings containing these invalid codepoints, I'm not sure. Are there any languages out there that have a Unicode string type that requires that all codepoints be valid (no surrogates, no U+FFFE, etc)? This is the kind of thing that's usually done in an obscure language before it hits a mainstream one. Pike is similar to Python here. I can create a string with invalid code points in it: > "\uFFFE\uDD00"; (1) Result: "\ufffe\udd00" but I can't UTF-8 encode that: > string_to_utf8("\uFFFE\uDD00"); Character 0x0000dd00 at index 1 is in the surrogate range and therefore invalid. Unknown program: string_to_utf8("\ufffe\udd00") HilfeInput:1: HilfeInput()->___HilfeWrapper() Or, using the streaming UTF-8 encoder instead of the short-hand: > Charset.encoder("UTF-8")->feed("\uFFFE\uDD00")->drain(); Error encoding "\ufffe"[0xdd00] using utf8: Unsupported character 56576. /usr/local/pike/8.1.0/lib/modules/_Charset.so:1: _Charset.UTF8enc()->feed("\ufffe\udd00") HilfeInput:1: HilfeInput()->___HilfeWrapper() Does anyone know of a language where you can't even construct the string? ChrisA From rosuav at gmail.com Sun Mar 8 17:15:27 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 Mar 2015 08:15:27 +1100 Subject: Opaque error message on UTF-8 decode Message-ID: >>> b"\xed\xb4\x80".decode() Traceback (most recent call last): File "", line 1, in UnicodeDecodeError: 'utf-8' codec can't decode byte 0xed in position 0: invalid continuation byte But 0xED is not a continuation byte, it's a start byte. And it's a perfectly valid one: >>> b"\xed\x9f\xbf".decode() '\ud7ff' Pike is more explicit about what the problem is: > utf8_to_string("\xed\xb4\x80"); UTF-8 sequence beginning with 0xed 0xb4 at index 0 would decode to a UTF-16 surrogate character. Is this something where Python's error message could do with improvement, or is it not worth the hassle? Should I raise a tracker issue about this? ChrisA From breamoreboy at yahoo.co.uk Sun Mar 8 17:23:50 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 08 Mar 2015 21:23:50 +0000 Subject: Opaque error message on UTF-8 decode In-Reply-To: References: Message-ID: On 08/03/2015 21:15, Chris Angelico wrote: >>>> b"\xed\xb4\x80".decode() > Traceback (most recent call last): > File "", line 1, in > UnicodeDecodeError: 'utf-8' codec can't decode byte 0xed in position > 0: invalid continuation byte > > But 0xED is not a continuation byte, it's a start byte. And it's a > perfectly valid one: > >>>> b"\xed\x9f\xbf".decode() > '\ud7ff' > > Pike is more explicit about what the problem is: > >> utf8_to_string("\xed\xb4\x80"); > UTF-8 sequence beginning with 0xed 0xb4 at index 0 would decode to a > UTF-16 surrogate character. > > Is this something where Python's error message could do with > improvement, or is it not worth the hassle? Should I raise a tracker > issue about this? > > ChrisA > I'd raise an issue so there's a formal record that we can refer to in the future. Besides what's one issue like this compared to the "Python can't do decimal sums properly" which gets raised every few months by newbies :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rosuav at gmail.com Sun Mar 8 17:36:53 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 Mar 2015 08:36:53 +1100 Subject: Opaque error message on UTF-8 decode In-Reply-To: References: Message-ID: On Mon, Mar 9, 2015 at 8:23 AM, Mark Lawrence wrote: > I'd raise an issue so there's a formal record that we can refer to in the > future. Besides what's one issue like this compared to the "Python can't do > decimal sums properly" which gets raised every few months by newbies :) http://bugs.python.org/issue23614 ChrisA From mparchet at sunrise.ch Sun Mar 8 17:43:24 2015 From: mparchet at sunrise.ch (Michael Parchet) Date: Sun, 08 Mar 2015 22:43:24 +0100 Subject: Visual kalendar like korganizer or evolution calendaar (outlook calendar) a print priview and enventualy an adressbook In-Reply-To: <54FCA1DC.1030106@parcheto.ch> References: <54FCA1DC.1030106@parcheto.ch> Message-ID: <54FCC27C.1080609@sunrise.ch> Hello, I am working with pyqt framework and i'm looking for a calendar (organizer) like korganizer, evolution or outlook calendar that is OS ind??pendent with recurrence event. writting in python with an UI framework (ex pyqt, pygtk, wkpython, tkinter or other ui framwork) Where could I find it ? I'm also loocking for a print preview and eventual an addressbook. Could your help me please ? Best regards mparchet From cs at zip.com.au Sun Mar 8 18:56:17 2015 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 9 Mar 2015 09:56:17 +1100 Subject: surprising exception text In-Reply-To: References: Message-ID: <20150308225617.GA92557@cskk.homeip.net> On 08Mar2015 18:52, Mark Lawrence wrote: >On 08/03/2015 18:20, Steven D'Aprano wrote: >>Mark Lawrence wrote: >>>On 08/03/2015 09:15, Cameron Simpson wrote: >>>>Gotta love this: >>>> >>>>TypeError: decoding with 'utf-8' codec failed (TypeError: >>>>'_io.BufferedReader' does not support the buffer interface) >>>> >>>>Not to worry:-) >>> >>>What is the bug report number? >> >>Who said it was a bug? Cameron called it "surprising", not "wrong". > >s/bug/issue/ It isn't an issue. The exception text make perfect sense and I can't think of anything I would actually change given what my code was doing wrong. I just thought it entertaining. Cheers, Cameron Simpson It's a, I say it's a *joke* son. Don't cha get it? You're built too short, the good ones go over yer head. Ya got a hole in yer glove, boy, I keep pitching them and you keep missing them. Ya gotta keep yer eye on the ball, son. Eye. Ball. Eyeball. I almost had a funny there. Joke, that is. - Foghorn Leghorn, as referenced by Dan Sorenson in rec.motorcycles From breamoreboy at yahoo.co.uk Sun Mar 8 19:52:24 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 08 Mar 2015 23:52:24 +0000 Subject: surprising exception text In-Reply-To: <20150308225617.GA92557@cskk.homeip.net> References: <20150308225617.GA92557@cskk.homeip.net> Message-ID: On 08/03/2015 22:56, Cameron Simpson wrote: > On 08Mar2015 18:52, Mark Lawrence wrote: >> On 08/03/2015 18:20, Steven D'Aprano wrote: >>> Mark Lawrence wrote: >>>> On 08/03/2015 09:15, Cameron Simpson wrote: >>>>> Gotta love this: >>>>> >>>>> TypeError: decoding with 'utf-8' codec failed (TypeError: >>>>> '_io.BufferedReader' does not support the buffer interface) >>>>> >>>>> Not to worry:-) >>>> >>>> What is the bug report number? >>> >>> Who said it was a bug? Cameron called it "surprising", not "wrong". >> >> s/bug/issue/ > > It isn't an issue. The exception text make perfect sense and I can't > think of anything I would actually change given what my code was doing > wrong. > > I just thought it entertaining. > Well I can't make head nor tail out of it, might as well be Double Dutch or is that Double UK English? :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From steve+comp.lang.python at pearwood.info Sun Mar 8 21:43:27 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 09 Mar 2015 12:43:27 +1100 Subject: Newbie question about text encoding References: <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <54fba9d4$0$12988$c3e8da3$5496439d@news.astraweb.com> <87y4n8uf9a.fsf@elektro.pacujo.net> <87twxvvrjl.fsf@elektro.pacujo.net> <54fc9400$0$13009$c3e8da3$5496439d@news.astraweb.com> <87d24juu8r.fsf@elektro.pacujo.net> Message-ID: <54fcfac0$0$12995$c3e8da3$5496439d@news.astraweb.com> Marko Rauhamaa wrote: > Steven D'Aprano : > >> Marko Rauhamaa wrote: >>> '\udd00' is a valid str object: >> >> Is it though? Perhaps the bug is not UTF-8's inability to encode lone >> surrogates, but that Python allows you to create lone surrogates in >> the first place. That's not a rhetorical question. It's a genuine >> question. > > The problem is that no matter how you shuffle surrogates, encoding > schemes, coding points and the like, a wrinkle always remains. Really? Define your terms. Can you define "wrinkles", and prove that it is impossible to remove them? What's so bad about wrinkles anyway? > I'm reminded of number sets where you go from ? to ? to ? to ? to ?. But > that's where the buck stops; traditional arithmetic functions are closed > under ?. That's simply incorrect. What's z/(0+0i)? There are many more number sets used by mathematicians, some going back to the 1800s. Here are just a few: * ?-overbar or [??, +?], which adds a pair of infinities to ?. * ?-caret or ?+{?}, which does the same but with a single unsigned infinity. * A similar extended version of ? with a single infinity. * Split-complex or hyperbolic numbers, defined similarly to ? except with i**2 = +1 (rather than the complex i**2 = -1). * Dual numbers, which add a single infinitesimal number ? != 0 with the property that ?**2 = 0. * Hyperreal numbers. * John Conway's surreal numbers, which may be the largest possible set, in the sense that it can construct all finite, infinite and infinitesimal numbers. (The hyperreals and dual numbers can be considered subsets of the surreals.) The process of extending ? to ? is formally known as Cayley?Dickson construction, and there is an infinite number of algebras (and hence number sets) which can be constructed this way. The next few are: * Hamilton's quaternions ?, very useful for dealing with rotations in 3D space. They fell out of favour for some decades, but are now experiencing something of a renaissance. * Octonions or Cayley numbers. * Sedenions. > Unicode apparently hasn't found a similar closure. Similar in what way? And why do you think this is important? It is not a requirement for every possible byte sequence to be a valid Unicode string, any more than it is a requirement for every possible byte sequence to be valid JPG, zip archive, or ELF executable. Some byte strings simply are not JPG images, zip archives or ELF executables -- or Unicode strings. So what? Why do you think that is a problem that needs fixing by the Unicode standard? It may be a problem that needs fixing by (for example) programming languages, and Python invented the surrogatesescape encoding to smuggle such invalid bytes into strings. Other solutions may exist as well. But that's not part of Unicode and it isn't a problem for Unicode. > That's why I think that while UTF-8 is a fabulous way to bring Unicode > to Linux, Linux should have taken the tack that Unicode is always an > application-level interpretation with few operating system tie-ins. "Should have"? That is *exactly* the status quo, and while it was the only practical solution given Linux's history, it's a horrible idea. That Unicode is stuck on top of an OS which is unaware of Unicode is precisely why we're left with problems like "how do you represent arbitrary bytes as Unicode strings?". > Unfortunately, the GNU world is busy trying to build a Unicode frosting > everywhere. The illusion can never be complete but is convincing enough > for application developers to forget to handle corner cases. > > To answer your question, I think every code point from 0 to 1114111 > should be treated as valid and analogous. Your opinion isn't very relevant. What is relevant is what the Unicode standard demands, and I think it requires that strings containing surrogates are illegal (rather like x/0 is illegal in the real numbers). Wikipedia states: The Unicode standard permanently reserves these code point values [U+D800 to U+DFFF] for UTF-16 encoding of the high and low surrogates, and they will never be assigned a character, so there should be no reason to encode them. The official Unicode standard says that no UTF forms, including UTF-16, can encode these code points. However UCS-2, UTF-8, and UTF-32 can encode these code points in trivial and obvious ways, and large amounts of software does so even though the standard states that such arrangements should be treated as encoding errors. It is possible to unambiguously encode them in UTF-16 by using a code unit equal to the code point, as long as no sequence of two code units can be interpreted as a legal surrogate pair (that is, as long as a high surrogate is never followed by a low surrogate). The majority of UTF-16 encoder and decoder implementations translate between encodings as though this were the case. http://en.wikipedia.org/wiki/UTF-16 So yet again we are left with the conclusion that *buggy implementations* of Unicode cause problems, not the Unicode standard itself. > Thus Python is correct here: > > >>> len('\udd00') > 1 > >>> len('\ufeff') > 1 > > The alternatives are far too messy to consider. Not at all. '\udd00' should be a SyntaxError. -- Steven From cs at zip.com.au Sun Mar 8 22:09:22 2015 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 9 Mar 2015 13:09:22 +1100 Subject: Newbie question about text encoding In-Reply-To: <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> References: <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20150309020922.GA69240@cskk.homeip.net> On 07Mar2015 22:09, Steven D'Aprano wrote: >Rustom Mody wrote: >>[...big snip...] >> Some parts are here some earlier and from my memory. >> If details wrong please correct: >> - 200 million records >> - Containing 4 strings with SMP characters >> - System made with python and mysql. SMP works with python, breaks mysql. >> So whole system broke due to those 4 in 200,000,000 records > >No, they broke because MySQL has buggy Unicode handling. [...] >> You could also choose do with "astral crap" (Roy's words) what we all do >> with crap -- throw it out as early as possible. > >And when Roy's customers demand that his product support emoji, or complain >that they cannot spell their own name because of his parochial and ignorant >idea of "crap", perhaps he will consider doing what he should have done >from the beginning: > >Stop using MySQL, which is a joke of a database[1], and use Postgres which >does not have this problem. > >[1] So I have been told. I use MySQL a fair bit, and Postgres very slightly. I would agree with your characterisation above; MySQL is littered with inconsistencies and arbitrary breakage, both in tools and SQL implementation. And Postgres has been a pure pleasure to work with, little though I have done that so far. Cheers, Cameron Simpson There is no human problem which could not be solved if people would simply do as I advise. - Gore Vidal From ben+python at benfinney.id.au Sun Mar 8 22:09:26 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 09 Mar 2015 13:09:26 +1100 Subject: Newbie question about text encoding References: <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <54fba9d4$0$12988$c3e8da3$5496439d@news.astraweb.com> <87y4n8uf9a.fsf@elektro.pacujo.net> <87twxvvrjl.fsf@elektro.pacujo.net> <54fc9400$0$13009$c3e8da3$5496439d@news.astraweb.com> <87d24juu8r.fsf@elektro.pacujo.net> <54fcfac0$0$12995$c3e8da3$5496439d@news.astraweb.com> Message-ID: <85y4n6x6p5.fsf@benfinney.id.au> Steven D'Aprano writes: > '\udd00' should be a SyntaxError. I find your argument convincing, that attempting to construct a Unicode string of a lone surrogate should be an error. Shouldn't the error type be a ValueError, though? The statement is not, to my mind, erroneous syntax. -- \ ?Please do not feed the animals. If you have any suitable food, | `\ give it to the guard on duty.? ?zoo, Budapest | _o__) | Ben Finney From rosuav at gmail.com Sun Mar 8 22:18:38 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 Mar 2015 13:18:38 +1100 Subject: Newbie question about text encoding In-Reply-To: <85y4n6x6p5.fsf@benfinney.id.au> References: <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <54fba9d4$0$12988$c3e8da3$5496439d@news.astraweb.com> <87y4n8uf9a.fsf@elektro.pacujo.net> <87twxvvrjl.fsf@elektro.pacujo.net> <54fc9400$0$13009$c3e8da3$5496439d@news.astraweb.com> <87d24juu8r.fsf@elektro.pacujo.net> <54fcfac0$0$12995$c3e8da3$5496439d@news.astraweb.com> <85y4n6x6p5.fsf@benfinney.id.au> Message-ID: On Mon, Mar 9, 2015 at 1:09 PM, Ben Finney wrote: > Steven D'Aprano writes: > >> '\udd00' should be a SyntaxError. > > I find your argument convincing, that attempting to construct a Unicode > string of a lone surrogate should be an error. > > Shouldn't the error type be a ValueError, though? The statement is not, > to my mind, erroneous syntax. For the string literal, I would say SyntaxError is more appropriate than ValueError, as a string object has to be constructed at compilation time. I'd still like to see a report from someone who has used a language that specifically disallows all surrogates in strings. Does it help? Is it more hassle than it's worth? Are there weird edge cases that it breaks? ChrisA From rustompmody at gmail.com Sun Mar 8 22:42:36 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 8 Mar 2015 19:42:36 -0700 (PDT) Subject: Newbie question about text encoding In-Reply-To: References: <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Monday, March 9, 2015 at 7:39:42 AM UTC+5:30, Cameron Simpson wrote: > On 07Mar2015 22:09, Steven D'Aprano wrote: > >Rustom Mody wrote: > >>[...big snip...] > >> Some parts are here some earlier and from my memory. > >> If details wrong please correct: > >> - 200 million records > >> - Containing 4 strings with SMP characters > >> - System made with python and mysql. SMP works with python, breaks mysql. > >> So whole system broke due to those 4 in 200,000,000 records > > > >No, they broke because MySQL has buggy Unicode handling. > [...] > >> You could also choose do with "astral crap" (Roy's words) what we all do > >> with crap -- throw it out as early as possible. > > > >And when Roy's customers demand that his product support emoji, or complain > >that they cannot spell their own name because of his parochial and ignorant > >idea of "crap", perhaps he will consider doing what he should have done > >from the beginning: > > > >Stop using MySQL, which is a joke of a database[1], and use Postgres which > >does not have this problem. > > > >[1] So I have been told. > > I use MySQL a fair bit, and Postgres very slightly. I would agree with your > characterisation above; MySQL is littered with inconsistencies and arbitrary > breakage, both in tools and SQL implementation. And Postgres has been a pure > pleasure to work with, little though I have done that so far. > > Cheers, > Cameron Simpson > > There is no human problem which could not be solved if people would simply > do as I advise. - Gore Vidal I think that last quote sums up the issue best. Ive written to Intel asking them to make their next generation have 21-bit wide bytes. Once they do that we will be back in the paradise we have been for the last 40 years which I call the 'Unix-assumption' http://blog.languager.org/2014/04/unicode-and-unix-assumption.html Until then... We have to continue living in the real world. Which includes 10 times more windows than linux users. Is windows 10 times better an OS than linux? In the 'real world' people make choices for all sorts of reasons. My guess is the top reason is the pointiness of the hair of pointy-haired-boss. Just like people choose windows over linux, people choose mysql over postgres, and that's the context of this discussion -- people stuck in sub-optimal choices From random832 at fastmail.us Mon Mar 9 00:27:56 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Mon, 09 Mar 2015 00:27:56 -0400 Subject: Newbie question about text encoding In-Reply-To: <85y4n6x6p5.fsf@benfinney.id.au> References: <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <54fba9d4$0$12988$c3e8da3$5496439d@news.astraweb.com> <87y4n8uf9a.fsf@elektro.pacujo.net> <87twxvvrjl.fsf@elektro.pacujo.net> <54fc9400$0$13009$c3e8da3$5496439d@news.astraweb.com> <87d24juu8r.fsf@elektro.pacujo.net> <54fcfac0$0$12995$c3e8da3$5496439d@news.astraweb.com> <85y4n6x6p5.fsf@benfinney.id.au> Message-ID: <1425875276.984461.237675405.1C95E1BF@webmail.messagingengine.com> On Sun, Mar 8, 2015, at 22:09, Ben Finney wrote: > Steven D'Aprano writes: > > > '\udd00' should be a SyntaxError. > > I find your argument convincing, that attempting to construct a Unicode > string of a lone surrogate should be an error. > > Shouldn't the error type be a ValueError, though? The statement is not, > to my mind, erroneous syntax. In this hypothetical, it's a problem with evaluating a literal - in the same way that '\U12345', or '\U00110000, is. From jven2eri at gmail.com Mon Mar 9 01:11:07 2015 From: jven2eri at gmail.com (Jason Venneri) Date: Sun, 8 Mar 2015 22:11:07 -0700 Subject: Append a file In-Reply-To: References: Message-ID: Jason; Thank you for your response. I?m just starting out with Python and the tutorials I have done are on 2.7.9. I will looking on to python3. It is preloaded on Mac :-). Jason _______________________________ jv92109 at gmail.com 619-227-0927 > On Mar 6, 2015, at 9:37 PM, Jason Friedman wrote: > > On Fri, Mar 6, 2015 at 2:55 PM, Jason Venneri wrote: >> Hello, I'm using the urllib.urlretrieve command to retrieve a couple of lines of data. I want to combine the two results into one file not two. >> >> Any suggestions? >> >> Sample >> urllib.urlretrieve('http://www.airplanes.com/data/boeing1.html','B747A.txt') >> urllib.urlretrieve('http://www.airplanes.com/data/boeing2.html','B747B.txt') >> >> I would like one file say B747C that contains the data from B747A and B747B in a file named B747C > >>>> f = open("B747C.txt", "w") >>>> look_for = "Aircraft," >>>> for line in open("B747A.txt"): > ... if look_for in line: > ... f.write(line) > ... >>>> for line in open("B747B.txt"): > ... if look_for in line: > ... f.write(line) > ... >>>> f.close() > > Seems like you are using Python 2, you ought to consider Python 3. > > The requests module > (http://docs.python-requests.org/en/latest/user/install/) makes this > kind of work easier. From marko at pacujo.net Mon Mar 9 02:31:28 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 09 Mar 2015 08:31:28 +0200 Subject: Newbie question about text encoding References: <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <54fba9d4$0$12988$c3e8da3$5496439d@news.astraweb.com> <87y4n8uf9a.fsf@elektro.pacujo.net> <87twxvvrjl.fsf@elektro.pacujo.net> <54fc9400$0$13009$c3e8da3$5496439d@news.astraweb.com> <87d24juu8r.fsf@elektro.pacujo.net> <54fcfac0$0$12995$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87zj7mu1fj.fsf@elektro.pacujo.net> Ben Finney : > Steven D'Aprano writes: > >> '\udd00' should be a SyntaxError. > > I find your argument convincing, that attempting to construct a > Unicode string of a lone surrogate should be an error. Then we're back to square one: >>> b'\x80'.decode('utf-8', errors='surrogateescape') '\udc80' Marko From steve+comp.lang.python at pearwood.info Mon Mar 9 02:34:55 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 09 Mar 2015 17:34:55 +1100 Subject: Newbie question about text encoding References: <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <54fba9d4$0$12988$c3e8da3$5496439d@news.astraweb.com> <87y4n8uf9a.fsf@elektro.pacujo.net> <87twxvvrjl.fsf@elektro.pacujo.net> <54fc9400$0$13009$c3e8da3$5496439d@news.astraweb.com> Message-ID: <54fd3f10$0$12977$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > As to the notion of rejecting the construction of strings containing > these invalid codepoints, I'm not sure. Are there any languages out > there that have a Unicode string type that requires that all > codepoints be valid (no surrogates, no U+FFFE, etc)? U+FFFE and U+FFFF are *noncharacters*, not invalid. There are a total of 66 noncharacters in Unicode, and they are legal in strings. http://www.unicode.org/faq/private_use.html#nonchar8 I think the only illegal code points are surrogates. Surrogates should only appear as bytes in UTF-16 byte-strings. -- Steven From mparchet at sunrise.ch Mon Mar 9 02:37:04 2015 From: mparchet at sunrise.ch (Michael Parchet) Date: Mon, 9 Mar 2015 07:37:04 +0100 Subject: Visual calendar like korganizer or evolution calendaar (outlook calendar) a print priview and enventualy an adressbook References: <54FCC27C.1080609@sunrise.ch> Message-ID: > > Hello, > I am working with pyqt framework and i'm looking for a calendar (organizer) like korganizer, evolution or outlook calendar that is OS ind??pendent with recurrence event. writting in python with an UI framework (ex pyqt, pygtk, wkpython, tkinter or other ui framwork) Where could I find it ? > > I'm also loocking for a print preview and eventual an addressbook. > > Could your help me please ? > > Best regards > > mparchet > From rosuav at gmail.com Mon Mar 9 02:44:54 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 Mar 2015 17:44:54 +1100 Subject: Newbie question about text encoding In-Reply-To: <54fd3f10$0$12977$c3e8da3$5496439d@news.astraweb.com> References: <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <54fba9d4$0$12988$c3e8da3$5496439d@news.astraweb.com> <87y4n8uf9a.fsf@elektro.pacujo.net> <87twxvvrjl.fsf@elektro.pacujo.net> <54fc9400$0$13009$c3e8da3$5496439d@news.astraweb.com> <54fd3f10$0$12977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Mar 9, 2015 at 5:34 PM, Steven D'Aprano wrote: > Chris Angelico wrote: > >> As to the notion of rejecting the construction of strings containing >> these invalid codepoints, I'm not sure. Are there any languages out >> there that have a Unicode string type that requires that all >> codepoints be valid (no surrogates, no U+FFFE, etc)? > > U+FFFE and U+FFFF are *noncharacters*, not invalid. There are a total of 66 > noncharacters in Unicode, and they are legal in strings. > > http://www.unicode.org/faq/private_use.html#nonchar8 > > I think the only illegal code points are surrogates. Surrogates should only > appear as bytes in UTF-16 byte-strings. U+FFFE would cause problems at the beginning of a UTF-16 stream, as it could be mistaken for a BOM - that's why it's a noncharacter. But sure, let's leave them out of the discussion. The question is whether surrogates are legal or not. ChrisA From larry at hastings.org Mon Mar 9 05:34:50 2015 From: larry at hastings.org (Larry Hastings) Date: Mon, 09 Mar 2015 02:34:50 -0700 Subject: [RELEASED] Python 3.5.0a2 is now available Message-ID: <54FD693A.5010704@hastings.org> On behalf of the Python development community and the Python 3.5 release team, I'm thrilled to announce the availability of Python 3.5.0a2. Python 3.5.0a2 is the second alpha release of Python 3.5, which will be the next major release of Python. Python 3.5 is still under heavy development, and is far from complete. This is a preview release, and its use is not recommended for production settings. Two important notes for Windows users about Python 3.5.0a2: * If you have previously installed Python 3.5.0a1, you must manually uninstall it before installing Python 3.5.0a2 (issue23612). * If installing Python 3.5.0a2 as a non-privileged user, you may need to escalate to administrator privileges to install an update to your C runtime libraries. You can find Python 3.5.0a2 here: https://www.python.org/downloads/release/python-350a2/ Happy hacking, //arry/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From vlastimil.brom at gmail.com Mon Mar 9 05:46:34 2015 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Mon, 9 Mar 2015 10:46:34 +0100 Subject: conditional sys.excepthook (outside of the interactive interpreter)? Message-ID: Hi all, I'd like to as for advise about posibilities of redirecting error traceback via sys.excepthook in a gui (wxpython in my case) with a requirement, that the errors from the code typed in the interactive interpreter (as part of my app) are printed there directly and are not catched from the excepthook. This worked in python 2.7, but was apparently changed for py 3 (3.4 in my case). Now, in the underlying library module the excepthook function is explicitly called: ... \Python34\Lib\code.py def showtraceback(self): [...] finally: tblist = tb = None if sys.excepthook is sys.__excepthook__: self.write(''.join(lines)) else: # If someone has set sys.excepthook, we let that take precedence # over self.write sys.excepthook(type, value, tb) I asume, this was an intentional change, but I could only find a rather hackish solution in specialcasing the intepreter calls in my excepthook function: def redirect_error(err_type, err_value, err_trace): if "wx\\py\\interpreter.py" in "".join(traceback.format_stack()): sys.__excepthook__(err_type, err_value, err_trace) return False ... Are there probably any drawbacks in using this, (apart from the additional item in the traceback, code.py ... )? >>> 1/0 # pyshell using redirect_error excethook Traceback (most recent call last): File "C:\Python34\lib\code.py", line 90, in runcode exec(code, self.locals) File "", line 1, in ZeroDivisionError: division by zero >>> Some more info including the wxpython specific context is included in my original post in the wxpython maillist: https://groups.google.com/forum/#!topic/wxpython-users/E-kqf-TeQJ0 Any hints or opinions on some more standard approaches are much appreciated. Thanks and regards, vbr From ahicks at p-o.co.uk Mon Mar 9 06:16:24 2015 From: ahicks at p-o.co.uk (Alan Hicks) Date: Mon, 09 Mar 2015 10:16:24 +0000 Subject: Django-DMARC making it easier to manage DMARC reports - Beta 0.1.3 on PyPI Message-ID: <54FD72F8.3080706@p-o.co.uk> With defending reputations as important as receiving email I'm pleased to announce another beta of django-dmarc 0.1.3 is released to PyPI. https://pypi.python.org/pypi/django-dmarc The Django DMARC project aims to help with implementing DMARC "Domain-based Message Authentication, Reporting & Conformance" and ongoing monitoring by importing feedback reports about messages that pass and/or fail DMARC evaluation into a more easily digested format. Alan Hicks https://plus.google.com/+AlanHicksLondon/ From mail at timgolden.me.uk Mon Mar 9 06:23:35 2015 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 09 Mar 2015 10:23:35 +0000 Subject: Python 3.4 and 2.7 installation no Script folder and pip installation failed In-Reply-To: References: Message-ID: <54FD74A7.9050808@timgolden.me.uk> On 07/03/2015 12:55, Daiyue Weng wrote: [... snip pip-related problems with installing 2.7.9 on Windows ...] The OP has raised this as issue23604. I've responded over there because it's a duplicate of a known issue (issue22028). http://bugs.python.org/issue23604#msg237628 TJG From antoon.pardon at rece.vub.ac.be Mon Mar 9 06:23:54 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 09 Mar 2015 11:23:54 +0100 Subject: Letter class in re Message-ID: <54FD74BA.8010803@rece.vub.ac.be> I am using PLY for a parsing task which uses re for the lexical analysis. Does anyone know what regular expression to use for a sequence of letters? There is a class for alphanumerics but I can't find one for just letters, which I find odd. I am using python 3.4 -- Antoon Pardon From wolfgang.maier at biologie.uni-freiburg.de Mon Mar 9 06:37:45 2015 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Mon, 09 Mar 2015 11:37:45 +0100 Subject: Letter class in re In-Reply-To: <54FD74BA.8010803@rece.vub.ac.be> References: <54FD74BA.8010803@rece.vub.ac.be> Message-ID: On 03/09/2015 11:23 AM, Antoon Pardon wrote: > I am using PLY for a parsing task which uses re for the lexical > analysis. Does anyone > know what regular expression to use for a sequence of letters? There is > a class for alphanumerics but I can't find one for just letters, which I > find odd. > > I am using python 3.4 > how about [a-zA-Z] ? From cfkaran2 at gmail.com Mon Mar 9 06:50:24 2015 From: cfkaran2 at gmail.com (Cem Karan) Date: Mon, 9 Mar 2015 06:50:24 -0400 Subject: Installed Python 3 on Mac OS X Yosemite but its still Python 2.7 In-Reply-To: References: Message-ID: On Mar 7, 2015, at 6:39 PM, James Dekker wrote: > I am currently running OS X Yosemite (10.10.2) on my MacBook Pro... By default, Apple ships Python 2.7.6 on Yosemite. > > Just downloaded and ran this installer for Python 3: > > python-3.4.3-macosx10.6.pkg > > When I opened up my Terminal and typed in python, this is what came up: > > Python 2.7.6 (default, Sep 9 2014, 15:04:36) > > > [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] > on darwin > > Type "help", "copyright", "credits" or "license" for more information. > >>> > Sorry, I am very new to Python... > > Question(s): > > (1) Does anyone know where the Python 3.4.3 interpreter was installed? It should be installed as either python3 or python3.4. To figure out which, type 'python' in the terminal, and hit tab twice. It should bring up a list of python interpreters you have installed. > (2) Do I need to uninstall Python 2.7.3 (if so, how do I go about doing this) before setting a global environmental variable such as PYTHON_HOME to the location of the installed Python 3.4.3? You don't need to uninstall python 2.7, and you shouldn't try. I tried it as an experiment at one time, and my system had various mysterious failures after that. It may be that Yosemite fixes those failures, but I wouldn't bet on it. Thanks, Cem Karan From antoon.pardon at rece.vub.ac.be Mon Mar 9 07:06:42 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 09 Mar 2015 12:06:42 +0100 Subject: Letter class in re In-Reply-To: References: <54FD74BA.8010803@rece.vub.ac.be> Message-ID: <54FD7EC2.2070006@rece.vub.ac.be> Op 09-03-15 om 11:37 schreef Wolfgang Maier: > On 03/09/2015 11:23 AM, Antoon Pardon wrote: >> I am using PLY for a parsing task which uses re for the lexical >> analysis. Does anyone >> know what regular expression to use for a sequence of letters? There is >> a class for alphanumerics but I can't find one for just letters, which I >> find odd. >> >> I am using python 3.4 >> > > how about [a-zA-Z] ? > No, that limits the characters to ASCII-letters. This is what the doc says about the alphanumeric class: \w For Unicode(str) patternsL Matches Unicode word characters; this includes most characters that can be part of a word in any language, as well as numbers and the underscore. If the ASCII flag is used, only [a-zA-Z0-9_] is matched. ... So what I want is a class that just includes those characters that can be part of a word in any language. From python.list at tim.thechases.com Mon Mar 9 07:17:36 2015 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 9 Mar 2015 06:17:36 -0500 Subject: Letter class in re In-Reply-To: References: <54FD74BA.8010803@rece.vub.ac.be> Message-ID: <20150309061736.07e0d944@bigbox.christie.dr> On 2015-03-09 11:37, Wolfgang Maier wrote: > On 03/09/2015 11:23 AM, Antoon Pardon wrote: >> Does anyone know what regular expression to use for a sequence of >> letters? There is a class for alphanumerics but I can't find one >> for just letters, which I find odd. > > how about [a-zA-Z] ? That breaks if you have Unicode letters. While ugly, since "\w" is composed of "letters, numbers, and underscores", you can assert that the "\w" you find is not a number or underscore by using (?:(?!_|\d)\w) as demonstrated: Python 3.2.3 (default, Feb 20 2013, 14:44:27) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> s = "??????" >>> import re >>> r = re.compile(r'^[a-zA-Z]*$', re.U) >>> r.match(s) >>> r = re.compile(r"^(?:(?!_|\d)\w)*$", re.U) >>> r.match(s) <_sre.SRE_Match object at 0x7fb205da9850> I do miss that Python used "\a" for "start of string" rather than "alphabetic" like Vim does (and correspondingly "\A" for "not an alphabetic"). -tkc From antoon.pardon at rece.vub.ac.be Mon Mar 9 08:26:51 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 09 Mar 2015 13:26:51 +0100 Subject: Letter class in re In-Reply-To: <20150309061736.07e0d944@bigbox.christie.dr> References: <54FD74BA.8010803@rece.vub.ac.be> <20150309061736.07e0d944@bigbox.christie.dr> Message-ID: <54FD918B.1030702@rece.vub.ac.be> Op 09-03-15 om 12:17 schreef Tim Chase: > On 2015-03-09 11:37, Wolfgang Maier wrote: >> On 03/09/2015 11:23 AM, Antoon Pardon wrote: >>> Does anyone know what regular expression to use for a sequence of >>> letters? There is a class for alphanumerics but I can't find one >>> for just letters, which I find odd. >> how about [a-zA-Z] ? > That breaks if you have Unicode letters. While ugly, since "\w" is > composed of "letters, numbers, and underscores", you can assert that > the "\w" you find is not a number or underscore by using > > (?:(?!_|\d)\w) So if I understand correctly the following should be a regular expression for a python3 identifier. (?:(?!_|\d)\w)\w+ It seems odd that one should need such an ugly expression for something that is used rather frequently for parsing computer languages and the like. -- Antoon Pardon From rustompmody at gmail.com Mon Mar 9 08:28:36 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 9 Mar 2015 05:28:36 -0700 (PDT) Subject: Newbie question about text encoding In-Reply-To: <54fd3f10$0$12977$c3e8da3$5496439d@news.astraweb.com> References: <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <54fba9d4$0$12988$c3e8da3$5496439d@news.astraweb.com> <87y4n8uf9a.fsf@elektro.pacujo.net> <87twxvvrjl.fsf@elektro.pacujo.net> <54fc9400$0$13009$c3e8da3$5496439d@news.astraweb.com> <54fd3f10$0$12977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3c91b930-2642-456e-a26d-3edd4cd014d1@googlegroups.com> On Monday, March 9, 2015 at 12:05:05 PM UTC+5:30, Steven D'Aprano wrote: > Chris Angelico wrote: > > > As to the notion of rejecting the construction of strings containing > > these invalid codepoints, I'm not sure. Are there any languages out > > there that have a Unicode string type that requires that all > > codepoints be valid (no surrogates, no U+FFFE, etc)? > > U+FFFE and U+FFFF are *noncharacters*, not invalid. There are a total of 66 > noncharacters in Unicode, and they are legal in strings. Interesting -- Thanks! I wonder whether that's one more instance of the anti-pattern (other thread)? Number thats not a number -- Nan Pointer that points nowhere -- NULL SQL data thats not there but there -- null > > http://www.unicode.org/faq/private_use.html#nonchar8 > > I think the only illegal code points are surrogates. Surrogates should only > appear as bytes in UTF-16 byte-strings. Even more interesting: So there's a whole hierarchy of illegality?? Could you suggest some good reference for 'surrogate'? From python.list at tim.thechases.com Mon Mar 9 08:50:17 2015 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 9 Mar 2015 07:50:17 -0500 Subject: Letter class in re In-Reply-To: <54FD918B.1030702@rece.vub.ac.be> References: <54FD74BA.8010803@rece.vub.ac.be> <20150309061736.07e0d944@bigbox.christie.dr> <54FD918B.1030702@rece.vub.ac.be> Message-ID: <20150309075017.7076718a@bigbox.christie.dr> On 2015-03-09 13:26, Antoon Pardon wrote: > Op 09-03-15 om 12:17 schreef Tim Chase: >> (?:(?!_|\d)\w) > > So if I understand correctly the following should be a regular > expression for a python3 identifier. > > (?:(?!_|\d)\w)\w+ If you don't have to treat it as an atom, you can simplify that to just (?!_|\d)\w+ which just means that the first character can't be an underscore or digit. Though for a Py3 identifier, the underscore is acceptable as a first character ("__init__"), so you can simplify it even further to just (?!\d)\w+ -tkc From jtim.arnold at gmail.com Mon Mar 9 09:20:25 2015 From: jtim.arnold at gmail.com (Tim) Date: Mon, 9 Mar 2015 06:20:25 -0700 (PDT) Subject: HELP!! How to ask a girl out with a simple witty Python code?? In-Reply-To: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> References: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> Message-ID: <8330d037-791f-4923-94fe-2dcacebe2447@googlegroups.com> On Wednesday, March 4, 2015 at 8:34:16 PM UTC-5, Xrrific wrote: > Guys, please Help!!! > > I am trying to impress a girl who is learning python and want ask her out at the same time. > > Could you please come up with something witty incorporating a simple python line like If...then... but..etc. > > You will make me a very happy man!!! > > Thank you very much!!! r = False while r != 'yes': r = raw_input('do you like me (yes/no): ') print 'i like you too!' might make her smile.... --Tim From wolfgang.maier at biologie.uni-freiburg.de Mon Mar 9 09:32:43 2015 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Mon, 09 Mar 2015 14:32:43 +0100 Subject: Letter class in re In-Reply-To: <54FD918B.1030702@rece.vub.ac.be> References: <54FD74BA.8010803@rece.vub.ac.be> <20150309061736.07e0d944@bigbox.christie.dr> <54FD918B.1030702@rece.vub.ac.be> Message-ID: On 03/09/2015 01:26 PM, Antoon Pardon wrote: > Op 09-03-15 om 12:17 schreef Tim Chase: >> On 2015-03-09 11:37, Wolfgang Maier wrote: >>> On 03/09/2015 11:23 AM, Antoon Pardon wrote: >>>> Does anyone know what regular expression to use for a sequence of >>>> letters? There is a class for alphanumerics but I can't find one >>>> for just letters, which I find odd. >>> how about [a-zA-Z] ? >> That breaks if you have Unicode letters. While ugly, since "\w" is >> composed of "letters, numbers, and underscores", you can assert that >> the "\w" you find is not a number or underscore by using >> >> (?:(?!_|\d)\w) > > So if I understand correctly the following should be a regular expression for > a python3 identifier. > > (?:(?!_|\d)\w)\w+ > No, that is not it. For one thing, a leading underscore is fine in identifier names. That is easy to fix in your expression though. Another thing are the Other_ID_Start and Other_ID_Continue categories defined in http://www.unicode.org/Public/6.3.0/ucd/PropList.txt, e.g., >>> '\u212E' '?' >>> ? = 10 >>> ? 10 though ? is not included in \w. > It seems odd that one should need such an ugly expression for something that is > used rather frequently for parsing computer languages and the like. > There is str.isidentifier, which returns True if something is a valid identifier name: >>> '?'.isidentifier() True From fomcl at yahoo.com Mon Mar 9 09:33:23 2015 From: fomcl at yahoo.com (Albert-Jan Roskam) Date: Mon, 9 Mar 2015 06:33:23 -0700 Subject: Letter class in re In-Reply-To: <20150309061736.07e0d944@bigbox.christie.dr> Message-ID: <1425908003.40588.YahooMailBasic@web163805.mail.gq1.yahoo.com> -------------------------------------------- On Mon, 3/9/15, Tim Chase wrote: Subject: Re: Letter class in re To: python-list at python.org Date: Monday, March 9, 2015, 12:17 PM On 2015-03-09 11:37, Wolfgang Maier wrote: > On 03/09/2015 11:23 AM, Antoon Pardon wrote: >> Does anyone know what regular expression to use for a sequence of >> letters? There is a class for alphanumerics but I can't find one >> for just letters, which I find odd. > > how about [a-zA-Z] ? That breaks if you have Unicode letters.? While ugly, since "\w" is composed of "letters, numbers, and underscores", you can assert that the "\w" you find is not a number or underscore by using ? (?:(?!_|\d)\w) I was going to make the same remark, but with a slightly different solution: In [1]: repr(re.search("[a-zA-Z]", "?")) Out[1]: 'None' In [2]: repr(re.search(u"[^\d\W_]+", u"?", re.I | re.U)) Out[2]: '<_sre.SRE_Match object at 0x027CDB10>' "[^\d\W_]+" means something like "one or more (+) of 'not (a digit, a non-word, an underscore)'. From rosuav at gmail.com Mon Mar 9 09:35:17 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 10 Mar 2015 00:35:17 +1100 Subject: Letter class in re In-Reply-To: <54FD918B.1030702@rece.vub.ac.be> References: <54FD74BA.8010803@rece.vub.ac.be> <20150309061736.07e0d944@bigbox.christie.dr> <54FD918B.1030702@rece.vub.ac.be> Message-ID: On Mon, Mar 9, 2015 at 11:26 PM, Antoon Pardon wrote: > It seems odd that one should need such an ugly expression for something that is > used rather frequently for parsing computer languages and the like. Possibly because computer language parsers don't use regular expressions. :) ChrisA From omar.aboumrad at gmail.com Mon Mar 9 09:39:19 2015 From: omar.aboumrad at gmail.com (Omar Abou Mrad) Date: Mon, 9 Mar 2015 15:39:19 +0200 Subject: HELP!! How to ask a girl out with a simple witty Python code?? In-Reply-To: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> References: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> Message-ID: On Thu, Mar 5, 2015 at 3:34 AM, Xrrific wrote: > Guys, please Help!!! > > I am trying to impress a girl who is learning python and want ask her out > at the same time. > > Could you please come up with something witty incorporating a simple > python line like If...then... but..etc. > > You will make me a very happy man!!! > > Thank you very much!!! > -- > https://mail.python.org/mailman/listinfo/python-list > >>> print "Svar lbh jva! V'yy cvpx lbh hc gbzbeebj ng 7 :)".decode('rot13') -------------- next part -------------- An HTML attachment was scrubbed... URL: From storchaka at gmail.com Mon Mar 9 09:43:00 2015 From: storchaka at gmail.com (Serhiy Storchaka) Date: Mon, 09 Mar 2015 15:43:00 +0200 Subject: Letter class in re In-Reply-To: <54FD918B.1030702@rece.vub.ac.be> References: <54FD74BA.8010803@rece.vub.ac.be> <20150309061736.07e0d944@bigbox.christie.dr> <54FD918B.1030702@rece.vub.ac.be> Message-ID: On 09.03.15 14:26, Antoon Pardon wrote: > So if I understand correctly the following should be a regular expression for > a python3 identifier. > > (?:(?!_|\d)\w)\w+ > > It seems odd that one should need such an ugly expression for something that is > used rather frequently for parsing computer languages and the like. Not all so easy. >>> allchars = ''.join(map(chr, range(sys.maxunicode+1))) >>> ''.join(c for c in allchars if ('a'+c).isidentifier() and not (c+'a').isidentifier() and not c.isdigit()) '?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ????????????????????????????????????????????????????????????????????????????????????????????? ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ????????????????????? ???????????????????????? ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????' From wolfgang.maier at biologie.uni-freiburg.de Mon Mar 9 10:04:24 2015 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Mon, 09 Mar 2015 15:04:24 +0100 Subject: Letter class in re In-Reply-To: <1425908003.40588.YahooMailBasic@web163805.mail.gq1.yahoo.com> References: <20150309061736.07e0d944@bigbox.christie.dr> <1425908003.40588.YahooMailBasic@web163805.mail.gq1.yahoo.com> Message-ID: On 03/09/2015 02:33 PM, Albert-Jan Roskam wrote: > -------------------------------------------- > On Mon, 3/9/15, Tim Chase wrote: > > "[^\d\W_]+" means something like "one or more (+) of 'not (a digit, a non-word, an underscore)'. > interesting (using Python3.4 and U+2188 ROMAN NUMERAL ONE HUNDRED THOUSAND ?): >>> re.search('[^\d\W_]+', '\u2188', re.I | re.U) <_sre.SRE_Match object; span=(0, 1), match='?'> ? and at least some other Nl (letter numbers) category characters seem to be part of \w (not part of \W). Would that be considered a bug ? Wolfgang From francogireddu at gmx.com Mon Mar 9 10:07:51 2015 From: francogireddu at gmx.com (MEMOCHE DUE) Date: Mon, 9 Mar 2015 07:07:51 -0700 (PDT) Subject: -- redacted -- In-Reply-To: References: Message-ID: -- redacted -- From wolfgang.maier at biologie.uni-freiburg.de Mon Mar 9 10:09:14 2015 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Mon, 09 Mar 2015 15:09:14 +0100 Subject: Letter class in re In-Reply-To: References: <20150309061736.07e0d944@bigbox.christie.dr> <1425908003.40588.YahooMailBasic@web163805.mail.gq1.yahoo.com> Message-ID: On 03/09/2015 03:04 PM, Wolfgang Maier wrote: > On 03/09/2015 02:33 PM, Albert-Jan Roskam wrote: >> -------------------------------------------- >> On Mon, 3/9/15, Tim Chase wrote: >> >> "[^\d\W_]+" means something like "one or more (+) of 'not (a digit, a >> non-word, an underscore)'. >> > > interesting (using Python3.4 and > U+2188 ROMAN NUMERAL ONE HUNDRED THOUSAND ?): > > >>> re.search('[^\d\W_]+', '\u2188', re.I | re.U) > <_sre.SRE_Match object; span=(0, 1), match='?'> > > ? and at least some other Nl (letter numbers) category characters seem > to be part of \w (not part of \W). > > Would that be considered a bug ? > Sorry for the potential confusion: I meant in the pattern search above (not in the definition of \w or \W). From davea at davea.name Mon Mar 9 10:15:23 2015 From: davea at davea.name (Dave Angel) Date: Mon, 09 Mar 2015 10:15:23 -0400 Subject: Idle - ImportError: No module named numpy In-Reply-To: <54FB4E6F.2050504@c2o.pro.br> References: <54FB4E6F.2050504@c2o.pro.br> Message-ID: <54FDAAFB.8030906@davea.name> On 03/07/2015 02:15 PM, Markos wrote: > Hi, > > I'm beginning to study the numpy. > > When I open a terminal (Debian Squeeze) and run the python interpreter > the command "import numpy as np" run without errors. > > But when I run the same command on idle3 the following error appears. > >>>> import numpy as np > Traceback (most recent call last): > File "", line 1, in > import numpy as np > ImportError: No module named numpy > > How configure idle to load the numpy module? > > Thanks, > Markos > You asked the exact same question 3 days ago on python-tutor, with four replies. Please read them, and if they're not clear, then follow up with more specifics. -- DaveA From mail at timgolden.me.uk Mon Mar 9 10:21:48 2015 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 09 Mar 2015 14:21:48 +0000 Subject: Idle - ImportError: No module named numpy In-Reply-To: <54FDAAFB.8030906@davea.name> References: <54FB4E6F.2050504@c2o.pro.br> <54FDAAFB.8030906@davea.name> Message-ID: <54FDAC7C.4030108@timgolden.me.uk> On 09/03/2015 14:15, Dave Angel wrote: > On 03/07/2015 02:15 PM, Markos wrote: >> Hi, >> >> I'm beginning to study the numpy. >> >> When I open a terminal (Debian Squeeze) and run the python interpreter >> the command "import numpy as np" run without errors. >> >> But when I run the same command on idle3 the following error appears. >> >>>>> import numpy as np >> Traceback (most recent call last): >> File "", line 1, in >> import numpy as np >> ImportError: No module named numpy >> >> How configure idle to load the numpy module? >> >> Thanks, >> Markos >> > > You asked the exact same question 3 days ago on python-tutor, with four > replies. Please read them, and if they're not clear, then follow up > with more specifics. > To defend the OP, I only released this from the moderator queue on python-list this morning. You can see from his header above that it was sent on the 7th (I assume that those are American-style dates we're seeing; otherwise he will have sent it in July) TJG From antoon.pardon at rece.vub.ac.be Mon Mar 9 10:29:51 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 09 Mar 2015 15:29:51 +0100 Subject: Letter class in re In-Reply-To: <20150309075017.7076718a@bigbox.christie.dr> References: <54FD74BA.8010803@rece.vub.ac.be> <20150309061736.07e0d944@bigbox.christie.dr> <54FD918B.1030702@rece.vub.ac.be> <20150309075017.7076718a@bigbox.christie.dr> Message-ID: <54FDAE5F.10504@rece.vub.ac.be> Op 09-03-15 om 13:50 schreef Tim Chase: > On 2015-03-09 13:26, Antoon Pardon wrote: >> Op 09-03-15 om 12:17 schreef Tim Chase: >>> (?:(?!_|\d)\w) >> So if I understand correctly the following should be a regular >> expression for a python3 identifier. >> >> (?:(?!_|\d)\w)\w+ > If you don't have to treat it as an atom, you can simplify that to > just > > (?!_|\d)\w+ > > which just means that the first character can't be an underscore or > digit. > > Though for a Py3 identifier, the underscore is acceptable as a first > character ("__init__"), so you can simplify it even further to just > > (?!\d)\w+ No that doesn't work. To begin with my attempt above shoud have been: (?:(?!_|\d)\w)\w* because an identifier can just be one letter. So when change the '+' into a "*' in your suggestion I get this: >>> r = re.compile(r"(?!\d)\w*") >>> r.match('?') <_sre.SRE_Match object; span=(0, 0), match=''> But the ? is not a letter. I have done some test with: (?:(?!\d)\w)\w*, which seems to work. From antoon.pardon at rece.vub.ac.be Mon Mar 9 10:34:42 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 09 Mar 2015 15:34:42 +0100 Subject: Letter class in re In-Reply-To: References: <54FD74BA.8010803@rece.vub.ac.be> <20150309061736.07e0d944@bigbox.christie.dr> <54FD918B.1030702@rece.vub.ac.be> Message-ID: <54FDAF82.2030201@rece.vub.ac.be> Op 09-03-15 om 14:32 schreef Wolfgang Maier: ... > >> It seems odd that one should need such an ugly expression for >> something that is >> used rather frequently for parsing computer languages and the like. >> > > There is str.isidentifier, which returns True if something is a valid > identifier name: > > >>> '?'.isidentifier() > True Which is not very usefull in a context of lexical analysis. I don't need to know if a particular string is useful as an identifier, I want to know which parts of a text are identifiers. From rosuav at gmail.com Mon Mar 9 10:39:30 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 10 Mar 2015 01:39:30 +1100 Subject: Letter class in re In-Reply-To: <54FDAF82.2030201@rece.vub.ac.be> References: <54FD74BA.8010803@rece.vub.ac.be> <20150309061736.07e0d944@bigbox.christie.dr> <54FD918B.1030702@rece.vub.ac.be> <54FDAF82.2030201@rece.vub.ac.be> Message-ID: On Tue, Mar 10, 2015 at 1:34 AM, Antoon Pardon wrote: >> There is str.isidentifier, which returns True if something is a valid >> identifier name: >> >> >>> '?'.isidentifier() >> True > > Which is not very usefull in a context of lexical analysis. I don't need to know > if a particular string is useful as an identifier, I want to know which parts of > a text are identifiers. If you're doing lexical analysis, you probably want a lexer. For Python, I would recommend parsing to AST and doing your analysis on that; I've had pretty good success doing that, and then using the line/column info to go back to the original text if I need it. A regex is probably not going to be sufficient for that kind of work. What exactly are you trying to accomplish here? More info would guide the recommendations, obviously. ChrisA From antoon.pardon at rece.vub.ac.be Mon Mar 9 10:41:03 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 09 Mar 2015 15:41:03 +0100 Subject: Letter class in re In-Reply-To: References: <54FD74BA.8010803@rece.vub.ac.be> <20150309061736.07e0d944@bigbox.christie.dr> <54FD918B.1030702@rece.vub.ac.be> Message-ID: <54FDB0FF.20504@rece.vub.ac.be> Op 09-03-15 om 14:35 schreef Chris Angelico: > On Mon, Mar 9, 2015 at 11:26 PM, Antoon Pardon > wrote: >> It seems odd that one should need such an ugly expression for something that is >> used rather frequently for parsing computer languages and the like. > Possibly because computer language parsers don't use regular expressions. :) > Trying to be funny by being pedantic. Maybe your experience is different from mine, but it rarely seems to work IMO. -- Antoon Pardon. From rosuav at gmail.com Mon Mar 9 10:44:38 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 10 Mar 2015 01:44:38 +1100 Subject: Letter class in re In-Reply-To: <54FDB0FF.20504@rece.vub.ac.be> References: <54FD74BA.8010803@rece.vub.ac.be> <20150309061736.07e0d944@bigbox.christie.dr> <54FD918B.1030702@rece.vub.ac.be> <54FDB0FF.20504@rece.vub.ac.be> Message-ID: On Tue, Mar 10, 2015 at 1:41 AM, Antoon Pardon wrote: > Op 09-03-15 om 14:35 schreef Chris Angelico: >> On Mon, Mar 9, 2015 at 11:26 PM, Antoon Pardon >> wrote: >>> It seems odd that one should need such an ugly expression for something that is >>> used rather frequently for parsing computer languages and the like. >> Possibly because computer language parsers don't use regular expressions. :) >> > Trying to be funny by being pedantic. Maybe your experience is different from mine, > but it rarely seems to work IMO. Not sure what you mean there - what "rarely seems to work"? I've never written a language parser based on regexps, which is the point of what I was saying. ChrisA From antoon.pardon at rece.vub.ac.be Mon Mar 9 11:00:51 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 09 Mar 2015 16:00:51 +0100 Subject: Letter class in re In-Reply-To: References: <54FD74BA.8010803@rece.vub.ac.be> <20150309061736.07e0d944@bigbox.christie.dr> <54FD918B.1030702@rece.vub.ac.be> <54FDAF82.2030201@rece.vub.ac.be> Message-ID: <54FDB5A3.5000608@rece.vub.ac.be> Op 09-03-15 om 15:39 schreef Chris Angelico: > On Tue, Mar 10, 2015 at 1:34 AM, Antoon Pardon > wrote: >>> There is str.isidentifier, which returns True if something is a valid >>> identifier name: >>> >>>>>> '?'.isidentifier() >>> True >> Which is not very usefull in a context of lexical analysis. I don't need to know >> if a particular string is useful as an identifier, I want to know which parts of >> a text are identifiers. > If you're doing lexical analysis, you probably want a lexer. For > Python, I would recommend parsing to AST and doing your analysis on > that; I've had pretty good success doing that, and then using the > line/column info to go back to the original text if I need it. A regex > is probably not going to be sufficient for that kind of work. Maybe I am getting behind, but until now the lexers that I used require a regular expression per kind of token you want to recognize. At least PLY still seems to work like that. So if an identifier is one such kind of token, I need a regular expression that matches what an identifier is. -- Antoon Pardon From antoon.pardon at rece.vub.ac.be Mon Mar 9 11:04:53 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 09 Mar 2015 16:04:53 +0100 Subject: Letter class in re In-Reply-To: References: <54FD74BA.8010803@rece.vub.ac.be> <20150309061736.07e0d944@bigbox.christie.dr> <54FD918B.1030702@rece.vub.ac.be> <54FDB0FF.20504@rece.vub.ac.be> Message-ID: <54FDB695.3080800@rece.vub.ac.be> Op 09-03-15 om 15:44 schreef Chris Angelico: > On Tue, Mar 10, 2015 at 1:41 AM, Antoon Pardon > wrote: >> Op 09-03-15 om 14:35 schreef Chris Angelico: >>> On Mon, Mar 9, 2015 at 11:26 PM, Antoon Pardon >>> wrote: >>>> It seems odd that one should need such an ugly expression for something that is >>>> used rather frequently for parsing computer languages and the like. >>> Possibly because computer language parsers don't use regular expressions. :) >>> >> Trying to be funny by being pedantic. Maybe your experience is different from mine, >> but it rarely seems to work IMO. > Not sure what you mean there - what "rarely seems to work"? I've never > written a language parser based on regexps, which is the point of what > I was saying. > May be you should pay better attention then to the history of the thread. I am not talking about parsing, I am talking about lexical analysis and that does uses regular expressions. And the result of that is used rather frequently for parsing computer languages,even if the parsing itself doesn't use regular expressions. -- Antoon Pardon From python.list at tim.thechases.com Mon Mar 9 11:17:42 2015 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 9 Mar 2015 10:17:42 -0500 Subject: Letter class in re In-Reply-To: <54FDAE5F.10504@rece.vub.ac.be> References: <54FD74BA.8010803@rece.vub.ac.be> <20150309061736.07e0d944@bigbox.christie.dr> <54FD918B.1030702@rece.vub.ac.be> <20150309075017.7076718a@bigbox.christie.dr> <54FDAE5F.10504@rece.vub.ac.be> Message-ID: <20150309101742.471b870c@bigbox.christie.dr> On 2015-03-09 15:29, Antoon Pardon wrote: > Op 09-03-15 om 13:50 schreef Tim Chase: > >> (?:(?!_|\d)\w)\w+ > > If you don't have to treat it as an atom, you can simplify that to > > just > > > > (?!_|\d)\w+ > > > > which just means that the first character can't be an underscore > > or digit. > > > > Though for a Py3 identifier, the underscore is acceptable as a > > first character ("__init__"), so you can simplify it even further > > to just > > > > (?!\d)\w+ > > No that doesn't work. To begin with my attempt above shoud have > been: > > (?:(?!_|\d)\w)\w* Did you actually test my suggestion? The "(?!\d)\w+" means "one or more Word characters, but the first one can't be a digit" because the "(?!...)" is zero-width. This should match single-character strings including a single underscore. > because an identifier can just be one letter. So when change the '+' > into a "*' in your suggestion I get this: > > >>> r = re.compile(r"(?!\d)\w*") > >>> r.match('?') > <_sre.SRE_Match object; span=(0, 0), match=''> > > But the ? is not a letter. Notice that you match an empty string there because the (?!\d) is zero width, and thus you match 0-or-more-word-characters by matching nothing. Try either anchoring it with a "$" at the end to see that it doesn't really match. -tkc From daniel.watrous at gmail.com Mon Mar 9 11:27:47 2015 From: daniel.watrous at gmail.com (Daniel) Date: Mon, 9 Mar 2015 08:27:47 -0700 (PDT) Subject: Mock return_value Message-ID: I have a dao.py module with a dao class declared and I want to use mock to set a return value for a dao function, dao.execute_ldap_search(). import mock import unittest import model, dao class TestPeopleDAO(unittest.TestCase): ldap_person_response = SOME_DICT @mock.patch('dao.dao') def test_find_by_last_first_comma(self, mock_dao): # setup the mock mock_dao.execute_ldap_search.return_value = self.ldap_person_response persondao = dao.person_dao() persondao.find_by_last_first_comma('name', '', '') self.assertEqual(len(persondao),1,"Wrong number of objects returned.") self.assertEqual(persondao[0].givenName, "FirstName", "Failed to parse response.") if __name__ == '__main__': unittest.main() When I run this, it fails when calling execute_ldap_search because it really calls it. I was expecting it to just return the value I specified. What am I doing wrong? From daniel.watrous at gmail.com Mon Mar 9 11:34:36 2015 From: daniel.watrous at gmail.com (Daniel) Date: Mon, 9 Mar 2015 08:34:36 -0700 (PDT) Subject: Mock return_value In-Reply-To: References: Message-ID: <4f6e3e71-4403-44e6-850a-d6d35b6a514b@googlegroups.com> I found that the following change worked: @mock.patch('dao.dao.execute_ldap_search') def test_find_by_last_first_comma(self, mock_dao): # setup the mock mock_dao.return_value = self.ldap_person_response Daniel On Monday, March 9, 2015 at 10:28:20 AM UTC-5, Daniel wrote: > I have a dao.py module with a dao class declared and I want to use mock to set a return value for a dao function, dao.execute_ldap_search(). > > import mock > import unittest > import model, dao > > class TestPeopleDAO(unittest.TestCase): > > ldap_person_response = SOME_DICT > > @mock.patch('dao.dao') > def test_find_by_last_first_comma(self, mock_dao): > # setup the mock > mock_dao.execute_ldap_search.return_value = self.ldap_person_response > > persondao = dao.person_dao() > persondao.find_by_last_first_comma('name', '', '') > self.assertEqual(len(persondao),1,"Wrong number of objects returned.") > self.assertEqual(persondao[0].givenName, "FirstName", "Failed to parse response.") > > if __name__ == '__main__': > unittest.main() > > When I run this, it fails when calling execute_ldap_search because it really calls it. I was expecting it to just return the value I specified. What am I doing wrong? From antoon.pardon at rece.vub.ac.be Mon Mar 9 11:39:54 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 09 Mar 2015 16:39:54 +0100 Subject: Letter class in re In-Reply-To: <1425908003.40588.YahooMailBasic@web163805.mail.gq1.yahoo.com> References: <1425908003.40588.YahooMailBasic@web163805.mail.gq1.yahoo.com> Message-ID: <54FDBECA.6000503@rece.vub.ac.be> Op 09-03-15 om 14:33 schreef Albert-Jan Roskam: > I was going to make the same remark, but with a slightly different solution: > In [1]: repr(re.search("[a-zA-Z]", "?")) > Out[1]: 'None' > > In [2]: repr(re.search(u"[^\d\W_]+", u"?", re.I | re.U)) > Out[2]: '<_sre.SRE_Match object at 0x027CDB10>' > > "[^\d\W_]+" means something like "one or more (+) of 'not (a digit, a non-word, an underscore)'. > Nice, I am seriously considering this, if only because I have less trouble understanding this. I'll run some tests to see what gives. -- Antoon Pardon From steve+comp.lang.python at pearwood.info Mon Mar 9 12:11:10 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 10 Mar 2015 03:11:10 +1100 Subject: Letter class in re References: Message-ID: <54fdc61f$0$12983$c3e8da3$5496439d@news.astraweb.com> Antoon Pardon wrote: > I am using PLY for a parsing task which uses re for the lexical > analysis. Does anyone > know what regular expression to use for a sequence of letters? There is > a class for alphanumerics but I can't find one for just letters, which I > find odd. > > I am using python 3.4 The re module in Python is pretty old and basic. Can you use Matthew Barnett's regex module, available on PyPI? I understand it has a richer set of flags for things such as Unicode letters and the like. -- Steven From dchichkov at gmail.com Mon Mar 9 14:03:53 2015 From: dchichkov at gmail.com (Dmitry Chichkov) Date: Mon, 9 Mar 2015 11:03:53 -0700 (PDT) Subject: A strange statement in the bisect documentation? In-Reply-To: <54fa614c$0$13014$c3e8da3$5496439d@news.astraweb.com> References: <9152f2c7-91c8-4898-a61d-c0b3b6358953@googlegroups.com> <54fa614c$0$13014$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven, I'm somewhat argeeing with you, regarding the general analysisn, yet I'm not quite sure about your analysis of the repeated bisect call code. In particular, in the sample that you've given: data = [i/100 for i in range(1, 7000001, 7)] data.sort(key=str) keyed_data = [str(x) for x in data] for x in many_x_values: key = str(x) pos = bisect.bisect(keyed_data, key) keyed_data.insert(pos, key) data.insert(pos, x) As per Python documentation "doing inserts or pops from the beginning of a list is slow (because all of the other elements have to be shifted by one)." so the complexity here would be O(M*N) [+ O(M*log(N))]. So this particular example looks like micro-optimization around bisect(), while loosing the big-picture out of sight. That inserts into the list are O(N) and in general are more expensive than O(log(N)) bisect calls, doing two inserts (into keyed_data and data) is worse than doing one, storing and maintaining an extra list of keys is relatively expensive, and some times plain impossible. The following statement that agrees with the documentation also doesn't seem to be very sound "If you call bisect less than (10% of N) times, then it doesn't matter, because that's comparatively a small number and will be fast enough either way. ". If the N is large (say 10000000000 records) even if you need to call bisect only once or twise, the speed may still matter a lot. Take an example of a container on a timestamped 1TB log file, where you need to navigate to a perticular record. It would be a very slow operation indead, to create a copy of all keys, like the documentation suggests. Yet it would be very fast, to just bisect to the right element, taking just O(ln(10000000000)) ~ 34 reads. So to me, it looks like the argument "it does not make sense for the bisect() functions to have key or reversed arguments because that would lead to an inefficient design" documentation is incorrect in general, because it suggest to do O(N) instead of O(log(N)) operation, to optimize a hypothetical scenario. To give examples, note, how it led you to an inefficient design in your sample code of doing *two* .insert() calls in your code, rather than just one. And I can easily see people writing something like .bisect([el.time for el in container]) just beceuse they don't expect the container to ever become large. On Friday, March 6, 2015 at 6:24:24 PM UTC-8, Steven D'Aprano wrote: > Dmitry Chichkov wrote: > > > I was looking over documentation of the bisect module and encountered the > > following very strange statement there: > > > > From https://docs.python.org/2/library/bisect.html > > > > ...it does not make sense for the bisect() functions to have key or > > reversed arguments because that would lead to an inefficient design > > (successive calls to bisect functions would not "remember" all of the > > previous key lookups). > > > > Instead, it is better to search a list of precomputed keys to find the > > index of the record in question... > > > > > > Is that right that the documentation encourages to use O(N) algorithm [by > > making a copy of all keys] instead of using O(log(N)) bisect with > > kay=attrgetter? And claims that O(N) is more efficient than O(log(N))? > > Apparently :-) > > > The documentation may not be completely clear, but what it is arguing is > this: > > If you are making repeated bisect calls, then using a key function is > inefficient because the key gets lost after each call and has to be > recalculated over and over again. A concrete example: > > data = [i/100 for i in range(1, 7000001, 7)] > data.sort(key=str) > > for x in many_x_values: > bisect.insort(data, x, key=str) # Pretend this works. > > > The first time you call insort, the key function (str in this case) will be > called O(log N) times. The second time you call insort, the key function > must be called again, even for the same data points, because the keys > str(x) are thrown away and lost after each call to insort. > > After M calls to insort, there will have been on average M*(log(N)+1) calls > to the key function. (The +1 is because the x gets str'ed as well, and > there are M loops.) > > > > As an alternative, suppose we do this: > > data = [i/100 for i in range(1, 7000001, 7)] > data.sort(key=str) > keyed_data = [str(x) for x in data] > > for x in many_x_values: > key = str(x) > pos = bisect.bisect(keyed_data, key) > keyed_data.insert(pos, key) > data.insert(pos, x) > > > This costs N calls to str in preparing the keyed_data list, plus M calls to > str in the loop. The documentation suggests that we consider this will be > cheaper in the long run, in other words: > > N + M < M*(log(N) + 1) > > N + M < M + M*log(N) > > > That's true whenever N < M*log(N). > > The documentation assumes we should care about large N and large M. As they > say, "everything is fast for small N": if you are doing three bisections on > a list with ten items, then *who cares* how you do it, it's going to be > quite fast. So let's say you have a list of 10000 items, that is N = 10000. > Then it is faster to build a second keyed_list when: > > 10000 < M*log(10000) = M*13 # approximately > > i.e. M > 770 give or take. That's a fairly small number, and it's only about > 8% of the size of N. > > So the general perspective is: > > If you have a list of N items, and you call bisect more than about (10% of > N) times, it will likely be faster to pre-prepare a keyed list than call a > key function repeatedly for each call to bisect. > > If you call bisect less than (10% of N) times, then it doesn't matter, > because that's comparatively a small number and will be fast enough either > way. > > > Is the documentation correct? I don't know. I don't have an opinion on this. > I recommend that you fork the bisect module, call it mybisect, add a key > function parameter, and compare the speed of the two versions, with or > without a key function. Remember: > > - Recent versions of bisect have a C accelerated version. Make sure you > disable that, so you are comparing the speed of Python versus Python not > Python versus C. > > - Nobody will care about small lists. I suggest that you start with at least > ten thousand items, and move up to ten billion or so. For each N in (10**4, > 10**5, ... 10**10) find out how many calls to insort or bisect does it take > before the key function version becomes slower. Or possibly faster. > > - Is there are difference between fast key functions like str, and slow ones > that have to do a lot of processing? > > > > -- > Steven From ben+python at benfinney.id.au Mon Mar 9 15:10:05 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 10 Mar 2015 06:10:05 +1100 Subject: Mock return_value References: Message-ID: <85mw3mvvg2.fsf@benfinney.id.au> Daniel writes: > I have a dao.py module with a dao class declared and I want to use > mock to set a return value for a dao function, > dao.execute_ldap_search(). You have found a change which worked, but you might not have understood why yet. The documentation for the ?unittest.mock? library covers the wrinkles of where to patch an object: 26.4.3.8. Where to patch patch() works by (temporarily) changing the object that a name points to with another one. There can be many names pointing to any individual object, so for patching to work you must ensure that you patch the name used by the system under test. The basic principle is that you patch where an object is looked up, which is not necessarily the same place as where it is defined. A couple of examples will help to clarify this. [?] Good hunting! -- \ ?There will be a Moscow Exhibition of the Arts by 15,000 Soviet | `\ Republic painters and sculptors. These were executed over the | _o__) past two years.? ?newspaper article, Soviet Weekly | Ben Finney From jonas at wielicki.name Mon Mar 9 15:12:24 2015 From: jonas at wielicki.name (Jonas Wielicki) Date: Mon, 09 Mar 2015 20:12:24 +0100 Subject: HELP!! How to ask a girl out with a simple witty Python code?? In-Reply-To: References: <8c09473e-92df-40ac-b083-d2b3a2b75188@googlegroups.com> Message-ID: <54FDF098.8090900@wielicki.name> On 09.03.2015 14:39, Omar Abou Mrad wrote: > On Thu, Mar 5, 2015 at 3:34 AM, Xrrific wrote: > >> Guys, please Help!!! >> >> I am trying to impress a girl who is learning python and want ask her out >> at the same time. >> >> Could you please come up with something witty incorporating a simple >> python line like If...then... but..etc. >> >> You will make me a very happy man!!! >> >> Thank you very much!!! >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > >>>> print "Svar lbh jva! V'yy cvpx lbh hc gbzbeebj ng 7 :)".decode('rot13') That won?t work if she?s actually smart. I mean, that?s python2. ;-) regards, jwi From fomcl at yahoo.com Mon Mar 9 15:58:53 2015 From: fomcl at yahoo.com (Albert-Jan Roskam) Date: Mon, 9 Mar 2015 19:58:53 +0000 (UTC) Subject: HELP!! How to ask a girl out with a simple witty Python code?? In-Reply-To: <54FDF098.8090900@wielicki.name> References: <54FDF098.8090900@wielicki.name> Message-ID: <796811348.486761.1425931133402.JavaMail.yahoo@mail.yahoo.com> ----- Original Message ----- > From: Jonas Wielicki > To: python-list at python.org > Cc: > Sent: Monday, March 9, 2015 8:12 PM > Subject: Re: HELP!! How to ask a girl out with a simple witty Python code?? > > On 09.03.2015 14:39, Omar Abou Mrad wrote: >> On Thu, Mar 5, 2015 at 3:34 AM, Xrrific wrote: >> >>> Guys, please Help!!! >>> >>> I am trying to impress a girl who is learning python and want ask her > out >>> at the same time. >>> >>> Could you please come up with something witty incorporating a simple >>> python line like If...then... but..etc. >>> >>> You will make me a very happy man!!! >>> >>> Thank you very much!!! >>> -- >>> https://mail.python.org/mailman/listinfo/python-list >>> >> >>>>> print "Svar lbh jva! V'yy cvpx lbh hc gbzbeebj ng 7 > :)".decode('rot13') > > That won?t work if she?s actually smart. I mean, that?s python2. ;-) Yeah you need from __future__ and codecs to also make it work in Python 3. But then, Python 3 does, alas, not accept rot13 in the shebang # -*- coding: rot13 -*- sebz __shgher__ vzcbeg cevag_shapgvba vzcbeg pbqrpf cevag(pbqrpf.qrpbqr("Svar lbh jva! V'yy cvpx lbh hc gbzbeebj ng 7 :)", "rot13")) From daniel.watrous at gmail.com Mon Mar 9 16:10:15 2015 From: daniel.watrous at gmail.com (Daniel) Date: Mon, 9 Mar 2015 13:10:15 -0700 (PDT) Subject: Mock return_value In-Reply-To: References: Message-ID: <6a9ae382-5fef-4470-b98c-190bf9063282@googlegroups.com> On Monday, March 9, 2015 at 10:28:20 AM UTC-5, Daniel wrote: > I have a dao.py module with a dao class declared and I want to use mock to set a return value for a dao function, dao.execute_ldap_search(). > > import mock > import unittest > import model, dao > > class TestPeopleDAO(unittest.TestCase): > > ldap_person_response = SOME_DICT > > @mock.patch('dao.dao') > def test_find_by_last_first_comma(self, mock_dao): > # setup the mock > mock_dao.execute_ldap_search.return_value = self.ldap_person_response > > persondao = dao.person_dao() > persondao.find_by_last_first_comma('name', '', '') > self.assertEqual(len(persondao),1,"Wrong number of objects returned.") > self.assertEqual(persondao[0].givenName, "FirstName", "Failed to parse response.") > > if __name__ == '__main__': > unittest.main() > > When I run this, it fails when calling execute_ldap_search because it really calls it. I was expecting it to just return the value I specified. What am I doing wrong? I ended up refactoring to setup patching once for a test class. https://docs.python.org/3.5/library/unittest.mock-examples.html#applying-the-same-patch-to-every-test-method From tjreedy at udel.edu Mon Mar 9 17:57:57 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 09 Mar 2015 17:57:57 -0400 Subject: [RELEASED] Python 3.5.0a2 is now available In-Reply-To: <54FD693A.5010704@hastings.org> References: <54FD693A.5010704@hastings.org> Message-ID: On 3/9/2015 5:34 AM, Larry Hastings wrote: > > > On behalf of the Python development community and the Python 3.5 release > team, I'm thrilled to announce the availability of Python 3.5.0a2. > Python 3.5.0a2 is the second alpha release of Python 3.5, which will be > the next major release of Python. Python 3.5 is still under heavy > development, and is far from complete. > > This is a preview release, and its use is not recommended for production > settings. > > Two important notes for Windows users about Python 3.5.0a2: > > * If you have previously installed Python 3.5.0a1, you must manually > uninstall it before installing Python 3.5.0a2 (issue23612). > * If installing Python 3.5.0a2 as a non-privileged user, you may need > to escalate to administrator privileges to install an update to your > C runtime libraries. There was an initial problem with the Windows installers that was fixed a couple of hours ago. > You can find Python 3.5.0a2 here: > > https://www.python.org/downloads/release/python-350a2/ -- Terry Jan Reedy From mparchet at sunrise.ch Mon Mar 9 18:30:58 2015 From: mparchet at sunrise.ch (Michael Parchet) Date: Mon, 9 Mar 2015 23:30:58 +0100 Subject: =?utf-8?Q?Use_=C3=A0_Python_2_module_with_Python_3?= Message-ID: Hello, For a new project, a person recommande me to use Python 3 can I use Python 3 with a Python 2 y module ex : pyQt 4 ? Tanks for your answer Best regards mparchet From phd at phdru.name Mon Mar 9 18:53:57 2015 From: phd at phdru.name (Oleg Broytman) Date: Mon, 9 Mar 2015 23:53:57 +0100 Subject: SQLObject 2.1.1 and 1.7.4 Message-ID: <20150309225357.GC23931@phdru.name> Hello! I'm pleased to announce minor bugfix releases 2.1.1 and 1.7.4. What's new in SQLObject ======================= * Minor fix in PostgresConnection: close the cursor and connection in _createOrDropDatabase even after an error. Contributor for this release is Gregor Horvath. 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 or 2.7 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/2.1.1 https://pypi.python.org/pypi/SQLObject/1.7.4 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 rgaddi at technologyhighland.invalid Mon Mar 9 18:58:18 2015 From: rgaddi at technologyhighland.invalid (Rob Gaddi) Date: Mon, 9 Mar 2015 22:58:18 +0000 (UTC) Subject: Matplotlib and cx_Freeze Message-ID: I'm having serious trouble getting cx_Freeze and matplotlib to agree where the mpl-data folder is on an Ubuntu 14.04 machine. I'm configured with python3-matplotlib 1.3.1 having come from the Ubuntu repositories, and a (now slightly modified) cx_Freeze 4.3.4 from the cheese shop. Originally I couldn't even get cx_Freeze to locate the mpl-data folder when freezing the package. I got around that by hacking the matplotlib hook from: def load_matplotlib(finder, module): """the matplotlib module requires data to be found in mpl-data in the same directory as the frozen executable so oblige it""" dir = os.path.join(module.path[0], "mpl-data") finder.IncludeFiles(dir, "mpl-data") to: def load_matplotlib(finder, module): """the matplotlib module requires data to be found in mpl-data in the same directory as the frozen executable so oblige it""" try: from matplotlib import get_data_path dir = get_data_path() except ImportError: dir = os.path.join(module.path[0], "mpl-data") finder.IncludeFiles(dir, "mpl-data") So now the freeze copies mpl-data into build/exe.linux-x86_64-3.4/mpl- data, but when I run my code: print('Matplotlib resource file:', matplotlib.matplotlib_fname()) print('Matplotlib rcParams["datapath"]:', matplotlib.rcParams ["datapath"]) print('Matplotlib data folder:', matplotlib.get_data_path()) I get: Matplotlib resource file: /etc/matplotlibrc Matplotlib rcParams["datapath"]: /usr/share/matplotlib/mpl-data Matplotlib data folder: /usr/share/matplotlib/mpl-data So I copy in matplotlibrc, and set the datapath to hardcode the current program directory; ugly but workable. And now I get: Matplotlib resource file: /home/rgaddi/Documents/Software/rsctest/build/ exe.linux-x86_64-3.4/matplotlibrc Matplotlib rcParams["datapath"]: /home/rgaddi/Documents/Software/ rsctest/build/exe.linux-x86_64-3.4/mpl-data Matplotlib data folder: /usr/share/matplotlib/mpl-data It recognizes that I've set the datapath, but it still will only use the global system directory, thus defeating the point of the freeze. I'm pretty much out of ideas at this point. Anyone have any advice? -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From breamoreboy at yahoo.co.uk Mon Mar 9 19:07:06 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 09 Mar 2015 23:07:06 +0000 Subject: Use =?windows-1252?Q?=E0_Python_2_module_with_Pyth?= =?windows-1252?Q?on_3?= In-Reply-To: References: Message-ID: On 09/03/2015 22:30, Michael Parchet wrote: > Hello, > > For a new project, a person recommande me to use Python 3 > > can I use Python 3 with a Python 2 y module ex : pyQt 4 ? > > Tanks for your answer > > Best regards > > mparchet > Python 2 code can be converted with https://docs.python.org/3/library/2to3.html For PyQt specifically see https://wiki.python.org/moin/PyQt IIRC I saw your name earlier today on the bug tracker regarding Windows. In that case this site http://www.lfd.uci.edu/~gohlke/pythonlibs/ is a must know about, it's often far easier to get a binary installer from there than mess about trying to build something yourself. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From steve+comp.lang.python at pearwood.info Mon Mar 9 19:47:51 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 10 Mar 2015 10:47:51 +1100 Subject: Use =?UTF-8?B?w6A=?= Python 2 module with Python 3 References: Message-ID: <54fe3128$0$13004$c3e8da3$5496439d@news.astraweb.com> Michael Parchet wrote: > Hello, > > For a new project, a person recommande me to use Python 3 > > can I use Python 3 with a Python 2 y module ex : pyQt 4 ? Maybe. If the module is really only Python 2, then no. If it is pure-Python, with no C extensions, then you might be able to fork it and update it to work with Python 3. The 2to3 tool may help with that. If a module's documentation says it works with Python 2, but doesn't mention Python 3 at all, it *might* work with Python 3. The author or maintainer of the project simply hasn't gotten around to fixing the documentation. So it may be worth just trying it and seeing for yourself. For PyQt specifically, googling suggests that PyQt does work with Python 3, but the documentation is out of date and you may have difficulty installing it: https://www.google.com.au/search?q=pyqt+python3 -- Steven From torriem at gmail.com Mon Mar 9 20:20:10 2015 From: torriem at gmail.com (Michael Torrie) Date: Mon, 09 Mar 2015 18:20:10 -0600 Subject: Use =?windows-1252?Q?=E0_Python_2_module_with_Pyth?= =?windows-1252?Q?on_3?= In-Reply-To: <54fe3128$0$13004$c3e8da3$5496439d@news.astraweb.com> References: <54fe3128$0$13004$c3e8da3$5496439d@news.astraweb.com> Message-ID: <54FE38BA.1010509@gmail.com> On 03/09/2015 05:47 PM, Steven D'Aprano wrote: > Michael Parchet wrote: > >> Hello, >> >> For a new project, a person recommande me to use Python 3 >> >> can I use Python 3 with a Python 2 y module ex : pyQt 4 ? > > Maybe. > > If the module is really only Python 2, then no. If it is pure-Python, with > no C extensions, then you might be able to fork it and update it to work > with Python 3. The 2to3 tool may help with that. > > If a module's documentation says it works with Python 2, but doesn't mention > Python 3 at all, it *might* work with Python 3. The author or maintainer of > the project simply hasn't gotten around to fixing the documentation. So it > may be worth just trying it and seeing for yourself. > > For PyQt specifically, googling suggests that PyQt does work with Python 3, > but the documentation is out of date and you may have difficulty installing > it: > > https://www.google.com.au/search?q=pyqt+python3 PySide does support Python 3. Last time I installed it, I think it did it with pip. It will require a working C++ compiler to install it. Both PyQt and PySide are not pure python. They have bridging code that must be compiled. From p_s_d_a_s_i_l_v_a_ns at netcabo.pt Mon Mar 9 20:45:49 2015 From: p_s_d_a_s_i_l_v_a_ns at netcabo.pt (Paulo da Silva) Date: Tue, 10 Mar 2015 00:45:49 +0000 Subject: Python3: Reading a text/binary mixed file Message-ID: Hi! What is the best way to read a file that begins with some few text lines and whose rest is a binary stream? As an exmaple ... files .pnm. Thanks for any comments/help on this. From davea at davea.name Mon Mar 9 20:55:44 2015 From: davea at davea.name (Dave Angel) Date: Mon, 09 Mar 2015 20:55:44 -0400 Subject: Python3: Reading a text/binary mixed file In-Reply-To: References: Message-ID: <54FE4110.5010402@davea.name> On 03/09/2015 08:45 PM, Paulo da Silva wrote: > Hi! > > What is the best way to read a file that begins with some few text lines > and whose rest is a binary stream? > > As an exmaple ... files .pnm. > > Thanks for any comments/help on this. > In which version of Python? there's a huge difference between 2.x and 3.x Generally speaking, you can treat a piece of a binary (input) file as an encoded string, so you want to open the file as binary, locate the part that's text, and then explicitly decode the string from that. -- DaveA From rosuav at gmail.com Mon Mar 9 20:56:21 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 10 Mar 2015 11:56:21 +1100 Subject: Python3: Reading a text/binary mixed file In-Reply-To: References: Message-ID: On Tue, Mar 10, 2015 at 11:45 AM, Paulo da Silva wrote: > Hi! > > What is the best way to read a file that begins with some few text lines > and whose rest is a binary stream? > > As an exmaple ... files .pnm. > > Thanks for any comments/help on this. Read the entire file in binary mode, and figure out which parts are text and how they're encoded (possibly ASCII or UTF-8). Then take just those snippets, and decode them. Something like this: data = open("some_file", "rb") text_part = data[2718:3142] decoded_text = text_part.decode("utf-8") That'll give you a usable Unicode string, assuming you have your offsets and encoding correct. ChrisA From davea at davea.name Mon Mar 9 21:01:19 2015 From: davea at davea.name (Dave Angel) Date: Mon, 09 Mar 2015 21:01:19 -0400 Subject: Python3: Reading a text/binary mixed file In-Reply-To: References: Message-ID: <54FE425F.8090602@davea.name> On 03/09/2015 08:56 PM, Chris Angelico wrote: > On Tue, Mar 10, 2015 at 11:45 AM, Paulo da Silva > wrote: >> Hi! >> >> What is the best way to read a file that begins with some few text lines >> and whose rest is a binary stream? >> >> As an exmaple ... files .pnm. >> >> Thanks for any comments/help on this. > > Read the entire file in binary mode, and figure out which parts are > text and how they're encoded (possibly ASCII or UTF-8). Then take just > those snippets, and decode them. Something like this: > > data = open("some_file", "rb") You accidentally omitted the part where you read() the data data = data.read() > text_part = data[2718:3142] > decoded_text = text_part.decode("utf-8") > > That'll give you a usable Unicode string, assuming you have your > offsets and encoding correct. > > ChrisA > -- DaveA From rosuav at gmail.com Mon Mar 9 21:04:04 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 10 Mar 2015 12:04:04 +1100 Subject: Python3: Reading a text/binary mixed file In-Reply-To: <54FE425F.8090602@davea.name> References: <54FE425F.8090602@davea.name> Message-ID: On Tue, Mar 10, 2015 at 12:01 PM, Dave Angel wrote: >> data = open("some_file", "rb") > > > You accidentally omitted the part where you read() the data > > data = data.read() You know, that would help... a LOT. :) ChrisA From p_s_d_a_s_i_l_v_a_ns at netcabo.pt Tue Mar 10 00:01:49 2015 From: p_s_d_a_s_i_l_v_a_ns at netcabo.pt (Paulo da Silva) Date: Tue, 10 Mar 2015 04:01:49 +0000 Subject: Python3: Reading a text/binary mixed file References: Message-ID: On 10-03-2015 00:55, Dave Angel wrote: > On 03/09/2015 08:45 PM, Paulo da Silva wrote: >> Hi! >> >> What is the best way to read a file that begins with some few text lines >> and whose rest is a binary stream? >> ... > > In which version of Python? there's a huge difference between 2.x and 3.x Python 3. See the subject please. > > Generally speaking, you can treat a piece of a binary (input) file as an > encoded string, so you want to open the file as binary, locate the part > that's text, and then explicitly decode the string from that. > That's waht I did. However, I was thinking of some other more efficient and simple way. For example a command to read text and another to read bytes. For .pnm photo files I read the entire file (I needed it in memory anyway), splited a copy separated by b'\n', got the headers stuff and then used the original remaining bytes as the photo pixels. But this is very tricky! I am on linux, but if I ran this program on windows I needed to change it to "eat" also the '\r'. In the .pnm case the headers don't have special chars. They fit into ascii. But in a file who have them it would be also difficult to compute the consumed length. Thanks. From p_s_d_a_s_i_l_v_a_ns at netcabo.pt Tue Mar 10 00:07:16 2015 From: p_s_d_a_s_i_l_v_a_ns at netcabo.pt (Paulo da Silva) Date: Tue, 10 Mar 2015 04:07:16 +0000 Subject: Python3: Reading a text/binary mixed file References: Message-ID: On 10-03-2015 00:56, Chris Angelico wrote: > On Tue, Mar 10, 2015 at 11:45 AM, Paulo da Silva > wrote: >> Hi! >> ... > Read the entire file in binary mode, and figure out which parts are > text and how they're encoded (possibly ASCII or UTF-8). Then take just > those snippets, and decode them. Something like this: > > data = open("some_file", "rb") > text_part = data[2718:3142] > decoded_text = text_part.decode("utf-8") > > That'll give you a usable Unicode string, assuming you have your > offsets and encoding correct. > Thanks Chris. Please read my response to Dave. From cs at zip.com.au Tue Mar 10 00:14:31 2015 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 10 Mar 2015 15:14:31 +1100 Subject: Python3: Reading a text/binary mixed file In-Reply-To: References: Message-ID: <20150310041431.GA45319@cskk.homeip.net> On 10Mar2015 04:01, Paulo da Silva wrote: >On 10-03-2015 00:55, Dave Angel wrote: >> On 03/09/2015 08:45 PM, Paulo da Silva wrote: >>> What is the best way to read a file that begins with some few text lines >>> and whose rest is a binary stream? [...] >> Generally speaking, you can treat a piece of a binary (input) file as an >> encoded string, so you want to open the file as binary, locate the part >> that's text, and then explicitly decode the string from that. > >That's waht I did. However, I was thinking of some other more efficient >and simple way. For example a command to read text and another to read >bytes. > >For .pnm photo files I read the entire file (I needed it in memory >anyway), splited a copy separated by b'\n', got the headers stuff and >then used the original remaining bytes as the photo pixels. >But this is very tricky! I am on linux, but if I ran this program on >windows I needed to change it to "eat" also the '\r'. If you're in Python 3 (recommended!) and you're parsing the headers as text, you should be converting your split binary into strings anyway. So you can just use .strip() or rstrip(); either will remove trailing '\r' and '\n', so it will work in both UNIX and Windows. >In the .pnm case the headers don't have special chars. They fit into >ascii. But in a file who have them it would be also difficult to compute >the consumed length. I presume you're gathering the headers in "binary" mode and decoding each to a string. So you know the consumed length from the binary half; that they're different lengths after decoding to strings is then irrelevant. Cheers, Cameron Simpson These are my principles, and if you don't like them, I have others. - Groucho Marx From shalini.ravishankar at gmail.com Tue Mar 10 01:04:06 2015 From: shalini.ravishankar at gmail.com (Shalini Ravishankar) Date: Mon, 9 Mar 2015 22:04:06 -0700 (PDT) Subject: Python Upload and Download file using Flask Web development Not Working Message-ID: Hello Everyone, I am new to Python Web development. I am creating a Web Page with FLask. The Pages takes input as file (file upload) and the process the file and gives the output as a file(downloading the file) But I am having error. My Python file : from flask import Flask from flask import render_template from flask import request, send_from_directory from werkzeug import secure_filename import os import commandFile app = Flask(__name__) UPLOAD_FOLDER = 'F:/uploads/' ALLOWED_EXTENSIONS = set(['txt']) @app.route('/') @app.route('/home') def home_page(): return render_template('home.html') @app.route('/process', methods=['GET', 'POST']) def process_page(): if request.method == 'POST': tool_selected = request.form['tool_list'] print tool_selected # Get the name of the uploaded file file = request.files['fileToupload'] filename = secure_filename(file.filename) file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) input_file = UPLOAD_FOLDER + filename print input_file return render_template('process.html', input_file = input_file, tool_selected =tool_selected ) The Form in home.html :

Input File

Action process.html :

You File has been Uploaded. Please wait ... Your file is being processed.

<% import commandFile processing = commandFile.Command_Process(tool_selected, input_file) %> processing.processFile() %>
But the output is You File is Processed. Download will begin Automatically <% import commandFile processing = commandFile.Command_Process(tool_selected, input_file) %> processing.processFile() %> The python script is not executing, it is displaying in html. Can some one tell me how do I do thid. From steve+comp.lang.python at pearwood.info Tue Mar 10 01:56:05 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 10 Mar 2015 16:56:05 +1100 Subject: Python3: Reading a text/binary mixed file References: Message-ID: <54fe8777$0$2793$c3e8da3$76491128@news.astraweb.com> Paulo da Silva wrote: > Hi! > > What is the best way to read a file that begins with some few text lines > and whose rest is a binary stream? > > As an exmaple ... files .pnm. > > Thanks for any comments/help on this. A mixed text/binary file is really a binary file that contains some binary data which is meant to be interpreted as text. (Just as other binary data is meant to be interpretered as floats, or ints, or pixel colours, or sound samples...) I would open the file in binary mode, then use readline() to extract the first few lines. If there is any chance that the lines could use Windows line endings, then you'll need to handle that yourself. Chances are you will call line.strip() to remove the trailing newline, and that will also remove the trailing carriage return, so that isn't hard. Strictly speaking, the lines you read will be *bytes*, not text, but if they are pure ASCII you won't notice any difference: byte strings in Python are displayed as if they were ASCII. If the lines are supposed to be encoded in some encoding, say Latin-1, or UTF-8, you can convert to text strings: line = line.decode('utf-8') for example. Read the documentation for the file format to learn what encoding you should use. If it isn't documented, the answer is probably ASCII or Latin-1. Remember that the ASCII encoding in Python is strictly 7- bit, so you'll get decoding errors if the strings contain bytes with the high-bit set. If you don't mind the risk of getting moji-bake, the "no brainer" solution is to use Latin-1 as the encoding. http://en.wikipedia.org/wiki/Mojibake Once you know there are no more lines, just swap to using the read() method instead of readline(). Something like this should work: with open(somefile, "rb") as f: process_text(f.readline().decode('latin-1')) process_text(f.readline().decode('latin-1')) process_text(f.readline().decode('latin-1')) data = f.read(10000) while data: process_binary(data) data = f.read(10000) -- Steve From antoon.pardon at rece.vub.ac.be Tue Mar 10 04:16:43 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 10 Mar 2015 09:16:43 +0100 Subject: Letter class in re In-Reply-To: <20150309101742.471b870c@bigbox.christie.dr> References: <54FD74BA.8010803@rece.vub.ac.be> <20150309061736.07e0d944@bigbox.christie.dr> <54FD918B.1030702@rece.vub.ac.be> <20150309075017.7076718a@bigbox.christie.dr> <54FDAE5F.10504@rece.vub.ac.be> <20150309101742.471b870c@bigbox.christie.dr> Message-ID: <54FEA86B.5010601@rece.vub.ac.be> Op 09-03-15 om 16:17 schreef Tim Chase: > On 2015-03-09 15:29, Antoon Pardon wrote: >> Op 09-03-15 om 13:50 schreef Tim Chase: >>>> (?:(?!_|\d)\w)\w+ >>> If you don't have to treat it as an atom, you can simplify that to >>> just >>> >>> (?!_|\d)\w+ >>> >>> which just means that the first character can't be an underscore >>> or digit. >>> >>> Though for a Py3 identifier, the underscore is acceptable as a >>> first character ("__init__"), so you can simplify it even further >>> to just >>> >>> (?!\d)\w+ >> No that doesn't work. To begin with my attempt above shoud have >> been: >> >> (?:(?!_|\d)\w)\w* > Did you actually test my suggestion? The "(?!\d)\w+" means "one or > more Word characters, but the first one can't be a digit" because > the "(?!...)" is zero-width. This should match single-character > strings including a single underscore. I had done some tests, but due to a misunderstanding I broke off testing prematurely. I didn't grasp the look ahead nature of the (?! combination and saw it just as a negation of the regular expression involved. But IIUC the (?!\d) will check that the next charachter is not a digit without advancing the position in the string. So that later checking for \w+ happens as if (?!\d) hadn't been present. So in effect you have part of the string that is checked against to sub regular expresssions. -- Antoon Pardon From antoon.pardon at rece.vub.ac.be Tue Mar 10 04:35:28 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 10 Mar 2015 09:35:28 +0100 Subject: Letter class in re In-Reply-To: <54fdc61f$0$12983$c3e8da3$5496439d@news.astraweb.com> References: <54fdc61f$0$12983$c3e8da3$5496439d@news.astraweb.com> Message-ID: <54FEACD0.9080308@rece.vub.ac.be> Op 09-03-15 om 17:11 schreef Steven D'Aprano: > Antoon Pardon wrote: > >> I am using PLY for a parsing task which uses re for the lexical >> analysis. Does anyone >> know what regular expression to use for a sequence of letters? There is >> a class for alphanumerics but I can't find one for just letters, which I >> find odd. >> >> I am using python 3.4 > > The re module in Python is pretty old and basic. Can you use Matthew > Barnett's regex module, available on PyPI? I understand it has a richer set > of flags for things such as Unicode letters and the like. Not really. I could use regex to build a lexer but that would mean having to do a lot of extra work, since I couldn't use the abstraction that is offered by PLY.lex. PLY.yacc allows the use of a different lexer but PLY.lex doesn't allow the use of a different regular expression engine. -- Antoon Pardon From fomcl at yahoo.com Tue Mar 10 04:46:12 2015 From: fomcl at yahoo.com (Albert-Jan Roskam) Date: Tue, 10 Mar 2015 01:46:12 -0700 Subject: Letter class in re In-Reply-To: <54FEACD0.9080308@rece.vub.ac.be> Message-ID: <1425977172.28075.YahooMailBasic@web163804.mail.gq1.yahoo.com> On Tue, 3/10/15, Antoon Pardon wrote: Subject: Re: Letter class in re To: python-list at python.org Date: Tuesday, March 10, 2015, 9:35 AM Op 09-03-15 om 17:11 schreef Steven D'Aprano: > Antoon Pardon wrote: > >> I am using PLY for a parsing task which uses re for the lexical >> analysis. Does anyone >> know what regular expression to use for a sequence of letters? There is >> a class for alphanumerics but I can't find one for just letters, which I >> find odd. >> >> I am using python 3.4 > > The re module in Python is pretty old and basic. Can you use Matthew > Barnett's regex module, available on PyPI? I understand it has a richer set > of flags for things such as Unicode letters and the like. Not really. I could use regex to build a lexer but that would mean having to do a lot of extra work, since I couldn't use the abstraction that is offered by PLY.lex. PLY.yacc allows the use of a different lexer but PLY.lex doesn't allow the use of a different regular expression engine. --> Perhaps you could use/abuse Pygments? http://pygments.org/docs/lexerdevelopment/ From miki.tebeka at gmail.com Tue Mar 10 07:12:08 2015 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Tue, 10 Mar 2015 04:12:08 -0700 (PDT) Subject: Did https://pypi.python.org/pypi/ became huge and slow? Message-ID: <0b7405e8-0caa-45ca-b629-73de6067eae3@googlegroups.com> Greetings, $ time curl -I https://pypi.python.org/pypi/ HTTP/1.1 200 OK Date: Tue, 10 Mar 2015 10:24:30 GMT ... Content-Length: 9870689 curl -I https://pypi.python.org/pypi/ 0.02s user 0.00s system 2% cpu 12.271 total $ Note the long time (for comparison hitting python.org takes 0.209 total) and the size (Content-Length). Anything gone wrong or am I missing something? Thanks, -- Miki From steve+comp.lang.python at pearwood.info Tue Mar 10 07:55:20 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 10 Mar 2015 22:55:20 +1100 Subject: Did https://pypi.python.org/pypi/ became huge and slow? References: <0b7405e8-0caa-45ca-b629-73de6067eae3@googlegroups.com> Message-ID: <54fedba9$0$12998$c3e8da3$5496439d@news.astraweb.com> Miki Tebeka wrote: > Greetings, > > $ time curl -I https://pypi.python.org/pypi/ > HTTP/1.1 200 OK > Date: Tue, 10 Mar 2015 10:24:30 GMT > ... > Content-Length: 9870689 > curl -I https://pypi.python.org/pypi/ 0.02s user 0.00s system 2% cpu > 12.271 total $ > > Note the long time (for comparison hitting python.org takes 0.209 total) > and the size (Content-Length). > > Anything gone wrong or am I missing something? I don't know. Am *I* missing something? What makes you think this is a problem? You're downloading via https, which has more overhead than http. There's a certificate that needs to be checked, the content can't be cached, and there's the cost of encryption. Do you have some reason for thinking that the content-length should not be 9870689 bytes? Should it be less or more? Have you tried opening the URL in your browser? -- Steven From rosuav at gmail.com Tue Mar 10 08:11:11 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 10 Mar 2015 23:11:11 +1100 Subject: Did https://pypi.python.org/pypi/ became huge and slow? In-Reply-To: <54fedba9$0$12998$c3e8da3$5496439d@news.astraweb.com> References: <0b7405e8-0caa-45ca-b629-73de6067eae3@googlegroups.com> <54fedba9$0$12998$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 10, 2015 at 10:55 PM, Steven D'Aprano wrote: > Miki Tebeka wrote: > >> Greetings, >> >> $ time curl -I https://pypi.python.org/pypi/ >> HTTP/1.1 200 OK >> Date: Tue, 10 Mar 2015 10:24:30 GMT >> ... >> Content-Length: 9870689 >> curl -I https://pypi.python.org/pypi/ 0.02s user 0.00s system 2% cpu >> 12.271 total $ >> >> Note the long time (for comparison hitting python.org takes 0.209 total) >> and the size (Content-Length). >> >> Anything gone wrong or am I missing something? > > I don't know. Am *I* missing something? What makes you think this is a > problem? > > You're downloading via https, which has more overhead than http. There's a > certificate that needs to be checked, the content can't be cached, and > there's the cost of encryption. Those costs don't factor in here; the content-length is what the server announces as the number of bytes of oncoming payload. > Do you have some reason for thinking that the content-length should not be > 9870689 bytes? Should it be less or more? > > Have you tried opening the URL in your browser? I just tried it now, and it's comparable in a browser. 9MB is a lot for a landing page, and while I don't have a specific record, I have a vague recollection that it wasn't quite this big before (which would mean that the landing page was paginated instead of having the entire list right there). Oh wait. What I was remembering was https://pypi.python.org/ without the extra pathing on it. And yes, that page _is_ short and fast. So that's an appropriate landing page. To the OP: You're downloading the entire list of packages, which is why it's taking so long. ChrisA From steve+comp.lang.python at pearwood.info Tue Mar 10 08:16:14 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 10 Mar 2015 23:16:14 +1100 Subject: Did https://pypi.python.org/pypi/ became huge and slow? References: <0b7405e8-0caa-45ca-b629-73de6067eae3@googlegroups.com> <54fedba9$0$12998$c3e8da3$5496439d@news.astraweb.com> Message-ID: <54fee08e$0$12993$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: [...] >> You're downloading via https, which has more overhead than http. There's >> a certificate that needs to be checked, the content can't be cached, and >> there's the cost of encryption. > > Those costs don't factor in here; the content-length is what the > server announces as the number of bytes of oncoming payload. I'm talking about the time taken to download, not the size. Downloading 9MB of encrypted data over https will be slower than downloading 9MB from a local cache over http :-) > To the OP: You're downloading the entire list of packages, which is > why it's taking so long. That seems to be the likely explanation. -- Steven From jwayodi at gmail.com Tue Mar 10 08:24:07 2015 From: jwayodi at gmail.com (Joseph Wayodi) Date: Tue, 10 Mar 2015 15:24:07 +0300 Subject: Did https://pypi.python.org/pypi/ became huge and slow? In-Reply-To: References: <0b7405e8-0caa-45ca-b629-73de6067eae3@googlegroups.com> <54fedba9$0$12998$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 10, 2015 at 3:11 PM, Chris Angelico wrote: > > Oh wait. What I was remembering was https://pypi.python.org/ without > the extra pathing on it. And yes, that page _is_ short and fast. So > that's an appropriate landing page. > > To the OP: You're downloading the entire list of packages, which is > why it's taking so long. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list I just tried, and redirects to . And you're right, the link the OP was asking about is the whole index of packages: . Does it make sense that and are completely different pages? The only difference in URLs being the slash at the end. Joseph. From rosuav at gmail.com Tue Mar 10 08:27:59 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 10 Mar 2015 23:27:59 +1100 Subject: Did https://pypi.python.org/pypi/ became huge and slow? In-Reply-To: <54fee08e$0$12993$c3e8da3$5496439d@news.astraweb.com> References: <0b7405e8-0caa-45ca-b629-73de6067eae3@googlegroups.com> <54fedba9$0$12998$c3e8da3$5496439d@news.astraweb.com> <54fee08e$0$12993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 10, 2015 at 11:16 PM, Steven D'Aprano wrote: > Chris Angelico wrote: > > [...] >>> You're downloading via https, which has more overhead than http. There's >>> a certificate that needs to be checked, the content can't be cached, and >>> there's the cost of encryption. >> >> Those costs don't factor in here; the content-length is what the >> server announces as the number of bytes of oncoming payload. > > I'm talking about the time taken to download, not the size. Downloading 9MB > of encrypted data over https will be slower than downloading 9MB from a > local cache over http :-) Ah, sure. Especially the bit about the cache :) Though I usually find that download times on https vs http aren't all that different; it takes a little bit longer to establish the connection, but less than the variation in DNS timing. Most of the time, the cost of encryption isn't the bottleneck - on a large download, transfer throughput is usually what takes the time, and on a small download, it's too hard to measure the cost anyway. ChrisA From random832 at fastmail.us Tue Mar 10 08:41:35 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Tue, 10 Mar 2015 08:41:35 -0400 Subject: Python3: Reading a text/binary mixed file In-Reply-To: References: Message-ID: <1425991295.1824462.238345477.04A1FB45@webmail.messagingengine.com> On Tue, Mar 10, 2015, at 00:01, Paulo da Silva wrote: > For .pnm photo files I read the entire file (I needed it in memory > anyway), splited a copy separated by b'\n', got the headers stuff and > then used the original remaining bytes as the photo pixels. > But this is very tricky! I am on linux, but if I ran this program on > windows I needed to change it to "eat" also the '\r'. Why? The file is the same file. If the .pnm format is allowed to have a '\r' there, you're just as likely to have to deal with it in Linux. From miki.tebeka at gmail.com Tue Mar 10 08:46:15 2015 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Tue, 10 Mar 2015 05:46:15 -0700 (PDT) Subject: Did https://pypi.python.org/pypi/ became huge and slow? In-Reply-To: References: <0b7405e8-0caa-45ca-b629-73de6067eae3@googlegroups.com> <54fedba9$0$12998$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3ae4df7f-040c-4165-8dd1-afc17fd4b4ea@googlegroups.com> Thanks Chris, I was hitting the wrong URL by mistake. Didn't think an extra / will make all that difference :) On Tuesday, March 10, 2015 at 2:12:13 PM UTC+2, Chris Angelico wrote: > On Tue, Mar 10, 2015 at 10:55 PM, Steven D'Aprano > wrote: > > Miki Tebeka wrote: > > > >> Greetings, > >> > >> $ time curl -I https://pypi.python.org/pypi/ > >> HTTP/1.1 200 OK > >> Date: Tue, 10 Mar 2015 10:24:30 GMT > >> ... > >> Content-Length: 9870689 > >> curl -I https://pypi.python.org/pypi/ 0.02s user 0.00s system 2% cpu > >> 12.271 total $ > >> > >> Note the long time (for comparison hitting python.org takes 0.209 total) > >> and the size (Content-Length). > >> > >> Anything gone wrong or am I missing something? > > > > I don't know. Am *I* missing something? What makes you think this is a > > problem? > > > > You're downloading via https, which has more overhead than http. There's a > > certificate that needs to be checked, the content can't be cached, and > > there's the cost of encryption. > > Those costs don't factor in here; the content-length is what the > server announces as the number of bytes of oncoming payload. > > > Do you have some reason for thinking that the content-length should not be > > 9870689 bytes? Should it be less or more? > > > > Have you tried opening the URL in your browser? > > I just tried it now, and it's comparable in a browser. 9MB is a lot > for a landing page, and while I don't have a specific record, I have a > vague recollection that it wasn't quite this big before (which would > mean that the landing page was paginated instead of having the entire > list right there). > > Oh wait. What I was remembering was https://pypi.python.org/ without > the extra pathing on it. And yes, that page _is_ short and fast. So > that's an appropriate landing page. > > To the OP: You're downloading the entire list of packages, which is > why it's taking so long. > > ChrisA From rosuav at gmail.com Tue Mar 10 08:55:22 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 10 Mar 2015 23:55:22 +1100 Subject: Did https://pypi.python.org/pypi/ became huge and slow? In-Reply-To: References: <0b7405e8-0caa-45ca-b629-73de6067eae3@googlegroups.com> <54fedba9$0$12998$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 10, 2015 at 11:24 PM, Joseph Wayodi wrote: > Does it make sense that and > are completely different pages? The > only difference in URLs being the slash at the end. Technically it's perfectly legal, of course, but wow, that is something I completely would not expect. ChrisA From mal at europython.eu Tue Mar 10 10:44:08 2015 From: mal at europython.eu (M.-A. Lemburg) Date: Tue, 10 Mar 2015 15:44:08 +0100 Subject: EuroPython 2015: Announcing standard ticket prices Message-ID: <54FF0338.8010003@europython.eu> Last week has been very busy. We?ve launched the website, started the early-bird ticket sales and handled the first round of attendee questions with our brand new help desk system (based on django-helpdesk). At the same time, we have been finalizing the budget for the conference, which now allows us to set the standard ticket prices for this year. We tried to keep student prices as low as possible, since we would like to see more students at the conference: Student: EUR 120.00 Personal: EUR 340.00 Business: EUR 530.00 (incl. 10% Spanish VAT) Early-bird tickets are nearly sold out but we still have a few left. If you want to save some money, you can still get these tickets at highly reduced prices. *** https://ep2015.europython.eu/en/registration/ *** After the early-bird tickets have sold out, we?ll close the registration for a short while and then reopen it with the standard prices. Given the rush to early-bird tickets, we expect the conference to sell out again this year, so don?t wait too long before getting one. Enjoy, -- EuroPython 2015 Team http://www.europython-society.org/ From ben+python at benfinney.id.au Tue Mar 10 15:50:30 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 11 Mar 2015 06:50:30 +1100 Subject: Did https://pypi.python.org/pypi/ became huge and slow? References: <0b7405e8-0caa-45ca-b629-73de6067eae3@googlegroups.com> <54fedba9$0$12998$c3e8da3$5496439d@news.astraweb.com> <3ae4df7f-040c-4165-8dd1-afc17fd4b4ea@googlegroups.com> Message-ID: <85a8zkws1l.fsf@benfinney.id.au> Miki Tebeka writes: > Thanks Chris, I was hitting the wrong URL by mistake. > Didn't think an extra / will make all that difference :) It is quite astonishing, I agree. I'd even call it a bug worth reporting; those two should be the same otherwise people are going to get quite confused. -- \ ?Faith is the determination to remain ignorant in the face of | `\ all evidence that you are ignorant.? ?Shaun Mason | _o__) | Ben Finney From p_s_d_a_s_i_l_v_a_ns at netcabo.pt Tue Mar 10 18:38:38 2015 From: p_s_d_a_s_i_l_v_a_ns at netcabo.pt (Paulo da Silva) Date: Tue, 10 Mar 2015 22:38:38 +0000 Subject: Python3: Reading a text/binary mixed file References: Message-ID: On 10-03-2015 04:14, Cameron Simpson wrote: > On 10Mar2015 04:01, Paulo da Silva wrote: >> On 10-03-2015 00:55, Dave Angel wrote: ... >> For .pnm photo files I read the entire file (I needed it in memory >> anyway), splited a copy separated by b'\n', got the headers stuff and >> then used the original remaining bytes as the photo pixels. >> But this is very tricky! I am on linux, but if I ran this program on >> windows I needed to change it to "eat" also the '\r'. > > If you're in Python 3 (recommended!) and you're parsing the headers as > text, you should be converting your split binary into strings anyway. So > you can just use .strip() or rstrip(); either will remove trailing '\r' > and '\n', so it will work in both UNIX and Windows. > I didn't know strip removes \r. >> In the .pnm case the headers don't have special chars. They fit into >> ascii. But in a file who have them it would be also difficult to compute >> the consumed length. > > I presume you're gathering the headers in "binary" mode and decoding > each to a string. So you know the consumed length from the binary half; > that they're different lengths after decoding to strings is then > irrelevant. You are right. I am still a little confused about python3. Thanks a lot From p_s_d_a_s_i_l_v_a_ns at netcabo.pt Tue Mar 10 18:48:17 2015 From: p_s_d_a_s_i_l_v_a_ns at netcabo.pt (Paulo da Silva) Date: Tue, 10 Mar 2015 22:48:17 +0000 Subject: Python3: Reading a text/binary mixed file References: Message-ID: On 10-03-2015 12:41, random832 at fastmail.us wrote: > On Tue, Mar 10, 2015, at 00:01, Paulo da Silva wrote: >> For .pnm photo files I read the entire file (I needed it in memory >> anyway), splited a copy separated by b'\n', got the headers stuff and >> then used the original remaining bytes as the photo pixels. >> But this is very tricky! I am on linux, but if I ran this program on >> windows I needed to change it to "eat" also the '\r'. > > Why? The file is the same file. If the .pnm format is allowed to have a > '\r' there, you're just as likely to have to deal with it in Linux. > Yes, but I'm creating and reading the files in linux. .pmm is just an example I'm facing now but my question was more general. According to the response of Cameron, this can be handled with 'strip'. From p_s_d_a_s_i_l_v_a_ns at netcabo.pt Tue Mar 10 18:55:44 2015 From: p_s_d_a_s_i_l_v_a_ns at netcabo.pt (Paulo da Silva) Date: Tue, 10 Mar 2015 22:55:44 +0000 Subject: Python3: Reading a text/binary mixed file References: <54fe8777$0$2793$c3e8da3$76491128@news.astraweb.com> Message-ID: On 10-03-2015 05:56, Steven D'Aprano wrote: ... Thank you very much for your post. I learned what I'm needing from it! Exactly what I was looking for. Thank you. From cs at zip.com.au Tue Mar 10 21:09:24 2015 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 11 Mar 2015 12:09:24 +1100 Subject: Python3: Reading a text/binary mixed file In-Reply-To: References: Message-ID: <20150311010924.GA84641@cskk.homeip.net> On 10Mar2015 22:38, Paulo da Silva wrote: >On 10-03-2015 04:14, Cameron Simpson wrote: >> On 10Mar2015 04:01, Paulo da Silva wrote: >>> But this is very tricky! I am on linux, but if I ran this program on >>> windows I needed to change it to "eat" also the '\r'. >> >> If you're in Python 3 (recommended!) and you're parsing the headers as >> text, you should be converting your split binary into strings anyway. So >> you can just use .strip() or rstrip(); either will remove trailing '\r' >> and '\n', so it will work in both UNIX and Windows. >> >I didn't know strip removes \r. The documentation for str.split says it strips "whitespace" by default. In the string module doco it says: string.whitespace A string containing all ASCII characters that are considered whitespace. This includes the characters space, tab, linefeed, return, formfeed, and vertical tab. [...] >> I presume you're gathering the headers in "binary" mode and decoding >> each to a string. So you know the consumed length from the binary half; >> that they're different lengths after decoding to strings is then >> irrelevant. >You are right. >I am still a little confused about python3. In this context the main point is that python 3 has a nice clean separation of str (as text) and bytes (as octet sized small ints). In general that makes it easier to work with in contexts like this because you are never confused about which you are dealing with. Since binary files (returning bytes from reads) also have a convenient readline method looking for byte 10 ('\n') this makes you current task tractable: read "binary" lines, getting bytes objects ending in byte 10, then decode each bhytes object into str objects based on the text encoding (typically utf-8, or iso8859-1 or ascii for some protocols/formats not thinking strongly about bytes vs text). Once decoded, you can then work on them as text without worrying about their former binary encoding. Cheers, Cameron Simpson Institutions will try to preserve the problem to which they are the solution. - Clay Shirky, 2012 From cs at zip.com.au Tue Mar 10 21:42:10 2015 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 11 Mar 2015 12:42:10 +1100 Subject: Did https://pypi.python.org/pypi/ became huge and slow? In-Reply-To: References: Message-ID: <20150311014210.GA87130@cskk.homeip.net> On 10Mar2015 23:27, Chris Angelico wrote: >Ah, sure. Especially the bit about the cache :) Though I usually find >that download times on https vs http aren't all that different; it >takes a little bit longer to establish the connection, but less than >the variation in DNS timing. Most of the time, the cost of encryption >isn't the bottleneck - on a large download, transfer throughput is >usually what takes the time, and on a small download, it's too hard to >measure the cost anyway. Unless you're using a satellite. High packet latency (and DNS and cert validation via said latency) put a VERY noticable upfront cost to every HTTPS connection versus HTTP. Once underway, they're essentially the same (per connection). Cheers, Cameron Simpson The Eight Fallacies of Distributed Computing - Peter Deutsch 1. The network is reliable 2. Latency is zero 3. Bandwidth is infinite 4. The network is secure 5. Topology doesn't change 6. There is one administrator 7. Transport cost is zero 8. The network is homogeneous From cs at zip.com.au Tue Mar 10 21:43:41 2015 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 11 Mar 2015 12:43:41 +1100 Subject: Did https://pypi.python.org/pypi/ became huge and slow? In-Reply-To: <85a8zkws1l.fsf@benfinney.id.au> References: <85a8zkws1l.fsf@benfinney.id.au> Message-ID: <20150311014341.GA93842@cskk.homeip.net> On 11Mar2015 06:50, Ben Finney wrote: >Miki Tebeka writes: >> Thanks Chris, I was hitting the wrong URL by mistake. >> Didn't think an extra / will make all that difference :) > >It is quite astonishing, I agree. I'd even call it a bug worth >reporting; those two should be the same otherwise people are going to >get quite confused. Yes. Also, "pypi" should redirect to "pypi/" otherwise all the relative links will be off-by-one. Not to mention normalising to a single URL for caching/mapping etc. Cheers, Cameron Simpson IE 5.0 introduces nothing but a bunch of DHTML extensions you'd never stoop to using, and yet more parochial Microsoft dialects (Want to view pages without annoying browser buttons? Just change all your .html files to .hma! Will they never learn?) - NTKnow, 16jun98, http://www.ntk.net/ From rosuav at gmail.com Tue Mar 10 21:49:43 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 11 Mar 2015 12:49:43 +1100 Subject: Did https://pypi.python.org/pypi/ became huge and slow? In-Reply-To: <20150311014210.GA87130@cskk.homeip.net> References: <20150311014210.GA87130@cskk.homeip.net> Message-ID: On Wed, Mar 11, 2015 at 12:42 PM, Cameron Simpson wrote: > On 10Mar2015 23:27, Chris Angelico wrote: >> >> Ah, sure. Especially the bit about the cache :) Though I usually find >> that download times on https vs http aren't all that different; it >> takes a little bit longer to establish the connection, but less than >> the variation in DNS timing. Most of the time, the cost of encryption >> isn't the bottleneck - on a large download, transfer throughput is >> usually what takes the time, and on a small download, it's too hard to >> measure the cost anyway. > > > Unless you're using a satellite. High packet latency (and DNS and cert > validation via said latency) put a VERY noticable upfront cost to every > HTTPS connection versus HTTP. Once underway, they're essentially the same > (per connection). Wouldn't DNS timing also be affected by that? Yes, you get more steps in the handshake with HTTPS, which means the latency is that much more significant; but all handshakes are going to be slow on satellite. And all it takes is one dropped DNS response and you're back to the top of the flowchart, hence my comment about the variation of DNS timing. But in any case, my main point still stands, when we're talking about a 9MB download. Encryption cost on the body of the transfer isn't significant. ChrisA From binki.c at mweb.co.za Wed Mar 11 05:19:17 2015 From: binki.c at mweb.co.za (binki.c at mweb.co.za) Date: Wed, 11 Mar 2015 11:19:17 +0200 Subject: I want to get involved with Python! Message-ID: Hi, I am currently a "Progress Programmer" and looking for new challenges! It seems that Python is a good language to get familiar with and I would like some advice. I am on the look-out for a new job anyway and I thought it well to look for a job as Python developer in my field. I have been working in the healthcare sector for many years now and perhaps the only way to find a job as Python programmer at this stage, will be to find a job in the healthcare sector, as this is what I am familiar with. Are there any healthcare companies using Python (anywhere in the world) that I can contact for opportunities and advice? I currently live in South Africa and would like to know what the demand for Python is in SA, but I will also consider relocating to Australia or the UK if I find it's going to be worth it. Please advise on what route you would suggest I take to become a Python developer! Thanks, Bianca. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mparchet at sunrise.ch Wed Mar 11 05:28:28 2015 From: mparchet at sunrise.ch (Michael Parchet) Date: Wed, 11 Mar 2015 10:28:28 +0100 Subject: =?utf-8?Q?Re:_Use_=C3=A0_Python_2_module_with_Python_3?= In-Reply-To: <54FE38BA.1010509@gmail.com> References: <54fe3128$0$13004$c3e8da3$5496439d@news.astraweb.com> <54FE38BA.1010509@gmail.com> Message-ID: <8B8F4288-BE25-46F7-8F30-01C2A05D42AD@sunrise.ch> Hello, The pyside project is ded. Dose pyqt4 support Python 3 ? Thanks for your answer Best regards mparchet > Le 10 mars 2015 ? 01:20, Michael Torrie a ?crit : > >> On 03/09/2015 05:47 PM, Steven D'Aprano wrote: >> Michael Parchet wrote: >> >>> Hello, >>> >>> For a new project, a person recommande me to use Python 3 >>> >>> can I use Python 3 with a Python 2 y module ex : pyQt 4 ? >> >> Maybe. >> >> If the module is really only Python 2, then no. If it is pure-Python, with >> no C extensions, then you might be able to fork it and update it to work >> with Python 3. The 2to3 tool may help with that. >> >> If a module's documentation says it works with Python 2, but doesn't mention >> Python 3 at all, it *might* work with Python 3. The author or maintainer of >> the project simply hasn't gotten around to fixing the documentation. So it >> may be worth just trying it and seeing for yourself. >> >> For PyQt specifically, googling suggests that PyQt does work with Python 3, >> but the documentation is out of date and you may have difficulty installing >> it: >> >> https://www.google.com.au/search?q=pyqt+python3 > > PySide does support Python 3. Last time I installed it, I think it did > it with pip. It will require a working C++ compiler to install it. > Both PyQt and PySide are not pure python. They have bridging code that > must be compiled. > -- > https://mail.python.org/mailman/listinfo/python-list From steve+comp.lang.python at pearwood.info Wed Mar 11 06:54:58 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 11 Mar 2015 21:54:58 +1100 Subject: Use =?UTF-8?B?w6A=?= Python 2 module with Python 3 References: <54fe3128$0$13004$c3e8da3$5496439d@news.astraweb.com> <54FE38BA.1010509@gmail.com> Message-ID: <55001f03$0$12990$c3e8da3$5496439d@news.astraweb.com> Michael Parchet wrote: > Hello, > > The pyside project is ded. What makes you think that Pyside is dead? It seems to be active to me. The latest update was just 29 days ago: https://github.com/PySide PySide supports Python 3: http://qt-project.org/wiki/PySide_Python_3_Support > Dose pyqt4 support Python 3 ? I can only repeat what I already wrote a few days ago: For PyQt specifically, googling suggests that PyQt does work with Python 3, but the documentation is out of date and you may have difficulty installing it: https://www.google.com.au/search?q=pyqt+python3 -- Steven From pcmanticore at gmail.com Wed Mar 11 09:14:03 2015 From: pcmanticore at gmail.com (Claudiu Popa) Date: Wed, 11 Mar 2015 15:14:03 +0200 Subject: [ANN] Pylint 1.4.2 / Astroid 1.3.5 released Message-ID: Hello, I'm happy to announce the release of Pylint 1.4.2 and astroid 1.3.5. The following changes were included in these releases: For pylint: * Don't require a docstring for empty modules. Closes issue #261. * Fix a false positive with `too-few-format-args` string warning, emitted when the string format contained a normal positional argument ('{0}'), mixed with a positional argument which did an attribute access ('{0.__class__}'). Closes issue #463. * Take in account all the methods from the ancestors when checking for too-few-public-methods. Closes issue #471. * Catch enchant errors and emit 'invalid-characters-in-docstring' when checking for spelling errors. Closes issue #469. * Use all the inferred statements for the super-init-not-called check. Closes issue #389. * Add a new warning, 'unichr-builtin', emitted by the Python 3 porting checker, when the unichr builtin is found. Closes issue #472. * Add a new warning, 'intern-builtin', emitted by the Python 3 porting checker, when the intern builtin is found. Closes issue #473. * Add support for editable installations. * The HTML output accepts the `--msg-template` option. Patch by Dan Goldsmith. * Add 'map-builtin-not-iterating' (replacing 'implicit-map-evaluation'), 'zip-builtin-not-iterating', 'range-builtin-not-iterating', and 'filter-builtin-not-iterating' which are emitted by `--py3k` when the appropriate built-in is not used in an iterating context (semantics taken from 2to3). * Add a new warning, 'unidiomatic-typecheck', emitted when an explicit typecheck uses type() instead of isinstance(). For example, `type(x) == Y` instead of `isinstance(x, Y)`. Patch by Chris Rebert. Closes issue #299. * Add support for combining the Python 3 checker mode with the --jobs flag (--py3k and --jobs). Closes issue #467. * Add a new warning for the Python 3 porting checker, 'using-cmp-argument', emitted when the `cmp` argument for the `list.sort` or `sorted builtin` is encountered. * Make the --py3k flag commutative with the -E flag. Also, this patch fixes the leaks of error messages from the Python 3 checker when the errors mode was activated. Closes issue #437. For astroid: * Add the ability to optimize small ast subtrees, with the first use in the optimization of multiple BinOp nodes. This removes recursivity in the rebuilder when dealing with a lot of small strings joined by the addition operator. Closes issue #59. * Obtain the methods for the nose brain tip through an unittest.TestCase instance. Closes Pylint issue #457. * Fix a crash which occurred when a class was the ancestor of itself. Closes issue #78. * Improve the scope_lookup method for Classes regarding qualified objects, with an attribute name exactly as one provided in the class itself. For example, a class containing an attribute 'first', which was also an import and which had, as a base, a qualified name or a Gettattr node, in the form 'module.first', then Pylint would have inferred the `first` name as the function from the Class, not the import. Closes Pylint issue #466. * Implement the assigned_stmts operation for Starred nodes, which was omitted when support for Python 3 was added in astroid. Closes issue #36. If you find any bugs, don't hesitate to open a new issue on our issue tracker. Enjoy! From tiya.akrid at gmail.com Wed Mar 11 09:17:05 2015 From: tiya.akrid at gmail.com (tiya.akrid at gmail.com) Date: Wed, 11 Mar 2015 06:17:05 -0700 (PDT) Subject: Urgent Need for Sr QE Automation Consultant - Sunnyvale CA (Local candidates ONLY) Message-ID: Hello, We have below position for one of the leading online retailer of sports merchandise. Let me know if you have LOCAL candidates. Please send resume with all the details asked below. Job title: Software Engineer in Quality Location: Sunnyvale, CA Rate: Open for the right candidate Type: 6 months +contract Interview Process: Onsite Only Responsibilities: - Work on an existing application in the Marketing Science team focused on maintaining internal application as well making enhancements and new features to the system. - Initially focus on quality by creating test plans, test data, data validation SQL scripts and analyze test results and then automate some of the testing and quality checks - Adding more integration to new channels and sources of data via web services as well as custom data feeds - Work closely with marketing business and technology teams and provide on-going support and guidance. - Develop scalable and reusable processes and automation frameworks for analyzing data and delivering ongoing quality metrics (leveraging SQL, PL SQL, UNIX, PYTHON and other tools) Required Skills and Experience: - 3 - 8 years' experience developing and testing highly distributed, complex eCommerce Platforms - At least 3 years hands-on software programming, Automation Scripting, White box testing experience - Python scripting experience, strong knowledge and experience in automated testing (API testing preferred), someone who has experience working in an Agile development environment, and someone who is comfortable owning the testing for a feature or project and working directly with API developers - Extensive hands-on QA & white box testing, and automation. - Nice to have - string prior QE , Python scripting - Hands-on experience working with relational DB ( Oracle, MySQL, PostgreSQL) as well NoSQL DB such as Cassandra, Redshift Please send your word format resume along with below details for further process Software Programming _______ years of experience Automation Scripting _______ years of experience WhiteBox testing _______ years of experience Python Scripting _______ years of experience Relational DB _______ years of experience Rates on c2c Availability Current Location Visa Status Regards Tiya Akrid Software Inc From torriem at gmail.com Wed Mar 11 09:44:33 2015 From: torriem at gmail.com (Michael Torrie) Date: Wed, 11 Mar 2015 07:44:33 -0600 Subject: Use =?UTF-8?B?w6AgUHl0aG9uIDIgbW9kdWxlIHdpdGggUHl0aG9uIDM=?= In-Reply-To: <8B8F4288-BE25-46F7-8F30-01C2A05D42AD@sunrise.ch> References: <54fe3128$0$13004$c3e8da3$5496439d@news.astraweb.com> <54FE38BA.1010509@gmail.com> <8B8F4288-BE25-46F7-8F30-01C2A05D42AD@sunrise.ch> Message-ID: <550046C1.8090404@gmail.com> On 03/11/2015 03:28 AM, Michael Parchet wrote: > The pyside project is ded. Why do you say PySide is dead? > Dose pyqt4 support Python 3 ? > Thanks for your answer > Best regards > mparchet Riverbank Computing has a web page that I'm sure has information on their PyQt product. (Yes PyQt is a commercial product with a GPL version). From torriem at gmail.com Wed Mar 11 09:47:17 2015 From: torriem at gmail.com (Michael Torrie) Date: Wed, 11 Mar 2015 07:47:17 -0600 Subject: Use =?windows-1252?Q?=E0_Python_2_module_with_Pyth?= =?windows-1252?Q?on_3?= In-Reply-To: <55001f03$0$12990$c3e8da3$5496439d@news.astraweb.com> References: <54fe3128$0$13004$c3e8da3$5496439d@news.astraweb.com> <54FE38BA.1010509@gmail.com> <55001f03$0$12990$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55004765.7090507@gmail.com> On 03/11/2015 04:54 AM, Steven D'Aprano wrote: >> Dose pyqt4 support Python 3 ? > > I can only repeat what I already wrote a few days ago: > > For PyQt specifically, googling suggests that PyQt does work with Python > 3, but the documentation is out of date and you may have difficulty > installing it: > > https://www.google.com.au/search?q=pyqt+python3 Yes apparently his google is broken. Here is the official site for PyQt that may have the information he seeks: http://www.riverbankcomputing.com/software/pyqt/download From jacob at blindza.co.za Wed Mar 11 09:48:23 2015 From: jacob at blindza.co.za (Jacob Kruger) Date: Wed, 11 Mar 2015 15:48:23 +0200 Subject: I want to get involved with Python! In-Reply-To: References: Message-ID: ----- Original Message ----- From: binki.c at mweb.co.za To: python-list at python.org Sent: Wednesday, March 11, 2015 11:19 AM Subject: I want to get involved with Python! > Please advise on what route you would suggest I take to become a Python > > developer! > > Thanks, > Bianca. Bianca, best bet to check out availability of positions in SA is to check out online job listing websites, like careers24, pnet and jobmail, etc. And, while have no idea about other forms of training, I just got into python by working through various forms of online tutorial material, etc., as well as working with some of the eBooks available - but, sure some of the other list members will have better/more specific suggestions in that regard. And, yes, I work in/with python, but, my other primary field of focus here in SA is web development, so not too sure about industry specific use of different languages/platforms. Stay well Jacob Kruger Blind Biker Skype: BlindZA "Roger Wilco wants to welcome you...to the space janitor's closet..." -------------- next part -------------- An HTML attachment was scrubbed... URL: From binki.c at mweb.co.za Wed Mar 11 10:10:10 2015 From: binki.c at mweb.co.za (binki.c at mweb.co.za) Date: Wed, 11 Mar 2015 16:10:10 +0200 Subject: I want to get involved with Python! Message-ID: Jacob, thanks for replying. The IT job market is soooo specific in what they are looking for here in SA and it is really hard to get a job in a programming language one hasn't been exposed to. Even when you explain to the agency that you want to learn new technologies and that the only way you can acquire it is if someone gives you a chance. The recruitment agencies blatantly block your CV for those positions and it never gets to the clients. So, I thought it best to subscribe to this mail forum and hopefully get some advice and comments. I will continue applying online though. From: jacob at blindza.co.za Sent: 2015/03/11 03:48:23 PM To: binki.c at mweb.co.za,python-list at python.org Cc: Subject: RE: Re: I want to get involved with Python! ? ----- Original Message ----- From:binki.c at mweb.co.zaTo:python-list at python.orgSent: Wednesday, March 11, 2015 11:19 AMSubject: I want to get involved with Python! > Please advise on what route you would suggest I take to become a Python > > developer! > > Thanks, > Bianca. Bianca, best bet to check out availability of positions in SA is to check out online job listing websites, like careers24, pnet and jobmail, etc. And, while have no idea about other forms of training, I just got into python by working through various forms of online tutorial material, etc., as well as working with some of the eBooks available - but, sure some of the other list members will have better/more specific suggestions in that regard. And, yes, I work in/with python, but, my other primary field of focus here in SA is web development, so not too sure about industry specific use of different languages/platforms. Stay well Jacob Kruger Blind Biker Skype: BlindZA "Roger Wilco wants to welcome you...to the space janitor's closet..." -------------- next part -------------- An HTML attachment was scrubbed... URL: From wolfgang.maier at biologie.uni-freiburg.de Wed Mar 11 10:41:02 2015 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Wed, 11 Mar 2015 15:41:02 +0100 Subject: when may sys.executable be empty Message-ID: From the documentation of sys.executable: A string giving the absolute path of the executable binary for the Python interpreter, on systems where this makes sense. If Python is unable to retrieve the real path to its executable, sys.executable will be an empty string or None. So on which systems does it not make sense ? Thanks for any help, Wolfgang From jacob at blindza.co.za Wed Mar 11 11:07:19 2015 From: jacob at blindza.co.za (Jacob Kruger) Date: Wed, 11 Mar 2015 17:07:19 +0200 Subject: I want to get involved with Python! In-Reply-To: References: Message-ID: <1B0192D6621644598702BFE88586627A@JakesPC> ----- Original Message ----- From: binki.c at mweb.co.za To: jacob at blindza.co.za Cc: python-list at python.org Sent: Wednesday, March 11, 2015 4:10 PM Subject: RE: Re: I want to get involved with Python! > Jacob, thanks for replying. The IT job market is soooo specific in what they > are looking for here in SA and it is really hard to get a job in a programming > language one hasn't been exposed to. Even when you explain to the agency > that you want to learn new technologies and that the only way you can > > > > acquire it is if someone gives you a chance. The recruitment agencies > > > blatantly block your CV for those positions and it never gets to the clients. Bianca, I know that too well - however, the one reason I got my current position was that while it primarily involves having PHP/web development abilities, they also specifically wanted a broader range of areas of experience, specifically including python, along with a couple of other languages/platforms, etc., but, it's not too common in that sense. Alternatively, UCT has recently started offering forms of online, location non-specific courses, relating to forms of certification qualifications, as well as learning, and think they might include offering some courses relating to python, etc. - and, while it's a form of remote learning, it is also a local education provider..? But, yes, am sure some of the other list members will have more to offer - I myself have no real formal training, and work in a slightly odd sector in terms of my own approach - but, will send you a bit more information specific to local python activity, off list. Stay well Jacob Kruger Blind Biker Skype: BlindZA "Roger Wilco wants to welcome you...to the space janitor's closet..." -------------- next part -------------- An HTML attachment was scrubbed... URL: From ybmess at nooos.fr.invalid Wed Mar 11 12:11:39 2015 From: ybmess at nooos.fr.invalid (YBM) Date: Wed, 11 Mar 2015 17:11:39 +0100 Subject: when may sys.executable be empty In-Reply-To: References: Message-ID: <55006939$0$3174$426a74cc@news.free.fr> Le 11/03/2015 15:41, Wolfgang Maier a ?crit : > From the documentation of sys.executable: > > A string giving the absolute path of the executable binary for the > Python interpreter, on systems where this makes sense. If Python is > unable to retrieve the real path to its executable, sys.executable will > be an empty string or None. > > So on which systems does it not make sense ? > > Thanks for any help, > Wolfgang On this kind of system (python for microcontroller, running on bare metal), I guess: http://micropython.org/ From mal at europython.eu Wed Mar 11 12:43:10 2015 From: mal at europython.eu (M.-A. Lemburg) Date: Wed, 11 Mar 2015 17:43:10 +0100 Subject: EuroPython 2015: Early-Bird tickets sold out! Message-ID: <5500709E.2090708@europython.eu> We are very happy to announce that early-bird tickets are sold out! The tickets were sold in less than a week! We?d like to thank everyone for the fantastic feedback. Given the rush to the early-bird tickets (we sold 100 tickets in the first 4 hours), we recommend to not wait too long before getting your standard ticket. It is likely, we?ll sell out early again this year. As announced we had temporarily closed the registration for a short while today and have now reopened it with the standard rate prices: *** https://ep2015.europython.eu/en/registration/ *** Enjoy, -- EuroPython 2015 Team http://www.europython-society.org/ From ian.g.kelly at gmail.com Wed Mar 11 13:06:51 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 11 Mar 2015 11:06:51 -0600 Subject: =?UTF-8?Q?Re=3A_Use_=C3=A0_Python_2_module_with_Python_3?= In-Reply-To: <55001f03$0$12990$c3e8da3$5496439d@news.astraweb.com> References: <54fe3128$0$13004$c3e8da3$5496439d@news.astraweb.com> <54FE38BA.1010509@gmail.com> <55001f03$0$12990$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Mar 11, 2015 at 4:54 AM, Steven D'Aprano wrote: > Michael Parchet wrote: > >> Hello, >> >> The pyside project is ded. > > What makes you think that Pyside is dead? It seems to be active to me. The > latest update was just 29 days ago: > > https://github.com/PySide 4 days ago, even. Seems that most of the development is still on gitorious: https://qt.gitorious.org/pyside From mparchet at sunrise.ch Wed Mar 11 13:30:25 2015 From: mparchet at sunrise.ch (Michael Parchet) Date: Wed, 11 Mar 2015 18:30:25 +0100 Subject: Use =?windows-1252?Q?=E0_Python_2_module_with_Pyth?= =?windows-1252?Q?on_3?= In-Reply-To: References: <54fe3128$0$13004$c3e8da3$5496439d@news.astraweb.com> <54FE38BA.1010509@gmail.com> <55001f03$0$12990$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55007BB1.1000106@sunrise.ch> Hello, Only one file of pyside project has update at 10 fob, What's your opinion Pyside is ded ? Best regards mparchet Le 11.03.15 18:06, Ian Kelly a ?crit : > On Wed, Mar 11, 2015 at 4:54 AM, Steven D'Aprano > wrote: >> Michael Parchet wrote: >> >>> Hello, >>> >>> The pyside project is ded. >> What makes you think that Pyside is dead? It seems to be active to me. The >> latest update was just 29 days ago: >> >> https://github.com/PySide > 4 days ago, even. Seems that most of the development is still on gitorious: > > https://qt.gitorious.org/pyside From davea at davea.name Wed Mar 11 14:15:23 2015 From: davea at davea.name (Dave Angel) Date: Wed, 11 Mar 2015 14:15:23 -0400 Subject: when may sys.executable be empty In-Reply-To: References: Message-ID: <5500863B.9020803@davea.name> On 03/11/2015 10:41 AM, Wolfgang Maier wrote: > From the documentation of sys.executable: > > A string giving the absolute path of the executable binary for the > Python interpreter, on systems where this makes sense. If Python is > unable to retrieve the real path to its executable, sys.executable will > be an empty string or None. > > So on which systems does it not make sense ? > Just speculating, but how about when the main executable is not python at all, but it uses a DLL or .so file with Python interpreter. -- DaveA From ian.g.kelly at gmail.com Wed Mar 11 14:30:08 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 11 Mar 2015 12:30:08 -0600 Subject: =?UTF-8?Q?Re=3A_Use_=C3=A0_Python_2_module_with_Python_3?= In-Reply-To: <55007BB1.1000106@sunrise.ch> References: <54fe3128$0$13004$c3e8da3$5496439d@news.astraweb.com> <54FE38BA.1010509@gmail.com> <55001f03$0$12990$c3e8da3$5496439d@news.astraweb.com> <55007BB1.1000106@sunrise.ch> Message-ID: On Wed, Mar 11, 2015 at 11:30 AM, Michael Parchet wrote: > Hello, > > Only one file of pyside project has update at 10 fob, > > What's your opinion > > Pyside is ded ? This thread has some discussion that would be useful in determining the current state of the project: https://groups.google.com/forum/#!topic/pyside-dev/weFDtFpgbzc Summarizing, it seems that Digia is not interested in PySide development, but there are a number of individuals who are. I'm not sure what the actual progress is of the work described there. PySide isn't dead. It's resting. Would it be advisable to use it at the current time for a new project that you intend to support into the future? Probably not. From tjreedy at udel.edu Wed Mar 11 14:31:43 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 11 Mar 2015 14:31:43 -0400 Subject: when may sys.executable be empty In-Reply-To: References: Message-ID: On 3/11/2015 10:41 AM, Wolfgang Maier wrote: > From the documentation of sys.executable: > > A string giving the absolute path of the executable binary for the > Python interpreter, on systems where this makes sense. If Python is > unable to retrieve the real path to its executable, sys.executable will > be an empty string or None. > > So on which systems does it not make sense ? Importing tkinter in a Python program starts up an embedded tcl interpreter to run tk, but as far as I know, there is no tcl.exe on my system, only the tcl/tk .dlls. I can imagine a similar situation with embedded python. If a python interpreter is being run as an embedded interpreter *and* there is the same version of python.exe installed, I don't know what happens. -- Terry Jan Reedy From tjreedy at udel.edu Wed Mar 11 14:43:42 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 11 Mar 2015 14:43:42 -0400 Subject: I want to get involved with Python! In-Reply-To: References: Message-ID: On 3/11/2015 5:19 AM, binki.c at mweb.co.za wrote: > I am currently a "Progress Programmer" and looking for new challenges! Are you referring to https://en.wikipedia.org/wiki/OpenEdge_Advanced_Business_Language > It seems that Python is a good language to get familiar with and I would > like some advice. I am on the look-out for a new job anyway and I > thought it well to look for a job as Python developer in my field. I > have been working in the healthcare sector for many years now and > perhaps the only way to find a job as Python programmer at this stage, > will be to find a job in the healthcare sector, as this is what I am > familiar with. Are there any healthcare companies using Python (anywhere > in the world) that I can contact for opportunities and advice? > > I currently live in South Africa and would like to know what the demand > for Python is in SA, but I will also consider relocating to Australia or > the UK if I find it's going to be worth it. > > Please advise on what route you would suggest I take to become a Python > developer! One way to establish credibility as a 'python programmer' is to make contributions to an open-source python project. Perhaps find or create a project to somehow integrate Python and Progress. -- Terry Jan Reedy From vincent.vande.vyvre at telenet.be Wed Mar 11 14:46:20 2015 From: vincent.vande.vyvre at telenet.be (Vincent Vande Vyvre) Date: Wed, 11 Mar 2015 19:46:20 +0100 Subject: Use =?windows-1252?Q?=E0_Python_2_module_with_Pyth?= =?windows-1252?Q?on_3?= In-Reply-To: References: <54fe3128$0$13004$c3e8da3$5496439d@news.astraweb.com> <54FE38BA.1010509@gmail.com> <55001f03$0$12990$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55008D7C.7000703@telenet.be> Le 11/03/2015 18:06, Ian Kelly a ?crit : > On Wed, Mar 11, 2015 at 4:54 AM, Steven D'Aprano > wrote: >> Michael Parchet wrote: >> >>> Hello, >>> >>> The pyside project is ded. >> What makes you think that Pyside is dead? It seems to be active to me. The >> latest update was just 29 days ago: >> >> https://github.com/PySide > 4 days ago, even. Seems that most of the development is still on gitorious: > > https://qt.gitorious.org/pyside In fact, the devel team of PySide has announced the official abandon of the project at the begin of this year. The announce was made in this page: http://qt-project.org/wiki/PySide ... but, now, I see this page was reversed to his old content. So, have a look at the bug tracker and you'll see some comment as this one: "PySide is abandoned by the initial development team due to a lack of funding, so right now the destiny of the bugs such as this is in hands of those who understand how to debug them." (Quoted from https://bugreports.qt.io/browse/PYSIDE-164) Vincent From devito.luigi at yahoo.com Wed Mar 11 15:12:49 2015 From: devito.luigi at yahoo.com (Dieffe Diciasette) Date: Wed, 11 Mar 2015 12:12:49 -0700 (PDT) Subject: -- redacted -- In-Reply-To: <4f5ceab4-d175-4b96-829b-8c8fab7f77f0@googlegroups.com> References: <4f5ceab4-d175-4b96-829b-8c8fab7f77f0@googlegroups.com> Message-ID: <82bdad71-f4ee-4afa-9f4f-a166301e4a14@googlegroups.com> -- redacted -- From torriem at gmail.com Wed Mar 11 15:20:23 2015 From: torriem at gmail.com (Michael Torrie) Date: Wed, 11 Mar 2015 13:20:23 -0600 Subject: Use =?windows-1252?Q?=E0_Python_2_module_with_Pyth?= =?windows-1252?Q?on_3?= In-Reply-To: <55007BB1.1000106@sunrise.ch> References: <54fe3128$0$13004$c3e8da3$5496439d@news.astraweb.com> <54FE38BA.1010509@gmail.com> <55001f03$0$12990$c3e8da3$5496439d@news.astraweb.com> <55007BB1.1000106@sunrise.ch> Message-ID: <55009577.2090808@gmail.com> On 03/11/2015 11:30 AM, Michael Parchet wrote: > Hello, > > Only one file of pyside project has update at 10 fob, > > What's your opinion > > Pyside is ded ? Qt 4 is very stable, with no new features. PySide works very well for me, and the few bugs/limitations that I know of can be worked around quite easily, and it's trivial to maintain direct compatibility with PyQt, so PyQt can always be a good fallback (remember PyQt is a commercial product, so you must buy a license if you want to use it under anything other than the GPL). My biggest complaint with PySide is that for historical reasons (looking at you, PyQt), it does not use pep8 naming conventions, which makes for some really ugly function and method names. From kwpolska at gmail.com Wed Mar 11 15:29:17 2015 From: kwpolska at gmail.com (Chris Warrick) Date: Wed, 11 Mar 2015 20:29:17 +0100 Subject: =?UTF-8?Q?Re=3A_Use_=C3=A0_Python_2_module_with_Python_3?= In-Reply-To: <55009577.2090808@gmail.com> References: <54fe3128$0$13004$c3e8da3$5496439d@news.astraweb.com> <54FE38BA.1010509@gmail.com> <55001f03$0$12990$c3e8da3$5496439d@news.astraweb.com> <55007BB1.1000106@sunrise.ch> <55009577.2090808@gmail.com> Message-ID: On Wed, Mar 11, 2015 at 8:20 PM, Michael Torrie wrote: > My biggest complaint with PySide is that for historical reasons (looking > at you, PyQt), it does not use pep8 naming conventions, which makes for > some really ugly function and method names. This isn?t PyQt?s fault. Both are more-or-less straight bindings to the underlying C++ Qt library, which does not follow Python?s naming conventions. -- Chris Warrick PGP: 5EAAEA16 From p_s_d_a_s_i_l_v_a_ns at netcabo.pt Wed Mar 11 15:29:55 2015 From: p_s_d_a_s_i_l_v_a_ns at netcabo.pt (Paulo da Silva) Date: Wed, 11 Mar 2015 19:29:55 +0000 Subject: Python3: Reading a text/binary mixed file References: Message-ID: On 11-03-2015 01:09, Cameron Simpson wrote: > On 10Mar2015 22:38, Paulo da Silva wrote: >> On 10-03-2015 04:14, Cameron Simpson wrote: ... > > Since binary files (returning bytes from reads) also have a convenient > readline method looking for byte 10 ('\n') this makes you current task > tractable ... That was the big part of my problem. I wrongly assumed that readline was not available in binary mode. I should have tried it in first place :-) Thanks From torriem at gmail.com Wed Mar 11 15:31:00 2015 From: torriem at gmail.com (Michael Torrie) Date: Wed, 11 Mar 2015 13:31:00 -0600 Subject: Use =?UTF-8?B?w6AgUHl0aG9uIDIgbW9kdWxlIHdpdGggUHl0aG9uIDM=?= In-Reply-To: References: <54fe3128$0$13004$c3e8da3$5496439d@news.astraweb.com> <54FE38BA.1010509@gmail.com> <55001f03$0$12990$c3e8da3$5496439d@news.astraweb.com> <55007BB1.1000106@sunrise.ch> <55009577.2090808@gmail.com> Message-ID: <550097F4.6070509@gmail.com> On 03/11/2015 01:29 PM, Chris Warrick wrote: > On Wed, Mar 11, 2015 at 8:20 PM, Michael Torrie wrote: >> My biggest complaint with PySide is that for historical reasons (looking >> at you, PyQt), it does not use pep8 naming conventions, which makes for >> some really ugly function and method names. > > This isn?t PyQt?s fault. Both are more-or-less straight bindings to > the underlying C++ Qt library, which does not follow Python?s naming > conventions. Yes, but they could have simply converted the native Qt names to pep8. Particularly when the bindings are automatically generated. From jcasale at activenetwerx.com Wed Mar 11 15:32:28 2015 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Wed, 11 Mar 2015 19:32:28 +0000 Subject: Callbacks with concurrent.futures Message-ID: I have a ProcessPoolExecutor for which I am attaching multiple callbacks. As this must be process based and not thread based, I don't have the luxury communication between threads. Without a queue, does something inherent exist in concurrent futures that allows me to accumulate some data from the final callback? Thanks, jlc From ian.g.kelly at gmail.com Wed Mar 11 15:40:36 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 11 Mar 2015 13:40:36 -0600 Subject: Callbacks with concurrent.futures In-Reply-To: References: Message-ID: On Wed, Mar 11, 2015 at 1:32 PM, Joseph L. Casale wrote: > I have a ProcessPoolExecutor for which I am attaching multiple callbacks. > As this must be process based and not thread based, I don't have the > luxury communication between threads. Without a queue, does something > inherent exist in concurrent futures that allows me to accumulate some > data from the final callback? ProcessPoolExecutor is built on the multiprocessing module, so I expect you should be able to use multiprocessing.Queue or multiprocessing.Pipe in place of threading.Queue. From jcasale at activenetwerx.com Wed Mar 11 16:18:02 2015 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Wed, 11 Mar 2015 20:18:02 +0000 Subject: Callbacks with concurrent.futures In-Reply-To: References: , Message-ID: <1426105082510.32347@activenetwerx.com> > ProcessPoolExecutor is built on the multiprocessing module, so I > expect you should be able to use multiprocessing.Queue or > multiprocessing.Pipe in place of threading.Queue. Hi Ian, Yeah I am using a Manager.Queue as the method polling the queue is itself in a process. I just wondered if there was some facility in the module that provided communication or if I had to handle. Thanks! jlc From robert.kern at gmail.com Wed Mar 11 17:36:11 2015 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 11 Mar 2015 21:36:11 +0000 Subject: Use =?UTF-8?B?w6AgUHl0aG9uIDIgbW9kdWxlIHdpdGggUHl0aG9uIDM=?= In-Reply-To: <550097F4.6070509@gmail.com> References: <54fe3128$0$13004$c3e8da3$5496439d@news.astraweb.com> <54FE38BA.1010509@gmail.com> <55001f03$0$12990$c3e8da3$5496439d@news.astraweb.com> <55007BB1.1000106@sunrise.ch> <55009577.2090808@gmail.com> <550097F4.6070509@gmail.com> Message-ID: On 2015-03-11 19:31, Michael Torrie wrote: > On 03/11/2015 01:29 PM, Chris Warrick wrote: >> On Wed, Mar 11, 2015 at 8:20 PM, Michael Torrie wrote: >>> My biggest complaint with PySide is that for historical reasons (looking >>> at you, PyQt), it does not use pep8 naming conventions, which makes for >>> some really ugly function and method names. >> >> This isn?t PyQt?s fault. Both are more-or-less straight bindings to >> the underlying C++ Qt library, which does not follow Python?s naming >> conventions. > > Yes, but they could have simply converted the native Qt names to pep8. > Particularly when the bindings are automatically generated. It is *extremely* helpful to have the names be the same in both C++ and PySide as the documentation uses the C++ names, as well as every Googleable conversation about Qt on the internet. It would be unnecessarily crippling to change the names to satisfy a purely optional style guide. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From robert.kern at gmail.com Wed Mar 11 17:38:02 2015 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 11 Mar 2015 21:38:02 +0000 Subject: Use =?UTF-8?B?w6AgUHl0aG9uIDIgbW9kdWxlIHdpdGggUHl0aG9uIDM=?= In-Reply-To: <55008D7C.7000703@telenet.be> References: <54fe3128$0$13004$c3e8da3$5496439d@news.astraweb.com> <54FE38BA.1010509@gmail.com> <55001f03$0$12990$c3e8da3$5496439d@news.astraweb.com> <55008D7C.7000703@telenet.be> Message-ID: On 2015-03-11 18:46, Vincent Vande Vyvre wrote: > Le 11/03/2015 18:06, Ian Kelly a ?crit : >> On Wed, Mar 11, 2015 at 4:54 AM, Steven D'Aprano >> wrote: >>> Michael Parchet wrote: >>> >>>> Hello, >>>> >>>> The pyside project is ded. >>> What makes you think that Pyside is dead? It seems to be active to me. The >>> latest update was just 29 days ago: >>> >>> https://github.com/PySide >> 4 days ago, even. Seems that most of the development is still on gitorious: >> >> https://qt.gitorious.org/pyside > > In fact, the devel team of PySide has announced the official abandon of the > project at the begin of this year. > > The announce was made in this page: > > http://qt-project.org/wiki/PySide > > ... but, now, I see this page was reversed to his old content. Indeed, because that comment was not placed there by the PySide dev team. > So, have a look at the bug tracker and you'll see some comment as this one: > > "PySide is abandoned by the initial development team due to a lack of funding, > so right now the destiny of the bugs such as this is in hands of those who > understand how to debug them." > > (Quoted from https://bugreports.qt.io/browse/PYSIDE-164) Anatoly was wrong. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From polyvertex at gmail.com Wed Mar 11 17:59:11 2015 From: polyvertex at gmail.com (polyvertex at gmail.com) Date: Wed, 11 Mar 2015 14:59:11 -0700 (PDT) Subject: MSVC2013 In-Reply-To: References: <7ec7c58b-f021-4a21-bd26-a2c9030c6ba9@googlegroups.com> <51172c2b-5262-4d09-bee7-06ca3fdbddf4@googlegroups.com> Message-ID: On Sunday, March 8, 2015 at 7:51:17 PM UTC+1, Mark Lawrence wrote: > On 08/03/2015 17:57, polyvertex at gmail.com wrote: > > On Saturday, March 7, 2015 at 5:36:07 PM UTC+1, Mark Lawrence wrote: > >> On 07/03/2015 15:55, polyvertex at gmail.com wrote: > >>> Out of curiosity, is there any plan to use a more recent version of Visual Studio (i.e.: 2013) to compile the official Python3 distribution for Windows? > >>> Is it in discussion? Maybe waiting for the 2015 version? > >>> > >>> I'm working on a C++ software that embeds Python3, currently compiled with MSVC2010 and would like to upgrade to MSVC2013, but it appears that, while being feasible, Python3 won't compile out of the box with that configuration. I would like to avoid that hassle if possible... > >>> > >>> Cheers, > >>> > >> > >> I'm building Python 3.5 every day with 2013 no problems at all, thanks > >> mainly to the work on the build system by Zach Ware and Steve Dower. If > >> 2015 is stable that will be used for 3.5 else we'll stick with 2013. > >> > >> -- > >> My fellow Pythonistas, ask not what our language can do for you, ask > >> what you can do for our language. > >> > >> Mark Lawrence > > > > For the record, I successfully compiled v3.5.0a1 (the latest 3.5 candidate as of today) with a fresh install of msvc2013. I ran the PCbuild/get_externals.bat script manually then opened the pcbuild.sln to launch a "Release/x64" build. > > > > Note that I had to launch the global build twice since the first one failed due to header not found during _tkinter build. Re-launching the global build without modifying any setting/property just did the job flawlessly. > > > > http://bugs.python.org/issue23452 > > > As a quick test, I copied the built binaries (python.exe, .dll and .pyd files) in a new directory, as well as the content of the Lib folder. Then I started an interpreter session and typed some random imports. It all worked like a charm. > > > > Thank you for your answers. > > > > No problem :) > > -- > My fellow Pythonistas, ask not what our language can do for you, ask > what you can do for our language. > > Mark Lawrence It seems I encountered issue #17797: http://bugs.python.org/issue17797 Should I update the bug with my config? (i.e.: native x64 GUI application embedding version 3.5a2, built with MSVC2013 SP4) Don't even know if I can as a guest... It is unclear to me whether or not a workaround will be implemented in 3.5 branch for pre-MSVC2015 compilers. From breamoreboy at yahoo.co.uk Wed Mar 11 19:02:42 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 11 Mar 2015 23:02:42 +0000 Subject: MSVC2013 In-Reply-To: References: <7ec7c58b-f021-4a21-bd26-a2c9030c6ba9@googlegroups.com> <51172c2b-5262-4d09-bee7-06ca3fdbddf4@googlegroups.com> Message-ID: On 11/03/2015 21:59, polyvertex at gmail.com wrote: > On Sunday, March 8, 2015 at 7:51:17 PM UTC+1, Mark Lawrence wrote: >> On 08/03/2015 17:57, polyvertex at gmail.com wrote: >>> On Saturday, March 7, 2015 at 5:36:07 PM UTC+1, Mark Lawrence wrote: >>>> On 07/03/2015 15:55, polyvertex at gmail.com wrote: >>>>> Out of curiosity, is there any plan to use a more recent version of Visual Studio (i.e.: 2013) to compile the official Python3 distribution for Windows? >>>>> Is it in discussion? Maybe waiting for the 2015 version? >>>>> >>>>> I'm working on a C++ software that embeds Python3, currently compiled with MSVC2010 and would like to upgrade to MSVC2013, but it appears that, while being feasible, Python3 won't compile out of the box with that configuration. I would like to avoid that hassle if possible... >>>>> >>>>> Cheers, >>>>> >>>> >>>> I'm building Python 3.5 every day with 2013 no problems at all, thanks >>>> mainly to the work on the build system by Zach Ware and Steve Dower. If >>>> 2015 is stable that will be used for 3.5 else we'll stick with 2013. >>>> >>>> -- >>>> My fellow Pythonistas, ask not what our language can do for you, ask >>>> what you can do for our language. >>>> >>>> Mark Lawrence >>> >>> For the record, I successfully compiled v3.5.0a1 (the latest 3.5 candidate as of today) with a fresh install of msvc2013. I ran the PCbuild/get_externals.bat script manually then opened the pcbuild.sln to launch a "Release/x64" build. >>> >>> Note that I had to launch the global build twice since the first one failed due to header not found during _tkinter build. Re-launching the global build without modifying any setting/property just did the job flawlessly. >>> >> >> http://bugs.python.org/issue23452 >> >>> As a quick test, I copied the built binaries (python.exe, .dll and .pyd files) in a new directory, as well as the content of the Lib folder. Then I started an interpreter session and typed some random imports. It all worked like a charm. >>> >>> Thank you for your answers. >>> >> >> No problem :) >> >> -- >> My fellow Pythonistas, ask not what our language can do for you, ask >> what you can do for our language. >> >> Mark Lawrence > > It seems I encountered issue #17797: > http://bugs.python.org/issue17797 > > Should I update the bug with my config? (i.e.: native x64 GUI application embedding version 3.5a2, built with MSVC2013 SP4) > Don't even know if I can as a guest... Just create yourself a login, doesn't take five minutes, ask the occasional spammer who gets in :) > > It is unclear to me whether or not a workaround will be implemented in 3.5 branch for pre-MSVC2015 compilers. > I would think not but please don't quote me on that, it's all down to the Windows core developers. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From marfig at gmail.com Wed Mar 11 19:33:17 2015 From: marfig at gmail.com (Mario Figueiredo) Date: Thu, 12 Mar 2015 00:33:17 +0100 Subject: __new__() does not return anything, on singletong pattern Message-ID: <6fh1ga59ia3m07kd20p6me5d2n2c3v7qhg@4ax.com> I'm fairly new to Python, so I don't know if the following is me abusing the programming language idioms, or simply a mistake of my IDE code inspection routine. I have a singleton Map class which is defined like so: class Map: _instance = None def __new__(cls): if Map._instance is None: Map._instance = super(Map, cls).__new__(cls) return Map._instance def __init__(self, filename): # Instantiates from the contents of a binary file I am now trying to add another way of constructing an instance of this class. (I need to be able to create a dirty empty instance that is going to be used by the separate map editor script). I added the following method to the class definition, above: @classmethod def generate(cls, width, height, fill=terrain[6]): if Map._instance is None: Map._instance = super(Map, cls).__new__(cls) else: raise Exception('Cannot generate an instance of Map.') Map._instance.author = None Map._instance.name = None Map._instance.description = None # etc... self.cells = [Cell(fill)] * width * height return Map._instance The following code runs just fine. But PyCharm flags the assignment with a warning telling me that generate() does not return anything and the I lose code completion on the mmap variable. if __name__ == '__main__': mmap = Map.generate(12, 24) print(mmap.width, mmap.height, mmap.author) I need to understand if this is just a glitch of the IDE or I am doing indeed something that is frowned upon and ended up caught in a misleading static analysis warning. From ethan at stoneleaf.us Wed Mar 11 19:47:32 2015 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 11 Mar 2015 16:47:32 -0700 Subject: __new__() does not return anything, on singletong pattern In-Reply-To: <6fh1ga59ia3m07kd20p6me5d2n2c3v7qhg@4ax.com> References: <6fh1ga59ia3m07kd20p6me5d2n2c3v7qhg@4ax.com> Message-ID: <5500D414.5010405@stoneleaf.us> On 03/11/2015 04:33 PM, Mario Figueiredo wrote: > The following code runs just fine. But PyCharm flags the assignment > with a warning telling me that generate() does not return anything and > the I lose code completion on the mmap variable. > > if __name__ == '__main__': > mmap = Map.generate(12, 24) > print(mmap.width, mmap.height, mmap.author) > > I need to understand if this is just a glitch of the IDE or I am doing > indeed something that is frowned upon and ended up caught in a > misleading static analysis warning. You're code is good. The only question is if you /really/ need a singleton -- and only you can answer that (although plenty of folks will tell you you don't ;) . -- ~Ethan~ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: OpenPGP digital signature URL: From frank at chagford.com Thu Mar 12 01:29:46 2015 From: frank at chagford.com (Frank Millman) Date: Thu, 12 Mar 2015 07:29:46 +0200 Subject: I want to get involved with Python! References: Message-ID: Original Message ----- From:binki.c at mweb.co.zaTo:python-list at python.orgSent: Wednesday, March 11, 2015 11:19 AMSubject: I want to get involved with Python! > Please advise on what route you would suggest I take to become a Python > > > developer! > > Thanks, > Bianca. There is a Capetown Python User Group and a Gauteng Python User Group. They both use Google Groups for communication - http://groups.google.com/group/ctpug. http://groups.google.com/group/gpugsa It is worth subscribing to both. Jobs are advertised from time to time (mostly in Capetown). Have a look through the archives. Both groups organise monthly meetings - a good opportunity to mix with other Python developers. Frank Millman From steve+comp.lang.python at pearwood.info Thu Mar 12 01:31:12 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 12 Mar 2015 16:31:12 +1100 Subject: __new__() does not return anything, on singletong pattern References: <6fh1ga59ia3m07kd20p6me5d2n2c3v7qhg@4ax.com> Message-ID: <550124a3$0$12920$c3e8da3$5496439d@news.astraweb.com> Mario Figueiredo wrote: > I'm fairly new to Python, so I don't know if the following is me > abusing the programming language idioms, or simply a mistake of my IDE > code inspection routine. > > I have a singleton Map class which is defined like so: > > class Map: > _instance = None > def __new__(cls): > if Map._instance is None: > Map._instance = super(Map, cls).__new__(cls) > return Map._instance In Python 2, you need to inherit from object for __new__ to be called. In Python 3, it doesn't matter. > def __init__(self, filename): > # Instantiates from the contents of a binary file > > I am now trying to add another way of constructing an instance of this > class. (I need to be able to create a dirty empty instance that is > going to be used by the separate map editor script). If this is supposed to be a singleton, you can't create more instances. The point of a singleton that there is only one instance (or perhaps a small number, two or three say). Why do you need two different ways to create instances if you only have one instance? > I added the following method to the class definition, above: > > @classmethod > def generate(cls, width, height, fill=terrain[6]): > if Map._instance is None: > Map._instance = super(Map, cls).__new__(cls) > else: > raise Exception('Cannot generate an instance of Map.') > > Map._instance.author = None > Map._instance.name = None Since this method modifies the singleton instance in place, it doesn't generate a new instance. It shouldn't be called generate(). In fact since this is a singleton, the method shouldn't exist at all. Just put the initialisation code in __new__, drop the __init__ and generate methods, and call Map(argument). def __new__(cls, width, height, fill=terrain[6]): if Map._instance is None: instance = Map._instance = super(Map, cls).__new__(cls) instance.author = None instance.name = None instance.description = None instance.cells = [Cell(fill)] * width * height else: # Ignore the arguments. Why are you passing different arguments # to a singleton class? Bleh. instance = Map._instance return instance > Map._instance.description = None > # etc... > self.cells = [Cell(fill)] * width * height > return Map._instance That's not your actual code, since the indentation is wrong. What does your actual code look like? You are running PyCharm on one piece of code, then showing us *different* (edited) code. We cannot see what PyCharm sees, so how do we know why PyCharm says what it says? > The following code runs just fine. But PyCharm flags the assignment > with a warning telling me that generate() does not return anything and > the I lose code completion on the mmap variable. > > if __name__ == '__main__': > mmap = Map.generate(12, 24) > print(mmap.width, mmap.height, mmap.author) > > I need to understand if this is just a glitch of the IDE or I am doing > indeed something that is frowned upon and ended up caught in a > misleading static analysis warning. Probably. -- Steve From binki.c at mweb.co.za Thu Mar 12 02:12:24 2015 From: binki.c at mweb.co.za (binki.c at mweb.co.za) Date: Thu, 12 Mar 2015 08:12:24 +0200 Subject: I want to get involved with Python! Message-ID: Thanks, everyone, for the advice so far - I am impressed with the way everyone wants to help! From: frank at chagford.com Sent: 2015/03/12 07:29:46 AM To: python-list at python.org Cc: Subject: RE: Re: I want to get involved with Python! Original Message ----- From:binki.c at mweb.co.zaTo:python-list at python.orgSent: Wednesday, March 11, 2015 11:19 AMSubject: I want to get involved with Python! > Please advise on what route you would suggest I take to become a Python > > > developer! > > Thanks, > Bianca. There is a Capetown Python User Group and a Gauteng Python User Group. They both use Google Groups for communication - http://groups.google.com/group/ctpug. http://groups.google.com/group/gpugsa It is worth subscribing to both. Jobs are advertised from time to time (mostly in Capetown). Have a look through the archives. Both groups organise monthly meetings - a good opportunity to mix with other Python developers. Frank Millman -- https://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From nispray at gmail.com Thu Mar 12 03:41:35 2015 From: nispray at gmail.com (Wesley) Date: Thu, 12 Mar 2015 00:41:35 -0700 (PDT) Subject: Pillow installation failed for python with my custom opcode Message-ID: <11c72c75-fd83-4ff8-bdd3-1ada8abb613c@googlegroups.com> Hi guys, I don't know if here is right place for asking this question, if not, please help me route to the right place. I do some simple tests on custom opcode for python. 1. change opcode.h: for example: #define PRINT_EXPR 70 #define PRINT_ITEM 71 #define PRINT_NEWLINE 72 #define PRINT_ITEM_TO 73 #define PRINT_NEWLINE_TO 74 to this new values: #define PRINT_EXPR 74 #define PRINT_ITEM 70 #define PRINT_NEWLINE 71 #define PRINT_ITEM_TO 72 #define PRINT_NEWLINE_TO 73 2. then, configure/make/make install I see the customized python is executable. And, I use pip to install other packages like django,south, mysql-python successfully. But, when I execute 'pip install pillow' to install pillow version 2.7, error happend and snippet here: Building using 4 processes gcc -pthread -shared build/temp.linux-x86_64-2.7-pydebug/_imaging.o build/temp.linux-x86_64-2.7-pydebug/decode.o build/temp.linux-x86_64-2.7-pydebug/encode.o build/temp.linux-x86_64-2.7-pydebug/map.o build/temp.linux-x86_64-2.7-pydebug/display.o build/temp.linux-x86_64-2.7-pydebug/outline.o build/temp.linux-x86_64-2.7-pydebug/path.o build/temp.linux-x86_64-2.7-pydebug/libImaging/Access.o build/temp.linux-x86_64-2.7-pydebug/libImaging/AlphaComposite.o build/temp.linux-x86_64-2.7-pydebug/libImaging/Resample.o build/temp.linux-x86_64-2.7-pydebug/libImaging/Bands.o build/temp.linux-x86_64-2.7-pydebug/libImaging/BitDecode.o build/temp.linux-x86_64-2.7-pydebug/libImaging/Blend.o build/temp.linux-x86_64-2.7-pydebug/libImaging/Chops.o build/temp.linux-x86_64-2.7-pydebug/libImaging/Convert.o build/temp.linux-x86_64-2.7-pydebug/libImaging/ConvertYCbCr.o build/temp.linux-x86_64-2.7-pydebug/libImaging/Copy.o build/temp.linux-x86_64-2.7-pydebug/libImaging/Crc32.o build/temp.linux-x86_64-2.7-pydebug/libImaging/Crop.o build/temp.linux-x86_64-2.7-pydebug/libImaging/Dib.o build/temp.linux-x86_64-2.7-pydebug/libImaging/Draw.o build/temp.linux-x86_64-2.7-pydebug/libImaging/Effects.o build/temp.linux-x86_64-2.7-pydebug/libImaging/EpsEncode.o build/temp.linux-x86_64-2.7-pydebug/libImaging/File.o build/temp.linux-x86_64-2.7-pydebug/libImaging/Fill.o build/temp.linux-x86_64-2.7-pydebug/libImaging/Filter.o build/temp.linux-x86_64-2.7-pydebug/libImaging/FliDecode.o build/temp.linux-x86_64-2.7-pydebug/libImaging/Geometry.o build/temp.linux-x86_64-2.7-pydebug/libImaging/GetBBox.o build/temp.linux-x86_64-2.7-pydebug/libImaging/GifDecode.o build/temp.linux-x86_64-2.7-pydebug/libImaging/GifEncode.o build/temp.linux-x86_64-2.7-pydebug/libImaging/HexDecode.o build/temp.linux-x86_64-2.7-pydebug/libImaging/Histo.o build/temp.linux-x86_64-2.7-pydebug/libImaging/JpegDecode.o build/temp.linux-x86_64-2.7-pydebug/libImaging/JpegEncode.o build/temp.linux-x86_64-2.7-pydebug/libImaging/LzwDecode.o build/temp.linux-x86_64-2.7-pydebug/libImaging/Matrix.o build/temp.linux-x86_64-2.7-pydebug/libImaging/ModeFilter.o build/temp.linux-x86_64-2.7-pydebug/libImaging/MspDecode.o build/temp.linux-x86_64-2.7-pydebug/libImaging/Negative.o build/temp.linux-x86_64-2.7-pydebug/libImaging/Offset.o build/temp.linux-x86_64-2.7-pydebug/libImaging/Pack.o build/temp.linux-x86_64-2.7-pydebug/libImaging/PackDecode.o build/temp.linux-x86_64-2.7-pydebug/libImaging/Palette.o build/temp.linux-x86_64-2.7-pydebug/libImaging/Paste.o build/temp.linux-x86_64-2.7-pydebug/libImaging/Quant.o build/temp.linux-x86_64-2.7-pydebug/libImaging/QuantOctree.o build/temp.linux-x86_64-2.7-pydebug/libImaging/QuantHash.o build/temp.linux-x86_64-2.7-pydebug/libImaging/QuantHeap.o build/temp.linux-x86_64-2.7-pydebug/libImaging/PcdDecode.o build/temp.linux-x86_64-2.7-pydebug/libImaging/PcxDecode.o build/temp.linux-x86_64-2.7-pydebug/libImaging/PcxEncode.o build/temp.linux-x86_64-2.7-pydebug/libImaging/Point.o build/temp.linux-x86_64-2.7-pydebug/libImaging/RankFilter.o build/temp.linux-x86_64-2.7-pydebug/libImaging/RawDecode.o build/temp.linux-x86_64-2.7-pydebug/libImaging/RawEncode.o build/temp.linux-x86_64-2.7-pydebug/libImaging/Storage.o build/temp.linux-x86_64-2.7-pydebug/libImaging/SunRleDecode.o build/temp.linux-x86_64-2.7-pydebug/libImaging/TgaRleDecode.o build/temp.linux-x86_64-2.7-pydebug/libImaging/Unpack.o build/temp.linux-x86_64-2.7-pydebug/libImaging/UnpackYCC.o build/temp.linux-x86_64-2.7-pydebug/libImaging/UnsharpMask.o build/temp.linux-x86_64-2.7-pydebug/libImaging/XbmDecode.o build/temp.linux-x86_64-2.7-pydebug/libImaging/XbmEncode.o build/temp.linux-x86_64-2.7-pydebug/libImaging/ZipDecode.o build/temp.linux-x86_64-2.7-pydebug/libImaging/ZipEncode.o build/temp.linux-x86_64-2.7-pydebug/libImaging/TiffDecode.o build/temp.linux-x86_64-2.7-pydebug/libImaging/Incremental.o build/temp.linux-x86_64-2.7-pydebug/libImaging/Jpeg2KDecode.o build/temp.linux-x86_64-2.7-pydebug/libImaging/Jpeg2KEncode.o build/temp.linux-x86_64-2.7-pydebug/libImaging/BoxBlur.o -L/home/src/mypy27/lib -L/lib64 -L/usr/lib64 -L/usr/local/lib -L/usr/lib -L/home/src/mypy276/lib -ljpeg -lz -lpython2.7 -o build/lib.linux-x86_64-2.7-pydebug/PIL/_imaging.so /usr/bin/ld: /usr/local/lib/libpython2.7.a(abstract.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC /usr/local/lib/libpython2.7.a: could not read symbols: Bad value collect2: ld return 1 error: command 'gcc' failed with exit status 1 [74447 refs] ---------------------------------------- Cleaning up... Command /home/src/mypy27/bin/python2.7 -c "import setuptools;__file__='/home/src/mypy27/build/pillow/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-Y7XweN-record/install-record.txt --single-version-externally-managed --install-headers /home/src/mypy27/include/site/python2.7 failed with error code 1 in /home/src/mypy27/build/pillow Traceback (most recent call last): File "/home/src/mypy27/bin/pip", line 9, in load_entry_point('pip==1.4.1', 'console_scripts', 'pip')() File "/home/src/mypy27/lib/python2.7/site-packages/pip/__init__.py", line 148, in main return command.main(args[1:], options) File "/home/src/mypy27/lib/python2.7/site-packages/pip/basecommand.py", line 169, in main text = '\n'.join(complete_log) UnicodeDecodeError: 'ascii' codec can't decode byte 0xe8 in position 17: ordinal not in range(128) [103880 refs] I see /usr/local/lib/libpython2.7.a is the formal python2.7.6's, and here is libpython2.7.a in my system: (mypy27)[root at localhost testforpythonencode]# find / -name libpython2.7.a /usr/local/lib/python2.7/config/libpython2.7.a /usr/local/lib/libpython2.7.a /home/src/Python-2.7.6/libpython2.7.a /home/src/mypy276/lib/python2.7/config/libpython2.7.a The last one is my customized python location. For pillow installation, shall I need to specify libpython2.7.a path? But I don't know why other packages are correct. Anyone knows what's wrong here? Thanks. Wesley From marfig at gmail.com Thu Mar 12 04:00:37 2015 From: marfig at gmail.com (Mario Figueiredo) Date: Thu, 12 Mar 2015 09:00:37 +0100 Subject: __new__() does not return anything, on singletong pattern References: <6fh1ga59ia3m07kd20p6me5d2n2c3v7qhg@4ax.com> <550124a3$0$12920$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, 12 Mar 2015 16:31:12 +1100, Steven D'Aprano wrote: >Mario Figueiredo wrote: > > >If this is supposed to be a singleton, you can't create more instances. The >point of a singleton that there is only one instance (or perhaps a small >number, two or three say). Why do you need two different ways to create >instances if you only have one instance? > The map is instantiated from the contents of a saved map file on the main application. A different application, a map editor, needs to also instantiate an object of the class Map. But in this case the map needs to either be empty (if the user wants to create a new map), or loaded from the saved map file (if the user wants to edit an existing map). > >> I added the following method to the class definition, above: >> >> @classmethod >> def generate(cls, width, height, fill=terrain[6]): >> if Map._instance is None: >> Map._instance = super(Map, cls).__new__(cls) >> else: >> raise Exception('Cannot generate an instance of Map.') >> >> Map._instance.author = None >> Map._instance.name = None > >Since this method modifies the singleton instance in place, it doesn't >generate a new instance. It shouldn't be called generate(). No sure what you mean. That method either creates a new instance or raises an exception. It doesn't modify an instance in-place. > >> Map._instance.description = None >> # etc... >> self.cells = [Cell(fill)] * width * height >> return Map._instance > >That's not your actual code, since the indentation is wrong. Map._instance.description = None # etc... self.cells = [Cell(fill)] * width * height return Map._instance From marfig at gmail.com Thu Mar 12 04:10:24 2015 From: marfig at gmail.com (Mario Figueiredo) Date: Thu, 12 Mar 2015 09:10:24 +0100 Subject: __new__() does not return anything, on singletong pattern References: <6fh1ga59ia3m07kd20p6me5d2n2c3v7qhg@4ax.com> Message-ID: On Wed, 11 Mar 2015 16:47:32 -0700, Ethan Furman wrote: > >You're code is good. Thanks for taking a weight off my shoulder. > > The only question is if you /really/ need a singleton -- and only > you can answer that (although plenty of folks will tell you you > don't ;) . Yeah. I debated that myself. But in the end the singleton won. It's just a cheap global, since is ubiquitous throughout the entire application, does behave like a singleton, and is a bit too expensive to create. A full map in the main application takes 3 or 4 seconds to instantiate and occupies around 2 Mb of memory. From greg.ewing at canterbury.ac.nz Thu Mar 12 04:38:00 2015 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 12 Mar 2015 21:38:00 +1300 Subject: __new__() does not return anything, on singletong pattern In-Reply-To: References: <6fh1ga59ia3m07kd20p6me5d2n2c3v7qhg@4ax.com> Message-ID: Mario Figueiredo wrote: > It's just a cheap global, since is ubiquitous throughout the entire > application, does behave like a singleton, and is a bit too expensive > to create. A full map in the main application takes 3 or 4 seconds to > instantiate and occupies around 2 Mb of memory. There's nothing wrong with having only one instance. The quesion is whether it's a good idea to make calling Map() be the way to get hold of that instance. I would say it's counterproductive. The implementation is convoluted, and it makes code that calls Map() confusing, because it looks like it's creating a new instance when it really isn't. I would just provide a function: _map = None def get_map(): global _map if _map is None: _map = Map() return _map and document the fact that you shouldn't call Map() directly. -- Greg From greg.ewing at canterbury.ac.nz Thu Mar 12 04:40:03 2015 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 12 Mar 2015 21:40:03 +1300 Subject: __new__() does not return anything, on singletong pattern In-Reply-To: References: <6fh1ga59ia3m07kd20p6me5d2n2c3v7qhg@4ax.com> <550124a3$0$12920$c3e8da3$5496439d@news.astraweb.com> Message-ID: Mario Figueiredo wrote: > A different application, a map editor, needs to also instantiate an > object of the class Map. But in this case the map needs to either be > empty (if the user wants to create a new map), or loaded from the > saved map file (if the user wants to edit an existing map). Then you have two functions for creating maps: new_empty_map() load_map_from_file(filename) Both of these can complain if there is already a Map instance. -- Greg From remisharoon at gmail.com Thu Mar 12 04:40:15 2015 From: remisharoon at gmail.com (remisharoon at gmail.com) Date: Thu, 12 Mar 2015 01:40:15 -0700 (PDT) Subject: python-wheel distribution, add a local dependency which is not available in PyPi Message-ID: Hi I have a dependency of a local .whl file, which is not in Pypi. How can I bundle that (local .whl file) inside the wheel file, so that inner .whl will get installed as a dependency. In simple terms a wheel file inside another wheel file. Can I add it as a package_data ? , if so how can get it automatically installed as a dependency? Please help From greg.ewing at canterbury.ac.nz Thu Mar 12 04:41:16 2015 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 12 Mar 2015 21:41:16 +1300 Subject: __new__() does not return anything, on singletong pattern In-Reply-To: <6fh1ga59ia3m07kd20p6me5d2n2c3v7qhg@4ax.com> References: <6fh1ga59ia3m07kd20p6me5d2n2c3v7qhg@4ax.com> Message-ID: Mario Figueiredo wrote: > But PyCharm flags the assignment > with a warning telling me that generate() does not return anything and > the I lose code completion on the mmap variable. My guess is that there is a syntax error somewhere in your code that's confusing the IDE. -- Greg From marfig at gmail.com Thu Mar 12 04:46:45 2015 From: marfig at gmail.com (Mario Figueiredo) Date: Thu, 12 Mar 2015 09:46:45 +0100 Subject: __new__() does not return anything, on singletong pattern References: <6fh1ga59ia3m07kd20p6me5d2n2c3v7qhg@4ax.com> Message-ID: On Thu, 12 Mar 2015 21:38:00 +1300, Gregory Ewing wrote: > >I would just provide a function: > >_map = None > >def get_map(): > global _map > if _map is None: > _map = Map() > return _map > >and document the fact that you shouldn't call Map() >directly. Oh, you are so right! Been so long since I last created a singleton I forgot all about the idiomatic approaches to the pattern. Thanks Greg. That is much, much, better. From binki.c at mweb.co.za Thu Mar 12 04:55:12 2015 From: binki.c at mweb.co.za (binki.c at mweb.co.za) Date: Thu, 12 Mar 2015 10:55:12 +0200 Subject: I want to get involved with Python! Message-ID: >https://en.wikipedia.org/wiki/OpenEdge_Advanced_Business_Language Yip, that's the one I am referring to, Terry. From: tjreedy at udel.edu Sent: 2015/03/11 08:43:42 PM To: python-list at python.org Cc: Subject: RE: Re: I want to get involved with Python! On 3/11/2015 5:19 AM, binki.c at mweb.co.za wrote: > I am currently a "Progress Programmer" and looking for new challenges! Are you referring to https://en.wikipedia.org/wiki/OpenEdge_Advanced_Business_Language > It seems that Python is a good language to get familiar with and I would > like some advice. I am on the look-out for a new job anyway and I > thought it well to look for a job as Python developer in my field. I > have been working in the healthcare sector for many years now and > perhaps the only way to find a job as Python programmer at this stage, > will be to find a job in the healthcare sector, as this is what I am > familiar with. Are there any healthcare companies using Python (anywhere > in the world) that I can contact for opportunities and advice? > > I currently live in South Africa and would like to know what the demand > for Python is in SA, but I will also consider relocating to Australia or > the UK if I find it's going to be worth it. > > Please advise on what route you would suggest I take to become a Python > developer! One way to establish credibility as a 'python programmer' is to make contributions to an open-source python project. Perhaps find or create a project to somehow integrate Python and Progress. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From marfig at gmail.com Thu Mar 12 05:00:54 2015 From: marfig at gmail.com (Mario Figueiredo) Date: Thu, 12 Mar 2015 10:00:54 +0100 Subject: __new__() does not return anything, on singletong pattern References: <6fh1ga59ia3m07kd20p6me5d2n2c3v7qhg@4ax.com> <550124a3$0$12920$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, 12 Mar 2015 21:40:03 +1300, Gregory Ewing wrote: >Mario Figueiredo wrote: > >> A different application, a map editor, needs to also instantiate an >> object of the class Map. But in this case the map needs to either be >> empty (if the user wants to create a new map), or loaded from the >> saved map file (if the user wants to edit an existing map). > >Then you have two functions for creating maps: > >new_empty_map() > >load_map_from_file(filename) > >Both of these can complain if there is already a >Map instance. new_empty_map(width, height, fill=terrain['sea']) load_map_from_file(filename) These would be the most likely signatures for those functions. The first function does not need to perform any of code to do with opening and reading a binary file, verifying an hash for possible file data corruption, filling the map header information and populating the cells. Both functions need to have knowledge of the Map class internals. Is it pythonic to create those functions in the same module of the Map class. Or because of how they have access to some "private" details of the class they should instead be made static methods as a means to signal that much? Map.new() Map.load() From info at egenix.com Thu Mar 12 06:57:13 2015 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Thu, 12 Mar 2015 11:57:13 +0100 Subject: ANN: eGenix mxODBC 3.3.2 - Python ODBC Database Interface Message-ID: <55017109.1010908@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix.com mxODBC Python ODBC Database Interface Version 3.3.2 mxODBC is our commercially supported Python extension providing ODBC database connectivity to Python applications on Windows, Mac OS X, Unix and BSD platforms with many advanced Python DB-API extensions and full support of stored procedures This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-mxODBC-3.3.2-GA.html ________________________________________________________________________ INTRODUCTION mxODBC provides an easy-to-use, high-performance, reliable and robust Python interface to ODBC compatible databases such as MS SQL Server, Oracle Database, IBM DB2, Informix and Netezza, SAP Sybase ASE and Sybase Anywhere, Teradata, MySQL, MariaDB, PostgreSQL, SAP MaxDB and many more: http://www.egenix.com/products/python/mxODBC/ The "eGenix mxODBC - Python ODBC Database Interface" product is a commercial extension to our open-source eGenix mx Base Distribution: http://www.egenix.com/products/python/mxBase/ ________________________________________________________________________ NEWS The 3.3.2 release of our mxODBC is a patch level release of our popular Python ODBC Interface for Windows, Linux, Mac OS X and FreeBSD. It includes these enhancements and fixes: Driver Compatibility -------------------- MS SQL Server * Fixed an "ODBC driver sent negative string size" error when using empty strings or None with output parameters for SQL Server ODBC drivers. * Clarified that due to the way the SQL Server ODBC driver sends data, mixing output parameters and output result sets is not possible. A work-around for this is to send back output parameters as additional result set. SAP Sybase ASE * Added a work-around for the Sybase ASE ODBC driver which has problems with BIGINT columns. These are now supported. * Fixed a possible "ODBC driver sent negative string size" error when using empty strings or None with output parameters for Sybase ASE ODBC drivers. Misc ---- * Fixed the handling of None as default value for output parameters in e.g. stored procedures to use VARCHAR binding rather than CHAR binding. The latter caused padding with some database backends. * Changed cursor.colcount to be determined on-demand rather than right after the prepare step of statement execution. * Fixed an issue with mxODBC triggering unwanted ODBC errors after the prepare step when calling a stored procedure. These were not reported, but do show up in the ODBC log. * Fixed some minor issues with the package web installer. For the full set of changes please check the mxODBC change log: http://www.egenix.com/products/python/mxODBC/changelog.html ________________________________________________________________________ FEATURES mxODBC 3.3 was released on 2014-04-08. Please see the full announcement for highlights of the 3.3 release: http://www.egenix.com/company/news/eGenix-mxODBC-3.3.0-GA.html For the full set of features mxODBC has to offer, please see: http://www.egenix.com/products/python/mxODBC/#Features ________________________________________________________________________ EDITIONS mxODBC is available in these two editions: * The Professional Edition, which gives full access to all mxODBC features. * The Product Development Edition, which allows including mxODBC in applications you develop. For a complete overview of the available editions, please see the product page: http://www.egenix.com/products/python/mxODBC/#mxODBCEditions ________________________________________________________________________ DOWNLOADS The download archives and instructions for installing the package can be found at: http://www.egenix.com/products/python/mxODBC/ In order to use the eGenix mxODBC package you will first need to install the eGenix mx Base package: http://www.egenix.com/products/python/mxBase/ You can also simply use: pip install egenix-mxodbc and then get evaluation licenses from our website to try mxODBC: http://www.egenix.com/products/python/mxODBC/#Evaluation ________________________________________________________________________ UPGRADING Users are encouraged to upgrade to this latest mxODBC release to benefit from the new features and updated ODBC driver support. We have taken special care not to introduce backwards incompatible changes, making the upgrade experience as smooth as possible. Customers who have purchased mxODBC 3.3 licenses can continue to use their licenses with this patch level release. For upgrade purchases, we will give out 20% discount coupons going from mxODBC 2.x to 3.3 and 50% coupons for upgrades from mxODBC 3.x to 3.3. Please contact the eGenix.com Sales Team with your existing license serials for details for an upgrade discount coupon. If you want to try the new release before purchase, you can request 30-day evaluation licenses by visiting our web-site http://www.egenix.com/products/python/mxODBC/#Evaluation or writing to sales at egenix.com, stating your name (or the name of the company) and the number of eval licenses that you need. _______________________________________________________________________ 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. _______________________________________________________________________ INFORMATION About Python (http://www.python.org/): Python is an object-oriented Open Source programming language which runs on all modern platforms. By integrating ease-of-use, clarity in coding, enterprise application connectivity and rapid application design, Python establishes an ideal programming platform for today's IT challenges. About eGenix (http://www.egenix.com/): eGenix is a software project, consulting and product company focusing on expert services and professional quality products for companies, Python users and developers. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Mar 12 2015) >>> Python Projects, Coaching and Consulting ... http://www.egenix.com/ >>> mxODBC Plone/Zope Database Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::::: Try our mxODBC.Connect Python Database Interface for free ! :::::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From steve+comp.lang.python at pearwood.info Thu Mar 12 07:04:30 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 12 Mar 2015 22:04:30 +1100 Subject: __new__() does not return anything, on singletong pattern References: <6fh1ga59ia3m07kd20p6me5d2n2c3v7qhg@4ax.com> Message-ID: <550172bf$0$12991$c3e8da3$5496439d@news.astraweb.com> Mario Figueiredo wrote: > It's just a cheap global, since is ubiquitous throughout the entire > application, does behave like a singleton, and is a bit too expensive > to create. A full map in the main application takes 3 or 4 seconds to > instantiate and occupies around 2 Mb of memory. 2MB is not that big. 3-4 seconds to instantiate is a bit worrying, but you should look at improving the efficiency of loading a map rather than insisting that there should be only one map instance. Particularly in the map editor, what if the user wants to copy parts of one map into a second map? I've often wanted to do that with games. Every other editor, from music editors to text editors, allows you to have multiple documents open. Why should game level editors be stuck in the 1980s? While Map is a singleton, editing multiple maps at once is impossible (or at least tiresomely difficult). -- Steven From steve+comp.lang.python at pearwood.info Thu Mar 12 07:29:24 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 12 Mar 2015 22:29:24 +1100 Subject: __new__() does not return anything, on singletong pattern References: <6fh1ga59ia3m07kd20p6me5d2n2c3v7qhg@4ax.com> <550124a3$0$12920$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55017896$0$12988$c3e8da3$5496439d@news.astraweb.com> Mario Figueiredo wrote: > On Thu, 12 Mar 2015 16:31:12 +1100, Steven D'Aprano > wrote: > >>Mario Figueiredo wrote: >> >> >>If this is supposed to be a singleton, you can't create more instances. >>The point of a singleton that there is only one instance (or perhaps a >>small number, two or three say). Why do you need two different ways to >>create instances if you only have one instance? >> > > The map is instantiated from the contents of a saved map file on the > main application. > > A different application, a map editor, needs to also instantiate an > object of the class Map. But in this case the map needs to either be > empty (if the user wants to create a new map), or loaded from the > saved map file (if the user wants to edit an existing map). An empty map is just a special case of an existing map, one with no features added. I would have a loadfile() method which takes a filename on disk, opens the file and passes the contents (or the open file object) to another method, load() to do the actual work: class Map: def __new__(cls, width, height, fill, treasure=None): # Include additional args as needed. map = super().__new__.(cls) map.width = width map.height = height map.fill = fill map.treasure = treasure return map @classmethod def loadfile(cls, filename): with open(filename, 'r') as f: map = cls.load(f) return map @classmethod def load(cls, f): # validate and parse file contents # extract width, height, fill, etc. map = cls(width, height, fill, treasure) return map To get an empty map, you pass the load method a file-like object that contains whatever an empty map data file will contain. That could literally be an external file, if you so choose, or you could simply read it from a global constant or even an embedded string/bytes object: @classmethod def new(cls): """Return a new empty map.""" emptymap = b"blah blah blah width=100 height=100 fill=1" f = io.StringIO(emptymap) return cls.load(f) This, naturally, assumes that your map format is simple enough and small enough that an empty map can be embedded into your code. If an empty map is 4MB on disk, you probably don't want to do this :-) Alternatively, set the default arguments to the __new__ constructor to be whatever values an empty map uses: def __new__(cls, width=100, height=100, fill=1, treasure=None): ... and now your "create empty map" command just calls Map() with no arguments. >>> I added the following method to the class definition, above: >>> >>> @classmethod >>> def generate(cls, width, height, fill=terrain[6]): >>> if Map._instance is None: >>> Map._instance = super(Map, cls).__new__(cls) >>> else: >>> raise Exception('Cannot generate an instance of Map.') >>> >>> Map._instance.author = None >>> Map._instance.name = None >> >>Since this method modifies the singleton instance in place, it doesn't >>generate a new instance. It shouldn't be called generate(). > > No sure what you mean. That method either creates a new instance or > raises an exception. It doesn't modify an instance in-place. My mistake, I was confused. You're right, if the instance already exists, it raises an exception. >>> Map._instance.description = None >>> # etc... >>> self.cells = [Cell(fill)] * width * height >>> return Map._instance >> >>That's not your actual code, since the indentation is wrong. > > Map._instance.description = None > # etc... > self.cells = [Cell(fill)] * width * height > return Map._instance What's "self"? That's a classmethod, it's not usual to have a self local variable. -- Steven From mal at europython.eu Thu Mar 12 09:18:33 2015 From: mal at europython.eu (M.-A. Lemburg) Date: Thu, 12 Mar 2015 14:18:33 +0100 Subject: EuroPython 2015: Call for proposal dates available Message-ID: <55019229.2070703@europython.eu> The Program work group (WG) has decided on the dates for the Call for Proposal (CFP) dates: Monday, 2015-03-16 Tuesday, 2015-04-14 You will be able to submit your proposals through the EuroPython website during these 4 weeks. We have these types of presentations available for submission: * Talks: 170 slots available (80x 30min, 85x 45min, 5x 60min) * Trainings: 20 slots * Posters: 25 slots * Help desks: 5 slots Please note that the exact number of submissions we can accept depends on schedule and room requirements, so the above numbers are only estimates. Talk times include time for questions. The full Call for Proposal with all details will be made available on Monday, 2015-03-16. We are publishing these dates early because we?ve been getting a lot of requests for the CFP dates. Talks/Trainings in Spanish and Basque ------------------------------------- Since EuroPython is hosted in Bilbao and EuroPython has traditionally always been very open to the local Python communities, we are also accepting a number of talks and trainings in Spanish and Basque. All other talks/trainings should be held in English. Talk voting ----------- As in 2013, we will again have talk voting, which means that attendees who have already registered will get to see the talk submissions and can vote on them. The Program WG will also set aside a number of slots which they will then select based on other criteria to e.g. increase diversity or give a chance to less mainstream topics. The schedule will then be announced early in May. Enjoy, -- EuroPython 2015 Team http://www.europython-society.org/ From rustompmody at gmail.com Thu Mar 12 09:35:26 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 12 Mar 2015 06:35:26 -0700 (PDT) Subject: generator/coroutine terminology Message-ID: This is more a question about standard terminology/conventions than about semantics - of course assuming I understand :-) Say I have a simple yielding function: def foo(x): yield x+1 yield x+2 And I have g = foo(2) If I look at type, g's type is 'generator' whereas foo is just plain-ol 'function.' Whereas in informal usage we say foo is a generator. So the question: What should we call foo and what should we call g? Same applies when foo is a 'coroutine' ie something having yield used in an rhs and used with '.send' from outside: What to call foo and what to call foo(x)? From rosuav at gmail.com Thu Mar 12 09:55:55 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 13 Mar 2015 00:55:55 +1100 Subject: generator/coroutine terminology In-Reply-To: References: Message-ID: On Fri, Mar 13, 2015 at 12:35 AM, Rustom Mody wrote: > If I look at type, g's type is 'generator' whereas foo is just plain-ol 'function.' > > Whereas in informal usage we say foo is a generator. > > So the question: > What should we call foo and what should we call g? g is a generator object; foo is a generator function - a function which returns generator objects. Usually, calling both of them "generators" isn't confusing, as there's not often any context in which they're ambiguous. ChrisA From breamoreboy at gmail.com Thu Mar 12 09:57:27 2015 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Thu, 12 Mar 2015 06:57:27 -0700 (PDT) Subject: generator/coroutine terminology In-Reply-To: References: Message-ID: <37db5324-c272-47e8-b9c8-892e09af2fef@googlegroups.com> On Thursday, March 12, 2015 at 1:35:48 PM UTC, Rustom Mody wrote: > This is more a question about standard terminology/conventions than about semantics - of course assuming I understand :-) > > Say I have a simple yielding function: > > def foo(x): > yield x+1 > yield x+2 > > And I have > > g = foo(2) > > If I look at type, g's type is 'generator' whereas foo is just plain-ol 'function.' > > Whereas in informal usage we say foo is a generator. > > So the question: > What should we call foo and what should we call g? > > Same applies when foo is a 'coroutine' ie > something having yield used in an rhs and used with '.send' from outside: > What to call foo and what to call foo(x)? Try the glossary https://docs.python.org/3/glossary.html If this comes out badly please free to shout as I'm on gg :) From steve+comp.lang.python at pearwood.info Thu Mar 12 12:27:54 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 13 Mar 2015 03:27:54 +1100 Subject: generator/coroutine terminology References: Message-ID: <5501be8b$0$13006$c3e8da3$5496439d@news.astraweb.com> Rustom Mody wrote: > This is more a question about standard terminology/conventions than about > semantics - of course assuming I understand :-) > > Say I have a simple yielding function: > > def foo(x): > yield x+1 > yield x+2 > > And I have > > g = foo(2) > > If I look at type, g's type is 'generator' whereas foo is just plain-ol > 'function.' > > Whereas in informal usage we say foo is a generator. Hopefully it is clear from context what we actually mean. When in doubt, we should be explicit. > So the question: > What should we call foo and what should we call g? foo is a generator function, i.e. a function which returns a generator. I'd also allow generator factory, naming it by intent rather than type. The result of calling foo, namely foo(x), which you have named g, is a generator object, which is a kind of iterator. > Same applies when foo is a 'coroutine' ie > something having yield used in an rhs and used with '.send' from outside: > What to call foo and what to call foo(x)? foo is a generator function, and foo(x) is a generator object. In this case we can call foo(x) by usage rather than type, and call it a coroutine. -- Steven From rustompmody at gmail.com Thu Mar 12 12:52:27 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 12 Mar 2015 09:52:27 -0700 (PDT) Subject: generator/coroutine terminology In-Reply-To: <5501be8b$0$13006$c3e8da3$5496439d@news.astraweb.com> References: <5501be8b$0$13006$c3e8da3$5496439d@news.astraweb.com> Message-ID: Guess I should be pleased that I am doing as good as you (and Chris) describe. For some reason or not I am not... On Thursday, March 12, 2015 at 9:58:07 PM UTC+5:30, Steven D'Aprano wrote: > Rustom Mody wrote: > > > This is more a question about standard terminology/conventions than about > > semantics - of course assuming I understand :-) > > > > Say I have a simple yielding function: > > > > def foo(x): > > yield x+1 > > yield x+2 > > > > And I have > > > > g = foo(2) > > > > If I look at type, g's type is 'generator' whereas foo is just plain-ol > > 'function.' > > > > Whereas in informal usage we say foo is a generator. > > Hopefully it is clear from context what we actually mean. When in doubt, we > should be explicit. There is a very important 'context' where both have to exist together -- teaching beginners. foo's are written to produce g's. g's come from foo-like. Better naming would help clarify -- your 'factory' is the best Ive seen so far. But the docs?!?! Hoo Boy My head spins trying to grok this https://docs.python.org/3/reference/expressions.html#generator-expressions And thats after being familiar with the origins of the idea in scheme/simula/CLU etc. Noobs could be forgiven for doing worse dont you think?? I guess we need 1. A clear ontology of the base concepts (which is a buzzword for nailed-down terminology) 2. Some neat pictures would sure help (me!) From robin at reportlab.com Thu Mar 12 12:55:32 2015 From: robin at reportlab.com (Robin Becker) Date: Thu, 12 Mar 2015 16:55:32 +0000 Subject: when may sys.executable be empty In-Reply-To: <5500863B.9020803@davea.name> References: <5500863B.9020803@davea.name> Message-ID: <5501C504.4010601@chamonix.reportlab.co.uk> On 11/03/2015 18:15, Dave Angel wrote: ......... > > Just speculating, but how about when the main executable is not python at all, > but it uses a DLL or .so file with Python interpreter. > > when I run a django wsgi.py using uwsgi sys.executable points at the uwsgi executable. To run subprocess etc I have to find the python that's parallel to uwsgi (works in a virtualenv at least). -- Robin Becker From robin at reportlab.com Thu Mar 12 12:55:32 2015 From: robin at reportlab.com (Robin Becker) Date: Thu, 12 Mar 2015 16:55:32 +0000 Subject: when may sys.executable be empty In-Reply-To: <5500863B.9020803@davea.name> References: <5500863B.9020803@davea.name> Message-ID: <5501C504.4010601@chamonix.reportlab.co.uk> On 11/03/2015 18:15, Dave Angel wrote: ......... > > Just speculating, but how about when the main executable is not python at all, > but it uses a DLL or .so file with Python interpreter. > > when I run a django wsgi.py using uwsgi sys.executable points at the uwsgi executable. To run subprocess etc I have to find the python that's parallel to uwsgi (works in a virtualenv at least). -- Robin Becker From marko at pacujo.net Thu Mar 12 13:55:21 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 12 Mar 2015 19:55:21 +0200 Subject: generator/coroutine terminology References: <5501be8b$0$13006$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87twxqqewm.fsf@elektro.pacujo.net> Rustom Mody : > I guess we need > 1. A clear ontology of the base concepts (which is a buzzword for > nailed-down terminology) According to the documentation, a function whose definition contains a yield statement is a generator: Using a yield expression in a function?s body causes that function to be a generator. generator A function which returns an iterator. Apparently, what we have here is a discrepancy between the documentation and the CPython implementation. In a word, it's a bug (somewhere). Marko From marfig at gmail.com Thu Mar 12 15:44:53 2015 From: marfig at gmail.com (Mario Figueiredo) Date: Thu, 12 Mar 2015 20:44:53 +0100 Subject: __new__() does not return anything, on singletong pattern References: <6fh1ga59ia3m07kd20p6me5d2n2c3v7qhg@4ax.com> <550124a3$0$12920$c3e8da3$5496439d@news.astraweb.com> <55017896$0$12988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, 12 Mar 2015 22:29:24 +1100, Steven D'Aprano wrote: > >I would have a loadfile() method which takes a filename on disk, opens the >file and passes the contents (or the open file object) to another method, >load() to do the actual work: > > >class Map: > def __new__(cls, width, height, fill, treasure=None): > # Include additional args as needed. > map = super().__new__.(cls) > map.width = width > map.height = height > map.fill = fill > map.treasure = treasure > return map > > @classmethod > def loadfile(cls, filename): > with open(filename, 'r') as f: > map = cls.load(f) > return map > > @classmethod > def load(cls, f): > # validate and parse file contents > # extract width, height, fill, etc. > map = cls(width, height, fill, treasure) > return map > > >To get an empty map, you pass the load method a file-like object that >contains whatever an empty map data file will contain. That could literally >be an external file, if you so choose, or you could simply read it from a >global constant or even an embedded string/bytes object: > > @classmethod > def new(cls): > """Return a new empty map.""" > emptymap = b"blah blah blah width=100 height=100 fill=1" > f = io.StringIO(emptymap) > return cls.load(f) > > >This, naturally, assumes that your map format is simple enough and small >enough that an empty map can be embedded into your code. If an empty map is >4MB on disk, you probably don't want to do this :-) > >Alternatively, set the default arguments to the __new__ constructor to be >whatever values an empty map uses: > > def __new__(cls, width=100, height=100, fill=1, treasure=None): > ... > > >and now your "create empty map" command just calls Map() with no arguments. > Your solution is excelent! Leveraging the __new__ method is something I wasn't considering. It gracefully deals with the absence of __init__, not forcing me to raise an exception or document the class to warn against its use. Thanks a bunch. From marfig at gmail.com Thu Mar 12 15:50:19 2015 From: marfig at gmail.com (Mario Figueiredo) Date: Thu, 12 Mar 2015 20:50:19 +0100 Subject: __new__() does not return anything, on singletong pattern References: <6fh1ga59ia3m07kd20p6me5d2n2c3v7qhg@4ax.com> Message-ID: On Thu, 12 Mar 2015 21:41:16 +1300, Gregory Ewing wrote: >Mario Figueiredo wrote: >> But PyCharm flags the assignment >> with a warning telling me that generate() does not return anything and >> the I lose code completion on the mmap variable. > >My guess is that there is a syntax error somewhere >in your code that's confusing the IDE. It's a PyCharm bug actually. Confirmed here: https://youtrack.jetbrains.com/issue/PY-11990 (sidenote: I wasn't finding that before. YouTrack search engine really needs to handle better word contractions. It was only when I was filling a bug report myself that it came up with that one in the list of possible related issues.) From nagle at animats.com Thu Mar 12 15:55:20 2015 From: nagle at animats.com (John Nagle) Date: Thu, 12 Mar 2015 12:55:20 -0700 Subject: Python3 "pickle" vs. stdin/stdout - unable to get clean byte streams in Python 3 Message-ID: I have working code from Python 2 which uses "pickle" to talk to a subprocess via stdin/stdio. I'm trying to make that work in Python 3. First, the subprocess Python is invoked with the "-d' option, so stdin and stdio are supposed to be unbuffered binary streams. That was enough in Python 2, but it's not enough in Python 3. The subprocess and its connections are set up with proc = subprocess.Popen(launchargs,stdin=subprocess.PIPE, stdout=subprocess.PIPE, env=env) ... self.reader = pickle.Unpickler(self.proc.stdout) self.writer = pickle.Pickler(self.proc.stdin, 2) after which I get result = self.reader.load() TypeError: 'str' does not support the buffer interface That's as far as traceback goes, so I assume this is disappearing into C code. OK, I know I need a byte stream. I tried self.reader = pickle.Unpickler(self.proc.stdout.buffer) self.writer = pickle.Pickler(self.proc.stdin.buffer, 2) That's not allowed. The "stdin" and "stdout" that are fields of "proc" do not have "buffer". So I can't do that in the parent process. In the child, though, where stdin and stdout come from "sys", "sys.stdin.buffer" is valid. That fixes the ""str" does not support the buffer interface error." But now I get the pickle error "Ran out of input" on the process child side. Probably because there's a str/bytes incompatibility somewhere. So how do I get clean binary byte streams between parent and child process? John Nagle From tjreedy at udel.edu Thu Mar 12 16:11:21 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 12 Mar 2015 16:11:21 -0400 Subject: generator/coroutine terminology In-Reply-To: References: Message-ID: On 3/12/2015 9:35 AM, Rustom Mody wrote: > This is more a question about standard terminology/conventions than about semantics - of course assuming I understand :-) > > Say I have a simple yielding function: > > def foo(x): > yield x+1 > yield x+2 This is a generator function > And I have > > g = foo(2) > > If I look at type, g's type is 'generator' whereas foo is just plain-ol 'function.' > > Whereas in informal usage we say foo is a generator. I do not, because it does cause confusion, in spite of denials by people who use 'generator' ambiguously. -- Terry Jan Reedy From marfig at gmail.com Thu Mar 12 16:16:23 2015 From: marfig at gmail.com (Mario Figueiredo) Date: Thu, 12 Mar 2015 21:16:23 +0100 Subject: __new__() does not return anything, on singletong pattern References: <6fh1ga59ia3m07kd20p6me5d2n2c3v7qhg@4ax.com> <550172bf$0$12991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7hr3gahdc3tdj7m6io4b1511v7ciaa2m6j@4ax.com> On Thu, 12 Mar 2015 22:04:30 +1100, Steven D'Aprano wrote: > >3-4 seconds to instantiate is a bit worrying, but you should look at >improving the efficiency of loading a map rather than insisting that there >should be only one map instance. Particularly in the map editor, what if >the user wants to copy parts of one map into a second map? I've often >wanted to do that with games. Every other editor, from music editors to >text editors, allows you to have multiple documents open. Why should game >level editors be stuck in the 1980s? > >While Map is a singleton, editing multiple maps at once is impossible (or at >least tiresomely difficult). Those scnearios don't apply here. And the map editor isn't even a first-class application in the system. Just a patch to corrupt map files that will thus stand a chance to be recovered. I can understand your resistance to the idea of yet another singleton being born to this world. I myself despise the pattern. I think the GoF were drunk by the time they reached the Singleton. The whole Creational Patterns section was really only going downhill, anyways. Starts strong and ends up with the justin bieber of patterns. And I'm not using it because of some ulterior design principle. I don't plan to justify it because I have a *real* reason to use a singleton. I don't. I'm just using it because it is really accomodating for me to have this global without having to trace it around function calls arguments. That's evil. I suppose I could just make it really global. But to me that's even more evil and I can't consider it. Of course. What is a singleton today can't be twins tomorrow, triplets the day after and a crowd the next. I realize this. But... yeah... I'm a sinner. Besides it's not that I never had to revisit my code before because of Best Practices (tm). In truth the road to damnation starts when we decide to write our first line of code. From marko at pacujo.net Thu Mar 12 16:22:49 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 12 Mar 2015 22:22:49 +0200 Subject: generator/coroutine terminology References: Message-ID: <87pp8eq82u.fsf@elektro.pacujo.net> Terry Reedy : > On 3/12/2015 9:35 AM, Rustom Mody wrote: >> This is more a question about standard terminology/conventions than >> about semantics - of course assuming I understand :-) >> >> Say I have a simple yielding function: >> >> def foo(x): >> yield x+1 >> yield x+2 > > This is a generator function Which in the official language specification is an elaborate synonym of a generator. Marko From breamoreboy at yahoo.co.uk Thu Mar 12 16:44:27 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 12 Mar 2015 20:44:27 +0000 Subject: PSF news - BBC launches MicroBit Message-ID: http://pyfound.blogspot.co.uk/2015/03/bbc-launches-microbit.html may be of interest to some of you. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rymg19 at gmail.com Thu Mar 12 17:56:02 2015 From: rymg19 at gmail.com (Ryan Gonzalez) Date: Thu, 12 Mar 2015 16:56:02 -0500 Subject: My emails are getting bounced? Message-ID: I'm posting this here because I have no clue who the heck the mailing list manager is. I got this message: Your membership in the mailing list Python-ideas has been disabled due to excessive bounces The last bounce received from you was dated 12-Mar-2015. You will not get any more messages from this list until you re-enable your membership. You will receive 3 more reminders like this before your membership in the list is deleted. A quick Google shows: Find out why list mail to you is bouncing and correct the problem. You may be able to see a returned bounce by setting bounce_notify_owner_on_disable to Yes. This will cause Mailman to send the triggering bounce to the owner, but since that's you, it may bounce too. Is it possible for someone to set this up for my email on Python-ideas? Again, not sure who the manager is, so I'm sending this here. -- Ryan [ERROR]: Your autotools build scripts are 200 lines longer than your program. Something?s wrong. http://kirbyfan64.github.io/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From cs at zip.com.au Thu Mar 12 17:56:04 2015 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 13 Mar 2015 08:56:04 +1100 Subject: Python3 "pickle" vs. stdin/stdout - unable to get clean byte streams in Python 3 In-Reply-To: References: Message-ID: <20150312215604.GA20975@cskk.homeip.net> On 12Mar2015 12:55, John Nagle wrote: > I have working code from Python 2 which uses "pickle" >to talk to a subprocess via stdin/stdio. I'm trying to >make that work in Python 3. > First, the subprocess Python is invoked with the "-d' option, >so stdin and stdio are supposed to be unbuffered binary streams. You shouldn't need to use unbuffered streams specificly. It should be enough to .flush() the output stream (at whichever end) after you have written the pickle data. I'm skipping some of your discussion; I can see nothing wong. I don't use pickle itself so aside from saying that your use seems to conform to the python 3 doco I can't comment more deeply. That said, I do use subprocess a fair bit. [...] > result = self.reader.load() >TypeError: 'str' does not support the buffer interface >That's as far as traceback goes, so I assume this is >disappearing into C code. No line numbers at all? Or, I suppose, just the line number from your program and nothing from the pickle module? >OK, I know I need a byte stream. I tried > self.reader = pickle.Unpickler(self.proc.stdout.buffer) > self.writer = pickle.Pickler(self.proc.stdin.buffer, 2) You should not need to care about these. They're not required. >That's not allowed. The "stdin" and "stdout" that are >fields of "proc" do not have "buffer". So I can't do that >in the parent process. In the child, though, where >stdin and stdout come from "sys", "sys.stdin.buffer" is valid. But irrelevant. Besides, the stream buffer may not contain the whole pickle data anyway; it will be empty before a read and quite possibly incomplete afterwards. It is just a buffer. >That fixes the ""str" does not support the buffer interface >error." I'm not sure "fix" is the right characterisation here. >But now I get the pickle error "Ran out of input" >on the process child side. Probably because there's a >str/bytes incompatibility somewhere. No, probably because the buffer is only ever a snapshot of part of the stream. str/bytes errors are more glaringly obviously so. >So how do I get clean binary byte streams between parent >and child process? This is where I'm confused: my experience is that Popen.subprocess gives you binary streams; I always need to put an encoder/decoder on them to use text. Did that just the other day. BTW, this is on some UNIX variant? Should not be very relevant... Further questions: What does self.proc.stdout.__class__ say? And for stdin? Cheers, Cameron Simpson My opinions are borrowed from someone who no longer needs them. -- KatmanDu at uga.cc.uga.edu From __peter__ at web.de Thu Mar 12 17:57:01 2015 From: __peter__ at web.de (Peter Otten) Date: Thu, 12 Mar 2015 22:57:01 +0100 Subject: Python3 "pickle" vs. stdin/stdout - unable to get clean byte streams in Python 3 References: Message-ID: John Nagle wrote: > I have working code from Python 2 which uses "pickle" > to talk to a subprocess via stdin/stdio. I'm trying to > make that work in Python 3. > > First, the subprocess Python is invoked with the "-d' option, > so stdin and stdio are supposed to be unbuffered binary streams. > That was enough in Python 2, but it's not enough in Python 3. > > The subprocess and its connections are set up with > > proc = subprocess.Popen(launchargs,stdin=subprocess.PIPE, > stdout=subprocess.PIPE, env=env) > > ... > self.reader = pickle.Unpickler(self.proc.stdout) > self.writer = pickle.Pickler(self.proc.stdin, 2) > > after which I get > > result = self.reader.load() > TypeError: 'str' does not support the buffer interface > > That's as far as traceback goes, so I assume this is > disappearing into C code. > > OK, I know I need a byte stream. I tried > > self.reader = pickle.Unpickler(self.proc.stdout.buffer) > self.writer = pickle.Pickler(self.proc.stdin.buffer, 2) > > That's not allowed. The "stdin" and "stdout" that are > fields of "proc" do not have "buffer". So I can't do that > in the parent process. In the child, though, where > stdin and stdout come from "sys", "sys.stdin.buffer" is valid. > That fixes the ""str" does not support the buffer interface > error." But now I get the pickle error "Ran out of input" > on the process child side. Probably because there's a > str/bytes incompatibility somewhere. > > So how do I get clean binary byte streams between parent > and child process? I don't know what you have to do to rule out deadlocks when you use pipes for both stdin and stdout, but binary streams are the default for subprocess. Can you provide a complete example? Anyway, here is a demo for two-way communication using the communicate() method: $ cat parent.py import pickle import subprocess data = (5, 4.3, "?blich ?hnlich n?tig") p = subprocess.Popen( ["python3", "child.py"], stdin=subprocess.PIPE, stdout=subprocess.PIPE) result = p.communicate(pickle.dumps(data, protocol=2))[0] print(pickle.loads(result)) $ cat child.py import sys import pickle a, b, c = pickle.load(sys.stdin.buffer) pickle.dump((a, b, c.upper()), sys.stdout.buffer) $ python3 parent.py (5, 4.3, '?BLICH ?HNLICH N?TIG') This is likely not what you want because here everything is buffered so that continuous interaction is not possible. From mail at timgolden.me.uk Thu Mar 12 18:00:49 2015 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 12 Mar 2015 22:00:49 +0000 Subject: My emails are getting bounced? In-Reply-To: References: Message-ID: <55020C91.2080408@timgolden.me.uk> On 12/03/2015 21:56, Ryan Gonzalez wrote: > I'm posting this here because I have no clue who the heck the mailing > list manager is. If you look at the bottom of this page: https://mail.python.org/mailman/listinfo/python-ideas you can see the list maintainers which is also a mailto: link which will reach them all. Hopefully they can look at the setup for your user over there. TJG From zachary.ware+pylist at gmail.com Thu Mar 12 18:03:51 2015 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Thu, 12 Mar 2015 17:03:51 -0500 Subject: My emails are getting bounced? In-Reply-To: References: Message-ID: On Thu, Mar 12, 2015 at 4:56 PM, Ryan Gonzalez wrote: > I'm posting this here because I have no clue who the heck the mailing list > manager is. > > I got this message: > > Your membership in the mailing list Python-ideas has been disabled due > to excessive bounces The last bounce received from you was dated > 12-Mar-2015. You will not get any more messages from this list until > you re-enable your membership. You will receive 3 more reminders like > this before your membership in the list is deleted. I just got the same and sent a mail to python-ideas-owner at python.org. I suspect the problem is that Gmail is bounces any message coming through the list from an @yahoo.com address; I've been having to not-spam every message from Andrew Barnett this week. -- Zach From rosuav at gmail.com Thu Mar 12 18:08:52 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 13 Mar 2015 09:08:52 +1100 Subject: My emails are getting bounced? In-Reply-To: References: Message-ID: On Fri, Mar 13, 2015 at 8:56 AM, Ryan Gonzalez wrote: > > Your membership in the mailing list Python-ideas has been disabled due > to excessive bounces The last bounce received from you was dated > 12-Mar-2015. You will not get any more messages from this list until > you re-enable your membership. You will receive 3 more reminders like > this before your membership in the list is deleted. I also got this notification, and in the past, it's been because Gmail mishandles spam - bouncing it instead of either accepting or discarding it. The post gets handed between Gmail and Mailman until one of them gives up, and in this case, it's Mailman. It may be that that's what happened again. (Irony would be if the post originated from Google Groups, which would mean it got past the Google spam filter on one side, but tripped the filter on the other side.) ChrisA From rymg19 at gmail.com Thu Mar 12 18:23:58 2015 From: rymg19 at gmail.com (rymg19 at gmail.com) Date: Thu, 12 Mar 2015 15:23:58 -0700 (PDT) Subject: My emails are getting bounced? In-Reply-To: References: Message-ID: <847ceec3-91bb-42f7-a0d9-adfd325f8d20@googlegroups.com> On Thursday, March 12, 2015 at 5:01:46 PM UTC-5, Tim Golden wrote: > On 12/03/2015 21:56, Ryan Gonzalez wrote: > > I'm posting this here because I have no clue who the heck the mailing > > list manager is. > > If you look at the bottom of this page: > > https://mail.python.org/mailman/listinfo/python-ideas > > you can see the list maintainers which is also a mailto: link which will > reach them all. Hopefully they can look at the setup for your user over > there. > > TJG Ok; I'm emailing now. I didn't even get this message. I had to go to the Google Groups interface to check for replies. From Joshua.R.English at gmail.com Thu Mar 12 18:26:08 2015 From: Joshua.R.English at gmail.com (Josh English) Date: Thu, 12 Mar 2015 15:26:08 -0700 (PDT) Subject: Google Code Shutting Down Message-ID: <36a41718-3eb6-445b-ba5b-caf124122542@googlegroups.com> I've been hosting Python projects on Google Code, and they're shutting down. Damn. What is the recommended replacement for Code Hosting that works reliably with PyPi and pip? From rymg19 at gmail.com Thu Mar 12 18:26:36 2015 From: rymg19 at gmail.com (rymg19 at gmail.com) Date: Thu, 12 Mar 2015 15:26:36 -0700 (PDT) Subject: My emails are getting bounced? In-Reply-To: References: Message-ID: <8b58a112-0077-44a7-9dc6-31fc98b959ae@googlegroups.com> On Thursday, March 12, 2015 at 5:09:16 PM UTC-5, Chris Angelico wrote: > On Fri, Mar 13, 2015 at 8:56 AM, Ryan Gonzalez wrote: > > > > Your membership in the mailing list Python-ideas has been disabled due > > to excessive bounces The last bounce received from you was dated > > 12-Mar-2015. You will not get any more messages from this list until > > you re-enable your membership. You will receive 3 more reminders like > > this before your membership in the list is deleted. > > I also got this notification, and in the past, it's been because Gmail > mishandles spam - bouncing it instead of either accepting or > discarding it. The post gets handed between Gmail and Mailman until > one of them gives up, and in this case, it's Mailman. It may be that > that's what happened again. (Irony would be if the post originated > from Google Groups, which would mean it got past the Google spam > filter on one side, but tripped the filter on the other side.) > > ChrisA Ugh. I love Gmail, but this sucks. From marfig at gmail.com Thu Mar 12 19:12:43 2015 From: marfig at gmail.com (Mario Figueiredo) Date: Fri, 13 Mar 2015 00:12:43 +0100 Subject: Google Code Shutting Down References: <36a41718-3eb6-445b-ba5b-caf124122542@googlegroups.com> Message-ID: On Thu, 12 Mar 2015 15:26:08 -0700 (PDT), Josh English wrote: >I've been hosting Python projects on Google Code, and they're shutting down. > >Damn. > >What is the recommended replacement for Code Hosting that works reliably with PyPi and pip? Essentially anywhere where either Git, Bazaar, Mercurial or Subversion are supported. See: https://pip.pypa.io/en/latest/reference/pip_install.html#vcs-support From nagle at animats.com Thu Mar 12 20:18:54 2015 From: nagle at animats.com (John Nagle) Date: Thu, 12 Mar 2015 17:18:54 -0700 Subject: Python3 "pickle" vs. stdin/stdout - unable to get clean byte streams in Python 3 In-Reply-To: References: Message-ID: On 3/12/2015 2:56 PM, Cameron Simpson wrote: > On 12Mar2015 12:55, John Nagle wrote: >> I have working code from Python 2 which uses "pickle" to talk to a >> subprocess via stdin/stdio. I'm trying to make that work in Python >> 3. First, the subprocess Python is invoked with the "-d' option, so >> stdin and stdio are supposed to be unbuffered binary streams. > > You shouldn't need to use unbuffered streams specifically. It should > be enough to .flush() the output stream (at whichever end) after you > have written the pickle data. Doing that. It's a repeat-transaction thing. Main process sends pickeled item to subprocess, subprocess reads item, subprocess does work, subprocess writes picked item to parent. This repeats. I call writer.clear_memo() and set reader.memo = {} at the end of each cycle, to clear Pickle's cache. That all worked fine in Python 2. Are there any known problems with reusing Python 3 "pickle"s streams? The identical code works with Python 2.7.9; it's converted to Python 3 using "six" so I can run on both Python versions and look for differences. I'm using Pickle format 2, for compatibility. (Tried 0, the ASCII format; it didn't help.) > I'm skipping some of your discussion; I can see nothing wrong. I > don't use pickle itself so aside from saying that your use seems to > conform to the python 3 docs I can't comment more deeply. That said, > I do use subprocess a fair bit. I'll have to put in more logging and see exactly what's going over the pipes. John Nagle From skip.montanaro at gmail.com Thu Mar 12 20:45:02 2015 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Thu, 12 Mar 2015 19:45:02 -0500 Subject: My emails are getting bounced? In-Reply-To: References: Message-ID: On Thu, Mar 12, 2015 at 4:56 PM, Ryan Gonzalez wrote: > Your membership in the mailing list Python-ideas has been disabled due > to excessive bounces I got the same treatment. Probably a mail loop involving Gmail. Skip -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Thu Mar 12 21:37:30 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 13 Mar 2015 12:37:30 +1100 Subject: Code hosting providers (was: Google Code Shutting Down) References: <36a41718-3eb6-445b-ba5b-caf124122542@googlegroups.com> Message-ID: <85d24dvfs5.fsf_-_@benfinney.id.au> Mario Figueiredo writes: > On Thu, 12 Mar 2015 15:26:08 -0700 (PDT), Josh English > wrote: > > > What is the recommended replacement for Code Hosting that works > > reliably with PyPi and pip? > > Essentially anywhere where either Git, Bazaar, Mercurial or Subversion > are supported. Installing directly from whatever the latest revision in VCS, is not a good replacement. What's needed is a VCS hosting provider that also expects you to publish tarballs at specific versions. For that, you want to choose a provider that runs entirely free software for the service ? not just the VCS, but whatever other features you use need to be freely available for someone to run another instance of the same service. Otherwise you're stuck any time you want to migrate your project, which is what led to this thread in the first place. This is called ?vendor lock-in?: services like GitHub and Google Code lock you in to the one provider, because if you want to migrate you can't take your project data (not just VCS but also issues, merge requests, etc.) with you to continue somewhere else. Any service which doesn't run their service on free software is one to avoid ; free software projects need free tools to remain that way. GitLab is a good option: they provide VCS, file hosting, wiki, issue tracker, code review via merge requests, etc. and all of it can be migrated to any other instance of the same service. Also worth watching is Kallithea, a new federated code hosting service . It supports Mercurial and Git for VCS, code review, and integrates with existing issue trackers. Because it's federated, you won't suffer from vendor lock-in. Good hunting in finding a free-software code hosting provider for your projects! -- \ ?I knew things were changing when my Fraternity Brothers threw | `\ a guy out of the house for mocking me because I'm gay.? | _o__) ?postsecret.com, 2010-01-19 | Ben Finney From rustompmody at gmail.com Thu Mar 12 22:23:12 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 12 Mar 2015 19:23:12 -0700 (PDT) Subject: generator/coroutine terminology In-Reply-To: <87twxqqewm.fsf@elektro.pacujo.net> References: <5501be8b$0$13006$c3e8da3$5496439d@news.astraweb.com> <87twxqqewm.fsf@elektro.pacujo.net> Message-ID: <4eec1709-dd11-4891-bfcc-60b27bb00ee3@googlegroups.com> On Thursday, March 12, 2015 at 11:25:32 PM UTC+5:30, Marko Rauhamaa wrote: > Rustom Mody : > > > I guess we need > > 1. A clear ontology of the base concepts (which is a buzzword for > > nailed-down terminology) > > According to the documentation, a function whose definition contains a > yield statement is a generator: > > Using a yield expression in a function's body causes that function to > be a generator. > > ressions> > > generator > A function which returns an iterator. > > > > Apparently, what we have here is a discrepancy between the documentation > and the CPython implementation. > > In a word, it's a bug (somewhere). Throwing out some thought for better terminology. [Yeah needs to be chewed on a bit...] With respect to my example above: def foo(x): yield x+1 yield x+2 g = foo(2) Generator-instance: g Generator-factory: foo Generator: Concept in python (ontology) elaborated in terms of the above Situation with coroutines is worse [Or I cant think of good terms...] From steve+comp.lang.python at pearwood.info Thu Mar 12 23:15:36 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 13 Mar 2015 14:15:36 +1100 Subject: My emails are getting bounced? References: <847ceec3-91bb-42f7-a0d9-adfd325f8d20@googlegroups.com> Message-ID: <55025659$0$12983$c3e8da3$5496439d@news.astraweb.com> rymg19 at gmail.com wrote: > I didn't even get this message. I had to go to the Google Groups interface > to check for replies. Have you checked your junk mail folder? Unfortunately, the three of the Big Four mail providers -- Yahoo, Gmail, and AOL[1] -- have collectively decided that mailing lists are oh-so-2012 and are putting in place policies which make it harder and harder for their users to successfully subscribe and post to mailing lists. Ironically, Hotmail is probably the best of the Big Four in this regard. I don't even think it is a conscious decision that mailing lists are obsolete, I think it's mostly just technical incompetence and malice. Apparently Yahoo and AOL got hacked a few years ago, the bad guys managed to send out masses of spam via their mail servers, and they panicked, over-reacted (or at least badly reacted) and implemented a half-arsed, badly thought out implementation of DMARC which effectively makes it all but impossible for Yahoo/AOL users to use mailing lists. I've been told that Yahoo basically treats all bulk email as spam unless it comes from Yahoo itself. And of course Gmail and Google Groups make it hard to interoperate with the rest of Usenet and non-Google mailing lists. They don't have the excuse of technical incompetence. It's ironic that as Microsoft has slowly but surely (and kicking and screaming most of the way) become a better web citizen, Google's motto "Don't Be Evil" has become a sad joke more often than not. [1] Hard to believe, but yes people do still use AOL. -- Steven From steve+comp.lang.python at pearwood.info Thu Mar 12 23:17:37 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 13 Mar 2015 14:17:37 +1100 Subject: Code hosting providers (was: Google Code Shutting Down) References: <36a41718-3eb6-445b-ba5b-caf124122542@googlegroups.com> Message-ID: <550256d2$0$12983$c3e8da3$5496439d@news.astraweb.com> Ben Finney wrote: > Also worth watching is Kallithea, a new federated code hosting service > . It supports Mercurial and Git for VCS, > code review, and integrates with existing issue trackers. Because it's > federated, you won't suffer from vendor lock-in. What do you mean by "federated"? -- Steven From torriem at gmail.com Thu Mar 12 23:28:21 2015 From: torriem at gmail.com (Michael Torrie) Date: Thu, 12 Mar 2015 21:28:21 -0600 Subject: Code hosting providers In-Reply-To: <550256d2$0$12983$c3e8da3$5496439d@news.astraweb.com> References: <36a41718-3eb6-445b-ba5b-caf124122542@googlegroups.com> <550256d2$0$12983$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55025955.3070901@gmail.com> On 03/12/2015 09:17 PM, Steven D'Aprano wrote: > Ben Finney wrote: >> Also worth watching is Kallithea, a new federated code hosting service >> . It supports Mercurial and Git for VCS, >> code review, and integrates with existing issue trackers. Because it's >> federated, you won't suffer from vendor lock-in. > > What do you mean by "federated"? I think it's a fancy way of saying you can run your own instance of the full web system on your own server under your own domain name. From skybuck2000 at hotmail.com Thu Mar 12 23:29:41 2015 From: skybuck2000 at hotmail.com (Skybuck Flying) Date: Fri, 13 Mar 2015 04:29:41 +0100 Subject: KB 2670838 - The EVIL UPDATE Message-ID: <850ad$550259dc$5419aafe$25863@news.ziggo.nl> KB 2670838 - The EVIL UPDATE This Windows 7 update wasted a lot of my time today. I could not find my own postings in the past... maybe I was unsure in the past... I am still unsure today.. but much more sure than previously. When installing IE11 I suspect this patch also gets installed. This patch will cause: 1. Windows Live Mail fail to crash, making mail inaccessible. 2. Company of Heroes, Tales of Valor to crash. 3. Call of Duty 5 World at War to stop loading. 4. Possibly even IE9 to keep crashing... 5. And perhaps other misschief. This patch is the worst patch I have ever seen... I am not 100% sure but it's a very good guess. Therefore it's time for me to spam this message all across usenet... so that I will always find it in google hopefully, next time it pops it's ugly head... Hopefully it will save my lost of time in the future. Also bare in mind: IE9 crashes IE10,IE11 is junk, it's slow... it's laggy and it's not worth this patch trouble. My advice is stick with Firefox and other browsers... always make sure to have multiple browsers installed otherwise you might be stranded... Also if you ever have a crashing internet explorer and you really can't recover... remember that you can de-install it... this will revert it back to IE8... at least that should give you a chance to become "unstranded" and access the web again for help. KB 2670838 - The EVIL UPDATE http://answers.microsoft.com/en-us/windows/forum/windows_7-windows_update/kb-2670838-the-evil-update/08bfdb2b-6896-4c34-89c2-16896a25dc3d I was hoping Microsoft fixed this patch by now... unfortunately they did not... and are probably too busy messing around with windows 8.1/windows 10 etc. Shame on them cause this is ONE BITCH OF A PATCH !!! Also FUCK Microsoft for intentionally DAMAGING computer software ! My trust in Microsoft is disappearing. Their behaviour is always the same basically: "Damage old software to try and get people to buy new systems/upgrade". This patch makes me sick to my stomach... mostly because it endangers my data ! If Microsoft causes my DATA to be lost or inaccessable their software will be TERMINATED by me and I will switch to something else. Even if it's just a stupid little patch like this... this kind of thing.... making my mail archieve inaccessible is unacceptable behaviour. I will keep a close eye on this patch to see if it ever gets fixed. If now I may get so sick to my stumach that I might just skip Windows 10 and go to Linux route... For now at least it can be deinstalled... but it comes at a great risk: no more internet explorer, no more internet explorer updates... Now I have to trust Mozilla and Open Source developers ?! What's the world coming too ?! ;) ;) ;) If Microsoft keeps this up they will drive everybody to open source... is that what you want Microsoft ? You guys are doing really bad right now... one little patch and you can't fix it ???? REally ??? I will examine your details about this patch... I probably did it n the past already... You know what I will do it right now... just to see if I can add some info to this posting. Basically this is some kind of graphics patch update for hybrid graphics cards... fuck that... please shove this up your ass. Integrated graphics probably.... HHHHHHHHHHHHHHHHHHHHHHHHHHHMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM WHERE HAVE I HEAR THAT BEFORE ???????????????? DOES INTEL WRING A BELLLL ????????????????? INTEGRATED ELECTRONICS = INTEL. This patch is apperently CODE-AUTHORED BY INTEL. INTEL IS PURPOSELY NUKING YOUR SYSTEMS. THIS PUTS A NEW PERSPECTIVE ON INTEL. I WAS PLANNING TO BUY THEIR NEW SKYLAKE PROCESSOR... THOUGH THEIR HASWELL HAD A TRANSACTIONAL MEMORY BUG. THIS LATEST RELEVATION/CONCLUSION SHEDS NEW LIGHT ON THIS POTENTIAL EVIL FROM INTEL. I can only advice researchers, academics, hackers, press... to investigate this matter further. IF THIS IS TRUE THEN THIS IS A GIGANTIC SCHANDAL OF IMAGINABLE PROPORTIONS AND NEEDS A SEVERE COUNTER REACTION. IF THIS IS TRUE I CAN RECOMMEND A BOYCOTT OF INTEL PROCESSORS AND MICROSOFT SOFTWARE AND SWITCH TO OPEN SOURCE SOFTWARE where these kind of trust issues and bugs can be more easily spotted and fixed and hopefully AVOIDED. Basically I DEMAND A FULL INVESTIGATION from the goverments INTO PATCH 2670838. GOODBYE, FAILURE TO DO SO PUTS YOUR SYSTEMS AT RISK ! Bye, Skybuck. From steve+comp.lang.python at pearwood.info Thu Mar 12 23:30:06 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 13 Mar 2015 14:30:06 +1100 Subject: generator/coroutine terminology References: <5501be8b$0$13006$c3e8da3$5496439d@news.astraweb.com> <87twxqqewm.fsf@elektro.pacujo.net> <4eec1709-dd11-4891-bfcc-60b27bb00ee3@googlegroups.com> Message-ID: <550259bf$0$12975$c3e8da3$5496439d@news.astraweb.com> Rustom Mody wrote: > On Thursday, March 12, 2015 at 11:25:32 PM UTC+5:30, Marko Rauhamaa wrote: >> Rustom Mody : >> >> > I guess we need >> > 1. A clear ontology of the base concepts (which is a buzzword for >> > nailed-down terminology) >> >> According to the documentation, a function whose definition contains a >> yield statement is a generator: >> >> Using a yield expression in a function's body causes that function to >> be a generator. >> >> > ressions> >> >> generator >> A function which returns an iterator. >> >> >> >> Apparently, what we have here is a discrepancy between the documentation >> and the CPython implementation. >> >> In a word, it's a bug (somewhere). > > Throwing out some thought for better terminology. > [Yeah needs to be chewed on a bit...] > > With respect to my example above: > > def foo(x): > yield x+1 > yield x+2 > > > g = foo(2) > > Generator-instance: g > Generator-factory: foo > Generator: Concept in python (ontology) elaborated in terms of the above I think that is is reasonable. I would include "generator function" as a synonym for generator factory. (Factories are more inclusive than functions -- a factory could include a class with a "make_generator" method, for example.) Where the distinction is clear, or not important, than calling both g and foo "generators" is acceptable shorthand. I realise that can be confusing to beginners, but jargon often is confusing to beginners until they have learned enough to be able to correctly interpret things in context. > Situation with coroutines is worse > [Or I cant think of good terms...] Not really. The difference between a coroutine and a generator is mostly in usage, that is, intent. They both use the same type, they both have send methods, they both are generated the same way. If you are foolish, you can even mix generator-behaviour and coroutine-behaviour in the same function: py> def g(): ... yield 1 ... yield 2 ... x = yield 3 ... yield x + 1000 ... py> a = g() py> next(a) 1 py> next(a) 2 py> next(a) 3 py> a.send(99) 1099 But don't do that. So as far as Python is concerned, a coroutine is just a generator instance which you use in a particular way, not a different kind of object. So I would use similar terminology: A generator function/factory returns a generator instance, which we use as a coroutine, so we can call it a coroutine. -- Steven From ben+python at benfinney.id.au Fri Mar 13 00:22:59 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 13 Mar 2015 15:22:59 +1100 Subject: Code hosting providers References: <36a41718-3eb6-445b-ba5b-caf124122542@googlegroups.com> <550256d2$0$12983$c3e8da3$5496439d@news.astraweb.com> Message-ID: <858uf1v84c.fsf@benfinney.id.au> Steven D'Aprano writes: > Ben Finney wrote: > > > Also worth watching is Kallithea, a new federated code hosting service > > . It supports Mercurial and Git for VCS, > > code review, and integrates with existing issue trackers. Because it's > > federated, you won't suffer from vendor lock-in. > > What do you mean by "federated"? A service is federated if an independent, perhaps even competing, vendor can provide the same service and all users of the service participate, moving freely from one vendor to another as they choose without losing any of their data or identity. Another term is ?decentralised?, though that says only what the service is not. I prefer the term ?federated? because it describes what the service *is*: composed of multiple parties, collaborating on equal terms enforced for the protection of the people participating in the service. If a service's features use proprietary protocols or undisclosed APIs or in any other way make it infeasible for a user joining today to reliably migrate their accumulated data to a different vendor at some future time, then that service is not federated and its users are vulnerable to vendor lock-in. The email system, for example, is federated: my data can reliably (and has, several times) survive migration to any vendor who provides standard email service, because I lose no access to any of my history or identity or accumulated data or access or ongoing functionality with the same data. By ?reliably? I mean that I can move it all from one vendor to another, and even back again if I choose, in the knowledge that the standard POP, IMAPv4, and SMTP protocols will be honoured, because to fail in that would be a bug severe enough that the vendor would be avoided as not providing the service. Other examples of federated systems include: * Avatar image serving: Libravatar . * Social networking: Diaspora . * Version control: Git . * The World Wide Web, and the internet as originally designed . To the extent that vendor lock-in is possible, the service is not federated. Corollary: some features of a vendor's offerings can be federated, and others not; and to talk of the vendor's complete set of offerings as ?federated? can only be true if they all are. The GitHub service, for example, is not federated, because while mere Git repositories *are* federated, significant GitHub features (issue tracker, pull requests, and other important history and project data) cannot reliably be migrated smoothly to another instance provided by a competing vendor. Ned Batchelder and Nick Coghlan have written insightfully on this with regard to why GitHub ? or any non-federated service ? is not a good option for projects that intend to stay viable. It will be good to see Kallithea come into its own; until then we have GitLab and Redmine and even the juggernaut of Launchpad ; they are all federated and avoid vendor lock-in. We should ask hard questions to projects that choose to host their irreplaceable data ? not just VCS but issues, user identities, discussions, documentation, etc. ? on services that they can't reliably migrate from. They are demonstrating they don't intend to be around for long; why should we invest any effort in them? -- \ ?The most common way people give up their power is by thinking | `\ they don't have any.? ?Alice Walker | _o__) | Ben Finney From ben+python at benfinney.id.au Fri Mar 13 00:27:03 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 13 Mar 2015 15:27:03 +1100 Subject: Code hosting providers References: <36a41718-3eb6-445b-ba5b-caf124122542@googlegroups.com> <550256d2$0$12983$c3e8da3$5496439d@news.astraweb.com> <55025955.3070901@gmail.com> Message-ID: <854mppv7xk.fsf@benfinney.id.au> Michael Torrie writes: > On 03/12/2015 09:17 PM, Steven D'Aprano wrote: > > What do you mean by "federated"? > > I think it's a fancy way of saying you can run your own instance of the > full web system on your own server under your own domain name. With the corollary that *any* vendor motivated to do so can serve the same function. Meaning the options aren't just ?use this vendor or get nothing?, as they are with a centralised service. With a federated service, anyone *can* run their own instance, which means that few people have to: vendors can pop up and compete with one another, participants have the option of moving to a different vendor taking their data and functionality and established relationships and discussions and identity where they choose. -- \ ?The aim of science is not to open the door to infinite wisdom, | `\ but to set some limit on infinite error.? ?Bertolt Brecht, | _o__) _Leben des Galilei_, 1938 | Ben Finney From ian.g.kelly at gmail.com Fri Mar 13 00:33:46 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 12 Mar 2015 22:33:46 -0600 Subject: Google Code Shutting Down In-Reply-To: <36a41718-3eb6-445b-ba5b-caf124122542@googlegroups.com> References: <36a41718-3eb6-445b-ba5b-caf124122542@googlegroups.com> Message-ID: On Thu, Mar 12, 2015 at 4:26 PM, Josh English wrote: > I've been hosting Python projects on Google Code, and they're shutting down. > > Damn. > > What is the recommended replacement for Code Hosting that works reliably with PyPi and pip? Google has been migrating most of its own open source projects to GitHub. From no.email at nospam.invalid Fri Mar 13 01:17:03 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 12 Mar 2015 22:17:03 -0700 Subject: Code hosting providers References: <36a41718-3eb6-445b-ba5b-caf124122542@googlegroups.com> Message-ID: <87a8zhxyr4.fsf@jester.gateway.sonic.net> Ben Finney writes: > Any service which doesn't run their service on free software is one to > avoid ; free software > projects need free tools to remain that way. > > GitLab is a good option: they provide > VCS, file hosting, wiki, issue tracker, code review via merge requests... > Also worth watching is Kallithea, a new federated code hosting service > . It supports Mercurial and Git for VCS, > code review, and integrates with existing issue trackers. Because it's > federated, you won't suffer from vendor lock-in. Thanks for that informative post: I've been uncomfortable with the reach of Github and you've done a good job explaining the reasons. I personally use self-hosted git repositories on cheap VPS servers which is easy to do, but doesn't supply issue tracking. I know various projects that use either Trac or Bugzilla but I haven't tried operating those. One interesting and very lightweight alternative is Fossil, which is an all-in-one program that does lots of the same stuff as Git, Trac, a web server, and a wiki, all rolled into a single C program that uses about 1 meg of ram. It's written by the guy who wrote SQLite and it in fact uses SQLite as the underlying data store. It has a philosophical difference with git in that it's difficult to "rewrite history" which some workflows expect you to do. I've sometimes wondered how difficult it would be to modify Fossil to support that feature. From rustompmody at gmail.com Fri Mar 13 01:28:11 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 12 Mar 2015 22:28:11 -0700 (PDT) Subject: generator/coroutine terminology In-Reply-To: <550259bf$0$12975$c3e8da3$5496439d@news.astraweb.com> References: <5501be8b$0$13006$c3e8da3$5496439d@news.astraweb.com> <87twxqqewm.fsf@elektro.pacujo.net> <4eec1709-dd11-4891-bfcc-60b27bb00ee3@googlegroups.com> <550259bf$0$12975$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Friday, March 13, 2015 at 9:00:17 AM UTC+5:30, Steven D'Aprano wrote: > Rustom Mody wrote: > > > On Thursday, March 12, 2015 at 11:25:32 PM UTC+5:30, Marko Rauhamaa wrote: > >> Rustom Mody : > >> > >> > I guess we need > >> > 1. A clear ontology of the base concepts (which is a buzzword for > >> > nailed-down terminology) > >> > >> According to the documentation, a function whose definition contains a > >> yield statement is a generator: > >> > >> Using a yield expression in a function's body causes that function to > >> be a generator. > >> > >> >> ressions> > >> > >> generator > >> A function which returns an iterator. > >> > >> > >> > >> Apparently, what we have here is a discrepancy between the documentation > >> and the CPython implementation. > >> > >> In a word, it's a bug (somewhere). > > > > Throwing out some thought for better terminology. > > [Yeah needs to be chewed on a bit...] > > > > With respect to my example above: > > > > def foo(x): > > yield x+1 > > yield x+2 > > > > > > g = foo(2) > > > > Generator-instance: g > > Generator-factory: foo > > Generator: Concept in python (ontology) elaborated in terms of the above > > I think that is is reasonable. Good that we agree! > Where the distinction is clear, or not important, than calling both g and > foo "generators" is acceptable shorthand. I realise that can be confusing > to beginners, but jargon often is confusing to beginners until they have > learned enough to be able to correctly interpret things in context. I would prefer -- when shortforming is required: generator-instance -> instance generator-factory -> factory rather than generator-instance -> generator generator-factory -> generator Yeah that can quarrel with the more usual OO notion of instance, but I find that ambiguity more remote > > > > Situation with coroutines is worse > > [Or I cant think of good terms...] > > Not really. The difference between a coroutine and a generator is mostly in > usage, that is, intent. They both use the same type, they both have send > methods, they both are generated the same way. If you are foolish, you can > even mix generator-behaviour and coroutine-behaviour in the same function: > > > py> def g(): > ... yield 1 > ... yield 2 > ... x = yield 3 > ... yield x + 1000 > ... > py> a = g() > py> next(a) > 1 > py> next(a) > 2 > py> next(a) > 3 > py> a.send(99) > 1099 > > But don't do that. > > So as far as Python is concerned, a coroutine is just a generator instance > which you use in a particular way, not a different kind of object. So I > would use similar terminology: > > A generator function/factory returns a generator instance, which we use as a > coroutine, so we can call it a coroutine. I think coroutines are intended to be symmetric in a way that generators are not. The nut-n-bolts of both may involve using yield but conceptually I find them different. And even there I would expect generators to close with StopIteration Whereas I would expect coroutines to close (on close method) with GeneratorExit [Ive not thought all this through properly so may be off the mark] From nagle at animats.com Fri Mar 13 02:05:41 2015 From: nagle at animats.com (John Nagle) Date: Thu, 12 Mar 2015 23:05:41 -0700 Subject: Python3 "pickle" vs. stdin/stdout - unable to get clean byte streams in Python 3 In-Reply-To: References: Message-ID: <55027E35.60505@animats.com> On 3/12/2015 5:18 PM, John Nagle wrote: > On 3/12/2015 2:56 PM, Cameron Simpson wrote: >> On 12Mar2015 12:55, John Nagle wrote: >>> I have working code from Python 2 which uses "pickle" to talk to a >>> subprocess via stdin/stdio. I'm trying to make that work in Python >>> 3. I'm starting to think that the "cpickle" module, which Python 3 uses by default, has a problem. After the program has been running for a while, I start seeing errors such as File "C:\projects\sitetruth\InfoSiteRating.py", line 200, in scansite if len(self.badbusinessinfo) > 0 : # if bad stuff NameError: name 'len' is not defined which ought to be impossible in Python, and File "C:\projects\sitetruth\subprocesscall.py", line 129, in send self.writer.dump(args) # send data OSError: [Errno 22] Invalid argument from somewhere deep inside CPickle. I got File "C:\projects\sitetruth\InfoSiteRating.py", line 223, in get_rating_text (ratingsmalliconurl, ratinglargiconurl, ratingalttext) = DetailsPageBuilder.getratingiconinfo(rating) NameError: name 'DetailsPageBuilder' is not defined (That's an imported module. It worked earlier in the run.) and finally, even after I deleted all .pyc files and all Python cache directories: Fatal Python error: GC object already tracked Current thread 0x00001a14 (most recent call first): File "C:\python34\lib\site-packages\pymysql\connections.py", line 411 in description File "C:\python34\lib\site-packages\pymysql\connections.py", line 1248 in _get_descriptions File "C:\python34\lib\site-packages\pymysql\connections.py", line 1182 in _read_result_packet File "C:\python34\lib\site-packages\pymysql\connections.py", line 1132 in read File "C:\python34\lib\site-packages\pymysql\connections.py", line 929 in _read_query_result File "C:\python34\lib\site-packages\pymysql\connections.py", line 768 in query File "C:\python34\lib\site-packages\pymysql\cursors.py", line 282 in _query File "C:\python34\lib\site-packages\pymysql\cursors.py", line 134 in execute File "C:\projects\sitetruth\domaincacheitem.py", line 128 in select File "C:\projects\sitetruth\domaincache.py", line 30 in search File "C:\projects\sitetruth\ratesite.py", line 31 in ratedomain File "C:\projects\sitetruth\RatingProcess.py", line 68 in call File "C:\projects\sitetruth\subprocesscall.py", line 140 in docall File "C:\projects\sitetruth\subprocesscall.py", line 158 in run File "C:\projects\sitetruth\RatingProcess.py", line 89 in main File "C:\projects\sitetruth\RatingProcess.py", line 95 in That's a definite memory error. So something is corrupting memory. Probably CPickle. All my code is in Python. Every library module came in via "pip", into a clean Python 3.4.3 (32 bit) installation on Win7/x86-64. Currently installed packages: beautifulsoup4 (4.3.2) dnspython3 (1.12.0) html5lib (0.999) pip (6.0.8) PyMySQL (0.6.6) pyparsing (2.0.3) setuptools (12.0.5) six (1.9.0) And it works fine with Python 2.7.9. Is there some way to force the use of the pure Python pickle module? My guess is that there's something about reusing "pickle" instances that botches memory uses in CPython 3's C code for "cpickle". John Nagle From rosuav at gmail.com Fri Mar 13 04:23:29 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 13 Mar 2015 19:23:29 +1100 Subject: generator/coroutine terminology In-Reply-To: References: <5501be8b$0$13006$c3e8da3$5496439d@news.astraweb.com> <87twxqqewm.fsf@elektro.pacujo.net> <4eec1709-dd11-4891-bfcc-60b27bb00ee3@googlegroups.com> <550259bf$0$12975$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 13, 2015 at 4:28 PM, Rustom Mody wrote: > And even there I would expect generators to close with StopIteration > Whereas I would expect coroutines to close (on close method) with GeneratorExit > [Ive not thought all this through properly so may be off the mark] I expect both of them to close with "return". You can throw GeneratorExit into a generator, but that's an implementation detail more than anything else (same as the throwing of SystemExist is, and for the same reason). When any iterator is exhausted, next() will raise StopIteration rather than returning something; if you're simply iterating over a generator, you can treat StopIteration as an implementation detail too: def squares_up_to(top): for n in range(top): if n*n > top: return yield n*n for sq in squares_up_to(50): print(sq) You don't need to be concerned about all those little details of resuming and stack frames and so on. You definitely don't need to worry about strange interactions around a "with" block inside the generator - you can confidently trust that everything will behave correctly. As it happens, this notion of "behaving correctly" is largely implemented using exceptions, but if it were implemented with a bunch of special cases in the CPython source code, it wouldn't matter. Write idiomatic source code and don't worry about the details. Learn how things work if you're curious, but it's seldom going to matter. ChrisA From mail at timgolden.me.uk Fri Mar 13 04:27:26 2015 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 13 Mar 2015 08:27:26 +0000 Subject: My emails are getting bounced? In-Reply-To: References: Message-ID: <55029F6E.6010801@timgolden.me.uk> On 12/03/2015 22:03, Zachary Ware wrote: > On Thu, Mar 12, 2015 at 4:56 PM, Ryan Gonzalez wrote: >> I'm posting this here because I have no clue who the heck the mailing list >> manager is. >> >> I got this message: >> >> Your membership in the mailing list Python-ideas has been disabled due >> to excessive bounces The last bounce received from you was dated >> 12-Mar-2015. You will not get any more messages from this list until >> you re-enable your membership. You will receive 3 more reminders like >> this before your membership in the list is deleted. > > I just got the same and sent a mail to python-ideas-owner at python.org. > I suspect the problem is that Gmail is bounces any message coming > through the list from an @yahoo.com address; I've been having to > not-spam every message from Andrew Barnett this week. > Only slightly ironically, I had to approve that email to python-list (not sure why; I just waved it through). TJG From rosuav at gmail.com Fri Mar 13 04:33:56 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 13 Mar 2015 19:33:56 +1100 Subject: Code hosting providers In-Reply-To: <87a8zhxyr4.fsf@jester.gateway.sonic.net> References: <36a41718-3eb6-445b-ba5b-caf124122542@googlegroups.com> <87a8zhxyr4.fsf@jester.gateway.sonic.net> Message-ID: On Fri, Mar 13, 2015 at 4:17 PM, Paul Rubin wrote: > Thanks for that informative post: I've been uncomfortable with the reach > of Github and you've done a good job explaining the reasons. > > I personally use self-hosted git repositories on cheap VPS servers which > is easy to do, but doesn't supply issue tracking. I know various > projects that use either Trac or Bugzilla but I haven't tried operating > those. It's worth noting, by the way, that sometimes it's worth using a non-federated service. I host most of my projects on GitHub, because the git repo is the part that's most important to me. I don't heavily use the bug tracker attached to any of those projects, nor the gh-pages branch, etc, etc. If ever I need to move off GitHub, the loss of my tracker history is almost entirely non-significant. But if someone goes looking at my repo there, and wants to raise an issue, I'm quite happy to have that come through the tracker - which means that, technically, I am using that non-federated service. It's not something to fear, just something to be aware of. With the example of moving emails around, the hard part usually isn't SMTP and co, but moving your email history. Can you download all your emails in a convenient format for unloading into your new host, or do you get a proprietary .PST file that you have to somehow deal with? I'm not speaking from any sort of experience here, of course. It's not like I've had to deal with several people who decided not to move to an open system because it would be too hard to move their data. No, of course not. That never happens. ChrisA From steve+comp.lang.python at pearwood.info Fri Mar 13 04:43:08 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 13 Mar 2015 19:43:08 +1100 Subject: Python3 "pickle" vs. stdin/stdout - unable to get clean byte streams in Python 3 References: <55027E35.60505@animats.com> Message-ID: <5502a31d$0$12997$c3e8da3$5496439d@news.astraweb.com> John Nagle wrote: > I'm starting to think that the "cpickle" module, which Python 3 > uses by default, has a problem. After the program has been > running for a while, I start seeing errors such as > > File "C:\projects\sitetruth\InfoSiteRating.py", line 200, in scansite > if len(self.badbusinessinfo) > 0 : # if bad stuff > NameError: name 'len' is not defined > > which ought to be impossible in Python, and "Impossible"? py> len py> import __builtin__ # use builtins in Python 3 py> del __builtin__.len py> len Traceback (most recent call last): File "", line 1, in NameError: name 'len' is not defined Why something is deleting builtins len is a mystery. Sounds to me that your Python installation is borked. > File "C:\projects\sitetruth\subprocesscall.py", line 129, in send > self.writer.dump(args) # send data > OSError: [Errno 22] Invalid argument > > from somewhere deep inside CPickle. Why do you say "deep inside CPickle"? The traceback says C:\projects\sitetruth\subprocesscall.py Is it possible you have accidentally shadowed the CPickle module with something? What does this say? import cPickle print cPickle.__file__ Use _pickle in Python 3. > I got > > File "C:\projects\sitetruth\InfoSiteRating.py", line 223, in > get_rating_text > (ratingsmalliconurl, ratinglargiconurl, ratingalttext) = > DetailsPageBuilder.getratingiconinfo(rating) > NameError: name 'DetailsPageBuilder' is not defined > (That's an imported module. It worked earlier in the run.) > > and finally, even after I deleted all .pyc files and all Python > cache directories: > > Fatal Python error: GC object already tracked > > Current thread 0x00001a14 (most recent call first): > File "C:\python34\lib\site-packages\pymysql\connections.py", line 411 > in description > File "C:\python34\lib\site-packages\pymysql\connections.py", line 1248 > in _get_descriptions > File "C:\python34\lib\site-packages\pymysql\connections.py", line 1182 > in _read_result_packet > File "C:\python34\lib\site-packages\pymysql\connections.py", line 1132 > in read > File "C:\python34\lib\site-packages\pymysql\connections.py", line 929 > in _read_query_result > File "C:\python34\lib\site-packages\pymysql\connections.py", line 768 > in query > File "C:\python34\lib\site-packages\pymysql\cursors.py", line 282 in > _query > File "C:\python34\lib\site-packages\pymysql\cursors.py", line 134 in > execute > File "C:\projects\sitetruth\domaincacheitem.py", line 128 in select > File "C:\projects\sitetruth\domaincache.py", line 30 in search > File "C:\projects\sitetruth\ratesite.py", line 31 in ratedomain > File "C:\projects\sitetruth\RatingProcess.py", line 68 in call > File "C:\projects\sitetruth\subprocesscall.py", line 140 in docall > File "C:\projects\sitetruth\subprocesscall.py", line 158 in run > File "C:\projects\sitetruth\RatingProcess.py", line 89 in main > File "C:\projects\sitetruth\RatingProcess.py", line 95 in > > That's a definite memory error. > > So something is corrupting memory. Probably CPickle. > All my code is in Python. Every library module came in via "pip", into a > clean Python 3.4.3 (32 bit) installation on Win7/x86-64. > Currently installed packages: > > beautifulsoup4 (4.3.2) > dnspython3 (1.12.0) > html5lib (0.999) > pip (6.0.8) > PyMySQL (0.6.6) > pyparsing (2.0.3) > setuptools (12.0.5) > six (1.9.0) > > And it works fine with Python 2.7.9. > > Is there some way to force the use of the pure Python pickle module? Try renaming the _pickle module. This works on Linux: mv /usr/local/lib/python3.3/lib-dynload/_pickle.cpython-33m.so /usr/local/lib/python3.3/lib-dynload/_pickle.cpython-33m.so~ > My guess is that there's something about reusing "pickle" instances > that botches memory uses in CPython 3's C code for "cpickle". How are you reusing instances? -- Steven From steve+comp.lang.python at pearwood.info Fri Mar 13 04:47:27 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 13 Mar 2015 19:47:27 +1100 Subject: Google Code Shutting Down References: <36a41718-3eb6-445b-ba5b-caf124122542@googlegroups.com> Message-ID: <5502a420$0$12997$c3e8da3$5496439d@news.astraweb.com> Ian Kelly wrote: > On Thu, Mar 12, 2015 at 4:26 PM, Josh English > wrote: >> I've been hosting Python projects on Google Code, and they're shutting >> down. >> >> Damn. >> >> What is the recommended replacement for Code Hosting that works reliably >> with PyPi and pip? > > Google has been migrating most of its own open source projects to GitHub. All that tells me is that Google is planning on buying GitHub, at which point they will continue the process of GitHub lock-in. http://nedbatchelder.com/blog/201405/github_monoculture.html -- Steven From steve+comp.lang.python at pearwood.info Fri Mar 13 04:59:28 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 13 Mar 2015 19:59:28 +1100 Subject: Code hosting providers References: <36a41718-3eb6-445b-ba5b-caf124122542@googlegroups.com> <87a8zhxyr4.fsf@jester.gateway.sonic.net> Message-ID: <5502a6f1$0$13007$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > It's worth noting, by the way, that sometimes it's worth using a > non-federated service. I host most of my projects on GitHub, because > the git repo is the part that's most important to me. I don't heavily > use the bug tracker attached to any of those projects, nor the > gh-pages branch, etc, etc. That is the complete opposite of making sense. If you had said, "Sometimes it's worth using a non-federated service, and risking vendor lock-in, because the extra features they provide are just that good" then I'd accept that. That makes sense. I don't like it, but that's the business model of proprietary services: provide more features, and use that to lock people in. But saying "I host my projects on GitHub because I DON'T use any of the features which differentiate GitHub from its federated competitors" makes no sense to me. You are actively helping to support a software monoculture, and you're not even getting any short-term benefit from it! That's the worst of all possible worlds -- selling out the future, for no gain today. Personally, I won't use Github if I can possibly ignore it. I have ethical issues with their corporate culture, and I dislike anything which smacks of a monoculture. The more Github gets treated as synonymous with revision control, the more I will push back, until I cannot push back any more. -- Steven From rustompmody at gmail.com Fri Mar 13 05:12:18 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 13 Mar 2015 02:12:18 -0700 (PDT) Subject: generator/coroutine terminology In-Reply-To: References: <5501be8b$0$13006$c3e8da3$5496439d@news.astraweb.com> <87twxqqewm.fsf@elektro.pacujo.net> <4eec1709-dd11-4891-bfcc-60b27bb00ee3@googlegroups.com> <550259bf$0$12975$c3e8da3$5496439d@news.astraweb.com> Message-ID: <00d9152a-f391-4c64-b2bd-52bdec2a6b67@googlegroups.com> On Friday, March 13, 2015 at 1:53:50 PM UTC+5:30, Chris Angelico wrote: > On Fri, Mar 13, 2015 at 4:28 PM, Rustom Mody wrote: > > And even there I would expect generators to close with StopIteration > > Whereas I would expect coroutines to close (on close method) with GeneratorExit > > [Ive not thought all this through properly so may be off the mark] > > I expect both of them to close with "return". Nice demo of the same confusing terminology we are talking about. When I say "expect generators to close" I mean 'generator-instances' ie at runtime When you say "expect both to close with return" you are talking of program-texts ie the 'factory' [Or I am guilty of the same I am accusing python of] From marko at pacujo.net Fri Mar 13 05:36:13 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 13 Mar 2015 11:36:13 +0200 Subject: generator/coroutine terminology References: <5501be8b$0$13006$c3e8da3$5496439d@news.astraweb.com> <87twxqqewm.fsf@elektro.pacujo.net> <4eec1709-dd11-4891-bfcc-60b27bb00ee3@googlegroups.com> <550259bf$0$12975$c3e8da3$5496439d@news.astraweb.com> <00d9152a-f391-4c64-b2bd-52bdec2a6b67@googlegroups.com> Message-ID: <8761a5s0he.fsf@elektro.pacujo.net> Rustom Mody : > Nice demo of the same confusing terminology we are talking about. Why don't you just stick with the terminology of the language specification? I think your students are going to be more confused if you try to come up with something better. > When I say "expect generators to close" I mean 'generator-instances' > ie at runtime > > When you say "expect both to close with return" you are talking of > program-texts ie the 'factory' > > [Or I am guilty of the same I am accusing python of] Your 'factory' is a: generator A function which returns an iterator. Your 'generator-instance' is an: iterator An object representing a stream of data. I don't think you should read much into what str(obj) returns. It's not much more than a random printable some CPython coder has cooked up in the heat of the moment. Marko From marfig at gmail.com Fri Mar 13 06:02:14 2015 From: marfig at gmail.com (Mario Figueiredo) Date: Fri, 13 Mar 2015 11:02:14 +0100 Subject: Code hosting providers (was: Google Code Shutting Down) References: <36a41718-3eb6-445b-ba5b-caf124122542@googlegroups.com> Message-ID: On Fri, 13 Mar 2015 12:37:30 +1100, Ben Finney wrote: > >Any service which doesn't run their service on free software is one to >avoid ; free software >projects need free tools to remain that way. > > >GitLab is a good option: they provide >VCS, file hosting, wiki, issue tracker, code review via merge requests, >etc. and all of it can be migrated to any other instance of the same >service. > For sure the Communition Edition offers self-hosting. But in face of Benjamin article above, what is your opinion on its commercial approach to provide only relevant features through its vendor lock-in service? I always wondered what would happen if the developers community chooses to take its open-source Community edition and fork it into a EE edition. Reminds me so much of MySQL and why MariaDB is today a superior DBMS... >Also worth watching is Kallithea, a new federated code hosting service >. It supports Mercurial and Git for VCS, >code review, and integrates with existing issue trackers. Because it's >federated, you won't suffer from vendor lock-in. > >Good hunting in finding a free-software code hosting provider for your >projects! And Redmine. Kallithea and Redmine seem like two great options. The only problem with Redmine is that it does not provide any Git workflow (correc tme if this is not true anymore). From rosuav at gmail.com Fri Mar 13 07:32:34 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 13 Mar 2015 22:32:34 +1100 Subject: generator/coroutine terminology In-Reply-To: <00d9152a-f391-4c64-b2bd-52bdec2a6b67@googlegroups.com> References: <5501be8b$0$13006$c3e8da3$5496439d@news.astraweb.com> <87twxqqewm.fsf@elektro.pacujo.net> <4eec1709-dd11-4891-bfcc-60b27bb00ee3@googlegroups.com> <550259bf$0$12975$c3e8da3$5496439d@news.astraweb.com> <00d9152a-f391-4c64-b2bd-52bdec2a6b67@googlegroups.com> Message-ID: On Fri, Mar 13, 2015 at 8:12 PM, Rustom Mody wrote: > On Friday, March 13, 2015 at 1:53:50 PM UTC+5:30, Chris Angelico wrote: >> On Fri, Mar 13, 2015 at 4:28 PM, Rustom Mody wrote: >> > And even there I would expect generators to close with StopIteration >> > Whereas I would expect coroutines to close (on close method) with GeneratorExit >> > [Ive not thought all this through properly so may be off the mark] >> >> I expect both of them to close with "return". > > Nice demo of the same confusing terminology we are talking about. > > When I say "expect generators to close" I mean 'generator-instances' ie at runtime > > When you say "expect both to close with return" you are talking of program-texts > ie the 'factory' > > [Or I am guilty of the same I am accusing python of] Well, if you're going to discuss the specifics of terminology, we'd best figure out what "close" means :) You spoke of generators closing "with" StopIteration. Does that mean that, once a generator closes, it raises StopIteration? That's the job of the next() method, in effect. Or do you mean that raising StopIteration will terminate the generator? That won't be true forever, and shouldn't be relied on - just use "return". If you use the close() method, Python throws a GeneratorExit into your generator. But unless you have something that catches that, you shouldn't need to worry about it; all you need to know is that you call close() and the function cleanly terminates. Like I said, there are implementation details that don't usually matter. ChrisA From rosuav at gmail.com Fri Mar 13 07:46:04 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 13 Mar 2015 22:46:04 +1100 Subject: Code hosting providers In-Reply-To: <5502a6f1$0$13007$c3e8da3$5496439d@news.astraweb.com> References: <36a41718-3eb6-445b-ba5b-caf124122542@googlegroups.com> <87a8zhxyr4.fsf@jester.gateway.sonic.net> <5502a6f1$0$13007$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 13, 2015 at 7:59 PM, Steven D'Aprano wrote: > If you had said, "Sometimes it's worth using a non-federated service, and > risking vendor lock-in, because the extra features they provide are just > that good" then I'd accept that. That makes sense. I don't like it, but > that's the business model of proprietary services: provide more features, > and use that to lock people in. > > But saying "I host my projects on GitHub because I DON'T use any of the > features which differentiate GitHub from its federated competitors" makes > no sense to me. You are actively helping to support a software monoculture, > and you're not even getting any short-term benefit from it! That's the > worst of all possible worlds -- selling out the future, for no gain today. Not quite. It's a matter of priorities. I will make use of their proprietary features, but they aren't important to me, and if ever I need to move away from GitHub, I'll just shrug and abandon all of that ancillary stuff. In the meantime, I get zero-dollar hosting of my repos, including zip download and such (I'm not sure how many other hosts have that, but it's a minor convenience rather than anything crucial), and it's a convenient place to point people. You're welcome to shun them. There is definitely benefit to encouraging a multiplicity of hosting services. But I'm not bothered by the GitHub non-free-ness, because I take a less philosophical and more pragmatic view of things. ChrisA From rosuav at gmail.com Fri Mar 13 07:58:10 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 13 Mar 2015 22:58:10 +1100 Subject: Django-DMARC making it easier to manage DMARC reports - Beta 0.1.3 on PyPI In-Reply-To: <54FD72F8.3080706@p-o.co.uk> References: <54FD72F8.3080706@p-o.co.uk> Message-ID: On Mon, Mar 9, 2015 at 9:16 PM, Alan Hicks wrote: > With defending reputations as important as receiving email I'm pleased to > announce another beta of django-dmarc 0.1.3 is released to PyPI. > https://pypi.python.org/pypi/django-dmarc > > The Django DMARC project aims to help with implementing DMARC "Domain-based > Message Authentication, Reporting & Conformance" and ongoing monitoring by > importing feedback reports about messages that pass and/or fail DMARC > evaluation into a more easily digested format. Welcome to irony. Your message got dropped into my Gmail spam box because DMARC is incompatible with mailing lists. Until that can be resolved, I don't want to deploy either end of DMARC for any of my domains or mail servers. ChrisA From skip.montanaro at gmail.com Fri Mar 13 11:17:50 2015 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Fri, 13 Mar 2015 10:17:50 -0500 Subject: Pexpect idea - but can I handle curses? Message-ID: I have this tweak I'd like to make to the top command (Linux only is fine). Most of the time I want to see just one user or all users. Every now and again though, I'd like to see all users except another. Top doesn't support this functionality, but I thought something like "-u -root" would be a handy extension. Another would be to watch multiple users, e.g. -u skip,bob. I thought I could fire up a top command showing all users in a pseudo tty with a fake huge number of lines, then elide the rows matching unwanted users. However... I have a feeling I might be fairly seriously challenged trying to work with top's raw output, as it probably does something more sophisticated than clear the screen and spit out rows. Will I be in over my head trying to tweak the output? Hmmm... maybe if I tell top TERM=dumb? Anyway, before I get in over my head on the input side, I thought I would check to see if I'm likely to hit a brick wall on the output side... Thx, Skip -------------- next part -------------- An HTML attachment was scrubbed... URL: From PointedEars at web.de Fri Mar 13 11:54:41 2015 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Fri, 13 Mar 2015 16:54:41 +0100 Subject: Pexpect idea - but can I handle curses? References: Message-ID: <1606564.hXcnK9StvT@PointedEars.de> Skip Montanaro wrote: > I have this tweak I'd like to make to the top command (Linux only is > fine). Most of the time I want to see just one user or all users. Every > now and again though, I'd like to see all users except another. Top > doesn't support this functionality, Yes, it (top(1) from procps-ng 3.3.9) does. Either run top -u '!root' or type ?o? (for case-insensitive filter), then e.g. ?!USER=root? to show processes started by all users except ?root?. RTFM. -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From larry.martell at gmail.com Fri Mar 13 12:05:57 2015 From: larry.martell at gmail.com (Larry Martell) Date: Fri, 13 Mar 2015 12:05:57 -0400 Subject: regex help Message-ID: I need to remove all trailing zeros to the right of the decimal point, but leave one zero if it's whole number. For example, if I have this: 14S,5.0000000000000000,4.56862745000000,3.7272727272727271,3.3947368421052630,5.7307692307692308,5.7547169811320753,4.9423076923076925,5.7884615384615383,5.137254901960000 I want to end up with: 14S,5.0,4.56862745,3.7272727272727271,3.394736842105263,5.7307692307692308,5.7547169811320753,4.9423076923076925,5.7884615384615383,5.13725490196 I have a regex to remove the zeros: '0+[,$]', '' But I can't figure out how to get the 5.0000000000000000 to be 5.0. I've been messing with the negative lookbehind, but I haven't found one that works for this. From skip.montanaro at gmail.com Fri Mar 13 12:20:11 2015 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Fri, 13 Mar 2015 11:20:11 -0500 Subject: Pexpect idea - but can I handle curses? In-Reply-To: <1606564.hXcnK9StvT@PointedEars.de> References: <1606564.hXcnK9StvT@PointedEars.de> Message-ID: On Fri, Mar 13, 2015 at 10:54 AM, Thomas 'PointedEars' Lahn < PointedEars at web.de> wrote: > Yes, it (top(1) from procps-ng 3.3.9) does. Either run > > top -u '!root' > > or type ?o? (for case-insensitive filter), then e.g. ?!USER=root? to show > processes started by all users except ?root?. RTFM. > Neither works on what I have available at work (OpenSuSE 12.2). -u only accepts a single user name or id in my world. -o doesn't exist at all. Thanks for the pointer though. Skip -------------- next part -------------- An HTML attachment was scrubbed... URL: From DLipman~nospam~ at Verizon.Net Fri Mar 13 12:35:41 2015 From: DLipman~nospam~ at Verizon.Net (David H. Lipman) Date: Fri, 13 Mar 2015 12:35:41 -0400 Subject: KB 2670838 - The EVIL UPDATE In-Reply-To: <850ad$550259dc$5419aafe$25863@news.ziggo.nl> References: <850ad$550259dc$5419aafe$25863@news.ziggo.nl> Message-ID: From: "Skybuck Flying" > KB 2670838 - The EVIL UPDATE < snip > > GOODBYE, > FAILURE TO DO SO PUTS YOUR SYSTEMS AT RISK ! > > > Bye, > Skybuck. I hope you like the taste of shoe leather. KB2670838 ==> 2013 ! It was not a part of the March '15 Patch tuesday release. -- Dave Multi-AV Scanning Tool - http://multi-av.thespykiller.co.uk http://www.pctipp.ch/downloads/dl/35905.asp From PointedEars at web.de Fri Mar 13 13:03:12 2015 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Fri, 13 Mar 2015 18:03:12 +0100 Subject: Pexpect idea - but can I handle curses? References: <1606564.hXcnK9StvT@PointedEars.de> Message-ID: <1597615.KAoEH8zO7A@PointedEars.de> Skip Montanaro wrote: > Thomas 'PointedEars' Lahn [?] wrote: >> Yes, it (top(1) from procps-ng 3.3.9) does. Either run >> >> top -u '!root' >> >> or type ?o? (for case-insensitive filter), then e.g. ?!USER=root? to show >> processes started by all users except ?root?. RTFM. > > Neither works on what I have available at work (OpenSuSE 12.2). -u only > accepts a single user name or id in my world. -o doesn't exist at all. ?o? is not an option, it is an interaktive keystroke command in (my) top(1). Press ?h? for help (I found out this way while reading your posting). OpenSUSE 12.2 has procps 3.3.3 which does not support ?-u '!$USER'? yet; however, OpenSUSE 12.2 has reached its end-of-life on 2014-01-27. > Thanks for the pointer though. You?re welcome. -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From PointedEars at web.de Fri Mar 13 13:10:30 2015 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Fri, 13 Mar 2015 18:10:30 +0100 Subject: regex help References: Message-ID: <2145563.lrZ297Te1a@PointedEars.de> Larry Martell wrote: > I need to remove all trailing zeros to the right of the decimal point, > but leave one zero if it's whole number. For example, if I have this: > > 14S,5.0000000000000000,4.56862745000000,3.7272727272727271,3.3947368421052630,5.7307692307692308,5.7547169811320753,4.9423076923076925,5.7884615384615383,5.137254901960000 > > I want to end up with: > > 14S,5.0,4.56862745,3.7272727272727271,3.394736842105263,5.7307692307692308,5.7547169811320753,4.9423076923076925,5.7884615384615383,5.13725490196 > > I have a regex to remove the zeros: > > '0+[,$]', '' > > But I can't figure out how to get the 5.0000000000000000 to be 5.0. > I've been messing with the negative lookbehind, but I haven't found > one that works for this. First of all, I find it unlikely that you really want to solve your problem with regular expressions. Google ?X-Y problem?. Second, if you must use regular expressions, the most simple approach is to use backreferences. Third, you need to show the relevant (Python) code. -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From skip.montanaro at gmail.com Fri Mar 13 13:25:17 2015 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Fri, 13 Mar 2015 12:25:17 -0500 Subject: Pexpect idea - but can I handle curses? In-Reply-To: <1597615.KAoEH8zO7A@PointedEars.de> References: <1606564.hXcnK9StvT@PointedEars.de> <1597615.KAoEH8zO7A@PointedEars.de> Message-ID: On Fri, Mar 13, 2015 at 12:03 PM, Thomas 'PointedEars' Lahn wrote: > ?o? is not an option, it is an interaktive keystroke command in (my) top(1). "o" is also an unrecognized keystroke. > OpenSUSE 12.2 has reached its end-of-life on 2014-01-27. I understand that. Tell that to management though. They were working on 13.1 for awhile, but seem to be focused on 13.2 now, though not all our internal software works on that. I'll give up on hoping I get access to a more modern top anytime soon. Can someone give me some feedback on my harebrained pexpect idea? Skip From python at mrabarnett.plus.com Fri Mar 13 13:29:36 2015 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 13 Mar 2015 17:29:36 +0000 Subject: regex help In-Reply-To: References: Message-ID: <55031E80.6030904@mrabarnett.plus.com> On 2015-03-13 16:05, Larry Martell wrote: > I need to remove all trailing zeros to the right of the decimal point, > but leave one zero if it's whole number. For example, if I have this: > > 14S,5.0000000000000000,4.56862745000000,3.7272727272727271,3.3947368421052630,5.7307692307692308,5.7547169811320753,4.9423076923076925,5.7884615384615383,5.137254901960000 > > I want to end up with: > > 14S,5.0,4.56862745,3.7272727272727271,3.394736842105263,5.7307692307692308,5.7547169811320753,4.9423076923076925,5.7884615384615383,5.13725490196 > > I have a regex to remove the zeros: > > '0+[,$]', '' > > But I can't figure out how to get the 5.0000000000000000 to be 5.0. > I've been messing with the negative lookbehind, but I haven't found > one that works for this. > Search: (\.\d+?)0+\b Replace: \1 which is: re.sub(r'(\.\d+?)0+\b', r'\1', string) From python.list at tim.thechases.com Fri Mar 13 13:38:38 2015 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 13 Mar 2015 12:38:38 -0500 Subject: regex help In-Reply-To: References: Message-ID: <20150313123838.0b79994f@bigbox.christie.dr> On 2015-03-13 12:05, Larry Martell wrote: > I need to remove all trailing zeros to the right of the decimal > point, but leave one zero if it's whole number. > > But I can't figure out how to get the 5.0000000000000000 to be 5.0. > I've been messing with the negative lookbehind, but I haven't found > one that works for this. You can do it with string-ops, or you can resort to regexp. Personally, I like the clarity of the string-ops version, but use what suits you. -tkc import re input = [ '14S', '5.0000000000000000', '4.56862745000000', '3.7272727272727271', '3.3947368421052630', '5.7307692307692308', '5.7547169811320753', '4.9423076923076925', '5.7884615384615383', '5.137254901960000', ] output = [ '14S', '5.0', '4.56862745', '3.7272727272727271', '3.394736842105263', '5.7307692307692308', '5.7547169811320753', '4.9423076923076925', '5.7884615384615383', '5.13725490196', ] def fn1(s): if '.' in s: s = s.rstrip('0') if s.endswith('.'): s += '0' return s def fn2(s): return re.sub(r'(\.\d+?)0+$', r'\1', s) for fn in (fn1, fn2): for i, o in zip(input, output): v = fn(i) print "%s: %s -> %s [%s]" % (v == o, i, v, o) From larry.martell at gmail.com Fri Mar 13 14:38:51 2015 From: larry.martell at gmail.com (Larry Martell) Date: Fri, 13 Mar 2015 14:38:51 -0400 Subject: regex help In-Reply-To: <55031E80.6030904@mrabarnett.plus.com> References: <55031E80.6030904@mrabarnett.plus.com> Message-ID: On Fri, Mar 13, 2015 at 1:29 PM, MRAB wrote: > On 2015-03-13 16:05, Larry Martell wrote: >> >> I need to remove all trailing zeros to the right of the decimal point, >> but leave one zero if it's whole number. For example, if I have this: >> >> >> 14S,5.0000000000000000,4.56862745000000,3.7272727272727271,3.3947368421052630,5.7307692307692308,5.7547169811320753,4.9423076923076925,5.7884615384615383,5.137254901960000 >> >> I want to end up with: >> >> >> 14S,5.0,4.56862745,3.7272727272727271,3.394736842105263,5.7307692307692308,5.7547169811320753,4.9423076923076925,5.7884615384615383,5.13725490196 >> >> I have a regex to remove the zeros: >> >> '0+[,$]', '' >> >> But I can't figure out how to get the 5.0000000000000000 to be 5.0. >> I've been messing with the negative lookbehind, but I haven't found >> one that works for this. >> > Search: (\.\d+?)0+\b > Replace: \1 > > which is: > > re.sub(r'(\.\d+?)0+\b', r'\1', string) Thanks! That works perfectly. From Joshua.R.English at gmail.com Fri Mar 13 15:53:34 2015 From: Joshua.R.English at gmail.com (Josh English) Date: Fri, 13 Mar 2015 12:53:34 -0700 (PDT) Subject: Google Code Shutting Down In-Reply-To: <36a41718-3eb6-445b-ba5b-caf124122542@googlegroups.com> References: <36a41718-3eb6-445b-ba5b-caf124122542@googlegroups.com> Message-ID: <180506df-0076-439d-90cb-5d3a1f6b577d@googlegroups.com> Thanks for the discussion. I found my original concern was supposedly about sourceforge. PyPi, according to a post over on pypubsub-dev that pip installs had anecdotal problems with sourcforge-hosted projects. I guess I wanted some more anecdotes and opinions before I tried moving anything. I barely understand the SVN I'm using now, so trying to learn a new VCS is a tad daunting for this hobbyist. From lmzentman at gmail.com Fri Mar 13 16:58:32 2015 From: lmzentman at gmail.com (lmzentman at gmail.com) Date: Fri, 13 Mar 2015 13:58:32 -0700 (PDT) Subject: The idle gui Message-ID: My python program was running for over six weeks. Then the idle gui stopped opening. I have reinstalled several times but it doesn't work. Any idea? From nagle at animats.com Fri Mar 13 17:08:15 2015 From: nagle at animats.com (John Nagle) Date: Fri, 13 Mar 2015 14:08:15 -0700 Subject: Python 2 to 3 conversion - embrace the pain Message-ID: <550351BF.5020108@animats.com> I'm approaching the end of converting a large system from Python 2 to Python 3. Here's why you don't want to do this. The language changes aren't that bad, and they're known and documented. It's the package changes that are the problem. Discovering and fixing all the new bugs takes a while. BeautifulSoup: BeautifulSoup 3 has been phased out. I had my own version of BeautifulSoup 3, modified for greater robustness. But that was years ago. So I converted to BeautifulSoup 4, as the documentation says to do. The HTML5parser module is claimed to parse as a browser does, with all the error tolerance specified in the HTML5 spec. (The spec actually specifies how to handle bad HTML consistently across browsers in great detail, and HTML5parser has code in it for that.) It doesn't deliver on that promise, though. Some sites crash BeautifulSoup 4/HTML5parser. Try "kroger.com", which has HTML with . The parse tree constructed has a bad link, and trying to use the parse tree results in exceptions. Submitted bug report. Appears to be another case of a known bug. No workaround at this time. https://bugs.launchpad.net/beautifulsoup/+bug/1270611 https://bugs.launchpad.net/beautifulsoup/+bug/1430633 PyMySQL: "Pymysql is a pure Python drop-in replacement for MySQLdb". Sounds good. Then I discover that LOAD DATA LOCAL wasn't implemented in the version on PyPi. It's on Github, though, and I got the authors to push that out to PyPi. It works on test cases. But it doesn't work on a big job, because the default size of MySQL packets was set to 16MB. This made the LOAD DATA LOCAL code try to send the entire file being loaded as one giant MySQL packet. Unless you configure the MySQL server with 16MB buffers, this fails, with an obscure "server has gone away" message. Found the problem, came up with a workaround, submitted a bug report, and it's being fixed. https://github.com/PyMySQL/PyMySQL/issues/317 SSL: All the new TLS/SSL support is in Python 3. That's good. Unfortunately, using Firefox's set of SSL certs, some important sites (such as "verisign.com") don't validate. This turned out to be a complex problem involving Verisign cross-signing a certificate, which created a certificate hierarchy that some versions of OpenSSL can't handle. There's now a version of OpenSSL that can handle it, but the Python library has to make a call to use it, and that's going in but isn't deployed yet. This bug resulted in much finger-pointing between the Python and OpenSSL developers, the Mozilla certificate store maintainers, and Verisign. It's now been sorted out, but not all the fixes are deployed. Because "ssl" is a core Python module, this will remain broken until the next Python release, on both the 2.7 and 3.4 lines. Also, for no particularly good reason, the exception "SSL.CertificateError" is not a subclass of "SSL.Error", resulting in a routine exception not being recognized. Bug reports submitted for both OpenSSL and Python SSL. Much discussion. Problem fixed, but fix is in next version of Python. No workaround at this time. http://bugs.python.org/issue23476 Pickle: As I just posted recently, CPickle on Python 3.4 seems to have a memory corruption bug. Pure-Python Pickle is fine. So a workaround is possible. Bug report submitted. http://bugs.python.org/issue23655 Converting a large application program to Python 3 thus required diagnosing four library bugs and filing bug reports on all of them. Workarounds are known for two of the problems. I can't deploy the Python 3 version on the servers yet. John Nagle From no.email at nospam.invalid Fri Mar 13 17:13:41 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 13 Mar 2015 14:13:41 -0700 Subject: Code hosting providers References: <36a41718-3eb6-445b-ba5b-caf124122542@googlegroups.com> <87a8zhxyr4.fsf@jester.gateway.sonic.net> <5502a6f1$0$13007$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87ioe4fvne.fsf@jester.gateway.sonic.net> Chris Angelico writes: > In the meantime, I get zero-dollar hosting of my repos, including zip > download and such ... You're welcome to shun them. There is > definitely benefit to encouraging a multiplicity of hosting > services. But I'm not bothered by the GitHub non-free-ness, because I > take a less philosophical and more pragmatic view of things. But you're making the problem worse for other people too. For example, I can't file a bug against your code or send you a pull request, without enrolling in Github myself. You can get a whole virtual server from Amazon for free that is perfectly good for hosting git repos and lots of other things too, or you can get them for a few dollars a year in other places if you don't want to deal with Amazon. Github adds some conveniences but I've never understood the attraction and mystique around it. From no.email at nospam.invalid Fri Mar 13 17:35:28 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 13 Mar 2015 14:35:28 -0700 Subject: Code hosting providers References: <36a41718-3eb6-445b-ba5b-caf124122542@googlegroups.com> Message-ID: <87egosfun3.fsf@jester.gateway.sonic.net> Ben Finney writes: > Also worth watching is Kallithea, a new federated code hosting service ... > Good hunting in finding a free-software code hosting provider for your > projects! Should also put in a mention for Savannah (savannah.gnu.org for GNU projects and savannah.nongnu.org for non-GNU free software) as the provider most philosophically committed to free software. In technical terms I think it's a fork of an early version of Sourceforge, so it's a bit old fashioned, but some good projects are there, and I'll probably use it if the need arises. It runs several VCS's including Arch, Bazaar, CVS, Git, Mercurial, and SVN. Also, if you like the avant-garde, hub.darcs.net might be of interest. I had an account on patch-tag.com (darcs host) for a while, but it apparently shut down last year. From sohcahtoa82 at gmail.com Fri Mar 13 17:58:17 2015 From: sohcahtoa82 at gmail.com (sohcahtoa82 at gmail.com) Date: Fri, 13 Mar 2015 14:58:17 -0700 (PDT) Subject: The idle gui In-Reply-To: References: Message-ID: <0d3d1ec0-d112-42fc-aeed-fb6674d2ee1b@googlegroups.com> On Friday, March 13, 2015 at 1:58:44 PM UTC-7, lmze... at gmail.com wrote: > My python program was running for over six weeks. Then the idle gui stopped opening. I have reinstalled several times but it doesn't work. Any idea? Not trying to be rude here, but do you really think we'll be able to help you when all you say is "It doesn't work"? What error message do you get? What exactly isn't working? Does IDLE not start *AT ALL*? Or is your Python program just not working? What version of Python/IDLE are you running? What operating system? We need more information than just "It doesn't work". You wouldn't go to a car mechanic and say "It makes a funny noise", would you? No. You'd say "It makes a metallic whining noise, like the brakes of a bus or semi-truck, when I make right-turns after going over a bump. It sounds like its coming from the rear driver-side wheel." Being up-front and describing your problem in detail saves everybody time. From emile at fenx.com Fri Mar 13 18:10:15 2015 From: emile at fenx.com (emile) Date: Fri, 13 Mar 2015 15:10:15 -0700 Subject: Odd ValueError using float Message-ID: On an older WinXP SP2 box with python2.6 that's been running this process fine for years, this week we're seeing: > c:\python26\lib\site-packages\fenx\sql_interface.py(144)normalized() -> return val (Pdb) val *** NameError: name 'val' is not defined (Pdb) l 139 try: 140 val = round(float(decval),1) 141 except: 142 import pdb; pdb.set_trace() 143 #val = round(float(int(decval)/10**((decval%100)*100)),1) 144 -> return val 145 146 147 def foodList(reference): 148 # return a list of (code,val) tuples for the ingredients of the foodlist referenced 149 # local internal use only to create sqlFoodListsByID (Pdb) decval '4' (Pdb) len(decval) 1 (Pdb) int(decval) *** ValueError: invalid literal for int() with base 10: '41.700000000000003' (Pdb) Any ideas? Thanks, Emile From breamoreboy at yahoo.co.uk Fri Mar 13 18:12:54 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 13 Mar 2015 22:12:54 +0000 Subject: The idle gui In-Reply-To: References: Message-ID: On 13/03/2015 20:58, lmzentman at gmail.com wrote: > My python program was running for over six weeks. Then the idle gui stopped opening. I have reinstalled several times but it doesn't work. Any idea? > Would you please read http://www.catb.org/esr/faqs/smart-questions.html and possibly http://sscce.org/ and then repost your question, thank you. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rosuav at gmail.com Fri Mar 13 18:14:01 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 14 Mar 2015 09:14:01 +1100 Subject: Odd ValueError using float In-Reply-To: References: Message-ID: On Sat, Mar 14, 2015 at 9:10 AM, emile wrote: > (Pdb) decval > '4' > (Pdb) len(decval) > 1 > (Pdb) int(decval) > *** ValueError: invalid literal for int() with base 10: '41.700000000000003' > (Pdb) > > > Any ideas? What's type(decval) tell you? I suspect you may have something other than a string, even though it looks like a string in its repr. ChrisA From songofacandy at gmail.com Fri Mar 13 18:27:44 2015 From: songofacandy at gmail.com (INADA Naoki) Date: Sat, 14 Mar 2015 07:27:44 +0900 Subject: Python 2 to 3 conversion - embrace the pain In-Reply-To: <550351BF.5020108@animats.com> References: <550351BF.5020108@animats.com> Message-ID: Hi, John. I'm maintainer of PyMySQL. I'm sorry about bug of PyMySQL. But the bug is completely unrelated to Python 3. You may encounter the bug on Python 2 too. I've already made mysqlclient, the fork of MySQLdb supporting Python 3. On Sat, Mar 14, 2015 at 6:08 AM, John Nagle wrote: > I'm approaching the end of converting a large system from Python 2 to > Python 3. Here's why you don't want to do this. > > The language changes aren't that bad, and they're known and > documented. It's the package changes that are the problem. > Discovering and fixing all the new bugs takes a while. > > > BeautifulSoup: > > BeautifulSoup 3 has been phased out. I had my own version of > BeautifulSoup 3, modified for greater robustness. But that was > years ago. So I converted to BeautifulSoup 4, as the documentation > says to do. > > The HTML5parser module is claimed to parse as a browser does, with > all the error tolerance specified in the HTML5 spec. (The spec > actually specifies how to handle bad HTML consistently across > browsers in great detail, and HTML5parser has code in it for that.) > > It doesn't deliver on that promise, though. Some sites crash > BeautifulSoup 4/HTML5parser. Try "kroger.com", which has HTML with > . The parse tree constructed has a bad link, > and trying to use the parse tree results in exceptions. > Submitted bug report. Appears to be another case of > a known bug. No workaround at this time. > > https://bugs.launchpad.net/beautifulsoup/+bug/1270611 > https://bugs.launchpad.net/beautifulsoup/+bug/1430633 > > > PyMySQL: > > "Pymysql is a pure Python drop-in replacement for MySQLdb". > Sounds good. Then I discover that LOAD DATA LOCAL wasn't > implemented in the version on PyPi. It's on Github, though, > and I got the authors to push that out to PyPi. It > works on test cases. But it doesn't work on a big job, > because the default size of MySQL packets was set to 16MB. > This made the LOAD DATA LOCAL code try to send the entire > file being loaded as one giant MySQL packet. Unless you > configure the MySQL server with 16MB buffers, this fails, with > an obscure "server has gone away" message. Found the > problem, came up with a workaround, submitted a bug report, > and it's being fixed. > > https://github.com/PyMySQL/PyMySQL/issues/317 > > > SSL: > > All the new TLS/SSL support is in Python 3. That's good. > Unfortunately, using Firefox's set of SSL certs, some > important sites (such as "verisign.com") don't validate. > This turned out to be a complex problem involving Verisign > cross-signing a certificate, which created a certificate > hierarchy that some versions of OpenSSL can't handle. > There's now a version of OpenSSL that can handle it, but > the Python library has to make a call to use it, and > that's going in but isn't deployed yet. This bug > resulted in much finger-pointing between the Python > and OpenSSL developers, the Mozilla certificate store > maintainers, and Verisign. It's now been sorted out, > but not all the fixes are deployed. Because "ssl" is > a core Python module, this will remain broken until the > next Python release, on both the 2.7 and 3.4 lines. > > Also, for no particularly good reason, the exception > "SSL.CertificateError" is not a subclass of "SSL.Error", > resulting in a routine exception not being recognized. > > Bug reports submitted for both OpenSSL and Python SSL. > Much discussion. Problem fixed, but fix is in next > version of Python. No workaround at this time. > > http://bugs.python.org/issue23476 > > > Pickle: > > As I just posted recently, CPickle on Python 3.4 seems to > have a memory corruption bug. Pure-Python Pickle is fine. > So a workaround is possible. Bug report submitted. > > http://bugs.python.org/issue23655 > > > Converting a large application program to Python 3 > thus required diagnosing four library bugs and filing > bug reports on all of them. Workarounds are known > for two of the problems. I can't deploy the Python 3 > version on the servers yet. > > John Nagle > -- > https://mail.python.org/mailman/listinfo/python-list -- INADA Naoki From cs at zip.com.au Fri Mar 13 18:37:51 2015 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 14 Mar 2015 09:37:51 +1100 Subject: regex help In-Reply-To: References: Message-ID: <20150313223751.GA31995@cskk.homeip.net> On 13Mar2015 12:05, Larry Martell wrote: >I need to remove all trailing zeros to the right of the decimal point, >but leave one zero if it's whole number. For example, if I have this: > >14S,5.0000000000000000,4.56862745000000,3.7272727272727271,3.3947368421052630,5.7307692307692308,5.7547169811320753,4.9423076923076925,5.7884615384615383,5.137254901960000 > >I want to end up with: > >14S,5.0,4.56862745,3.7272727272727271,3.394736842105263,5.7307692307692308,5.7547169811320753,4.9423076923076925,5.7884615384615383,5.13725490196 > >I have a regex to remove the zeros: > >'0+[,$]', '' > >But I can't figure out how to get the 5.0000000000000000 to be 5.0. >I've been messing with the negative lookbehind, but I haven't found >one that works for this. Leaving aside the suggested non-greedy match, you can rephrase this: strip trailing zeroes _after_ the first decimal digit. Then you can consider a number to be: digits point any digit other digits to be right-zero stripped so: (\d+\.\d)(\d*[1-9])?0*\b and keep .group(1) and .group(2) from the match. Another way of considering the problem. Or you could two step it. Strip all trailing zeroes. If the result ends in a dot, add a single zero. Cheers, Cameron Simpson C'mon. Take the plunge. By the time you go through rehab the first time, you'll be surrounded by the most interesting people, and if it takes years off of your life, don't sweat it. They'll be the last ones anyway. - Vinnie Jordan, alt.peeves From emile at fenx.com Fri Mar 13 18:44:22 2015 From: emile at fenx.com (emile) Date: Fri, 13 Mar 2015 15:44:22 -0700 Subject: Odd ValueError using float In-Reply-To: References: Message-ID: On 03/13/2015 03:14 PM, Chris Angelico wrote: > On Sat, Mar 14, 2015 at 9:10 AM, emile wrote: >> (Pdb) decval >> '4' >> (Pdb) len(decval) >> 1 >> (Pdb) int(decval) >> *** ValueError: invalid literal for int() with base 10: '41.700000000000003' >> (Pdb) >> >> >> Any ideas? > > What's type(decval) tell you? I suspect you may have something other > than a string, even though it looks like a string in its repr. >sigh< Now it's running again. Up to 20 minutes ago when I posted it continually. Is-it-time-to-go-pick-grapes-yet?-ly y'rs, Emile From auriocus at gmx.de Fri Mar 13 18:47:04 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Fri, 13 Mar 2015 23:47:04 +0100 Subject: Pexpect idea - but can I handle curses? In-Reply-To: References: <1606564.hXcnK9StvT@PointedEars.de> <1597615.KAoEH8zO7A@PointedEars.de> Message-ID: Am 13.03.15 um 18:25 schrieb Skip Montanaro: > I understand that. Tell that to management though. They were working > on 13.1 for awhile, but seem to be focused on 13.2 now, though not all > our internal software works on that. > > I'll give up on hoping I get access to a more modern top anytime soon. Why? Do you not have a C compiler? Christian From nagle at animats.com Fri Mar 13 19:01:44 2015 From: nagle at animats.com (John Nagle) Date: Fri, 13 Mar 2015 16:01:44 -0700 Subject: Python 2 to 3 conversion - embrace the pain In-Reply-To: References: <550351BF.5020108@animats.com> Message-ID: On 3/13/2015 3:27 PM, INADA Naoki wrote: > Hi, John. I'm maintainer of PyMySQL. > > I'm sorry about bug of PyMySQL. But the bug is completely unrelated > to Python 3. > You may encounter the bug on Python 2 too. True. But much of the pain of converting to Python 3 comes from having to switch packages because the Python 2 package didn't make it to Python 3. All the bugs I'm discussing reflect forced package changes or upgrades. None were voluntary on my part. John Nagle From nad at acm.org Fri Mar 13 19:14:14 2015 From: nad at acm.org (Ned Deily) Date: Fri, 13 Mar 2015 16:14:14 -0700 Subject: Python 2 to 3 conversion - embrace the pain References: <550351BF.5020108@animats.com> Message-ID: In article , John Nagle wrote: > All the bugs I'm discussing reflect forced package > changes or upgrades. None were voluntary on my part. You would have run into the SSL certificate issue if you upgraded your Python 2 instance to the current Python 2.7.9. -- Ned Deily, nad at acm.org From gheskett at wdtv.com Fri Mar 13 19:38:09 2015 From: gheskett at wdtv.com (Gene Heskett) Date: Fri, 13 Mar 2015 19:38:09 -0400 Subject: Code hosting providers In-Reply-To: <87ioe4fvne.fsf@jester.gateway.sonic.net> References: <36a41718-3eb6-445b-ba5b-caf124122542@googlegroups.com> <87ioe4fvne.fsf@jester.gateway.sonic.net> Message-ID: <201503131938.09814.gheskett@wdtv.com> On Friday 13 March 2015 17:13:41 Paul Rubin wrote: > Chris Angelico writes: > > In the meantime, I get zero-dollar hosting of my repos, including > > zip download and such ... You're welcome to shun them. There is > > definitely benefit to encouraging a multiplicity of hosting > > services. But I'm not bothered by the GitHub non-free-ness, because > > I take a less philosophical and more pragmatic view of things. > > But you're making the problem worse for other people too. For > example, I can't file a bug against your code or send you a pull > request, without enrolling in Github myself. That alone is grounds enough to get the heck out of github. This is classic vendor lockin, or lockout if you don't want to play by githubs rules. A classic demonstration of TANSTAAFL if there ever was one. The above quoted problem YOU, Chris do not see, but that should be reason enough to bail out AND take your code with you before you find yourself locked out of your own code. Running your own server is a piece of cake, and if I, at 80 yo, can do it, I don't see a single reason you can't do likewise. The code I write, for what is called a legacy computer, is just one of the things I share at the link in my sig. That link is actually _this_ machine. Sure, I blow my own horn a bit, & you have to look at my ugly mug while it loads on the front page, but that is the only advertising you will ever see on that site. If I am still breathing regular when the 5 year namecheap registration expires, I'll renew it for another 5 years. I'll be approaching 84 yo then. That namecheap registration, and the electricity to run it are my only extra expenses over and above my use of the machine as a web tourer, and an email system. Or as a remote terminal into one of my milling machines so I can write gcode and test execute it here in a comfy office chair, which beats the hell out of extended periods standing in front of the machines own keyboard. An hour of that at my age is very painfull. But don't even think of using the std http port 80, thats blocked at your isp, precisely to force you to use, and pay for, space on their servers. Your /etc/services contains a list of ports, and what they are supposed to be used for. The 6309 that I use, is the simplified jedec number of a cpu chip that can be transplanted into a TRS-80 Color Computer to replace its normal 6809, is 10% faster at the same clock speed, and often 4x faster than a 6809 with some of its added instructions. It was not listed in /etc/services, so there was zero reason not to use it as I wasn't stepping on any toes to use it. Surely this group can look at the ascii code for the word python, and come up with a port number that is unique AND not in /etc/services. If you all do that, and agree on a common port number you will establish a common port number that can be used for python code interchange and even broadcasting among the group. Since thats a 4 byte wide hex number, and there's 65536 of them, it shouldn't be that hard to find one that will serve the purpose. But I do also, have a router running dd-wrt facing the net, my guard dog with the big teeth. It (that number) will in time, become that standard. > You can get a whole virtual server from Amazon for free that is > perfectly good for hosting git repos and lots of other things too, or > you can get them for a few dollars a year in other places if you don't > want to deal with Amazon. Github adds some conveniences but I've > never understood the attraction and mystique around it. Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From skip.montanaro at gmail.com Fri Mar 13 20:14:45 2015 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Fri, 13 Mar 2015 19:14:45 -0500 Subject: Pexpect idea - but can I handle curses? In-Reply-To: References: <1606564.hXcnK9StvT@PointedEars.de> <1597615.KAoEH8zO7A@PointedEars.de> Message-ID: On Fri, Mar 13, 2015 at 5:47 PM, Christian Gollwitzer wrote: > Why? Do you not have a C compiler? Sure I do, and I'm not afraid to use it. I realize top is just one not-terribly-critical tool, but every divergence between my machines and the "standard" install just makes it that much more difficult for me to track changes when our IT group *does* move us to a more up-to-date environment. I develop and build software which runs in a production environment. I can't afford to diverge more than absolutely necessary. Let's just let this thread die, shall we? So far, nobody seems interested in attempting to answer my original question. I thought it might be an interesting hack if I could make it work. If I plunge in and try it, I will report back with results. Skip -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Fri Mar 13 20:48:19 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 14 Mar 2015 11:48:19 +1100 Subject: regex help References: Message-ID: <55038554$0$12988$c3e8da3$5496439d@news.astraweb.com> Larry Martell wrote: > I need to remove all trailing zeros to the right of the decimal point, > but leave one zero if it's whole number. def strip_zero(s): if '.' not in s: return s s = s.rstrip('0') if s.endswith('.'): s += '0' return s And in use: py> strip_zero('-10.2500') '-10.25' py> strip_zero('123000') '123000' py> strip_zero('123000.0000') '123000.0' It doesn't support exponential format: py> strip_zero('1.2300000e3') '1.2300000e3' because it isn't clear what you intend to do under those circumstances. -- Steven From marfig at gmail.com Fri Mar 13 20:48:36 2015 From: marfig at gmail.com (Mario Figueiredo) Date: Sat, 14 Mar 2015 01:48:36 +0100 Subject: Code hosting providers References: <36a41718-3eb6-445b-ba5b-caf124122542@googlegroups.com> <87ioe4fvne.fsf@jester.gateway.sonic.net> Message-ID: <5707ga9lmg7noatcfkmf6tlotj8vnelva5@4ax.com> On Fri, 13 Mar 2015 19:38:09 -0400, Gene Heskett wrote: > >Running your own server is a piece of cake, and if I, at 80 yo, can do >it, I don't see a single reason you can't do likewise. The code I >write, for what is called a legacy computer, is just one of the things I >share at the link in my sig. That link is actually _this_ machine. That's taking things too far. And when people speak of hosting your own server, they don't necessarily mean hosting in your home computer. Speaking for myself, I refuse to collaborate on any project that is hosted on some dude's personal computer. The uptime can never match that of a data center and and if you decide to stream some movies while torrenting the latest linux distro, I'm basically screwed. If you are the sole developer of your project, why not. But if that is the case, I'd say most project managers are just overkill and the choice of what to choose shouldn't even be considered. Just grab your VCS of choice. Issue tracking can be safely managed in your code with TODO and FIXME. If by any chance you need to work on more than one computer, don't bloody open your ports at home. Just get an usb pen and make a bare repo in there from where you can push/pull. The ability to host your own server means: 1. Your code hosting provider doesn't lock you in. You can take your *full* repository history and host it yourself somewhere else outside their domain. 2. You will want to host this ASAP on some web hosting provider. From steve+comp.lang.python at pearwood.info Fri Mar 13 21:24:10 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 14 Mar 2015 12:24:10 +1100 Subject: The idle gui References: <0d3d1ec0-d112-42fc-aeed-fb6674d2ee1b@googlegroups.com> Message-ID: <55038dba$0$12990$c3e8da3$5496439d@news.astraweb.com> sohcahtoa82 at gmail.com wrote: > We need more information than just "It doesn't work". You wouldn't go to > a car mechanic and say "It makes a funny noise", would you? No. Actually, most likely yes.It's remarkably hard to describe noises, and often difficult to pin-point where they come from. My wife and I can sit in the same car, listening to the same noise, and she swears it is coming from the front left and I'm sure its coming from the rear right. (Invariably she's correct.) But at least the car mechanic can jump in the car and take it for a drive. -- Steven From davea at davea.name Fri Mar 13 21:35:38 2015 From: davea at davea.name (Dave Angel) Date: Fri, 13 Mar 2015 21:35:38 -0400 Subject: The idle gui In-Reply-To: <55038dba$0$12990$c3e8da3$5496439d@news.astraweb.com> References: <0d3d1ec0-d112-42fc-aeed-fb6674d2ee1b@googlegroups.com> <55038dba$0$12990$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5503906A.6040802@davea.name> On 03/13/2015 09:24 PM, Steven D'Aprano wrote: > sohcahtoa82 at gmail.com wrote: > > >> We need more information than just "It doesn't work". You wouldn't go to >> a car mechanic and say "It makes a funny noise", would you? No. > > Actually, most likely yes.It's remarkably hard to describe noises, and often > difficult to pin-point where they come from. My wife and I can sit in the > same car, listening to the same noise, and she swears it is coming from the > front left and I'm sure its coming from the rear right. (Invariably she's > correct.) > > But at least the car mechanic can jump in the car and take it for a drive. > Not if you don't take it to him. If you just call him on the phone, and say "Jimmy doesn't work" he doesn't even know what make and model the vehicle is. Or whether it's even a car. Maybe "it" is a son who refuses to get a job. -- DaveA From rosuav at gmail.com Fri Mar 13 21:40:13 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 14 Mar 2015 12:40:13 +1100 Subject: Python 2 to 3 conversion - embrace the pain In-Reply-To: References: <550351BF.5020108@animats.com> Message-ID: On Sat, Mar 14, 2015 at 10:14 AM, Ned Deily wrote: > In article , John Nagle > wrote: >> All the bugs I'm discussing reflect forced package >> changes or upgrades. None were voluntary on my part. > > You would have run into the SSL certificate issue if you upgraded your > Python 2 instance to the current Python 2.7.9. And the same applies to many MANY other upgrades. I was trying to delve into a VLC issue by compiling the latest version from source control, but it wouldn't build with the version of libsomething-or-other that shipped with Debian Wheezy, so I had to upgrade that... and then it needed a newer Linux kernel as well, I think, but at that point I accepted building from a couple dozen commits ago. If you upgrade your Python from 2.3 to 2.7, you'll find some breakage, too. Any upgrade can do that. That's why stable OS releases don't just randomly upgrade you... which is a bit of a pain for people who want to distribute Python code that will "just work", but it sure is better than something unexpectedly going belly-up on a live server! ChrisA From no.email at nospam.invalid Fri Mar 13 22:30:02 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 13 Mar 2015 19:30:02 -0700 Subject: Code hosting providers References: <36a41718-3eb6-445b-ba5b-caf124122542@googlegroups.com> <87ioe4fvne.fsf@jester.gateway.sonic.net> <5707ga9lmg7noatcfkmf6tlotj8vnelva5@4ax.com> Message-ID: <87bnjw71lh.fsf@nightsong.com> Mario Figueiredo writes: > That's taking things too far. And when people speak of hosting your > own server, they don't necessarily mean hosting in your home computer. > Speaking for myself, I refuse to collaborate on any project that is > hosted on some dude's personal computer. Meh, you don't necessarily know where it is, but you can get a year of EC2 VPS for free (https://aws.amazon.com/free/), or for ridiculously cheap at tons of smaller providers (http://list.lowendserv.net/). Even the smallest of such VPS is plenty for a moderate sized Git repo. From no.email at nospam.invalid Fri Mar 13 22:33:20 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 13 Mar 2015 19:33:20 -0700 Subject: Odd ValueError using float References: Message-ID: <877fuk71fz.fsf@nightsong.com> emile writes: > *** NameError: name 'val' is not defined > (Pdb) l > 139 try: > 140 val = round(float(decval),1) > 141 except: > 142 import pdb; pdb.set_trace() If 'float' or 'round' throw an exception, the assignment to 'val' never happens, so 'val' is undefined. Try examining the value of 'decval' in the debugger to see what is making the conversion fail. From rosuav at gmail.com Fri Mar 13 23:09:37 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 14 Mar 2015 14:09:37 +1100 Subject: Odd ValueError using float In-Reply-To: <877fuk71fz.fsf@nightsong.com> References: <877fuk71fz.fsf@nightsong.com> Message-ID: On Sat, Mar 14, 2015 at 1:33 PM, Paul Rubin wrote: > emile writes: >> *** NameError: name 'val' is not defined >> (Pdb) l >> 139 try: >> 140 val = round(float(decval),1) >> 141 except: >> 142 import pdb; pdb.set_trace() > > If 'float' or 'round' throw an exception, the assignment to 'val' never > happens, so 'val' is undefined. Try examining the value of 'decval' in > the debugger to see what is making the conversion fail. That's exactly what the OP did :) Trouble is, it didn't help, because it sure looked as if decval was the string '4'. My best guess was - and is - that it's not just a string. We're looking at an SQL interface routine here, so it may be that there's a string subclass that length-limits itself, on the assumption that it's going into a fixed-length database field. Let's see if I can recreate the OP's situation... >>> def Char(maxlen): class CharN(str): def __repr__(self): return repr(self[:maxlen]) CharN.__qualname__ = CharN.__name__ = "Char(%d)"%maxlen return CharN >>> four = Char(1)('41.700000000000003') >>> four '4' >>> int(four) Traceback (most recent call last): File "", line 1, in int(four) ValueError: invalid literal for int() with base 10: '4' ... well, close. Anyway, a string subclass could probably do this by accident somehow. ChrisA From gheskett at wdtv.com Fri Mar 13 23:13:17 2015 From: gheskett at wdtv.com (Gene Heskett) Date: Fri, 13 Mar 2015 23:13:17 -0400 Subject: Code hosting providers In-Reply-To: <5707ga9lmg7noatcfkmf6tlotj8vnelva5@4ax.com> References: <36a41718-3eb6-445b-ba5b-caf124122542@googlegroups.com> <5707ga9lmg7noatcfkmf6tlotj8vnelva5@4ax.com> Message-ID: <201503132313.17645.gheskett@wdtv.com> On Friday 13 March 2015 20:48:36 Mario Figueiredo wrote: > On Fri, 13 Mar 2015 19:38:09 -0400, Gene Heskett > > wrote: > >Running your own server is a piece of cake, and if I, at 80 yo, can > > do it, I don't see a single reason you can't do likewise. The code > > I write, for what is called a legacy computer, is just one of the > > things I share at the link in my sig. That link is actually _this_ > > machine. > > That's taking things too far. And when people speak of hosting your > own server, they don't necessarily mean hosting in your home computer. > Speaking for myself, I refuse to collaborate on any project that is > hosted on some dude's personal computer. Chuckle. 1. My finished, running code is copied to at least 200 other users machines because it is useful code. 2. If I fall over, there is close to that many copies extant that include the src code since that is virtually the only way I have released anything in the last 25 years. > The uptime can never match > that of a data center and and if you decide to stream some movies > while torrenting the latest linux distro, I'm basically screwed. That is much more of a function of the bandwidth available to me, 10 megbit dl, 2.5 megbit ul. I, on SS, do not have the budget for a gigabit pipe, and I have serious doubts that level of bandwidth is even available locally. > If you are the sole developer of your project, why not. Generally I am, unless a circuit board is under construction in our group, in which case I might offer to make a couple of non-plated thru copies if I get to keep one for my time. However, on my small machinery, mechanical etching, while great on the environment as there's no downright nasty chemistry to dispose of, is also very slow, limited by the 2500 rpms max speed of the spindle, so a busy double sided 4"x8" board is over 8 hours to machine. That big, I'd also have to make a vacuum pallet, which for a given sized board is about a day. > But if that is > the case, I'd say most project managers are just overkill and the > choice of what to choose shouldn't even be considered. Just grab your > VCS of choice. Issue tracking can be safely managed in your code with > TODO and FIXME. If by any chance you need to work on more than one > computer, don't bloody open your ports at home. Just get an usb pen > and make a bare repo in there from where you can push/pull. And if the next box you plug it into has a different first user number, and you don't have a root account handy, how do you access the data, written say on a fedora system, but you need to read it on a debian system. And you are not the first user, and you are not in /etc/sudoers. Go ahead, I'll wait for you to suss that out. :) Besides, thats way more trouble than NFS shares or ssh -Y sessions on my local network assuming I am the first user and therefore in the sudoers file.. And with dd-wrt playing guard dog for the whole system, I don't worry about somebody stomping in and doing an rm -Rf /. No one has in well over a decade. But, while I have done quite a few scripts on this machine, the one my legacy code runs on is not accessible from the outside world. The kernel modules to support that are not in any of the several choices of specialized bootfiles for it. > The ability to host your own server means: > > 1. Your code hosting provider doesn't lock you in. You can take > your *full* repository history and host it yourself somewhere > else outside their domain. > 2. You will want to host this ASAP on some web hosting provider. What for? I keep backups using amanda. Because of that, and despite several hard drive deaths, my email corpus for some mailing lists is now 13 yo, and several gigabytes. Question: How much money is this group, taken as the whole of the python world, spending on remote hosting per month? 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 marfig at gmail.com Fri Mar 13 23:41:16 2015 From: marfig at gmail.com (Mario Figueiredo) Date: Sat, 14 Mar 2015 04:41:16 +0100 Subject: Code hosting providers References: <36a41718-3eb6-445b-ba5b-caf124122542@googlegroups.com> <5707ga9lmg7noatcfkmf6tlotj8vnelva5@4ax.com> Message-ID: On Fri, 13 Mar 2015 23:13:17 -0400, Gene Heskett wrote: > >> >> That's taking things too far. And when people speak of hosting your >> own server, they don't necessarily mean hosting in your home computer. >> Speaking for myself, I refuse to collaborate on any project that is >> hosted on some dude's personal computer. > >Chuckle. 1. My finished, running code is copied to at least 200 other >users machines because it is useful code. I said collaborating, not just downloading your code. By collaborating I mean forking and branching your project, making pull requests, merging, opening and closing tickets, etc. > >> If you are the sole developer of your project, why not. > >Generally I am, unless a circuit board is under construction in our >group, in which case I might offer to make a couple of non-plated thru >copies if I get to keep one for my time. However, on my small machinery, >mechanical etching, while great on the environment as there's no >downright nasty chemistry to dispose of, is also very slow, limited by >the 2500 rpms max speed of the spindle, so a busy double sided 4"x8" >board is over 8 hours to machine. That big, I'd also have to make a >vacuum pallet, which for a given sized board is about a day. You aren't talking about software anymore... I don't know why you are telling me this. > >> But if that is >> the case, I'd say most project managers are just overkill and the >> choice of what to choose shouldn't even be considered. Just grab your >> VCS of choice. Issue tracking can be safely managed in your code with >> TODO and FIXME. If by any chance you need to work on more than one >> computer, don't bloody open your ports at home. Just get an usb pen >> and make a bare repo in there from where you can push/pull. > >And if the next box you plug it into has a different first user number, >and you don't have a root account handy, how do you access the data, >written say on a fedora system, but you need to read it on a debian >system. And you are not the first user, and you are not in /etc/sudoers. > >Go ahead, I'll wait for you to suss that out. :) What do you mean? If you have those problems with a bare repo in a usb pen, you will have those problems with a bare repo anywhere, including in your computer back at home. How do you propose to solve any local access previligies by having your project management system hosted at your home? I don't understand. ...I'm getting the feeling we are talking of different things. >What for? I keep backups using amanda. Because of that, and despite >several hard drive deaths, my email corpus for some mailing lists is now >13 yo, and several gigabytes. Right. You won't ever lose your data. Heard that before. I'm a bit old too, you know. And I learned the following, back in the late 80s when I was initiating my computer carreer doing nightly backups on a ES9000: "You will never lose your data until you lost it." > >Question: How much money is this group, taken as the whole of the python >world, spending on remote hosting per month? I'd wager very little, since most options are completely free. From no.email at nospam.invalid Fri Mar 13 23:45:29 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 13 Mar 2015 20:45:29 -0700 Subject: Code hosting providers References: <36a41718-3eb6-445b-ba5b-caf124122542@googlegroups.com> <5707ga9lmg7noatcfkmf6tlotj8vnelva5@4ax.com> Message-ID: <87r3ss5jja.fsf@nightsong.com> Mario Figueiredo writes: >>Question: How much money is this group, taken as the whole of the python >>world, spending on remote hosting per month? > I'd wager very little, since most options are completely free. Oh come on, if you count all forms of hosting, some of us are spending a lot (megabucks per month on AWS in some cases I'm sure). If you just mean VCS hosting, the free Github plans are only for FOSS projects. Prices of paid plans vary depending on project size etc. Lots of companies pay to use Github for closed source stuff. From rustompmody at gmail.com Sat Mar 14 01:03:48 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 13 Mar 2015 22:03:48 -0700 (PDT) Subject: Code hosting providers In-Reply-To: <87r3ss5jja.fsf@nightsong.com> References: <36a41718-3eb6-445b-ba5b-caf124122542@googlegroups.com> <5707ga9lmg7noatcfkmf6tlotj8vnelva5@4ax.com> <87r3ss5jja.fsf@nightsong.com> Message-ID: <09ee5b15-6648-49e0-a4e0-909692da6f06@googlegroups.com> On Saturday, March 14, 2015 at 9:15:39 AM UTC+5:30, Paul Rubin wrote: > Mario Figueiredo writes: > >>Question: How much money is this group, taken as the whole of the python > >>world, spending on remote hosting per month? > > I'd wager very little, since most options are completely free. > > Oh come on, if you count all forms of hosting, some of us are spending a > lot (megabucks per month on AWS in some cases I'm sure). If you just > mean VCS hosting, the free Github plans are only for FOSS projects. > Prices of paid plans vary depending on project size etc. Lots of > companies pay to use Github for closed source stuff. Bitbucket will give you closed source repos for upto 5 users collaborating for FREE. I use it the way others (I guess) you dropbox/googledrive etc From steve+comp.lang.python at pearwood.info Sat Mar 14 02:04:14 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 14 Mar 2015 17:04:14 +1100 Subject: generator/coroutine terminology References: <5501be8b$0$13006$c3e8da3$5496439d@news.astraweb.com> <87twxqqewm.fsf@elektro.pacujo.net> <4eec1709-dd11-4891-bfcc-60b27bb00ee3@googlegroups.com> <550259bf$0$12975$c3e8da3$5496439d@news.astraweb.com> <00d9152a-f391-4c64-b2bd-52bdec2a6b67@googlegroups.com> <8761a5s0he.fsf@elektro.pacujo.net> Message-ID: <5503cf5f$0$12985$c3e8da3$5496439d@news.astraweb.com> Marko Rauhamaa wrote: > Your 'factory' is a: > > generator > A function which returns an iterator. > That glossary entry is misleading, or at least incomplete, and it fails to match the way "generator" is used by actual Python programmers. Here is a function which returns an iterator. According to the docs, it's a generator, but that's simply wrong. In no way, shape or form should it be considered to be a generator: def not_a_generator(): return iter([1, 2, 3]) A generator (function) may be a function which returns an iterator, but not all functions that return iterators are generators, and in some ways returning an iterator is the *least* interesting part of what makes a generator a generator. What distinguishes a generator from a regular function is the use of `yield`. Any definition which fails to mention that fact is useless. "Generator" is used to describe both functions with the `yield` statement, and the return result of calling such functions. Where it is necessary to distinguish the two, we call the function-with-yield a "generator function". This terminology comes straight from the PEP introducing generators: https://www.python.org/dev/peps/pep-0255/ Such functions-with-yield *are* functions (or methods): py> def gen(): ... yield 1 ... py> type(gen) but they're a special kind of function, distinguished by a flag on the __code__ object (also known as func_code in Python 2). The inspect module has a function to check that flag, which looks like this: def isgeneratorfunction(object): return bool((isfunction(object) or ismethod(object)) and object.func_code.co_flags & CO_GENERATOR) The result of calling `gen` is an instance of the generator type, that is to say, an instance of a type which considers its own name to be "generator": py> x = gen() py> type(x) Although this type is built-in, it is not available in the builtins namespace, but it is bound to the name "GeneratorType" in the types module. The inspect module has a function for this too: def isgenerator(object): return isinstance(object, types.GeneratorType) For brevity, I've deleted the docstring, but it is very informative to read it. Run `import inspect; help(inspect.isgenerator)` for more details. Like many English words, we have two meanings for "generator": (1) A function containing the `yield` keyword, or "generator-function". (2) The result of calling such a function, an instance of types.GeneratorType. PEP 255 calls that a "generator-iterator", but that name doesn't appear to have caught on anywhere. If people can cope with the difference between a TV program and a computer program, they can cope with "generator" having two meanings, especially since we have ways to disambiguate between the two when needed. > Your 'generator-instance' is an: > > iterator > An object representing a stream of data. > Generator instances are iterators, but not all iterators are generator instances. Generator instances are special: they are subroutines which can be suspended and resumed, with multiple exit points (each yield is an exit point). Generators are a subset of coroutines, which are a generalization of generators. Coroutines have multiple entry points and exit points (each yield is both an entry point and exit point). CPython uses the same internal mechanism for both, and as far as I know, there is no programmatic way to distinguish a coroutine from a generator. Or at least no obvious way -- there's no `inspect.iscoroutine` function that I know of. > I don't think you should read much into what str(obj) returns. It's not > much more than a random printable some CPython coder has cooked up in > the heat of the moment. I think that is completely wrong. The repr() and str() of generator instances is hardly "random", it reflects the consensus of the PEP authors and the Python core developers, in particular the BDFL Guido who approved the PEP, that the type of object it is should be called "generator". -- Steven From no.email at nospam.invalid Sat Mar 14 02:43:08 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 13 Mar 2015 23:43:08 -0700 Subject: Micropython? Message-ID: <87egos5bb7.fsf@nightsong.com> http://www.micropython.org/ Has anyone used this? Know anything about it? I don't remember seeing any mention of it here. I remember there was a stripped down Python some years back that didn't work very well, but I think this is different. I just came across it by accident. Thanks. From marko at pacujo.net Sat Mar 14 03:54:37 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 14 Mar 2015 09:54:37 +0200 Subject: generator/coroutine terminology References: <5501be8b$0$13006$c3e8da3$5496439d@news.astraweb.com> <87twxqqewm.fsf@elektro.pacujo.net> <4eec1709-dd11-4891-bfcc-60b27bb00ee3@googlegroups.com> <550259bf$0$12975$c3e8da3$5496439d@news.astraweb.com> <00d9152a-f391-4c64-b2bd-52bdec2a6b67@googlegroups.com> <8761a5s0he.fsf@elektro.pacujo.net> <5503cf5f$0$12985$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87zj7govya.fsf@elektro.pacujo.net> Steven D'Aprano : > Marko Rauhamaa wrote: > >> Your 'factory' is a: >> >> generator >> A function which returns an iterator. >> > > That glossary entry is misleading, or at least incomplete, and it > fails to match the way "generator" is used by actual Python > programmers. I am an actual Python programmer (I develop Python programs) and my definitive source for Python is the documentation. If there is an error in the documentation, I would very much like it to be corrected. > A generator (function) may be a function which returns an iterator, > but not all functions that return iterators are generators, and in > some ways returning an iterator is the *least* interesting part of > what makes a generator a generator. > > What distinguishes a generator from a regular function is the use of > `yield`. Any definition which fails to mention that fact is useless. The language reference had better use more precise language. It *is* the definitive source, after all. > Like many English words, we have two meanings for "generator": > > (1) A function containing the `yield` keyword, or "generator-function". > > (2) The result of calling such a function, an instance of > types.GeneratorType. PEP 255 calls that a "generator-iterator", but > that name doesn't appear to have caught on anywhere. > > If people can cope with the difference between a TV program and a > computer program, they can cope with "generator" having two meanings, > especially since we have ways to disambiguate between the two when > needed. I think that is untenable when you talk about a programming language. >> I don't think you should read much into what str(obj) returns. It's >> not much more than a random printable some CPython coder has cooked >> up in the heat of the moment. > > I think that is completely wrong. The repr() and str() of generator > instances is hardly "random", it reflects the consensus of the PEP > authors and the Python core developers, in particular the BDFL Guido > who approved the PEP, that the type of object it is should be called > "generator". Be that as it may, and are the definitive sources for Python application programmers. Or is there a better reference you would recommend? Marko From marko at pacujo.net Sat Mar 14 04:00:10 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 14 Mar 2015 10:00:10 +0200 Subject: Python 2 to 3 conversion - embrace the pain References: <550351BF.5020108@animats.com> Message-ID: <87vbi4ovp1.fsf@elektro.pacujo.net> John Nagle : > I'm approaching the end of converting a large system from Python 2 > to Python 3. Here's why you don't want to do this. A nice report, thanks. Shows that the slowness of Python 3 adoption is not only social inertia. Marko From breamoreboy at yahoo.co.uk Sat Mar 14 04:04:04 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 14 Mar 2015 08:04:04 +0000 Subject: generator/coroutine terminology In-Reply-To: <87zj7govya.fsf@elektro.pacujo.net> References: <5501be8b$0$13006$c3e8da3$5496439d@news.astraweb.com> <87twxqqewm.fsf@elektro.pacujo.net> <4eec1709-dd11-4891-bfcc-60b27bb00ee3@googlegroups.com> <550259bf$0$12975$c3e8da3$5496439d@news.astraweb.com> <00d9152a-f391-4c64-b2bd-52bdec2a6b67@googlegroups.com> <8761a5s0he.fsf@elektro.pacujo.net> <5503cf5f$0$12985$c3e8da3$5496439d@news.astraweb.com> <87zj7govya.fsf@elektro.pacujo.net> Message-ID: On 14/03/2015 07:54, Marko Rauhamaa wrote: > Steven D'Aprano : > >> Marko Rauhamaa wrote: >> >>> Your 'factory' is a: >>> >>> generator >>> A function which returns an iterator. >>> >> >> That glossary entry is misleading, or at least incomplete, and it >> fails to match the way "generator" is used by actual Python >> programmers. > > I am an actual Python programmer (I develop Python programs) and my > definitive source for Python is the documentation. If there is an error > in the documentation, I would very much like it to be corrected. > Five minutes work for you (singular) on the bug tracker. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From marko at pacujo.net Sat Mar 14 04:30:30 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 14 Mar 2015 10:30:30 +0200 Subject: generator/coroutine terminology References: <5501be8b$0$13006$c3e8da3$5496439d@news.astraweb.com> <87twxqqewm.fsf@elektro.pacujo.net> <4eec1709-dd11-4891-bfcc-60b27bb00ee3@googlegroups.com> <550259bf$0$12975$c3e8da3$5496439d@news.astraweb.com> <00d9152a-f391-4c64-b2bd-52bdec2a6b67@googlegroups.com> <8761a5s0he.fsf@elektro.pacujo.net> <5503cf5f$0$12985$c3e8da3$5496439d@news.astraweb.com> <87zj7govya.fsf@elektro.pacujo.net> Message-ID: <87pp8couah.fsf@elektro.pacujo.net> Mark Lawrence : > On 14/03/2015 07:54, Marko Rauhamaa wrote: >> I am an actual Python programmer (I develop Python programs) and my >> definitive source for Python is the documentation. If there is an >> error in the documentation, I would very much like it to be >> corrected. > > Five minutes work for you (singular) on the bug tracker. I haven't determined that there is an error. I couldn't because to me, the documentation defines right and wrong. The only sign of discord so far has been between the return value of str() and the language of the documentation. The return values of str() and repr() are not defined very precisely: object.__repr__(self) Called by the repr() built-in function to compute the ?official? string representation of an object. If at all possible, this should look like a valid Python expression that could be used to recreate an object with the same value (given an appropriate environment). If this is not possible, a string of the form <...some useful description...> should be returned. The return value must be a string object. [...] object.__str__(self) Called by str(object) and the built-in functions format() and print() to compute the ?informal? or nicely printable string representation of an object. The return value must be a string object. Thus one shouldn't read too much into what str() and repr() return. In particular, there is no requirement that two valid Python implementations ought to return similar-looking strings. Marko From breamoreboy at yahoo.co.uk Sat Mar 14 05:05:25 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 14 Mar 2015 09:05:25 +0000 Subject: Python 2 to 3 conversion - embrace the pain In-Reply-To: <550351BF.5020108@animats.com> References: <550351BF.5020108@animats.com> Message-ID: On 13/03/2015 21:08, John Nagle wrote: > I'm approaching the end of converting a large system from Python 2 to > Python 3. Here's why you don't want to do this. > One reason why you should https://speakerdeck.com/pyconslides/python-3-dot-3-trust-me-its-better-than-python-2-dot-7-by-dr-brett-cannon Of course I understand the problems of time when it comes to porting code. Taking this Tue Mar 21 06:19:36 CET 2006, the time of the first email on the Python 3000 development mailing list, as the start date for Python 3, developers have only had nine years to port their libraries. Rome wasn't destroyed in a day? :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rosuav at gmail.com Sat Mar 14 05:57:45 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 14 Mar 2015 20:57:45 +1100 Subject: The idle gui In-Reply-To: <5503906A.6040802@davea.name> References: <0d3d1ec0-d112-42fc-aeed-fb6674d2ee1b@googlegroups.com> <55038dba$0$12990$c3e8da3$5496439d@news.astraweb.com> <5503906A.6040802@davea.name> Message-ID: On Sat, Mar 14, 2015 at 12:35 PM, Dave Angel wrote: > Not if you don't take it to him. If you just call him on the phone, and say > "Jimmy doesn't work" he doesn't even know what make and model the vehicle > is. Or whether it's even a car. Maybe "it" is a son who refuses to get a > job. In the OP's defense, we were at least told that the "idle gui" was the thing that didn't work. So unless you named your son "gui", we can safely assume that this isn't the case :) ChrisA From jason.heeris at gmail.com Sat Mar 14 06:50:35 2015 From: jason.heeris at gmail.com (Jason Heeris) Date: Sat, 14 Mar 2015 21:50:35 +1100 Subject: Module/lib for controlling a terminal program using redrawing? Message-ID: I am trying to automate the use of some old, in-house terminal-based programs that use screen redrawing for their interface. This includes single line redrawing (eg. using '\r' and overwriting), complete screen clearing, and fine-grained cursor movement and overwriting (probably not all in the same program at the same time though). Is there a module/library that can help me with this? I know of pexpect, but that seems more oriented towards line-by-line prompts that don't involve redraws (eg. login prompt, then password prompt on a new line). Think instead of trying to automate applications like emacs, aptitude or even nethack that redraw sections of the screen without making the terminal scroll. This automation requires more than just sending a set of keystrokes, but also reading what is displayed on screen and making decisions based up on that. Is there a library that can abstract the received redrawing activity so I don't have to even know if the application has, eg. used a carriage return or some other kind of cursor movement? Is there a way to just ask "if this were to be run in an ANSI terminal, what would be in each cell?" Python 2 or 3 are both fine, external packages are fine, but it has to work on Linux (eg. Ubuntu 14.04 or later, Debian Wheezy or later). Any pointers appreciated. Cheers, Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at davea.name Sat Mar 14 09:04:29 2015 From: davea at davea.name (Dave Angel) Date: Sat, 14 Mar 2015 09:04:29 -0400 Subject: The idle gui In-Reply-To: References: <0d3d1ec0-d112-42fc-aeed-fb6674d2ee1b@googlegroups.com> <55038dba$0$12990$c3e8da3$5496439d@news.astraweb.com> <5503906A.6040802@davea.name> Message-ID: <550431DD.90502@davea.name> On 03/14/2015 05:57 AM, Chris Angelico wrote: > On Sat, Mar 14, 2015 at 12:35 PM, Dave Angel wrote: >> Not if you don't take it to him. If you just call him on the phone, and say >> "Jimmy doesn't work" he doesn't even know what make and model the vehicle >> is. Or whether it's even a car. Maybe "it" is a son who refuses to get a >> job. > > In the OP's defense, we were at least told that the "idle gui" was the > thing that didn't work. So unless you named your son "gui", we can > safely assume that this isn't the case :) > I wasn't actually trying to pick on the OP this time, but to make a joke. Jimmy is the common nickname model of an SUV (truck/car), by General Motors. Idle could be taken two ways (if it weren't for the capitalization), or even three (My Chevy won't idle.). My father used to tell a triple pun involving the John Deere, and I can't recall it. It's been said that puns are the lowest form of humor, but I rather like them. -- DaveA From davea at davea.name Sat Mar 14 09:11:14 2015 From: davea at davea.name (Dave Angel) Date: Sat, 14 Mar 2015 09:11:14 -0400 Subject: Module/lib for controlling a terminal program using redrawing? In-Reply-To: References: Message-ID: <55043372.4040707@davea.name> On 03/14/2015 06:50 AM, Jason Heeris wrote: > I am trying to automate the use of some old, in-house terminal-based > programs that use screen redrawing for their interface. This includes > single line redrawing (eg. using '\r' and overwriting), complete screen > clearing, and fine-grained cursor movement and overwriting (probably not > all in the same program at the same time though). > > Is there a module/library that can help me with this? https://docs.python.org/3/howto/curses.html That's in the standard library for both Python2 and 3. I don't know if it'll do everything you need, but if not, there are also various wrappers for curses that can be found with a google search. -- DaveA From rustompmody at gmail.com Sat Mar 14 11:16:32 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 14 Mar 2015 08:16:32 -0700 (PDT) Subject: The idle gui In-Reply-To: References: <0d3d1ec0-d112-42fc-aeed-fb6674d2ee1b@googlegroups.com> <55038dba$0$12990$c3e8da3$5496439d@news.astraweb.com> <5503906A.6040802@davea.name> Message-ID: <3d1ea8c9-3bf2-4f14-99a1-c55b5b684688@googlegroups.com> On Saturday, March 14, 2015 at 3:28:11 PM UTC+5:30, Chris Angelico wrote: > On Sat, Mar 14, 2015 at 12:35 PM, Dave Angel wrote: > > Not if you don't take it to him. If you just call him on the phone, and say > > "Jimmy doesn't work" he doesn't even know what make and model the vehicle > > is. Or whether it's even a car. Maybe "it" is a son who refuses to get a > > job. > > In the OP's defense, we were at least told that the "idle gui" was the > thing that didn't work. So unless you named your son "gui", we can > safely assume that this isn't the case :) > > ChrisA Saw this yesterday on the Haskell list: "How do I use lens confusing?" "You mean 'it's confusing'?" "No, I mean Control.Lens.Traversal.confusing" From emile at fenx.com Sat Mar 14 11:28:23 2015 From: emile at fenx.com (emile) Date: Sat, 14 Mar 2015 08:28:23 -0700 Subject: Odd ValueError using float In-Reply-To: References: <877fuk71fz.fsf@nightsong.com> Message-ID: On 03/13/2015 08:09 PM, Chris Angelico wrote: > On Sat, Mar 14, 2015 at 1:33 PM, Paul Rubin wrote: >> emile writes: >>> *** NameError: name 'val' is not defined >>> (Pdb) l >>> 139 try: >>> 140 val = round(float(decval),1) >>> 141 except: >>> 142 import pdb; pdb.set_trace() >> >> If 'float' or 'round' throw an exception, the assignment to 'val' never >> happens, so 'val' is undefined. Try examining the value of 'decval' in >> the debugger to see what is making the conversion fail. > > That's exactly what the OP did :) Trouble is, it didn't help, because > it sure looked as if decval was the string '4'. My best guess was - > and is - that it's not just a string. We're looking at an SQL > interface routine here, so it may be that there's a string subclass > that length-limits itself, on the assumption that it's going into a > fixed-length database field. It ran almost to completion before generating the error again -- (Pdb) decval '4' (Pdb) type(decval) (Pdb) len(decval) 1 (Pdb) int(decval) *** ValueError: invalid literal for int() with base 10: '41.700000000000003' So there's still something amiss. Emile From rustompmody at gmail.com Sat Mar 14 11:29:09 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 14 Mar 2015 08:29:09 -0700 (PDT) Subject: generator/coroutine terminology In-Reply-To: <5503cf5f$0$12985$c3e8da3$5496439d@news.astraweb.com> References: <5501be8b$0$13006$c3e8da3$5496439d@news.astraweb.com> <87twxqqewm.fsf@elektro.pacujo.net> <4eec1709-dd11-4891-bfcc-60b27bb00ee3@googlegroups.com> <550259bf$0$12975$c3e8da3$5496439d@news.astraweb.com> <00d9152a-f391-4c64-b2bd-52bdec2a6b67@googlegroups.com> <8761a5s0he.fsf@elektro.pacujo.net> <5503cf5f$0$12985$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Saturday, March 14, 2015 at 11:34:27 AM UTC+5:30, Steven D'Aprano wrote: > > A generator (function) may be a function which returns an iterator,... I find "generator-function" misleading in the same way that "pineapple" misleadingly suggests "apple that grows on pines" A builtin function is a function in the builtin (or builtins -- can never remember) module A pure function is function that does not assign or mutate non-locals A Steven-function is a function that presumably Steven wrote However a "generator function" is a weird sort of function (at best). Not regarding it as a function is IMO more reasonable. From rosuav at gmail.com Sat Mar 14 11:52:07 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 15 Mar 2015 02:52:07 +1100 Subject: Odd ValueError using float In-Reply-To: References: <877fuk71fz.fsf@nightsong.com> Message-ID: On Sun, Mar 15, 2015 at 2:28 AM, emile wrote: > It ran almost to completion before generating the error again -- > > (Pdb) decval > '4' > (Pdb) type(decval) > > (Pdb) len(decval) > 1 > (Pdb) int(decval) > *** ValueError: invalid literal for int() with base 10: '41.700000000000003' > > So there's still something amiss. Compare these two lines' outputs: print("str %d, int %d" % (id(str), id(int))) print("str %d, int %d" % (id(type("")), id(type(0))) Any difference in id would indicate that the names have been shadowed - seems unlikely, but worth checking. And then, just to be absolutely sure: type(decval) is type("") There is another, and very nasty, possibility. If you're working with a C extension that has a refcount bug in it, all sorts of bizarre things can happen - crucial type objects getting garbage collected, objects getting disposed of and others taking their places, all kinds of weird and wonderful things. Normally that'll eventually cause a crash, but who knows... ChrisA From rosuav at gmail.com Sat Mar 14 11:56:54 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 15 Mar 2015 02:56:54 +1100 Subject: generator/coroutine terminology In-Reply-To: References: <5501be8b$0$13006$c3e8da3$5496439d@news.astraweb.com> <87twxqqewm.fsf@elektro.pacujo.net> <4eec1709-dd11-4891-bfcc-60b27bb00ee3@googlegroups.com> <550259bf$0$12975$c3e8da3$5496439d@news.astraweb.com> <00d9152a-f391-4c64-b2bd-52bdec2a6b67@googlegroups.com> <8761a5s0he.fsf@elektro.pacujo.net> <5503cf5f$0$12985$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Mar 15, 2015 at 2:29 AM, Rustom Mody wrote: > However a "generator function" is a weird sort of function (at best). > Not regarding it as a function is IMO more reasonable. But it *is* a function. You call it, possibly with positional and/or keyword arguments, and you get back a returned object. How is this different from any other function? (Yes, by this definition a class could be called an "object function". But the line is already somewhat blurry; if I've read my history correctly, "int" used to be a function, but now it's a type. A class is really just a special type of factory function, just as a generator function is.) ChrisA From rustompmody at gmail.com Sat Mar 14 11:59:36 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 14 Mar 2015 08:59:36 -0700 (PDT) Subject: generator/coroutine terminology In-Reply-To: References: <5501be8b$0$13006$c3e8da3$5496439d@news.astraweb.com> <87twxqqewm.fsf@elektro.pacujo.net> <4eec1709-dd11-4891-bfcc-60b27bb00ee3@googlegroups.com> <550259bf$0$12975$c3e8da3$5496439d@news.astraweb.com> <00d9152a-f391-4c64-b2bd-52bdec2a6b67@googlegroups.com> <8761a5s0he.fsf@elektro.pacujo.net> <5503cf5f$0$12985$c3e8da3$5496439d@news.astraweb.com> Message-ID: <83d579c1-ab61-4a3d-a834-e65d28eace8a@googlegroups.com> On Saturday, March 14, 2015 at 8:59:22 PM UTC+5:30, Rustom Mody wrote: > On Saturday, March 14, 2015 at 11:34:27 AM UTC+5:30, Steven D'Aprano wrote: > > > > A generator (function) may be a function which returns an iterator,... > > I find "generator-function" misleading in the same way that "pineapple" > misleadingly suggests "apple that grows on pines" > > A builtin function is a function in the builtin (or builtins -- can never remember) module > A pure function is function that does not assign or mutate non-locals > A Steven-function is a function that presumably Steven wrote > > However a "generator function" is a weird sort of function (at best). > Not regarding it as a function is IMO more reasonable. Another analogy somewhat closer home than pineapples. In Pascal there are procedures and functions. Even in the venerable Fortran there are subroutine-subprogram and (sub)function-subprogram. C took the stupid approach of just throwing out one of these. A decade of troubles was enough to convince people that it was needed and the mysterious 'void-returning' function was introduced to simulate procedures Causing all sorts of unnecessary confusions: An int-function returns int and a char*-functions returns char*. Does a void-function return void?? No a void function doesn't return anything! Ah So a void function does a longjmp? All of which is to say that in retrospect we need (at least in imperative programming) procedures and functions. Best if the language supports them If not, then we need them all the more in the conceptual ontology we use to build programs. Analogously we need the generator 'design-pattern' as well as the function design-pattern. Conflating one as a special case of the other is a recipe for confusion From __peter__ at web.de Sat Mar 14 12:08:11 2015 From: __peter__ at web.de (Peter Otten) Date: Sat, 14 Mar 2015 17:08:11 +0100 Subject: Odd ValueError using float References: <877fuk71fz.fsf@nightsong.com> Message-ID: emile wrote: > On 03/13/2015 08:09 PM, Chris Angelico wrote: >> On Sat, Mar 14, 2015 at 1:33 PM, Paul Rubin >> wrote: >>> emile writes: >>>> *** NameError: name 'val' is not defined >>>> (Pdb) l >>>> 139 try: >>>> 140 val = round(float(decval),1) >>>> 141 except: >>>> 142 import pdb; pdb.set_trace() >>> >>> If 'float' or 'round' throw an exception, the assignment to 'val' never >>> happens, so 'val' is undefined. Try examining the value of 'decval' in >>> the debugger to see what is making the conversion fail. >> >> That's exactly what the OP did :) Trouble is, it didn't help, because >> it sure looked as if decval was the string '4'. My best guess was - >> and is - that it's not just a string. We're looking at an SQL >> interface routine here, so it may be that there's a string subclass >> that length-limits itself, on the assumption that it's going into a >> fixed-length database field. > > It ran almost to completion before generating the error again -- > > (Pdb) decval > '4' > (Pdb) type(decval) > > (Pdb) len(decval) > 1 > (Pdb) int(decval) > *** ValueError: invalid literal for int() with base 10: > '41.700000000000003' > > So there's still something amiss. Why are you checking int(decval) when the actual failing expression is round(float(decval),1) ? Try to evaluate the latter in the debugger, and if that gives no clue change >>>> 139 try: >>>> 140 val = round(float(decval),1) >>>> 141 except: >>>> 142 import pdb; pdb.set_trace() to just val = round(float(decval), 1) to get a meaningful traceback and post that. From rosuav at gmail.com Sat Mar 14 12:14:35 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 15 Mar 2015 03:14:35 +1100 Subject: generator/coroutine terminology In-Reply-To: <83d579c1-ab61-4a3d-a834-e65d28eace8a@googlegroups.com> References: <5501be8b$0$13006$c3e8da3$5496439d@news.astraweb.com> <87twxqqewm.fsf@elektro.pacujo.net> <4eec1709-dd11-4891-bfcc-60b27bb00ee3@googlegroups.com> <550259bf$0$12975$c3e8da3$5496439d@news.astraweb.com> <00d9152a-f391-4c64-b2bd-52bdec2a6b67@googlegroups.com> <8761a5s0he.fsf@elektro.pacujo.net> <5503cf5f$0$12985$c3e8da3$5496439d@news.astraweb.com> <83d579c1-ab61-4a3d-a834-e65d28eace8a@googlegroups.com> Message-ID: On Sun, Mar 15, 2015 at 2:59 AM, Rustom Mody wrote: > Causing all sorts of unnecessary confusions: > An int-function returns int and a char*-functions returns char*. > Does a void-function return void?? > No a void function doesn't return anything! > Ah So a void function does a longjmp? > > All of which is to say that in retrospect we need (at least in imperative programming) procedures and functions. > > Best if the language supports them Python has a broad concept of "functions/methods that return something interesting" and "functions/methods that always return None". (The distinction often corresponds to non-mutator and mutator methods, but that's just convention.) Pike has void and non-void functions, but you can sometimes trick the system into giving you the return value of a void function. (Spoiler: It'll be the integer 0.) HTTP has some responses which contain no body (eg 304 NOT MODIFIED) as well as many which do. Ditto many other languages and protocols. In each case, there's no _real_ distinction between functions and procedures (Pike follows C in having "void functions", but they're still functions), and I don't see any evidence indicating that this has damaged the languages or protocols concerned - can you show otherwise? ChrisA From rustompmody at gmail.com Sat Mar 14 12:33:59 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 14 Mar 2015 09:33:59 -0700 (PDT) Subject: generator/coroutine terminology In-Reply-To: References: <5501be8b$0$13006$c3e8da3$5496439d@news.astraweb.com> <87twxqqewm.fsf@elektro.pacujo.net> <4eec1709-dd11-4891-bfcc-60b27bb00ee3@googlegroups.com> <550259bf$0$12975$c3e8da3$5496439d@news.astraweb.com> <00d9152a-f391-4c64-b2bd-52bdec2a6b67@googlegroups.com> <8761a5s0he.fsf@elektro.pacujo.net> <5503cf5f$0$12985$c3e8da3$5496439d@news.astraweb.com> <83d579c1-ab61-4a3d-a834-e65d28eace8a@googlegroups.com> Message-ID: <976313df-00f6-4845-a774-e5902b0fb2ce@googlegroups.com> On Saturday, March 14, 2015 at 9:45:10 PM UTC+5:30, Chris Angelico wrote: > On Sun, Mar 15, 2015 at 2:59 AM, Rustom Mody wrote: > > Causing all sorts of unnecessary confusions: > > An int-function returns int and a char*-functions returns char*. > > Does a void-function return void?? > > No a void function doesn't return anything! > > Ah So a void function does a longjmp? > > > > All of which is to say that in retrospect we need (at least in imperative programming) procedures and functions. > > > > Best if the language supports them > > Python has a broad concept of "functions/methods that return something > interesting" and "functions/methods that always return None". (The > distinction often corresponds to non-mutator and mutator methods, but > that's just convention.) With due respect Chris, you are confused: Sure any effective *pythonista* (who writes useful python) will have this concept. Python (as against pythonistas) has no such concept? as "function that ALWAYS returns None" Consider this foo >>> def foo(x): ... if x>0: return x-1 ... >>> foo(3) 2 >>> foo(-1) >>> As best as I can see python makes no distinction between such a foo and the more usual function/methods that have no returns. You can I can talk about these and distinguish them Python has no clue about it. ---------------- Leaving aside latest type-annotation proposal. From rosuav at gmail.com Sat Mar 14 12:51:48 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 15 Mar 2015 03:51:48 +1100 Subject: generator/coroutine terminology In-Reply-To: <976313df-00f6-4845-a774-e5902b0fb2ce@googlegroups.com> References: <5501be8b$0$13006$c3e8da3$5496439d@news.astraweb.com> <87twxqqewm.fsf@elektro.pacujo.net> <4eec1709-dd11-4891-bfcc-60b27bb00ee3@googlegroups.com> <550259bf$0$12975$c3e8da3$5496439d@news.astraweb.com> <00d9152a-f391-4c64-b2bd-52bdec2a6b67@googlegroups.com> <8761a5s0he.fsf@elektro.pacujo.net> <5503cf5f$0$12985$c3e8da3$5496439d@news.astraweb.com> <83d579c1-ab61-4a3d-a834-e65d28eace8a@googlegroups.com> <976313df-00f6-4845-a774-e5902b0fb2ce@googlegroups.com> Message-ID: On Sun, Mar 15, 2015 at 3:33 AM, Rustom Mody wrote: > As best as I can see python makes no distinction between such a foo and > the more usual function/methods that have no returns. > You can I can talk about these and distinguish them > Python has no clue about it. But what support is actually needed? Look, I can write functions that return values: def square(x): return x*x four = square(2) and functions that don't: def save_to_file(fn): with open(fn, "w") as f: f.write(stuff) f.write(more_stuff) save_to_file("/tmp/asdf") Who cares that the second one actually returns None and then ignores that? It's not returning anything, it's not using the function return value. This is, in effect, a procedure. How is Python worse off for doing things this way rather than having a true "function with no return value" or "procedure" concept? ChrisA From breamoreboy at yahoo.co.uk Sat Mar 14 12:56:53 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 14 Mar 2015 16:56:53 +0000 Subject: generator/coroutine terminology In-Reply-To: <976313df-00f6-4845-a774-e5902b0fb2ce@googlegroups.com> References: <5501be8b$0$13006$c3e8da3$5496439d@news.astraweb.com> <87twxqqewm.fsf@elektro.pacujo.net> <4eec1709-dd11-4891-bfcc-60b27bb00ee3@googlegroups.com> <550259bf$0$12975$c3e8da3$5496439d@news.astraweb.com> <00d9152a-f391-4c64-b2bd-52bdec2a6b67@googlegroups.com> <8761a5s0he.fsf@elektro.pacujo.net> <5503cf5f$0$12985$c3e8da3$5496439d@news.astraweb.com> <83d579c1-ab61-4a3d-a834-e65d28eace8a@googlegroups.com> <976313df-00f6-4845-a774-e5902b0fb2ce@googlegroups.com> Message-ID: On 14/03/2015 16:33, Rustom Mody wrote: > On Saturday, March 14, 2015 at 9:45:10 PM UTC+5:30, Chris Angelico wrote: >> On Sun, Mar 15, 2015 at 2:59 AM, Rustom Mody wrote: >>> Causing all sorts of unnecessary confusions: >>> An int-function returns int and a char*-functions returns char*. >>> Does a void-function return void?? >>> No a void function doesn't return anything! >>> Ah So a void function does a longjmp? >>> >>> All of which is to say that in retrospect we need (at least in imperative programming) procedures and functions. >>> >>> Best if the language supports them >> >> Python has a broad concept of "functions/methods that return something >> interesting" and "functions/methods that always return None". (The >> distinction often corresponds to non-mutator and mutator methods, but >> that's just convention.) > > With due respect Chris, you are confused: > > Sure any effective *pythonista* (who writes useful python) will have this concept. > > Python (as against pythonistas) has no such concept? as "function that ALWAYS > returns None" > > Consider this foo > >>>> def foo(x): > ... if x>0: return x-1 > ... >>>> foo(3) > 2 >>>> foo(-1) >>>> > > As best as I can see python makes no distinction between such a foo and > the more usual function/methods that have no returns. > You can I can talk about these and distinguish them > Python has no clue about it. > Python *ALWAYS* returns None for any path through a function that doesn't specify a return value. Taking your example. >>> def foo(x): ... if x>0: return x-1 ... >>> import dis >>> dis.dis(foo) 2 0 LOAD_FAST 0 (x) 3 LOAD_CONST 1 (0) 6 COMPARE_OP 4 (>) 9 POP_JUMP_IF_FALSE 20 12 LOAD_FAST 0 (x) 15 LOAD_CONST 2 (1) 18 BINARY_SUBTRACT 19 RETURN_VALUE >> 20 LOAD_CONST 0 (None) 23 RETURN_VALUE -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From joepureddu at yahoo.com Sat Mar 14 12:59:08 2015 From: joepureddu at yahoo.com (Dieffe Diciotto) Date: Sat, 14 Mar 2015 09:59:08 -0700 (PDT) Subject: -- redacted -- In-Reply-To: References: Message-ID: -- redacted -- From joepureddu at yahoo.com Sat Mar 14 13:00:19 2015 From: joepureddu at yahoo.com (Dieffe Diciotto) Date: Sat, 14 Mar 2015 10:00:19 -0700 (PDT) Subject: -- redacted -- In-Reply-To: <4f5ceab4-d175-4b96-829b-8c8fab7f77f0@googlegroups.com> References: <4f5ceab4-d175-4b96-829b-8c8fab7f77f0@googlegroups.com> Message-ID: -- redacted -- From davea at davea.name Sat Mar 14 13:07:45 2015 From: davea at davea.name (Dave Angel) Date: Sat, 14 Mar 2015 13:07:45 -0400 Subject: generator/coroutine terminology In-Reply-To: References: <5501be8b$0$13006$c3e8da3$5496439d@news.astraweb.com> <87twxqqewm.fsf@elektro.pacujo.net> <4eec1709-dd11-4891-bfcc-60b27bb00ee3@googlegroups.com> <550259bf$0$12975$c3e8da3$5496439d@news.astraweb.com> <00d9152a-f391-4c64-b2bd-52bdec2a6b67@googlegroups.com> <8761a5s0he.fsf@elektro.pacujo.net> <5503cf5f$0$12985$c3e8da3$5496439d@news.astraweb.com> <83d579c1-ab61-4a3d-a834-e65d28eace8a@googlegroups.com> <976313df-00f6-4845-a774-e5902b0fb2ce@googlegroups.com> Message-ID: <55046AE1.6000704@davea.name> On 03/14/2015 12:51 PM, Chris Angelico wrote: > On Sun, Mar 15, 2015 at 3:33 AM, Rustom Mody wrote: >> As best as I can see python makes no distinction between such a foo and >> the more usual function/methods that have no returns. >> You can I can talk about these and distinguish them >> Python has no clue about it. > > But what support is actually needed? Look, I can write functions that > return values: > > def square(x): > return x*x > > four = square(2) > > and functions that don't: > > def save_to_file(fn): > with open(fn, "w") as f: > f.write(stuff) > f.write(more_stuff) > > save_to_file("/tmp/asdf") > > Who cares that the second one actually returns None and then ignores > that? It's not returning anything, it's not using the function return > value. This is, in effect, a procedure. > > How is Python worse off for doing things this way rather than having a > true "function with no return value" or "procedure" concept? > And in C (at least the 80x86 implementations that I used) returns a value from a void function as well. The value is an undefined int value, whatever the AX (EAX) register happened to contain. The check that you didn't use such a value is made at compile time. Further, in the original C definition, if you didn't define a return value, it was assumed to be int. And if you didn't define the arguments, they were assumed to be right. In the "C calling convention," the caller was responsible for popping off the arguments, since the called function didn't necessarily have a clue how many there were. Then later, for "efficiency reasons," they came up with the "Pascal calling convention," where the callee popped the arguments. It perhaps was related to the fact that the 80x86 instruction set had the "return N" instruction which decremented the call stack pointer an additional amount, at the same time as doing the return. I think the Python convention is exactly right for its other characteristics. No declarations, no distinction. -- DaveA From emile at fenx.com Sat Mar 14 13:08:01 2015 From: emile at fenx.com (emile) Date: Sat, 14 Mar 2015 10:08:01 -0700 Subject: Odd ValueError using float In-Reply-To: References: <877fuk71fz.fsf@nightsong.com> Message-ID: On 03/14/2015 09:08 AM, Peter Otten wrote: > emile wrote: > >> On 03/13/2015 08:09 PM, Chris Angelico wrote: >>> On Sat, Mar 14, 2015 at 1:33 PM, Paul Rubin >>> wrote: >>>> emile writes: >>>>> *** NameError: name 'val' is not defined >>>>> (Pdb) l >>>>> 139 try: >>>>> 140 val = round(float(decval),1) >>>>> 141 except: >>>>> 142 import pdb; pdb.set_trace() >>>> >>>> If 'float' or 'round' throw an exception, the assignment to 'val' never >>>> happens, so 'val' is undefined. Try examining the value of 'decval' in >>>> the debugger to see what is making the conversion fail. >>> >>> That's exactly what the OP did :) Trouble is, it didn't help, because >>> it sure looked as if decval was the string '4'. My best guess was - >>> and is - that it's not just a string. We're looking at an SQL >>> interface routine here, so it may be that there's a string subclass >>> that length-limits itself, on the assumption that it's going into a >>> fixed-length database field. >> >> It ran almost to completion before generating the error again -- >> >> (Pdb) decval >> '4' >> (Pdb) type(decval) >> >> (Pdb) len(decval) >> 1 >> (Pdb) int(decval) >> *** ValueError: invalid literal for int() with base 10: >> '41.700000000000003' >> >> So there's still something amiss. > > Why are you checking > > int(decval) because it sure smells like int should work: (Pdb) "3" > when the actual failing expression is > > round(float(decval),1) > > ? Try to evaluate the latter in the debugger, and if that gives no clue > change > >>>>> 139 try: >>>>> 140 val = round(float(decval),1) >>>>> 141 except: >>>>> 142 import pdb; pdb.set_trace() > > to just > > val = round(float(decval), 1) > > to get a meaningful traceback and post that. I don't get a traceback -- it spews: Fatal Python error: deletion of interned string failed This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. then crashes and I get a Microsoft pop-up that says python.exe has encountered a problem and needs to close. Emile From rustompmody at gmail.com Sat Mar 14 13:17:40 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 14 Mar 2015 10:17:40 -0700 (PDT) Subject: generator/coroutine terminology In-Reply-To: References: <5501be8b$0$13006$c3e8da3$5496439d@news.astraweb.com> <87twxqqewm.fsf@elektro.pacujo.net> <4eec1709-dd11-4891-bfcc-60b27bb00ee3@googlegroups.com> <550259bf$0$12975$c3e8da3$5496439d@news.astraweb.com> <00d9152a-f391-4c64-b2bd-52bdec2a6b67@googlegroups.com> <8761a5s0he.fsf@elektro.pacujo.net> <5503cf5f$0$12985$c3e8da3$5496439d@news.astraweb.com> <83d579c1-ab61-4a3d-a834-e65d28eace8a@googlegroups.com> <976313df-00f6-4845-a774-e5902b0fb2ce@googlegroups.com> Message-ID: <7eb603f1-f949-4e30-bcbf-d63226a717ba@googlegroups.com> On Saturday, March 14, 2015 at 10:22:51 PM UTC+5:30, Chris Angelico wrote: > On Sun, Mar 15, 2015 at 3:33 AM, Rustom Mody wrote: > > As best as I can see python makes no distinction between such a foo and > > the more usual function/methods that have no returns. > > You can I can talk about these and distinguish them > > Python has no clue about it. > > But what support is actually needed? Look, I can write functions that > return values: > > def square(x): > return x*x > > four = square(2) > > and functions that don't: > > def save_to_file(fn): > with open(fn, "w") as f: > f.write(stuff) > f.write(more_stuff) > > save_to_file("/tmp/asdf") > > Who cares that the second one actually returns None and then ignores > that? It's not returning anything, it's not using the function return > value. This is, in effect, a procedure. > > How is Python worse off for doing things this way rather than having a > true "function with no return value" or "procedure" concept? Well... We can talk about that... maybe in another thread... My more pressing question is that when I try to read the explanations of generators, my tongue gets stuck behind my ears. And I suspect the problem is with the terminology My original question was quite genuine: Thanks to Marko's collections from the docs and also Steven's > That glossary entry is misleading, or at least incomplete, and it fails to > match the way "generator" is used by actual Python programmers. I guess I can confirm that the docs are messy the concepts are confused and we (teachers) have to do whatever we will with that state of affairs. [I admit to even having (tried to) teach C++. But I would not try to repeat that feat if I had a choice] From emile at fenx.com Sat Mar 14 13:17:57 2015 From: emile at fenx.com (emile) Date: Sat, 14 Mar 2015 10:17:57 -0700 Subject: Odd ValueError using float In-Reply-To: References: <877fuk71fz.fsf@nightsong.com> Message-ID: On 03/14/2015 08:52 AM, Chris Angelico wrote: > On Sun, Mar 15, 2015 at 2:28 AM, emile wrote: >> It ran almost to completion before generating the error again -- >> >> (Pdb) decval >> '4' >> (Pdb) type(decval) >> >> (Pdb) len(decval) >> 1 >> (Pdb) int(decval) >> *** ValueError: invalid literal for int() with base 10: '41.700000000000003' >> >> So there's still something amiss. > > Compare these two lines' outputs: > > print("str %d, int %d" % (id(str), id(int))) > print("str %d, int %d" % (id(type("")), id(type(0))) > (Pdb) print("str %d, int %d" % (id(str), id(int))) str 505366496, int 505399904 (Pdb) print("str %d, int %d" % (id(type("")), id(type(0)))) str 505366496, int 505399904 > Any difference in id would indicate that the names have been shadowed > - seems unlikely, but worth checking. And then, just to be absolutely > sure: > > type(decval) is type("") (Pdb) type(decval) is type("") True > There is another, and very nasty, possibility. If you're working with > a C extension that has a refcount bug in it, all sorts of bizarre > things can happen - crucial type objects getting garbage collected, > objects getting disposed of and others taking their places, all kinds > of weird and wonderful things. Normally that'll eventually cause a > crash, but who knows... Here're the imports: import os, time, re, shutil, subprocess from fenx.BBxXlate.bbxfile import BBxFile # a pure python module from fenx import RealPyOdbc2 and of course, pdb when I break for the error condition. Emile From no.email at nospam.invalid Sat Mar 14 14:00:37 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 14 Mar 2015 11:00:37 -0700 Subject: Module/lib for controlling a terminal program using redrawing? References: Message-ID: <87h9tncvcq.fsf@jester.gateway.sonic.net> Dave Angel writes: >> Is there a module/library that can help me with this? > https://docs.python.org/3/howto/curses.html That's the opposite of what the OP wanted. Curses generates the escape codes and so on to draw your desired stuff on the terminal. The OP wants a screen scraper, something that takes the escape codes generated by another program and interprets them to figure out what the screen is supposed to look like. The classic program that does this is Rog-o-matic. I don't happen to know of any Python code that does it but the search terms "python ansi screen scraping" find some results that might be worth looking into. It also shouldn't be all that terribly hard to implement. Leaving out the "ansi" keyword finds mostly HTML scrapers which aren't what is wanted. Trying other terminal types like "vt100" might find desirable stuff though. From jjperonin at free.fr Sat Mar 14 14:10:38 2015 From: jjperonin at free.fr (peronin jean jacques) Date: Sat, 14 Mar 2015 19:10:38 +0100 Subject: =?iso-8859-1?Q?t=E9l=E9chaegement?= Message-ID: Bonjour Je rencontre des probl?mes d?ouverture de la console python . J?ai donc tout d?sinstall?. Je vous demande donc qu?elle version je dois installer ? partir de votre site . J?utilise Windows 8-1 sur PC portable. Merci . Cordialement. -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Sat Mar 14 14:24:26 2015 From: __peter__ at web.de (Peter Otten) Date: Sat, 14 Mar 2015 19:24:26 +0100 Subject: Odd ValueError using float References: <877fuk71fz.fsf@nightsong.com> Message-ID: emile wrote: > On 03/14/2015 09:08 AM, Peter Otten wrote: >> emile wrote: >> >>> On 03/13/2015 08:09 PM, Chris Angelico wrote: >>>> On Sat, Mar 14, 2015 at 1:33 PM, Paul Rubin >>>> wrote: >>>>> emile writes: >>>>>> *** NameError: name 'val' is not defined >>>>>> (Pdb) l >>>>>> 139 try: >>>>>> 140 val = round(float(decval),1) >>>>>> 141 except: >>>>>> 142 import pdb; pdb.set_trace() >>>>> >>>>> If 'float' or 'round' throw an exception, the assignment to 'val' >>>>> never >>>>> happens, so 'val' is undefined. Try examining the value of 'decval' >>>>> in the debugger to see what is making the conversion fail. >>>> >>>> That's exactly what the OP did :) Trouble is, it didn't help, because >>>> it sure looked as if decval was the string '4'. My best guess was - >>>> and is - that it's not just a string. We're looking at an SQL >>>> interface routine here, so it may be that there's a string subclass >>>> that length-limits itself, on the assumption that it's going into a >>>> fixed-length database field. >>> >>> It ran almost to completion before generating the error again -- >>> >>> (Pdb) decval >>> '4' >>> (Pdb) type(decval) >>> >>> (Pdb) len(decval) >>> 1 >>> (Pdb) int(decval) >>> *** ValueError: invalid literal for int() with base 10: >>> '41.700000000000003' >>> >>> So there's still something amiss. >> >> Why are you checking >> >> int(decval) > > > because it sure smells like int should work: > > (Pdb) "3" True That's a normal string comparison when decval is a string. This and the ValueError is expected Python behaviour: Python 2.7.6 (default, Mar 22 2014, 22:59:56) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> decval = "41.700000000000003" >>> "3" < decval < "5" True >>> int(decval) Traceback (most recent call last): File "", line 1, in ValueError: invalid literal for int() with base 10: '41.700000000000003' >> when the actual failing expression is >> >> round(float(decval),1) >> >> ? Try to evaluate the latter in the debugger, and if that gives no clue >> change >> >>>>>> 139 try: >>>>>> 140 val = round(float(decval),1) >>>>>> 141 except: >>>>>> 142 import pdb; pdb.set_trace() >> >> to just >> >> val = round(float(decval), 1) >> >> to get a meaningful traceback and post that. > > I don't get a traceback -- it spews: > > Fatal Python error: deletion of interned string failed > > This application has requested the Runtime to terminate it in an unusual > way. > Please contact the application's support team for more information. > > then crashes and I get a Microsoft pop-up that says python.exe has > encountered a problem and needs to close. That does look bad. Most likely an extension written in C corrupts the interpreter or it's even a bug in the interpreter itself. From kevin.p.dwyer at gmail.com Sat Mar 14 14:24:51 2015 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Sat, 14 Mar 2015 18:24:51 +0000 Subject: =?UTF-8?B?dMOpbMOpY2hhZWdlbWVudA==?= References: Message-ID: peronin jean jacques wrote: > Bonjour > > Je rencontre des probl?mes d?ouverture de la console python . J?ai donc > tout d?sinstall?. Je vous demande donc qu?elle version je dois installer ? > partir > de votre site . J?utilise Windows 8-1 sur PC portable. > > Merci . Cordialement. Essayez python at aful.org - python-list en francais si vous ne peut pas ecrire en anglais. (et excusez ma francais pauvre, s'il vous plait) Kev From tjreedy at udel.edu Sat Mar 14 14:37:01 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 Mar 2015 14:37:01 -0400 Subject: The idle gui In-Reply-To: References: Message-ID: On 3/13/2015 4:58 PM, lmzentman at gmail.com wrote: > My python program was running for over six weeks. This is not clear. Do you mean that you wrote a program in python and that it ran continously, day and night, for 6 weeks? Or that you successfully used python on and off for 6 weeks? In either case, what version of python and what platform? > Then the idle gui stopped opening. How are you trying to open Idle? When happens when you try? In any case, try opening from a command line with 'python -m idlelib' (or idlelib.idle on 2.7 or before). > I have reinstalled several times but it doesn't work. What does not work? Python itself or just Idle? > Any idea? One reason that Idle can stop working is that you (or something) made a bad configuration change. The way to fix this is to find .idlerc in your home directory and empty it to remove the bad configuration. Another possible reason is that you installed something or made a change to a system setting that interferes with Idle starting. -- Terry Jan Reedy From tjreedy at udel.edu Sat Mar 14 14:50:47 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 Mar 2015 14:50:47 -0400 Subject: Module/lib for controlling a terminal program using redrawing? In-Reply-To: References: Message-ID: On 3/14/2015 6:50 AM, Jason Heeris wrote: > I am trying to automate the use of some old, in-house terminal-based > programs that use screen redrawing for their interface. This includes > single line redrawing (eg. using '\r' and overwriting), complete screen > clearing, and fine-grained cursor movement and overwriting (probably not > all in the same program at the same time though). > > Is there a module/library that can help me with this? > > I know of pexpect, but that seems more oriented towards line-by-line > prompts that don't involve redraws (eg. login prompt, then password > prompt on a new line). Think instead of trying to automate applications > like emacs, aptitude or even nethack that redraw sections of the screen > without making the terminal scroll. > > This automation requires more than just sending a set of keystrokes, but > also reading what is displayed on screen and making decisions based up > on that. > > Is there a library that can abstract the received redrawing activity so > I don't have to even know if the application has, eg. used a carriage > return or some other kind of cursor movement? Is there a way to just ask > "if this were to be run in an ANSI terminal, what would be in each cell?" > > Python 2 or 3 are both fine, external packages are fine, but it has to > work on Linux (eg. Ubuntu 14.04 or later, Debian Wheezy or later). > > Any pointers appreciated. Perhaps you can use the guts of a terminal emulation program, removing the part that displays the interpreted stream (a 24 x 80 array) on the screen. Searching 'python terminal emulation' returns these terminal.py - A Pure Python Terminal Emulator - GitHub Pages liftoff.github.io/GateOne/Developer/terminal.html This crux of this module is the Terminal class which is a pure-Python implementation of the quintessential Unix terminal emulator. It does its best to emulate an ... pyte 0.4.9 : Python Package Index https://pypi.python.org/pypi/pyte/ Python Dec 3, 2014 - What is pyte? It's an in memory VTXXX-compatible terminal emulator. XXX stands for a series of video terminals, developed by DEC between ... -- Terry Jan Reedy From PointedEars at web.de Sat Mar 14 15:19:19 2015 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Sat, 14 Mar 2015 20:19:19 +0100 Subject: Pexpect idea - but can I handle curses? References: <1606564.hXcnK9StvT@PointedEars.de> <1597615.KAoEH8zO7A@PointedEars.de> Message-ID: <3609192.4N8UZPzsLB@PointedEars.de> Skip Montanaro wrote: > Let's just let this thread die, shall we? So far, nobody seems interested > in attempting to answer my original question. That might have to do with , specifically . -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From emile at fenx.com Sat Mar 14 16:01:50 2015 From: emile at fenx.com (emile) Date: Sat, 14 Mar 2015 13:01:50 -0700 Subject: Odd ValueError using float In-Reply-To: References: <877fuk71fz.fsf@nightsong.com> Message-ID: On 03/14/2015 11:24 AM, Peter Otten wrote: > emile wrote: > >> On 03/14/2015 09:08 AM, Peter Otten wrote: >>> Why are you checking >>> >>> int(decval) >> >> >> because it sure smells like int should work: >> >> (Pdb) "3"> True > > That's a normal string comparison when decval is a string. This and the > ValueError is expected Python behaviour: yes -- but i'd previously shown decval to have a length of 1, and how many things then fit that equation? >>> to get a meaningful traceback and post that. >> >> I don't get a traceback -- it spews: >> >> Fatal Python error: deletion of interned string failed >> >> This application has requested the Runtime to terminate it in an unusual >> way. >> Please contact the application's support team for more information. >> >> then crashes and I get a Microsoft pop-up that says python.exe has >> encountered a problem and needs to close. > > That does look bad. Most likely an extension written in C corrupts the > interpreter or it's even a bug in the interpreter itself. I'm tight on time the rest of the day, but I think I'll next zap all the pyc versions, install a fresh 2.6.x python, and let it recompile. About the only theory I have at the moment to explain the sudden failure after years of non-failure is disk based bit-rot. Emile From ian.g.kelly at gmail.com Sat Mar 14 16:14:35 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 14 Mar 2015 14:14:35 -0600 Subject: generator/coroutine terminology In-Reply-To: <87zj7govya.fsf@elektro.pacujo.net> References: <5501be8b$0$13006$c3e8da3$5496439d@news.astraweb.com> <87twxqqewm.fsf@elektro.pacujo.net> <4eec1709-dd11-4891-bfcc-60b27bb00ee3@googlegroups.com> <550259bf$0$12975$c3e8da3$5496439d@news.astraweb.com> <00d9152a-f391-4c64-b2bd-52bdec2a6b67@googlegroups.com> <8761a5s0he.fsf@elektro.pacujo.net> <5503cf5f$0$12985$c3e8da3$5496439d@news.astraweb.com> <87zj7govya.fsf@elektro.pacujo.net> Message-ID: On Sat, Mar 14, 2015 at 1:54 AM, Marko Rauhamaa wrote: > Steven D'Aprano : > >> Marko Rauhamaa wrote: >> >>> Your 'factory' is a: >>> >>> generator >>> A function which returns an iterator. >>> >> >> That glossary entry is misleading, or at least incomplete, and it >> fails to match the way "generator" is used by actual Python >> programmers. > > I am an actual Python programmer (I develop Python programs) and my > definitive source for Python is the documentation. If there is an error > in the documentation, I would very much like it to be corrected. I think that Steven was basing his statement on the definition you cited. I don't think that he actually went and looked up the definition. If he had, he would have seen that you omitted 90% of it. Here's the full entry: """ A function which returns an iterator. It looks like a normal function except that it contains yield statements for producing a series of values usable in a for-loop or that can be retrieved one at a time with the next() function. Each yield temporarily suspends processing, remembering the location execution state (including local variables and pending try-statements). When the generator resumes, it picks-up where it left-off (in contrast to functions which start fresh on every invocation). """ >> A generator (function) may be a function which returns an iterator, >> but not all functions that return iterators are generators, and in >> some ways returning an iterator is the *least* interesting part of >> what makes a generator a generator. >> >> What distinguishes a generator from a regular function is the use of >> `yield`. Any definition which fails to mention that fact is useless. As can be seen above, the glossary definition *does* in fact discuss the use of yield. > The language reference had better use more precise language. It *is* the > definitive source, after all. Okay, but you cited the glossary entry, not the language reference. The language reference says this [1]: "When a generator function is called, it returns an iterator known as a generator." Which I think is quite clear, although to be fair the same section also uses "generator" alone to refer to the function in the preceding paragraph. That usage however is justified by PEP 255 [2]: """ When a generator function is called, the actual arguments are bound to function-local formal argument names in the usual way, but no code in the body of the function is executed. Instead a generator-iterator object is returned; this conforms to the iterator protocol, so in particular can be used in for-loops in a natural way. Note that when the intent is clear from context, the unqualified name "generator" may be used to refer either to a generator-function or a generator-iterator. """ Now which should be considered definitive, the language reference or the PEP? This question is not rhetorical; I don't know the answer. Regardless of the answer though, the PEP at least illuminates the design intent of the terminology. [1] https://docs.python.org/3/reference/expressions.html#yield-expressions [2] https://www.python.org/dev/peps/pep-0255/ From breamoreboy at yahoo.co.uk Sat Mar 14 16:31:18 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 14 Mar 2015 20:31:18 +0000 Subject: generator/coroutine terminology In-Reply-To: References: <5501be8b$0$13006$c3e8da3$5496439d@news.astraweb.com> <87twxqqewm.fsf@elektro.pacujo.net> <4eec1709-dd11-4891-bfcc-60b27bb00ee3@googlegroups.com> <550259bf$0$12975$c3e8da3$5496439d@news.astraweb.com> <00d9152a-f391-4c64-b2bd-52bdec2a6b67@googlegroups.com> <8761a5s0he.fsf@elektro.pacujo.net> <5503cf5f$0$12985$c3e8da3$5496439d@news.astraweb.com> <87zj7govya.fsf@elektro.pacujo.net> Message-ID: On 14/03/2015 20:14, Ian Kelly wrote: > > Now which should be considered definitive, the language reference or > the PEP? This question is not rhetorical; I don't know the answer. > Regardless of the answer though, the PEP at least illuminates the > design intent of the terminology. > The language reference should be the definitive guide. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From jkn_gg at nicorp.f9.co.uk Sat Mar 14 17:13:21 2015 From: jkn_gg at nicorp.f9.co.uk (jkn) Date: Sat, 14 Mar 2015 14:13:21 -0700 (PDT) Subject: Micropython? In-Reply-To: <87egos5bb7.fsf@nightsong.com> References: <87egos5bb7.fsf@nightsong.com> Message-ID: <01e4ac0f-e788-44e3-b3d8-f98896547d95@googlegroups.com> On Saturday, 14 March 2015 06:43:18 UTC, Paul Rubin wrote: > http://www.micropython.org/ > > Has anyone used this? Know anything about it? I don't remember seeing > any mention of it here. I remember there was a stripped down Python > some years back that didn't work very well, but I think this is > different. I just came across it by accident. Thanks. I started a short thread on it last year; search for "FYI: Micro Python running on kickstarter pyBoard project, now shipping" Our Tech Support department have a few of the boards and seem happy with them. I don't know much about what they are being used for though. I'd like to have the time... J^n From cs at zip.com.au Sat Mar 14 18:01:36 2015 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 15 Mar 2015 09:01:36 +1100 Subject: Pexpect idea - but can I handle curses? In-Reply-To: References: Message-ID: <20150314220136.GA33760@cskk.homeip.net> On 13Mar2015 10:17, Skip Montanaro wrote: >I have this tweak I'd like to make to the top command (Linux only is fine). >[...] However... I have a feeling I might be fairly seriously >challenged trying to work with top's raw output, as it probably does >something more sophisticated than clear the screen and spit out rows. Will >I be in over my head trying to tweak the output? Hmmm... maybe if I tell >top TERM=dumb? You may need to tell it TERM=dumb, though it might also refuse to run. Like many full screen terminal apps, top is built on top of curses or ncurses; these libraries try to do minimal tty output, so they maintain an in memory image of the screen and only emit the terminal sequences requires to update changes. Much escape sequence parsing etc if you want to hack their output. Now, if TERM-dumb is a no-go with top, another alternative is to write your own terminal definition (not trivial, but not too hard either as you don't need to implement all the operations, or even many of them: curses, given _sufficient_ capabilities, will figure it out). You might write an easy to parse terminal definition and run your own parser, and have _it_ output to python curses (with the correct $TERM on the output side). But I suspect it might be just as easy to implement your own top by parsing stuff from /proc. Your call... Cheers, Cameron Simpson From oscar.j.benjamin at gmail.com Sat Mar 14 18:02:02 2015 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Sat, 14 Mar 2015 22:02:02 +0000 Subject: generator/coroutine terminology In-Reply-To: References: <5501be8b$0$13006$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 12 March 2015 at 16:52, Rustom Mody wrote: > > On Thursday, March 12, 2015 at 9:58:07 PM UTC+5:30, Steven D'Aprano wrote: >> Rustom Mody wrote: >> >> > >> > Say I have a simple yielding function: >> > >> > def foo(x): >> > yield x+1 >> > yield x+2 >> > >> > And I have >> > >> > g = foo(2) >> > >> > If I look at type, g's type is 'generator' whereas foo is just plain-ol >> > 'function.' >> > >> > Whereas in informal usage we say foo is a generator. >> >> Hopefully it is clear from context what we actually mean. When in doubt, we >> should be explicit. > > There is a very important 'context' where both have to exist together -- teaching beginners. It is definitely important to draw the distinction between a generator function and a generator in teaching. I would use distinct terminology in any case. It's also important where possible to use the same terminology as is used in the various different sources of documentation that your students will encounter so inventing a new term like "generator factory" is probably a bad idea. > foo's are written to produce g's. g's come from foo-like. > > Better naming would help clarify -- your 'factory' is the best Ive seen so far. I dislike the term "generator factory". To me it suggests something like foo below: def baz(): yield 4 def bar(): yield 6 yield 7 def foo(x): if x > 4: return baz() else: return bar() The existing terminology seems fine to me: A generator function is a special kind of function containing a yield statement that always returns a generator. A generator expression is a special kind of expression that evaluates to a generator. A generator is a special type of iterator that results from generator functions and generator expressions. > But the docs?!?! Hoo Boy My head spins trying to grok this > https://docs.python.org/3/reference/expressions.html#generator-expressions > And thats after being familiar with the origins of the idea in > scheme/simula/CLU etc. Perhaps the docs can be improved. I wouldn't recommend that particular page to anyone who wasn't already familiar with the subject though. Oscar From cs at zip.com.au Sat Mar 14 18:09:07 2015 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 15 Mar 2015 09:09:07 +1100 Subject: Odd ValueError using float In-Reply-To: References: Message-ID: <20150314220907.GA67310@cskk.homeip.net> On 14Mar2015 08:28, Emile van Sebille wrote: >It ran almost to completion before generating the error again -- > >(Pdb) decval >'4' >(Pdb) type(decval) > >(Pdb) len(decval) >1 >(Pdb) int(decval) >*** ValueError: invalid literal for int() with base 10: '41.700000000000003' > >So there's still something amiss. Am I missing something obvious here? int() likes only ints, not floats: Python 2.7.9 (default, Dec 13 2014, 15:13:49) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> int('1.3') Traceback (most recent call last): File "", line 1, in ValueError: invalid literal for int() with base 10: '1.3' Python 3.4.3 (default, Feb 27 2015, 00:22:26) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> int('1.3') Traceback (most recent call last): File "", line 1, in ValueError: invalid literal for int() with base 10: '1.3' Cheers, Cameron Simpson C++ also supports the notion of *friends*: cooperative classes that are permitted to see each other's private parts. - Grady Booch, "Object Oriented Design with Applications" From marko at pacujo.net Sat Mar 14 18:15:32 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 15 Mar 2015 00:15:32 +0200 Subject: generator/coroutine terminology References: <5501be8b$0$13006$c3e8da3$5496439d@news.astraweb.com> Message-ID: <874mpnp6nv.fsf@elektro.pacujo.net> Oscar Benjamin : > A generator is a special type of iterator that results from generator > functions and generator expressions. Is it necessary/useful for a Python application programmer to be conscious of the different types of iterator? What mistaken usage could arise if the application just treated all iterators as, well, iterators? Marko From rosuav at gmail.com Sat Mar 14 18:20:18 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 15 Mar 2015 09:20:18 +1100 Subject: Odd ValueError using float In-Reply-To: <20150314220907.GA67310@cskk.homeip.net> References: <20150314220907.GA67310@cskk.homeip.net> Message-ID: On Sun, Mar 15, 2015 at 9:09 AM, Cameron Simpson wrote: > On 14Mar2015 08:28, Emile van Sebille wrote: >> >> It ran almost to completion before generating the error again -- >> >> (Pdb) decval >> '4' >> (Pdb) type(decval) >> >> (Pdb) len(decval) >> 1 >> (Pdb) int(decval) >> *** ValueError: invalid literal for int() with base 10: >> '41.700000000000003' >> >> So there's still something amiss. > > > Am I missing something obvious here? int() likes only ints, not floats: Possibly missing the bit where decval looks to be a string containing the one character U+0034 DIGIT FOUR, and then suddenly has a whole mess of extra characters. :) Check out the fenx stuff, as that's the only non-stdlib code you have. Maybe it calls on a C extension module somewhere deep inside it. ChrisA From rosuav at gmail.com Sat Mar 14 18:24:15 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 15 Mar 2015 09:24:15 +1100 Subject: generator/coroutine terminology In-Reply-To: <874mpnp6nv.fsf@elektro.pacujo.net> References: <5501be8b$0$13006$c3e8da3$5496439d@news.astraweb.com> <874mpnp6nv.fsf@elektro.pacujo.net> Message-ID: On Sun, Mar 15, 2015 at 9:15 AM, Marko Rauhamaa wrote: > Oscar Benjamin : > >> A generator is a special type of iterator that results from generator >> functions and generator expressions. > > Is it necessary/useful for a Python application programmer to be > conscious of the different types of iterator? What mistaken usage could > arise if the application just treated all iterators as, well, iterators? If you treat them all as iterators, then you're safe, because that's the lowest common denominator. But there are a number of other iterators that have more features, including files, generators, etc. ChrisA From jason.heeris at gmail.com Sat Mar 14 18:28:54 2015 From: jason.heeris at gmail.com (Jason Heeris) Date: Sun, 15 Mar 2015 09:28:54 +1100 Subject: Module/lib for controlling a terminal program using redrawing? In-Reply-To: References: Message-ID: Yes, Paul Rubin had it right: I hadn't thought of the term "screen scraper," but that might help my searching. On 15 March 2015 at 05:50, Terry Reedy wrote: > > Perhaps you can use the guts of a terminal emulation program, removing the part that displays the interpreted stream (a 24 x 80 array) on the screen. Searching 'python terminal emulation' returns these Thanks for those results. I also discovered that someone wrote a Python ANSI terminal scraper originally for use with Nethack: https://github.com/helgefmi/ansiterm (although it seems generic enough). Cheers, Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sat Mar 14 18:39:07 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 15 Mar 2015 09:39:07 +1100 Subject: Micropython? In-Reply-To: <87egos5bb7.fsf@nightsong.com> References: <87egos5bb7.fsf@nightsong.com> Message-ID: On Sat, Mar 14, 2015 at 5:43 PM, Paul Rubin wrote: > http://www.micropython.org/ > > Has anyone used this? Know anything about it? I don't remember seeing > any mention of it here. I remember there was a stripped down Python > some years back that didn't work very well, but I think this is > different. I just came across it by accident. Thanks. It's a rare thing: an alternative Python implementatin that targets Py3 instead of Py2. I haven't been following the project lately (largely because I don't use microcontrollers), but it's something that should be encouraged, just on the basis of Python version. ChrisA From rosuav at gmail.com Sat Mar 14 18:59:31 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 15 Mar 2015 09:59:31 +1100 Subject: The idle gui In-Reply-To: <550431DD.90502@davea.name> References: <0d3d1ec0-d112-42fc-aeed-fb6674d2ee1b@googlegroups.com> <55038dba$0$12990$c3e8da3$5496439d@news.astraweb.com> <5503906A.6040802@davea.name> <550431DD.90502@davea.name> Message-ID: On Sun, Mar 15, 2015 at 12:04 AM, Dave Angel wrote: > I wasn't actually trying to pick on the OP this time, but to make a joke. > Idle could be taken two ways (if it weren't for the capitalization), or even > three (My Chevy won't idle.). Beware the Idles of March? ChrisA From marko at pacujo.net Sat Mar 14 20:15:39 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 15 Mar 2015 02:15:39 +0200 Subject: generator/coroutine terminology References: <5501be8b$0$13006$c3e8da3$5496439d@news.astraweb.com> <874mpnp6nv.fsf@elektro.pacujo.net> Message-ID: <87y4mznmj8.fsf@elektro.pacujo.net> Chris Angelico : > On Sun, Mar 15, 2015 at 9:15 AM, Marko Rauhamaa wrote: >> Is it necessary/useful for a Python application programmer to be >> conscious of the different types of iterator? What mistaken usage >> could arise if the application just treated all iterators as, well, >> iterators? > > If you treat them all as iterators, then you're safe, because that's > the lowest common denominator. But there are a number of other > iterators that have more features, including files, generators, etc. What features do generator iterators provide on top of generic iterators? Marko From rosuav at gmail.com Sat Mar 14 20:22:57 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 15 Mar 2015 11:22:57 +1100 Subject: generator/coroutine terminology In-Reply-To: <87y4mznmj8.fsf@elektro.pacujo.net> References: <5501be8b$0$13006$c3e8da3$5496439d@news.astraweb.com> <874mpnp6nv.fsf@elektro.pacujo.net> <87y4mznmj8.fsf@elektro.pacujo.net> Message-ID: On Sun, Mar 15, 2015 at 11:15 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> On Sun, Mar 15, 2015 at 9:15 AM, Marko Rauhamaa wrote: >>> Is it necessary/useful for a Python application programmer to be >>> conscious of the different types of iterator? What mistaken usage >>> could arise if the application just treated all iterators as, well, >>> iterators? >> >> If you treat them all as iterators, then you're safe, because that's >> the lowest common denominator. But there are a number of other >> iterators that have more features, including files, generators, etc. > > What features do generator iterators provide on top of generic > iterators? You can send values into them, throw exceptions into them, and close them (which is a special case of the latter). ChrisA From marko at pacujo.net Sat Mar 14 20:48:50 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 15 Mar 2015 02:48:50 +0200 Subject: generator/coroutine terminology References: <5501be8b$0$13006$c3e8da3$5496439d@news.astraweb.com> <874mpnp6nv.fsf@elektro.pacujo.net> <87y4mznmj8.fsf@elektro.pacujo.net> Message-ID: <87twxnnkzx.fsf@elektro.pacujo.net> Chris Angelico : > On Sun, Mar 15, 2015 at 11:15 AM, Marko Rauhamaa wrote: >> What features do generator iterators provide on top of generic >> iterators? > > You can send values into them, throw exceptions into them, and close > them (which is a special case of the latter). Hm. I wonder why the distinction was made. IOW, why is iter([1, 2, 3]) not equivalent with (x for x in [1, 2, 3]) I can close the latter but not the former. After all, yield from [1, 2, 3] works all right. Marko From skip.montanaro at gmail.com Sat Mar 14 21:05:55 2015 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Sat, 14 Mar 2015 20:05:55 -0500 Subject: Pexpect idea - but can I handle curses? In-Reply-To: <3609192.4N8UZPzsLB@PointedEars.de> References: <1606564.hXcnK9StvT@PointedEars.de> <1597615.KAoEH8zO7A@PointedEars.de> <3609192.4N8UZPzsLB@PointedEars.de> Message-ID: > That might have to do with > , specifically > . Thanks, but not really helpful. I'm well aware of Eric Raymond's contributions to the open source world. I'm also aware aware that my question was not perfectly well-formed. Skip -------------- next part -------------- An HTML attachment was scrubbed... URL: From skip.montanaro at gmail.com Sat Mar 14 21:09:49 2015 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Sat, 14 Mar 2015 20:09:49 -0500 Subject: Pexpect idea - but can I handle curses? In-Reply-To: <20150314220136.GA33760@cskk.homeip.net> References: <20150314220136.GA33760@cskk.homeip.net> Message-ID: >> Will I be in over my head trying to tweak the output? Hmmm... maybe if I tell top TERM=dumb? > > You may need to tell it TERM=dumb, though it might also refuse to run. It does run w/ TERM=dumb, so hopefully I won't have to resort to defining my own terminal definition. (Now, *that* takes me back.) Now to see how simple the output is... Skip -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sat Mar 14 22:02:33 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 15 Mar 2015 13:02:33 +1100 Subject: generator/coroutine terminology In-Reply-To: <87twxnnkzx.fsf@elektro.pacujo.net> References: <5501be8b$0$13006$c3e8da3$5496439d@news.astraweb.com> <874mpnp6nv.fsf@elektro.pacujo.net> <87y4mznmj8.fsf@elektro.pacujo.net> <87twxnnkzx.fsf@elektro.pacujo.net> Message-ID: On Sun, Mar 15, 2015 at 11:48 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> On Sun, Mar 15, 2015 at 11:15 AM, Marko Rauhamaa wrote: >>> What features do generator iterators provide on top of generic >>> iterators? >> >> You can send values into them, throw exceptions into them, and close >> them (which is a special case of the latter). > > Hm. I wonder why the distinction was made. IOW, why is > > iter([1, 2, 3]) > > not equivalent with > > (x for x in [1, 2, 3]) > > I can close the latter but not the former. You don't need to close the former. > After all, > > yield from [1, 2, 3] > > works all right. That's using it as an iterable, which is not quite the same as an iterator. (Iterators are themselves iterable; iter(x) is x, for any iterator.) What you're doing there is roughly equivalent to: for x in [1, 2, 3]: yield x but with a bunch of other simplifications and guarantees for edge cases and things. So it's going to call iter() on what you give it. If you treat things as iterators, you can use all sorts of things. You don't need to distinguish the different types. The distinction is important if you want to do more than just iterate over something. >>> def gather(): lst = [] try: while True: lst.append((yield len(lst))) except StopIteration: yield lst >>> n = gather() >>> next(n) 0 >>> n.send("Hello") 1 >>> n.send("World") 2 >>> n.throw(StopIteration) ['Hello', 'World'] You can't do that with a simple iterator. (Not that I'm saying this is good design...) ChrisA From rustompmody at gmail.com Sun Mar 15 00:15:01 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 14 Mar 2015 21:15:01 -0700 (PDT) Subject: generator/coroutine terminology In-Reply-To: References: <5501be8b$0$13006$c3e8da3$5496439d@news.astraweb.com> <87twxqqewm.fsf@elektro.pacujo.net> <4eec1709-dd11-4891-bfcc-60b27bb00ee3@googlegroups.com> <550259bf$0$12975$c3e8da3$5496439d@news.astraweb.com> <00d9152a-f391-4c64-b2bd-52bdec2a6b67@googlegroups.com> <8761a5s0he.fsf@elektro.pacujo.net> <5503cf5f$0$12985$c3e8da3$5496439d@news.astraweb.com> <87zj7govya.fsf@elektro.pacujo.net> Message-ID: On Sunday, March 15, 2015 at 1:45:37 AM UTC+5:30, Ian wrote: > Now which should be considered definitive, the language reference or > the PEP? This question is not rhetorical; I don't know the answer. > Regardless of the answer though, the PEP at least illuminates the > design intent of the terminology. > > > [1] https://docs.python.org/3/reference/expressions.html#yield-expressions > > [2] https://www.python.org/dev/peps/pep-0255/ Thanks That PEP deserves careful reading, particularly the end... | BDFL Pronouncements | Issue: Introduce another new keyword (say, "gen" or "generator") in | place of "def", or otherwise alter the syntax, to distinguish | generator-functions from non-generator functions. | | Con: In practice (how you think about them), generators *are* | functions, but with the twist that they're resumable. The mechanics of | how they're set up is a comparatively minor technical issue, and | introducing a new keyword would unhelpfully overemphasize the | mechanics of how generators get started (a vital but tiny part of a | generator's life). | | Pro: In reality (how you think about them), generator-functions are | actually factory functions that produce generator-iterators as if by | magic. In this respect they're radically different from non-generator | functions, acting more like a constructor than a function, so reusing | "def" is at best confusing. A "yield" statement buried in the body is | not enough warning that the semantics are so different. | | BDFL: "def" it stays. No argument on either side is totally | convincing, so I have consulted my language designer's intuition. It | tells me that the syntax proposed in the PEP is exactly right - not too | hot, not too cold. But, like the Oracle at Delphi in Greek mythology, | it doesn't tell me why, so I don't have a rebuttal for the arguments | against the PEP syntax. The best I can come up with (apart from | agreeing with the rebuttals ... already made) is "FUD". If this had | been part of the language from day one, I very much doubt it would have | made Andrew Kuchling's "Python Warts" page. So while I dont go to the extent of suggesting introducing a different keyword for generators, the fact that the overloading of def is problematic and arbitrary comes from the horse's (ie BDFL's) mouth. From phd at phdru.name Sun Mar 15 00:17:50 2015 From: phd at phdru.name (Oleg Broytman) Date: Sun, 15 Mar 2015 05:17:50 +0100 Subject: SQLObject 2.1.2 and 1.7.5 Message-ID: <20150315041750.GA18828@phdru.name> Hello! I'm pleased to announce versions 2.1.2 and 1.7.5, minor feature releases of of SQLObject. What's new in SQLObject ======================= * Use fdb adapter for Firebird. Contributor for this release is Neil Muller. 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 or 2.7 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/2.1.2 https://pypi.python.org/pypi/SQLObject/1.7.5 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 songofacandy at gmail.com Sun Mar 15 03:01:47 2015 From: songofacandy at gmail.com (INADA Naoki) Date: Sun, 15 Mar 2015 16:01:47 +0900 Subject: Python 2 to 3 conversion - embrace the pain In-Reply-To: References: <550351BF.5020108@animats.com> Message-ID: What I want to say is, MySQLdb -> PyMySQL conversion is not required for porting from Python 2 to Python 3. mysqlclient is straight upgrade path from MySQLdb. On Sat, Mar 14, 2015 at 8:01 AM, John Nagle wrote: > On 3/13/2015 3:27 PM, INADA Naoki wrote: >> Hi, John. I'm maintainer of PyMySQL. >> >> I'm sorry about bug of PyMySQL. But the bug is completely unrelated >> to Python 3. >> You may encounter the bug on Python 2 too. > > True. But much of the pain of converting to Python 3 > comes from having to switch packages because the Python 2 > package didn't make it to Python 3. > > All the bugs I'm discussing reflect forced package > changes or upgrades. None were voluntary on my part. > > John Nagle > > -- > https://mail.python.org/mailman/listinfo/python-list -- INADA Naoki From DaveFarrance at OMiTTHiSyahooANDTHiS.co.uk Sun Mar 15 03:26:19 2015 From: DaveFarrance at OMiTTHiSyahooANDTHiS.co.uk (Dave Farrance) Date: Sun, 15 Mar 2015 07:26:19 +0000 Subject: PSF news - BBC launches MicroBit References: Message-ID: Mark Lawrence wrote: >http://pyfound.blogspot.co.uk/2015/03/bbc-launches-microbit.html may be >of interest to some of you. "Python is one of the three languages that work with the device." That's cool, and the article says that the Raspberry Pi Foundation is involved in creating learning content for it, which I presume would emphasise Python, given that Python was the RPi Foundation's first choice for controlling the Pi. The RPi has helped to raise the profile of Python, so hopefully this new device will add to that. I wonder what the other two languages are? I'd guess a C++ subset for one, like the Arduino. Not sure about the other. HTML/Javascript is becoming popular in education because it's the easiest way put shapes and animation on the screen, but I don't think it's suited to an embedded device. From steve+comp.lang.python at pearwood.info Sun Mar 15 04:37:23 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 15 Mar 2015 19:37:23 +1100 Subject: generator/coroutine terminology References: <5501be8b$0$13006$c3e8da3$5496439d@news.astraweb.com> <87twxqqewm.fsf@elektro.pacujo.net> <4eec1709-dd11-4891-bfcc-60b27bb00ee3@googlegroups.com> <550259bf$0$12975$c3e8da3$5496439d@news.astraweb.com> <00d9152a-f391-4c64-b2bd-52bdec2a6b67@googlegroups.com> <8761a5s0he.fsf@elektro.pacujo.net> <5503cf5f$0$12985$c3e8da3$5496439d@news.astraweb.com> Message-ID: <550544c4$0$12993$c3e8da3$5496439d@news.astraweb.com> Rustom Mody wrote: > On Saturday, March 14, 2015 at 11:34:27 AM UTC+5:30, Steven D'Aprano > wrote: >> >> A generator (function) may be a function which returns an iterator,... > > I find "generator-function" misleading in the same way that "pineapple" > misleadingly suggests "apple that grows on pines" You would be wrong. There's nothing objectionable or misleading about "generator-function" meaning a function which returns generators. English is very flexible like that, and compound nouns can be used in many different ways: * a greenhouse is not a house that happens to be green; * a mushroom is not a room where people mush; * a butterfly is not a fly made of butter; * a swimming pool is not a pool which swims; * but a flying squirrel is a squirrel which (almost) flies. Where a compound noun is made of two nouns, the "important" one can appear either at the beginning or the end: * a printer cartridge is a type of cartridge, not a type of printer; * but an attorney general is a type of attorney, not a type of general. So there is nothing unusual about "generator-function" being a type of function. > A builtin function is a function in the builtin (or builtins -- can never > remember) module A pure function is function that does not assign or > mutate non-locals A Steven-function is a function that presumably Steven > wrote > > However a "generator function" is a weird sort of function (at best). > Not regarding it as a function is IMO more reasonable. But it is a function. You can regard it as a kind of yoghurt, if you like, but it isn't one. py> def g(): ... yield 1 ... py> from inspect import isfunction py> isfunction(g) True -- Steven From PointedEars at web.de Sun Mar 15 05:23:18 2015 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Sun, 15 Mar 2015 10:23:18 +0100 Subject: Pexpect idea - but can I handle curses? References: <1606564.hXcnK9StvT@PointedEars.de> <1597615.KAoEH8zO7A@PointedEars.de> <3609192.4N8UZPzsLB@PointedEars.de> Message-ID: <15698001.HJZeQnlvbi@PointedEars.de> Skip Montanaro wrote: >> That might have to do with >> , specifically >> . > > Thanks, but not really helpful. I'm well aware of Eric Raymond's > contributions to the open source world. I'm also aware aware that my > question was not perfectly well-formed. It was really helpful, you just do not realize it yet. F'up2 poster -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From random832 at fastmail.us Sun Mar 15 07:41:35 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Sun, 15 Mar 2015 07:41:35 -0400 Subject: Odd ValueError using float In-Reply-To: <20150314220907.GA67310@cskk.homeip.net> References: <20150314220907.GA67310@cskk.homeip.net> Message-ID: <1426419695.1837423.240564865.238FED92@webmail.messagingengine.com> On Sat, Mar 14, 2015, at 18:09, Cameron Simpson wrote: > >So there's still something amiss. > > Am I missing something obvious here? int() likes only ints, not floats: What you're missing is that when directly examined in pdb, the value appeared to be '4', but then when passed to the int constructor, it appeared to be '41.700000000000003'. Something seriously messed-up is going on. From ahicks at p-o.co.uk Sun Mar 15 08:20:55 2015 From: ahicks at p-o.co.uk (Alan Hicks) Date: Sun, 15 Mar 2015 12:20:55 +0000 Subject: Django-DMARC making it easier to manage DMARC reports - Beta 0.1.3 on PyPI In-Reply-To: References: <54FD72F8.3080706@p-o.co.uk> Message-ID: <55057927.9020502@p-o.co.uk> On 13/03/2015 11:58, Chris Angelico wrote: > On Mon, Mar 9, 2015 at 9:16 PM, Alan Hicks wrote: >> With defending reputations as important as receiving email I'm pleased to >> announce another beta of django-dmarc 0.1.3 is released to PyPI. >> https://pypi.python.org/pypi/django-dmarc >> >> The Django DMARC project aims to help with implementing DMARC "Domain-based >> Message Authentication, Reporting & Conformance" and ongoing monitoring by >> importing feedback reports about messages that pass and/or fail DMARC >> evaluation into a more easily digested format. > > Welcome to irony. Your message got dropped into my Gmail spam box > because DMARC is incompatible with mailing lists. > > Until that can be resolved, I don't want to deploy either end of DMARC > for any of my domains or mail servers. > > ChrisA > Mailing lists are an issue on many levels, and dmarc has an faq that may help http://dmarc.org/faq/receivers/#r_2 I take your point, though when defending a reputation, dmarc along with spf and dkim are tools that can help. Gmail are in the process of implementing dmarc, try dig _dmarc.gmail.com txt for their current policy. My company along with many others has previously been impersonated by asian spam (Korean I think). With a few clients that deal internationally including asia it's important to be pro-active and address spam both for my company and as a good netizen reduce the effect on others as well - we all win. It's work in progress hence django-dmarc. Alan From rosuav at gmail.com Sun Mar 15 08:29:37 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 15 Mar 2015 23:29:37 +1100 Subject: Django-DMARC making it easier to manage DMARC reports - Beta 0.1.3 on PyPI In-Reply-To: <55057927.9020502@p-o.co.uk> References: <54FD72F8.3080706@p-o.co.uk> <55057927.9020502@p-o.co.uk> Message-ID: On Sun, Mar 15, 2015 at 11:20 PM, Alan Hicks wrote: > Mailing lists are an issue on many levels, and dmarc has an faq that may > help http://dmarc.org/faq/receivers/#r_2 No, they're not; the issue is only with DMARC. I have no problems with mailing lists and SPF records, because the list software changes the envelope addresses. Mailing lists are excellent, and I run a number of them - but not nearly as many as I'm a member of - and spam can be dealt with in the absence of DMARC. I've seen no benefit from it, unlike with SPF which has blocked no end of dead mail; and it causes issues on several lists. ChrisA From __peter__ at web.de Sun Mar 15 10:01:43 2015 From: __peter__ at web.de (Peter Otten) Date: Sun, 15 Mar 2015 15:01:43 +0100 Subject: Odd ValueError using float References: <877fuk71fz.fsf@nightsong.com> Message-ID: emile wrote: > On 03/14/2015 11:24 AM, Peter Otten wrote: >> emile wrote: >> >>> On 03/14/2015 09:08 AM, Peter Otten wrote: > >>>> Why are you checking >>>> >>>> int(decval) >>> >>> >>> because it sure smells like int should work: >>> >>> (Pdb) "3">> True >> >> That's a normal string comparison when decval is a string. This and the >> ValueError is expected Python behaviour: > > > yes -- but i'd previously shown decval to have a length of 1, and how > many things then fit that equation? > > > >>>> to get a meaningful traceback and post that. >>> >>> I don't get a traceback -- it spews: >>> >>> Fatal Python error: deletion of interned string failed >>> >>> This application has requested the Runtime to terminate it in an unusual >>> way. >>> Please contact the application's support team for more information. >>> >>> then crashes and I get a Microsoft pop-up that says python.exe has >>> encountered a problem and needs to close. >> >> That does look bad. Most likely an extension written in C corrupts the >> interpreter or it's even a bug in the interpreter itself. > > I'm tight on time the rest of the day, but I think I'll next zap all the > pyc versions, install a fresh 2.6.x python, and let it recompile. About > the only theory I have at the moment to explain the sudden failure after > years of non-failure is disk based bit-rot. Probably not helpful, but I can provoke the behaviour you see by toggling bytes with ctypes, thus simulating a corrupted str object: Python 2.7.6 (default, Mar 22 2014, 22:59:56) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import ctypes >>> s = "41.700000000000003" >>> ctypes.c_ubyte.from_address(id(s) + 16).value = 1 >>> s '4' >>> len(s) 1 >>> float(s) Traceback (most recent call last): File "", line 1, in ValueError: invalid literal for float(): 41.700000000000003 >>> int(s) Traceback (most recent call last): File "", line 1, in ValueError: invalid literal for int() with base 10: '41.700000000000003' From ahicks at p-o.co.uk Sun Mar 15 11:19:40 2015 From: ahicks at p-o.co.uk (Alan Hicks) Date: Sun, 15 Mar 2015 15:19:40 -0000 Subject: [Fwd: Re: Django-DMARC making it easier to manage DMARC reports - Beta 0.1.3 on PyPI] Message-ID: ---------------------------- Original Message ---------------------------- Subject: Re: Django-DMARC making it easier to manage DMARC reports - Beta 0.1.3 on PyPI From: "Alan Hicks" Date: Sun, March 15, 2015 2:10 pm To: "Chris Angelico" -------------------------------------------------------------------------- On 15/03/2015 12:29, Chris Angelico wrote: > On Sun, Mar 15, 2015 at 11:20 PM, Alan Hicks wrote: >> Mailing lists are an issue on many levels, and dmarc has an faq that may >> help http://dmarc.org/faq/receivers/#r_2 > > No, they're not; the issue is only with DMARC. I have no problems with > mailing lists and SPF records, because the list software changes the > envelope addresses. Mailing lists are excellent, and I run a number of > them - but not nearly as many as I'm a member of - and spam can be > dealt with in the absence of DMARC. I've seen no benefit from it, > unlike with SPF which has blocked no end of dead mail; and it causes > issues on several lists. > > ChrisA > DMARC is only reinforcing SPF and DKIM so DMARC is not the core issue. If issues are not surfacing it is more likely that both SPF and DKIM are not strong spam indicators rather than there are no issues. SPF is rarely implemented decisively ~all instead of -all so is not very strong. This email failed dkim from gmail.com but was not rejected (2015-03-15 12:30:13 1YX7gL-000JG2-Iv DKIM: d=gmail.com s=20120113 c=relaxed/relaxed a=rsa-sha256 [verification failed - signature did not verify (headers probably modified in transit)]). This issue only raised itself by my company implementing a stronger policy than currently necessary. With the volume of spam increasing, I don't see things getting easier, DMARC is just encouraging use of SPF and DKIM and appears to be gaining traction in a global world where reputation matters. Alan From jhale7021 at gmail.com Sun Mar 15 11:43:32 2015 From: jhale7021 at gmail.com (Jenny Hale) Date: Sun, 15 Mar 2015 08:43:32 -0700 (PDT) Subject: Help me please urgently! Message-ID: <43223410-538e-4834-82d4-98ab0702ae2d@googlegroups.com> Hi How would I do this? The teacher wants to keep track of the scores each member of the class obtains in the quiz. There are three classes in the school and the data should be kept separately for each class. Here is my code: import random import operator MATHS_OPERATIONS = [ (operator.add, "+"), (operator.mul, "*"), (operator.sub, "-") ] NUM_QUESTIONS = 10 def get_int_input(prompt=''): while True: try: return int(input(prompt)) except ValueError: print("Not a valid input (integer is expected)") def get_bool_input(prompt=''): while True: val = input(prompt).lower() if val == 'yes': return True elif val == 'no': return False else: print("Not a valid input (yes/no is expected)") if __name__ == '__main__': name = input("What is your name?").title() class_name = input("What is your Class? ") print(name, ", Welcome to the Maths Test") score = 0 for _ in range(NUM_QUESTIONS): num1 = random.randint(1,100) num2 = random.randint(1,100) op, symbol = random.choice(MATHS_OPERATIONS) print("What is", num1, symbol, num2) if get_int_input() == op(num1, num2): print("Correct") score += 1 else: print("Incorrect") print("Well done", name, "you scored", score, "/", NB_QUESTIONS) filename = class_name + ".txt" with open(filename, 'a') as f: f.write(str(name) + " : " + str(score) + '\n') if get_bool_input("Do you wish to view previous results for your class"): with open(filename, 'r') as f: print(f.read()) else: input ("Press any key to exit") Could somebody here me please? From rosuav at gmail.com Sun Mar 15 12:00:00 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 16 Mar 2015 03:00:00 +1100 Subject: Help me please urgently! In-Reply-To: <43223410-538e-4834-82d4-98ab0702ae2d@googlegroups.com> References: <43223410-538e-4834-82d4-98ab0702ae2d@googlegroups.com> Message-ID: On Mon, Mar 16, 2015 at 2:43 AM, Jenny Hale wrote: > How would I do this? > The teacher wants to keep track of the scores each member of the class obtains in the quiz. There are three classes in the school and the data should be kept separately for each class. > Thank you for being honest about this being course work. So what's your code not doing correctly? You've shown us a pageful of Python; I could point out problems like that your last line won't do quite what it looks like, but that'd probably not what you're talking about. Be aware that you hopefully won't get your code written for you. What you'll get is hints pointing you toward solving the problem yourself. Ask with that in mind and you should be able to word up questions that will help you with what you're stuck on. So have your best shot at it yourself, then figure out what it is you're unable to do, and ask a very specific question (or maybe several questions, as the case may be); we're happy to help you to learn Python, but we won't simply give you the answers so you can pass the course. All the best! ChrisA From ian.g.kelly at gmail.com Sun Mar 15 12:10:33 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 15 Mar 2015 10:10:33 -0600 Subject: Help me please urgently! In-Reply-To: <43223410-538e-4834-82d4-98ab0702ae2d@googlegroups.com> References: <43223410-538e-4834-82d4-98ab0702ae2d@googlegroups.com> Message-ID: On Sun, Mar 15, 2015 at 9:43 AM, Jenny Hale wrote: > Hi > > How would I do this? > The teacher wants to keep track of the scores each member of the class obtains in the quiz. There are three classes in the school and the data should be kept separately for each class. Is this a homework assignment? It looks like you already have a solution or most of one. Do you have any specific question that you need help with? Since it's not clear to me what sort of help you're looking for, I've added some constructive style comments below. It mostly looks good to me. > import random > import operator > > MATHS_OPERATIONS = [ > (operator.add, "+"), > (operator.mul, "*"), > (operator.sub, "-") > ] > > NUM_QUESTIONS = 10 > > def get_int_input(prompt=''): > while True: > try: > return int(input(prompt)) > except ValueError: > print("Not a valid input (integer is expected)") > > def get_bool_input(prompt=''): > while True: > val = input(prompt).lower() > if val == 'yes': > return True > elif val == 'no': > return False It's generally polite to your user if you accept additional variations such as y/n. An easy way to do that is with the test ('yes'.startswith(val)) which will match the word 'yes' or any prefix of it. > else: > print("Not a valid input (yes/no is expected)") > > if __name__ == '__main__': This should all be moved into a function, and the body of the if statement would then just be a call to the function. This way you won't be polluting your global namespace with lots of variables that should really be local in scope. It also makes code reuse easier -- if another module wants to launch this script, all it has to do is import this module and call the function. > name = input("What is your name?").title() > class_name = input("What is your Class? ") > print(name, ", Welcome to the Maths Test") > > score = 0 > for _ in range(NUM_QUESTIONS): > num1 = random.randint(1,100) > num2 = random.randint(1,100) > op, symbol = random.choice(MATHS_OPERATIONS) > print("What is", num1, symbol, num2) > if get_int_input() == op(num1, num2): > print("Correct") > score += 1 > else: > print("Incorrect") > > print("Well done", name, "you scored", score, "/", NB_QUESTIONS) This would probably be a bit cleaner with a formatted string, either the % style or using str.format. The former would look like this: print("Well done, %s! You scored %d / %d." % (name, score, NB_QUESTIONS)) The latter is the new(er) hotness and would look like this: print("Well done, {}! You scored {} / {}.".format(name, score, NB_QUESTIONS)) It's up to you (and your instructor) which style you prefer. > > filename = class_name + ".txt" > > with open(filename, 'a') as f: > f.write(str(name) + " : " + str(score) + '\n') Another place where I would suggest a formatted string. > if get_bool_input("Do you wish to view previous results for your class"): > with open(filename, 'r') as f: > print(f.read()) > else: > input ("Press any key to exit") input is going to wait for the user to press Enter, not "any key". From python at mrabarnett.plus.com Sun Mar 15 12:12:18 2015 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 15 Mar 2015 16:12:18 +0000 Subject: PSF news - BBC launches MicroBit In-Reply-To: References: Message-ID: <5505AF62.2050806@mrabarnett.plus.com> On 2015-03-15 07:26, Dave Farrance wrote: > Mark Lawrence wrote: > >>http://pyfound.blogspot.co.uk/2015/03/bbc-launches-microbit.html may be >>of interest to some of you. > > "Python is one of the three languages that work with the device." > > That's cool, and the article says that the Raspberry Pi Foundation is > involved in creating learning content for it, which I presume would > emphasise Python, given that Python was the RPi Foundation's first choice > for controlling the Pi. The RPi has helped to raise the profile of Python, > so hopefully this new device will add to that. > > I wonder what the other two languages are? I'd guess a C++ subset for > one, like the Arduino. Not sure about the other. HTML/Javascript is > becoming popular in education because it's the easiest way put shapes and > animation on the screen, but I don't think it's suited to an embedded > device. > http://www.bbc.co.uk/news/technology-31834927 says: """When it launches in September it will be compatible with three coding languages - Touch Develop, Python and C++.""" From ahicks at p-o.co.uk Sun Mar 15 13:06:50 2015 From: ahicks at p-o.co.uk (Alan Hicks) Date: Sun, 15 Mar 2015 17:06:50 +0000 Subject: Django-DMARC making it easier to manage DMARC reports - Beta 0.1.3 on PyPI In-Reply-To: References: <54FD72F8.3080706@p-o.co.uk> <55057927.9020502@p-o.co.uk> <550592C8.1030303@p-o.co.uk> Message-ID: <5505BC2A.5090108@p-o.co.uk> On 15/03/2015 15:52, Chris Angelico wrote: > On Mon, Mar 16, 2015 at 1:10 AM, Alan Hicks wrote: >> If issues are not surfacing it is more likely that both SPF and DKIM are not >> strong spam indicators rather than there are no issues. >> >> SPF is rarely implemented decisively ~all instead of -all so is not very >> strong. > > All of my domains end with -all, so that's not the distinction. With > SPF checking, the list software is what gets checked; my server might > send mail out with an envelope-from address of > "committee-bounces at gilbertandsullivan.org.au", which is a domain that > I control, and for which the SPF record specifies that my server is > allowed to send mail. So list mail is accepted. Can you do and > guarantee the same for DMARC? > > ChrisA > To deploy DMARC you need to deploy both SPF and DKIM. As I'm not part of either the standard or any of its implementations, guarantees are out of my scope. I'm only implementing DMARC on behalf of my organisation and as part of that offered django-dmarc in the hope it might help others with their implementation. If you set your DMARC policy to none then there will be no rejections due to dmarc. If you are interested in how your email is evaluated then as part of the policy you can receive daily reports. DMARC merely helps in co-ordinating DKIM and SPF. A DMARC policy allows a sender to indicate that their emails are protected by SPF and DKIM, and tells a receiver what to do if neither of those authentication methods passes. The benefit of implementing DMARC here at Persistent Objects is to receive reports on how mail from p-o.co.uk is evaluated. This is being used to guide policy as well as trace and fix edge cases so that our email can be relied upon. There's a good overview of how the parts fit together at http://dmarc.org/overview/ Some organisations have found it useful http://dmarc.org/2015/02/dmarc-is-a-proven-tool-in-the-fight-against-fraudulent-email/ Alan From jonas.thornvall at gmail.com Sun Mar 15 14:07:44 2015 From: jonas.thornvall at gmail.com (jonas.thornvall at gmail.com) Date: Sun, 15 Mar 2015 11:07:44 -0700 (PDT) Subject: More or less code in python? Message-ID: <8412cc81-fbd2-4590-9db3-12c65ba2ee35@googlegroups.com> From joel.goldstick at gmail.com Sun Mar 15 14:31:31 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sun, 15 Mar 2015 14:31:31 -0400 Subject: More or less code in python? In-Reply-To: <8412cc81-fbd2-4590-9db3-12c65ba2ee35@googlegroups.com> References: <8412cc81-fbd2-4590-9db3-12c65ba2ee35@googlegroups.com> Message-ID: On Sun, Mar 15, 2015 at 2:07 PM, wrote: > > -- > https://mail.python.org/mailman/listinfo/python-list I'm guessing less, if your question is whether this code would be fewer lines in python. However, it would be nice if you formatted it so that it is readable, and gave a description of what you think the code is doing, or should be doing. Its an odd question in that python generally runs on a server and javascript in a browser -- Joel Goldstick http://joelgoldstick.com From jonas.thornvall at gmail.com Sun Mar 15 14:56:24 2015 From: jonas.thornvall at gmail.com (jonas.thornvall at gmail.com) Date: Sun, 15 Mar 2015 11:56:24 -0700 (PDT) Subject: More or less code in python? In-Reply-To: References: <8412cc81-fbd2-4590-9db3-12c65ba2ee35@googlegroups.com> Message-ID: <1a02b56e-cce3-4485-9b13-bd801a65bd07@googlegroups.com> Den s?ndag 15 mars 2015 kl. 19:32:02 UTC+1 skrev Joel Goldstick: > On Sun, Mar 15, 2015 at 2:07 PM, wrote: > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > > I'm guessing less, if your question is whether this code would be > fewer lines in python. However, it would be nice if you formatted it > so that it is readable, and gave a description of what you think the > code is doing, or should be doing. Its an odd question in that python > generally runs on a server and javascript in a browser > > -- > Joel Goldstick > http://joelgoldstick.com It add two postive numbers working in any base you prefer. There is no restriction on the size of operands, it dependens upon the memory of your computer or string limitations in the implementation of ECMASCRIPT.(If there is). Basicly the function doing addition in Python shell, but you can chose base you work in. From jonas.thornvall at gmail.com Sun Mar 15 15:00:36 2015 From: jonas.thornvall at gmail.com (jonas.thornvall at gmail.com) Date: Sun, 15 Mar 2015 12:00:36 -0700 (PDT) Subject: More or less code in python? In-Reply-To: References: <8412cc81-fbd2-4590-9db3-12c65ba2ee35@googlegroups.com> Message-ID: <53b202e7-327b-412a-a5e0-debca5c3b489@googlegroups.com> Den s?ndag 15 mars 2015 kl. 19:32:02 UTC+1 skrev Joel Goldstick: > On Sun, Mar 15, 2015 at 2:07 PM, wrote: > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > > I'm guessing less, if your question is whether this code would be > fewer lines in python. However, it would be nice if you formatted it > so that it is readable, and gave a description of what you think the > code is doing, or should be doing. Its an odd question in that python > generally runs on a server and javascript in a browser > > -- > Joel Goldstick > http://joelgoldstick.com I though it would be interesting doing comparissons in timing adding massive digits in different bases. Especially in Python. From no.email at nospam.invalid Sun Mar 15 15:01:25 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 15 Mar 2015 12:01:25 -0700 Subject: More or less code in python? References: <8412cc81-fbd2-4590-9db3-12c65ba2ee35@googlegroups.com> <53b202e7-327b-412a-a5e0-debca5c3b489@googlegroups.com> Message-ID: <87h9tmt796.fsf@jester.gateway.sonic.net> jonas.thornvall at gmail.com writes: > I though it would be interesting doing comparissons in timing adding > massive digits in different bases. Especially in Python. Python has built-in bignums. Try "print 2**500". From jonas.thornvall at gmail.com Sun Mar 15 15:03:46 2015 From: jonas.thornvall at gmail.com (jonas.thornvall at gmail.com) Date: Sun, 15 Mar 2015 12:03:46 -0700 (PDT) Subject: More or less code in python? In-Reply-To: <87h9tmt796.fsf@jester.gateway.sonic.net> References: <8412cc81-fbd2-4590-9db3-12c65ba2ee35@googlegroups.com> <53b202e7-327b-412a-a5e0-debca5c3b489@googlegroups.com> <87h9tmt796.fsf@jester.gateway.sonic.net> Message-ID: Den s?ndag 15 mars 2015 kl. 20:01:36 UTC+1 skrev Paul Rubin: > jonas.thornvall at gmail.com writes: > > I though it would be interesting doing comparissons in timing adding > > massive digits in different bases. Especially in Python. > > Python has built-in bignums. Try "print 2**500". I know. From nagle at animats.com Sun Mar 15 15:05:21 2015 From: nagle at animats.com (John Nagle) Date: Sun, 15 Mar 2015 12:05:21 -0700 Subject: Python 2 to 3 conversion - embrace the pain In-Reply-To: <87vbi4ovp1.fsf@elektro.pacujo.net> References: <550351BF.5020108@animats.com> <87vbi4ovp1.fsf@elektro.pacujo.net> Message-ID: On 3/14/2015 1:00 AM, Marko Rauhamaa wrote: > John Nagle : >> I'm approaching the end of converting a large system from Python 2 >> to Python 3. Here's why you don't want to do this. > > A nice report, thanks. Shows that the slowness of Python 3 adoption is > not only social inertia. > Marko Thanks. Some of the bugs I listed are so easy to hit that I suspect those packages aren't used much. Those bugs should have been found years ago. Fixed, even. I shouldn't be discovering them in 2015. I appreciate all the effort put in by developers in fixing these problems. Python 3 is still a long way from being ready for prime time, though. John Nagle From jonas.thornvall at gmail.com Sun Mar 15 15:09:27 2015 From: jonas.thornvall at gmail.com (jonas.thornvall at gmail.com) Date: Sun, 15 Mar 2015 12:09:27 -0700 (PDT) Subject: More or less code in python? In-Reply-To: <87h9tmt796.fsf@jester.gateway.sonic.net> References: <8412cc81-fbd2-4590-9db3-12c65ba2ee35@googlegroups.com> <53b202e7-327b-412a-a5e0-debca5c3b489@googlegroups.com> <87h9tmt796.fsf@jester.gateway.sonic.net> Message-ID: Den s?ndag 15 mars 2015 kl. 20:01:36 UTC+1 skrev Paul Rubin: > jonas.thornvall at gmail.com writes: > > I though it would be interesting doing comparissons in timing adding > > massive digits in different bases. Especially in Python. > > Python has built-in bignums. Try "print 2**500". I will try implement the common operators + - * / pow sqrt operators mod floor and and a generic parser taking arguments in any base. From __peter__ at web.de Sun Mar 15 15:15:22 2015 From: __peter__ at web.de (Peter Otten) Date: Sun, 15 Mar 2015 20:15:22 +0100 Subject: More or less code in python? References: <8412cc81-fbd2-4590-9db3-12c65ba2ee35@googlegroups.com> Message-ID: jonas.thornvall at gmail.com wrote: >

IPDB Data Input Window

Address:{{ form.address }}
Filename:{{ form.filename }}

{{ form.box }}

Description:{{ form.description }}
Expiry date:{{ form.expiry }}

-------------------------------------------

IPDB Asset Input

{% if errors %}
    {% for error in errors %}
  • {{ error }}
  • {% endfor %}
{% endif %}
{% csrf_token %}
IP Address, Address Range, or FQDNSelect CSV file
       OR/AND            Rating: Neutral
Good
Bad


Source
Description

Assets to Submit

{% if err %}

    {% for e in err %}
  • {{ e }}
  • {% endfor %}
{% endif %} {% if msg %}

{{ msg }}

{% endif %}

-------------------------------------- {% block title %}{% endblock %}

IPDB Search

{% csrf_token %}

IP Address Search Query
Textual Search Query
{% if match_q %}

Search Results for: {{ match_q }}
{% else %}

Search Results
{% endif %}

     NAME       COUNTRY   RATING      DESCRIPTION

{% if nomatch_q %}

No matches found for: {{ nomatch_q }}

{% endif %} {% if err %}

  • {{ err }}
  • {% endif %}

    ------------------------------ From rosuav at gmail.com Tue Mar 24 23:04:26 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 Mar 2015 14:04:26 +1100 Subject: test1 In-Reply-To: <7edc4671-8f96-491a-be30-0ad3f2175e07@googlegroups.com> References: <7edc4671-8f96-491a-be30-0ad3f2175e07@googlegroups.com> Message-ID: On Wed, Mar 25, 2015 at 1:47 PM, Tiglath Suriol wrote: > {% block title %}{% endblock %} Looks to me like you're playing around with a templating system like Jinja, but may I suggest that you send tests to yourself rather than to an entire mailing list/newsgroup? :) ChrisA From tiglathsuriol at gmail.com Tue Mar 24 23:11:04 2015 From: tiglathsuriol at gmail.com (Tiglath Suriol) Date: Tue, 24 Mar 2015 20:11:04 -0700 (PDT) Subject: test2 Message-ID: # Django settings for ipdb project. DEBUG = True TEMPLATE_DEBUG = DEBUG ADMINS = ( # ('Your Name', 'your_email at example.com'), ('jol', 'tegijjjlath.net'), ('totis', 'tis at oint.com'), ) MANAGERS = ADMINS DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'ipdb_db', # Or path to database file if using sqlite3. 'USER': 'ipdb', # Not used with sqlite3. 'PASSWORD': 'admin', # Not used with sqlite3. 'HOST': 'localhost', # Set to empty string for localhost (NOT TRUE). Not used with sqlite3. 'PORT': '', # Set to empty string for default. Not used with sqlite3. } } PROJECT_PATH = '/var/opt/ipdb/ipdb/' # this dir contains 'ipdb' and 'manage.py' GEOIP_PATH = PROJECT_PATH + '/ipdb/asset/geo' AS_IPV4_PATH = PROJECT_PATH + '/ipdb/asset/geo/GeoIPASNum.dat' AS_IPV6_PATH = PROJECT_PATH + '/ipdb/asset/geo/GeoIPASNumv6.dat' RUN_DIR = PROJECT_PATH + '/ipdb/asset/run' LOCK_FILE = PROJECT_PATH + '/ipdb/asset/crawler.pid' # Local time zone for this installation. Choices can be found here: # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name # although not all choices may be available on all operating systems. # In a Windows environment this must be set to your system time zone. TIME_ZONE = 'America/Atikokan' # Language code for this installation. All choices can be found here: # http://www.i18nguy.com/unicode/language-identifiers.html LANGUAGE_CODE = 'en-us' SITE_ID = 1 # If you set this to False, Django will make some optimizations so as not # to load the internationalization machinery. USE_I18N = True # If you set this to False, Django will not format dates, numbers and # calendars according to the current locale. USE_L10N = True # If you set this to False, Django will not use timezone-aware datetimes. USE_TZ = True # Absolute filesystem path to the directory that will hold user-uploaded files. # Example: "/home/media/media.lawrence.com/media/" MEDIA_ROOT = PROJECT_PATH + '/ipdb/asset/media/' # URL that handles the media served from MEDIA_ROOT. Make sure to use a # trailing slash. # Examples: "http://media.lawrence.com/media/", "http://example.com/media/" MEDIA_URL = '/media/' # Absolute path to the directory static files should be collected to. # Don't put anything in this directory yourself; store your static files # in apps' "static/" subdirectories and in STATICFILES_DIRS. # Example: "/home/media/media.lawrence.com/static/" STATIC_ROOT = PROJECT_PATH + '/ipdb/asset/static/' # # Temporary client files. # FILE_UPLOAD_DIR = '/tmp/' LOG_DIR = PROJECT_PATH + '/ipdb/asset/log/' # URL prefix for static files. # Example: "http://media.lawrence.com/static/" STATIC_URL = '/static/' # Additional locations of static files STATICFILES_DIRS = ( # Put strings here, like "/home/html/static" or "C:/www/django/static". # Always use forward slashes, even on Windows. # Don't forget to use absolute paths, not relative paths. ) # List of finder classes that know how to find static files in # various locations. STATICFILES_FINDERS = ( 'django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder', # 'django.contrib.staticfiles.finders.DefaultStorageFinder', ) # Make this unique, and don't share it with anybody. SECRET_KEY = '42=kv!a-il*!4j&7v+0(@a at vq_3j-+ysatta@l6-h63odj2)75' # List of callables that know how to import templates from various sources. TEMPLATE_LOADERS = ( 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', # 'django.template.loaders.eggs.Loader', ) MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', # Uncomment the next line for simple clickjacking protection: # 'django.middleware.clickjacking.XFrameOptionsMiddleware', ) CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache', 'LOCATION': '127.0.0.1:11211', } } SESSION_ENGINE = 'django.contrib.sessions.backends.cache' ROOT_URLCONF = 'ipdb.urls' # Python dotted path to the WSGI application used by Django's runserver. WSGI_APPLICATION = 'ipdb.wsgi.application' TEMPLATE_DIRS = ( # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". # Always use forward slashes, even on Windows. # Don't forget to use absolute paths, not relative paths. PROJECT_PATH + '/ipdb/asset/templates', # Change this to your own directory. ) INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', # Uncomment the next line to enable the admin: 'django.contrib.admin', # Uncomment the next line to enable admin documentation: 'django.contrib.admindocs', 'django.contrib.flatpages', 'ipdb.asset', 'registration', ) # # Send logs to the console and to a file. # LOGGING = { 'version': 1, 'disable_existing_loggers': True, 'formatters': { 'standard': { 'format' : "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s", 'datefmt' : "%d/%b/%Y %H:%M:%S" }, }, 'handlers': { 'null': { 'level':'DEBUG', 'class':'django.utils.log.NullHandler', }, 'logfile': { 'level':'DEBUG', 'class':'logging.handlers.RotatingFileHandler', 'filename': LOG_DIR + "/ipdb.log", 'maxBytes': 50000, 'backupCount': 2, 'formatter': 'standard', }, 'console':{ 'level':'DEBUG', 'class':'logging.StreamHandler', 'formatter': 'standard' }, }, 'loggers': { 'django': { 'handlers':['console'], 'propagate': True, 'level':'DEBUG', }, 'django.db.backends': { 'handlers': ['console'], 'level': 'DEBUG', 'propagate': False, }#from django.conf.urls.defaults import patterns, include, url from django.conf import * from django.conf.urls.static import static from django.views.static import serve from django.conf.urls import * #from ip_db.views import ipdb_input_add, ipdb_input_start, ipdb_input_delete, ipdb_input_save, ipdb_api_add, ipdb_api_search from asset.views import api_add, api_search, gui_search, gui_add, ipdb_overview, api_file from asset.utils.elastic_func import country_tally, grid, newest_to_oldest, country_tally_web_top10, country_tally_web, asset_tally from django.http import HttpResponsePermanentRedirect from django.shortcuts import render_to_response from django.contrib import admin admin.autodiscover() import os PROJECT_PATH = os.path.realpath(os.path.dirname(__file__)) # Uncomment the next two lines to enable the admin: from django.contrib import admin admin.autodiscover() urlpatterns = patterns('asset.views', # Examples: # url(r'^$', 'ipdb.views.home', name='home'), # url(r'^ipdb/', include('ipdb.foo.urls')), # Uncomment the admin/doc line below to enable admin documentation: # Uncomment the next line to enable the admin: url(r'^admin/', include(admin.site.urls)), #(r'^accounts/', include('registration.urls')), (r'^$', lambda request: HttpResponsePermanentRedirect('/asset/overview')), (r'^heatmap/', country_tally), (r'^grid/',grid), (r'^nto/',newest_to_oldest), (r'^ctwtt/',country_tally_web_top10), (r'^ctw/',country_tally_web), (r'^at/',asset_tally), #(r'^/$', ipdb_overview), #Start #(r'^$', ipdb_overview), #Start (r'^asset/overview/$', ipdb_overview), #Start (r'^input/$', gui_add), (r'^search/$', gui_search), (r'^search$', gui_search), # (r'^delete/$', ipdb_input_delete), (r'^api/add/$', api_add), #check sensornet urls.py and views/sensors.py for cool tricks. (r'^api/search/$', api_search), #check sensornet urls.py and views/sensors.py for cool tricks. (r'^api/file/$', api_file), #(r'^asset/media/(?P.*)$', 'django.views.static.serve', {'document_root': os.path.join(PROJECT_PATH, '../asset/media')}), #(r'^ip_db/media/(?P.*)$', 'django.views.static.serve', {'document_root': os.path.join(PROJECT_PATH, 'ip_db/media')}), #(r'^media/(?P.*)$', 'django.views.static.serve', {'document_root': os.path.join(PROJECT_PATH, 'media')}), #(r'^static/(?P.*)$', 'django.views.static.serve', {'document_root': '/home/sensornet/static'}), # extjs4 stuff #(r'^asset/overview/extjs/(?P.*)$', 'serve', {'document_root': os.path.join(PROJECT_PATH, '../asset/extjs')}), #(r'^extjs/(?P.*)$', 'django.views.static.serve', {'document_root': os.path.join(PROJECT_PATH, '../ip_db/extjs')}), #(r'^extjs/(?P.*)$', 'django.views.static.serve', {'document_root': '/home/totis/tree/ipdb/django/ipdb/asset/static/extjs'}), ) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT), 'ipdb.asset': { 'handlers': ['console', 'logfile'], 'level': 'DEBUG', }, } } =========== From otaksoftspamtrap at gmail.com Tue Mar 24 23:13:56 2015 From: otaksoftspamtrap at gmail.com (otaksoftspamtrap at gmail.com) Date: Tue, 24 Mar 2015 20:13:56 -0700 (PDT) Subject: Newbie looking for elegant solution Message-ID: I have a list containing 9600 integer elements - each integer is either 0 or 1. Starting at the front of the list, I need to combine 8 list elements into 1 by treating them as if they were bits of one byte with 1 and 0 denoting bit on/off (the 8th element would be the rightmost bit of the first byte). The end result should be a new list that is 8 x shorter than the original list containing integers between 0 and 255. Speed is not of utmost importance - an elegant solution is. Any suggestions? Thanks for all input, Kai From rosuav at gmail.com Tue Mar 24 23:22:23 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 Mar 2015 14:22:23 +1100 Subject: test2 In-Reply-To: References: Message-ID: On Wed, Mar 25, 2015 at 2:11 PM, Tiglath Suriol wrote: > # Make this unique, and don't share it with anybody. > SECRET_KEY = '42=kv!a-il*!4j&7v+0(@a at vq_3j-+ysatta@l6-h63odj2)75' This right here is a reason to send your test messages someplace other than a huge, high-traffic mailing list! ChrisA From rosuav at gmail.com Tue Mar 24 23:28:13 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 Mar 2015 14:28:13 +1100 Subject: Newbie looking for elegant solution In-Reply-To: References: Message-ID: On Wed, Mar 25, 2015 at 2:13 PM, wrote: > I have a list containing 9600 integer elements - each integer is either 0 or 1. > > Starting at the front of the list, I need to combine 8 list elements into 1 by treating them as if they were bits of one byte with 1 and 0 denoting bit on/off (the 8th element would be the rightmost bit of the first byte). > > Speed is not of utmost importance - an elegant solution is. Any suggestions? Oooh fun! >>> l = [1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1] >>> list(int(''.join(str(i) for i in l),2).to_bytes(len(l)//8,'big')) [177, 105, 117] Convert it into a string, convert the string to an integer (interpreting it as binary), then convert the integer into a series of bytes, and interpret those bytes as a list of integers. Example works in Python 3. For Python 2, you'll need ord() to get the integers at the end. I'm not sure how elegant this is, but it's a fun trick to play with :) Next idea please! I love these kinds of threads. ChrisA From otaksoftspamtrap at gmail.com Tue Mar 24 23:31:21 2015 From: otaksoftspamtrap at gmail.com (otaksoftspamtrap at gmail.com) Date: Tue, 24 Mar 2015 20:31:21 -0700 (PDT) Subject: Newbie looking for elegant solution In-Reply-To: References: Message-ID: <9ed2a38f-412c-400e-854a-3ed4d1f86ea0@googlegroups.com> On Tuesday, March 24, 2015 at 8:29:24 PM UTC-7, Chris Angelico wrote: > On Wed, Mar 25, 2015 at 2:13 PM, wrote: > > I have a list containing 9600 integer elements - each integer is either 0 or 1. > > > > Starting at the front of the list, I need to combine 8 list elements into 1 by treating them as if they were bits of one byte with 1 and 0 denoting bit on/off (the 8th element would be the rightmost bit of the first byte). > > > > Speed is not of utmost importance - an elegant solution is. Any suggestions? > > Oooh fun! > > >>> l = [1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1] > >>> list(int(''.join(str(i) for i in l),2).to_bytes(len(l)//8,'big')) > [177, 105, 117] > > Convert it into a string, convert the string to an integer > (interpreting it as binary), then convert the integer into a series of > bytes, and interpret those bytes as a list of integers. > > Example works in Python 3. For Python 2, you'll need ord() to get the > integers at the end. > > I'm not sure how elegant this is, but it's a fun trick to play with :) > > Next idea please! I love these kinds of threads. > > ChrisA Impressive - thanks! From no.email at nospam.invalid Wed Mar 25 00:04:10 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 24 Mar 2015 21:04:10 -0700 Subject: Newbie looking for elegant solution References: Message-ID: <874mp97mf9.fsf@jester.gateway.sonic.net> otaksoftspamtrap at gmail.com writes: > I have a list containing 9600 integer elements - each integer is > either 0 or 1. Is that a homework problem? This works for me in Python 2.7 but I think Python 3 gratuitously broke tuple unpacking so it won't work there: ================================================================ from itertools import count, groupby old = [0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1] new = [reduce(lambda x,(y,i):x*2+y, g, 0) for k,g in groupby(zip(old,count()), lambda (a,b): b//8)] print new >>> [18, 222, 53] ================================================================ From kai.peters at gmail.com Wed Mar 25 00:19:06 2015 From: kai.peters at gmail.com (kai.peters at gmail.com) Date: Tue, 24 Mar 2015 21:19:06 -0700 (PDT) Subject: Newbie looking for elegant solution In-Reply-To: <874mp97mf9.fsf@jester.gateway.sonic.net> References: <874mp97mf9.fsf@jester.gateway.sonic.net> Message-ID: <65ed9f2b-a2d7-485b-95cc-e2cbc13045e5@googlegroups.com> On Tuesday, 24 March 2015 21:04:37 UTC-7, Paul Rubin wrote: > nobody writes: > > I have a list containing 9600 integer elements - each integer is > > either 0 or 1. > > Is that a homework problem? This works for me in Python 2.7 but I think > Python 3 gratuitously broke tuple unpacking so it won't work there: > > ================================================================ > > from itertools import count, groupby > old = [0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1] > new = [reduce(lambda x,(y,i):x*2+y, g, 0) > for k,g in groupby(zip(old,count()), lambda (a,b): b//8)] > print new > > >>> [18, 222, 53] > ================================================================ no homework - real life. thanks for your contribution From rosuav at gmail.com Wed Mar 25 00:19:55 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 Mar 2015 15:19:55 +1100 Subject: Newbie looking for elegant solution In-Reply-To: <874mp97mf9.fsf@jester.gateway.sonic.net> References: <874mp97mf9.fsf@jester.gateway.sonic.net> Message-ID: On Wed, Mar 25, 2015 at 3:04 PM, Paul Rubin wrote: > This works for me in Python 2.7 but I think > Python 3 gratuitously broke tuple unpacking so it won't work there: > > ================================================================ > > from itertools import count, groupby > old = [0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1] > new = [reduce(lambda x,(y,i):x*2+y, g, 0) > for k,g in groupby(zip(old,count()), lambda (a,b): b//8)] > print new > >>>> [18, 222, 53] > ================================================================ You don't need tuple unpacking. Here's the Py3 version of the above: from functools import reduce new = [reduce(lambda x,y:x*2+y[0], g, 0) for k,g in groupby(zip(old,count()), lambda a: a[1]//8)] ChrisA From kai.peters at gmail.com Wed Mar 25 00:46:23 2015 From: kai.peters at gmail.com (kai.peters at gmail.com) Date: Tue, 24 Mar 2015 21:46:23 -0700 (PDT) Subject: Newbie looking for elegant solution In-Reply-To: References: <874mp97mf9.fsf@jester.gateway.sonic.net> Message-ID: <0e0fbfec-0265-490b-9300-d2c1f2bb4391@googlegroups.com> On Tuesday, 24 March 2015 21:20:11 UTC-7, Chris Angelico wrote: > On Wed, Mar 25, 2015 at 3:04 PM, Paul Rubin wrote: > > This works for me in Python 2.7 but I think > > Python 3 gratuitously broke tuple unpacking so it won't work there: > > > > ================================================================ > > > > from itertools import count, groupby > > old = [0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1] > > new = [reduce(lambda x,(y,i):x*2+y, g, 0) > > for k,g in groupby(zip(old,count()), lambda (a,b): b//8)] > > print new > > > >>>> [18, 222, 53] > > ================================================================ > > You don't need tuple unpacking. Here's the Py3 version of the above: > > from functools import reduce > new = [reduce(lambda x,y:x*2+y[0], g, 0) > for k,g in groupby(zip(old,count()), lambda a: a[1]//8)] > > ChrisA Now I have just read the latest spec and speed/memory may become issues: 1 bit images of a size of 1024 x 1280 need to be processed this way, so 1310720 list elements. Also needs to be 2.7 only. Any recommendations? From ryan.stuart.85 at gmail.com Wed Mar 25 00:55:36 2015 From: ryan.stuart.85 at gmail.com (Ryan Stuart) Date: Wed, 25 Mar 2015 14:55:36 +1000 Subject: test2 In-Reply-To: References: Message-ID: On Wed, Mar 25, 2015 at 1:11 PM, Tiglath Suriol wrote: > # Make this unique, and don't share it with anybody. > ....... > SECRET_KEY = '42=kv!a-il*!4j&7v+0(@a at vq_3j-+ysatta@l6-h63odj2)75' > > # List of callables that know how to import templates from various sources. > TEMPLATE_LOADERS = ( > 'django.template.loaders.filesystem.Loader', > 'django.template.loaders.app_directories.Loader', > # 'django.template.loaders.eggs.Loader', > ) > > MIDDLEWARE_CLASSES = ( > 'django.middleware.common.CommonMiddleware', > 'django.middleware.csrf.CsrfViewMiddleware', > 'django.contrib.sessions.middleware.SessionMiddleware', > 'django.contrib.auth.middleware.AuthenticationMiddleware', > 'django.contrib.messages.middleware.MessageMiddleware', > # Uncomment the next line for simple clickjacking protection: > # 'django.middleware.clickjacking.XFrameOptionsMiddleware', > ) > > CACHES = { > 'default': { > 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache', > 'LOCATION': '127.0.0.1:11211', > } > } > > SESSION_ENGINE = 'django.contrib.sessions.backends.cache' > > ROOT_URLCONF = 'ipdb.urls' > > # Python dotted path to the WSGI application used by Django's runserver. > WSGI_APPLICATION = 'ipdb.wsgi.application' > > TEMPLATE_DIRS = ( > # Put strings here, like "/home/html/django_templates" or > "C:/www/django/templates". > # Always use forward slashes, even on Windows. > # Don't forget to use absolute paths, not relative paths. > PROJECT_PATH + '/ipdb/asset/templates', # Change this to your own > directory. > ) > > INSTALLED_APPS = ( > 'django.contrib.auth', > 'django.contrib.contenttypes', > 'django.contrib.sessions', > 'django.contrib.sites', > 'django.contrib.messages', > 'django.contrib.staticfiles', > # Uncomment the next line to enable the admin: > 'django.contrib.admin', > # Uncomment the next line to enable admin documentation: > 'django.contrib.admindocs', > 'django.contrib.flatpages', > 'ipdb.asset', > 'registration', > ) > > # > # Send logs to the console and to a file. > # > LOGGING = { > 'version': 1, > 'disable_existing_loggers': True, > 'formatters': { > 'standard': { > 'format' : "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] > %(message)s", > 'datefmt' : "%d/%b/%Y %H:%M:%S" > }, > }, > 'handlers': { > 'null': { > 'level':'DEBUG', > 'class':'django.utils.log.NullHandler', > }, > 'logfile': { > 'level':'DEBUG', > 'class':'logging.handlers.RotatingFileHandler', > 'filename': LOG_DIR + "/ipdb.log", > 'maxBytes': 50000, > 'backupCount': 2, > 'formatter': 'standard', > }, > 'console':{ > 'level':'DEBUG', > 'class':'logging.StreamHandler', > 'formatter': 'standard' > }, > }, > 'loggers': { > 'django': { > 'handlers':['console'], > 'propagate': True, > 'level':'DEBUG', > }, > 'django.db.backends': { > 'handlers': ['console'], > 'level': 'DEBUG', > 'propagate': False, > }#from django.conf.urls.defaults import patterns, include, url > from django.conf import * > from django.conf.urls.static import static > from django.views.static import serve > from django.conf.urls import * > #from ip_db.views import ipdb_input_add, ipdb_input_start, > ipdb_input_delete, ipdb_input_save, ipdb_api_add, ipdb_api_search > from asset.views import api_add, api_search, gui_search, gui_add, > ipdb_overview, api_file > from asset.utils.elastic_func import country_tally, grid, > newest_to_oldest, country_tally_web_top10, country_tally_web, asset_tally > from django.http import HttpResponsePermanentRedirect > from django.shortcuts import render_to_response > from django.contrib import admin > admin.autodiscover() > > import os > > PROJECT_PATH = os.path.realpath(os.path.dirname(__file__)) > > # Uncomment the next two lines to enable the admin: > from django.contrib import admin > admin.autodiscover() > > urlpatterns = patterns('asset.views', > # Examples: > # url(r'^$', 'ipdb.views.home', name='home'), > # url(r'^ipdb/', include('ipdb.foo.urls')), > > # Uncomment the admin/doc line below to enable admin documentation: > > # Uncomment the next line to enable the admin: > url(r'^admin/', include(admin.site.urls)), > #(r'^accounts/', include('registration.urls')), > (r'^$', lambda request: > HttpResponsePermanentRedirect('/asset/overview')), > (r'^heatmap/', country_tally), > (r'^grid/',grid), > (r'^nto/',newest_to_oldest), > (r'^ctwtt/',country_tally_web_top10), > (r'^ctw/',country_tally_web), > (r'^at/',asset_tally), > > #(r'^/$', ipdb_overview), #Start > #(r'^$', ipdb_overview), #Start > (r'^asset/overview/$', ipdb_overview), #Start > (r'^input/$', gui_add), > (r'^search/$', gui_search), > (r'^search$', gui_search), > # (r'^delete/$', ipdb_input_delete), > (r'^api/add/$', api_add), #check sensornet urls.py and > views/sensors.py for cool tricks. > (r'^api/search/$', api_search), #check sensornet urls.py and > views/sensors.py for cool tricks. > (r'^api/file/$', api_file), > > #(r'^asset/media/(?P.*)$', 'django.views.static.serve', > {'document_root': os.path.join(PROJECT_PATH, '../asset/media')}), > > #(r'^ip_db/media/(?P.*)$', 'django.views.static.serve', > {'document_root': os.path.join(PROJECT_PATH, 'ip_db/media')}), > #(r'^media/(?P.*)$', 'django.views.static.serve', > {'document_root': os.path.join(PROJECT_PATH, 'media')}), > #(r'^static/(?P.*)$', 'django.views.static.serve', > {'document_root': '/home/sensornet/static'}), > > # extjs4 stuff > #(r'^asset/overview/extjs/(?P.*)$', 'serve', {'document_root': > os.path.join(PROJECT_PATH, '../asset/extjs')}), > #(r'^extjs/(?P.*)$', 'django.views.static.serve', > {'document_root': os.path.join(PROJECT_PATH, '../ip_db/extjs')}), > #(r'^extjs/(?P.*)$', 'django.views.static.serve', > {'document_root': '/home/totis/tree/ipdb/django/ipdb/asset/static/extjs'}), > ) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT), > 'ipdb.asset': { > 'handlers': ['console', 'logfile'], > 'level': 'DEBUG', > }, > } > } > > =========== > > > > -- > https://mail.python.org/mailman/listinfo/python-list > -- Ryan Stuart, B.Eng Software Engineer ABN: 81-206-082-133 W: http://www.textisbeautiful.net/ M: +61-431-299-036 -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Wed Mar 25 00:59:03 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 25 Mar 2015 15:59:03 +1100 Subject: test2 References: Message-ID: <5512409a$0$12916$c3e8da3$5496439d@news.astraweb.com> On Wednesday 25 March 2015 14:11, Tiglath Suriol wrote: > # Make this unique, and don't share it with anybody. > SECRET_KEY = '42=kv!a-il*!4j&7v+0(@a at vq_3j-+ysatta@l6-h63odj2)75' You'll need to change the comment to say "don't share it with anybody unless they have an internet connection." -- Steven From rosuav at gmail.com Wed Mar 25 01:05:05 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 Mar 2015 16:05:05 +1100 Subject: Newbie looking for elegant solution In-Reply-To: <0e0fbfec-0265-490b-9300-d2c1f2bb4391@googlegroups.com> References: <874mp97mf9.fsf@jester.gateway.sonic.net> <0e0fbfec-0265-490b-9300-d2c1f2bb4391@googlegroups.com> Message-ID: On Wed, Mar 25, 2015 at 3:46 PM, wrote: > Now I have just read the latest spec and speed/memory may become issues: > > 1 bit images of a size of 1024 x 1280 need to be processed this way, so > 1310720 list elements. Also needs to be 2.7 only. > > Any recommendations? 2.7 only? Then my solution won't work (I just tried to port it, and integers don't have to_bytes). Paul's solution works. Here's an alternative: >>> import numpy >>> list(numpy.packbits(numpy.array(l),-1)) [177, 105, 117] Of course, this does mean installing numpy. It is crushing the nut with the triphammer - an absurd extravagance of energy, but the nut is effectively crushed all the same. ChrisA From steve+comp.lang.python at pearwood.info Wed Mar 25 01:24:59 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 25 Mar 2015 16:24:59 +1100 Subject: Newbie looking for elegant solution References: Message-ID: <551246ad$0$2831$c3e8da3$76491128@news.astraweb.com> On Wednesday 25 March 2015 14:13, otaksoftspamtrap at gmail.com wrote: > I have a list containing 9600 integer elements - each integer is either 0 > or 1. > > Starting at the front of the list, I need to combine 8 list elements into > 1 by treating them as if they were bits of one byte with 1 and 0 denoting > bit on/off (the 8th element would be the rightmost bit of the first byte). > > The end result should be a new list that is 8 x shorter than the original > list containing integers between 0 and 255. > > Speed is not of utmost importance - an elegant solution is. Any > suggestions? Collate the list into groups of 8. Here, I pad the list with zeroes at the end. If you prefer to drop any excess bits instead of padding them, use itertools.izip instead of izip_longest. import itertools mylist = [1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1] grouped = itertools.izip_longest(*([iter(mylist)]*8), fillvalue=0) Now convert each group of eight into a byte: def byte(bits): n = 0 for b in bits: assert b in (0, 1) n = n*2 + b return n [byte(x) for x in grouped] Or if you prefer using built-ins: [int(''.join(str(b) for b in x), 2) for x in grouped] I have no idea which will be faster. Exercise for the reader: izip will drop any bits that don't make up an octet. izip_longest will pad with zeroes on the least-significant side, e.g. [1, 1] -> 192. How to pad on the most-significant side, or equivalently, don't pad at all, so that [1, 1] -> 3? -- Steve From ben+python at benfinney.id.au Wed Mar 25 01:28:35 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 25 Mar 2015 16:28:35 +1100 Subject: Newbie looking for elegant solution References: <874mp97mf9.fsf@jester.gateway.sonic.net> <0e0fbfec-0265-490b-9300-d2c1f2bb4391@googlegroups.com> Message-ID: <851tkd7iik.fsf@benfinney.id.au> Chris Angelico writes: > Of course, this does mean installing numpy. It is crushing the nut > with the triphammer - an absurd extravagance of energy, but the nut is > effectively crushed all the same. It also has the advantage that it hopefully won't be acceptable for a homework assignment. Whether homework assignment or not, the original poster is well advised to try the problem themselves, and present their code for us to discuss. -- \ ?Skepticism is the highest duty and blind faith the one | `\ unpardonable sin.? ?Thomas Henry Huxley, _Essays on | _o__) Controversial Questions_, 1889 | Ben Finney From no.email at nospam.invalid Wed Mar 25 01:52:54 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 24 Mar 2015 22:52:54 -0700 Subject: Newbie looking for elegant solution References: <874mp97mf9.fsf@jester.gateway.sonic.net> <0e0fbfec-0265-490b-9300-d2c1f2bb4391@googlegroups.com> Message-ID: <87wq2562tl.fsf@jester.gateway.sonic.net> kai.peters at gmail.com writes: > 1 bit images of a size of 1024 x 1280 need to be processed this way, > so 1310720 list elements. Also needs to be 2.7 only. Where are these lists going to come from? Files? Process the file differently, probably. Use generators instead of lists, maybe. Or process one scan line at a time instead of the whole image. Or something. Basically your plan and your question seem kind of naive. If you can describe the ACTUAL application, you might be able to get some better answers. E.g. if it's image conversion, maybe there's an existing tool for the formats you want. How many of these images do you want to process? If just a few, who cares if it takes a little while? If a lot, think about writing a C program. From DaveFarrance at OMiTTHiSyahooANDTHiS.co.uk Wed Mar 25 02:05:45 2015 From: DaveFarrance at OMiTTHiSyahooANDTHiS.co.uk (Dave Farrance) Date: Wed, 25 Mar 2015 06:05:45 +0000 Subject: Newbie looking for elegant solution References: Message-ID: <7kj4haheo8ui8avf1lpt7in9g743qn4er3@4ax.com> otaksoftspamtrap at gmail.com wrote: >I have a list containing 9600 integer elements - each integer is either 0 or 1. >Starting at the front of the list, I need to combine 8 list elements into 1 by treating them as if they were bits of one byte with 1 and 0 denoting bit on/off (the 8th element would be the rightmost bit of the first byte). >The end result should be a new list that is 8 x shorter than the original list containing integers between 0 and 255. >Speed is not of utmost importance - an elegant solution is. Any suggestions? >Thanks for all input, Here's another way. Works in Python 2 and 3. >>> x = [1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1] >>> [int(''.join( str(y) for y in x[z:z+8]),2) for z in range(0, len(x), 8)] [177, 105, 117] From rustompmody at gmail.com Wed Mar 25 02:32:54 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 24 Mar 2015 23:32:54 -0700 (PDT) Subject: Newbie looking for elegant solution In-Reply-To: <87wq2562tl.fsf@jester.gateway.sonic.net> References: <874mp97mf9.fsf@jester.gateway.sonic.net> <0e0fbfec-0265-490b-9300-d2c1f2bb4391@googlegroups.com> <87wq2562tl.fsf@jester.gateway.sonic.net> Message-ID: On Wednesday, March 25, 2015 at 11:23:08 AM UTC+5:30, Paul Rubin wrote: > kai.peters writes > > 1 bit images of a size of 1024 x 1280 need to be processed this way, > > so 1310720 list elements. Also needs to be 2.7 only. > > Where are these lists going to come from? Files? Process the file > differently, probably. Use generators instead of lists, maybe. Some C-ish solutions and then two loop-unrollings: def foo(lst): i = 0 while i < len(lst): acc = 0 for j in range(8): acc = 2*acc+lst[i] i += 1 yield acc def bar(lst): i = 0 while i < len(lst): acc = 0 acc = 2*acc+lst[i] acc = 2*acc+lst[i+1] acc = 2*acc+lst[i+2] acc = 2*acc+lst[i+3] acc = 2*acc+lst[i+4] acc = 2*acc+lst[i+5] acc = 2*acc+lst[i+6] acc = 2*acc+lst[i+7] i += 8 yield acc def baz(lst): i = 0 while i < len(lst): acc = (128*lst[i] + 64*lst[i+1] + 32*lst[i+2] + 16*lst[i+3] + 8*lst[i+4] + 4*lst[i+5] + 2*lst[i+6] + lst[i+7]) i += 8 yield acc From rosuav at gmail.com Wed Mar 25 04:56:16 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 Mar 2015 19:56:16 +1100 Subject: Daylight savings time question In-Reply-To: <5511F0BD.1010504@oddbird.net> References: <5511F0BD.1010504@oddbird.net> Message-ID: On Wed, Mar 25, 2015 at 10:18 AM, Carl Meyer wrote: > US/Pacific is an alias for America/Los_Angeles, and is also part of the > Olson database (though I guess it's considered an "old" name for the > timezone): https://github.com/eggert/tz/blob/master/backward Ah, okay. No problem then. If it works, it works. ChrisA From marko at pacujo.net Wed Mar 25 07:39:26 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 25 Mar 2015 13:39:26 +0200 Subject: Sudoku solver Message-ID: <87r3sdnw5t.fsf@elektro.pacujo.net> A lot of discussion was generated by the good, old fibonacci sequence. I have yet to find practical use for fibonacci numbers. However, the technique behind a sudoku solver come up every now and again in practical situations. I post below a sudoku solver. I eagerly await neater implementations (as well as bug reports). Usage: ======================================================================== ./sudoku.py References: <55120eed$0$13001$c3e8da3$5496439d@news.astraweb.com> Message-ID: From: "Steven D'Aprano" > On Tue, 24 Mar 2015 11:32 pm, alister wrote: > >> On Tue, 24 Mar 2015 00:05:46 -0700, jeffreyciross wrote: > [off-topic spam] >> >> Calibre does a very god job as well. > > Please don't reply to spam. Unless the product is a Python library, or is > given in direct reply to an explicit request for an application which is > usable by Python, it is off-topic and spam. > > I see Calibre is a Python application, not sure if it is importable by > Python scripts though. > > Thank you, > Exactly and this is the 2cnd SourceForge project spam post in the last few days. In fact, the two URLs are the same but posted with two different projects descriptions. Subjects: "To Change A Pdf Ebook To Kindle" and "convert pdf to excel xls file " both point to... sourceforge.net/projects/pdftoexcelconverter They must be treated as spam. abuse at sourceforge.net -- Dave Multi-AV Scanning Tool - http://multi-av.thespykiller.co.uk http://www.pctipp.ch/downloads/dl/35905.asp From larry.martell at gmail.com Wed Mar 25 10:20:41 2015 From: larry.martell at gmail.com (Larry Martell) Date: Wed, 25 Mar 2015 08:20:41 -0600 Subject: Python 2.7 issue with decimal value 0.0 Message-ID: I have an app that works with 2.6, but in 2.7 it is failing. I traced it down to an issue with decimal.Decimal being passed a value of 0.0. It 2.6 this is fine, but in 2.7 it throws an exception: TypeError: Cannot convert float to Decimal. First convert the float to a string This is easy enough to deal with, but I find it odd. Is this a known issue? From invalid at invalid.invalid Wed Mar 25 10:26:26 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 25 Mar 2015 14:26:26 +0000 (UTC) Subject: Python 2.7 issue with decimal value 0.0 References: Message-ID: On 2015-03-25, Larry Martell wrote: > I have an app that works with 2.6, but in 2.7 it is failing. I traced > it down to an issue with decimal.Decimal being passed a value of 0.0. > It 2.6 this is fine, but in 2.7 it throws an exception: > > TypeError: Cannot convert float to Decimal. First convert the float to a string > > This is easy enough to deal with, but I find it odd. Is this a known issue? $ python Python 2.7.9 (default, Jan 2 2015, 09:51:10) [GCC 4.8.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import decimal >>> decimal.Decimal(0) Decimal('0') >>> decimal.Decimal(0.0) Decimal('0') >>> decimal.Decimal('0') Decimal('0') >>> -- Grant Edwards grant.b.edwards Yow! Half a mind is a at terrible thing to waste! gmail.com From oscar.j.benjamin at gmail.com Wed Mar 25 10:29:38 2015 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 25 Mar 2015 14:29:38 +0000 Subject: Python 2.7 issue with decimal value 0.0 In-Reply-To: References: Message-ID: On 25 March 2015 at 14:20, Larry Martell wrote: > I have an app that works with 2.6, but in 2.7 it is failing. I traced > it down to an issue with decimal.Decimal being passed a value of 0.0. > It 2.6 this is fine, but in 2.7 it throws an exception: > > TypeError: Cannot convert float to Decimal. First convert the float to a string > > This is easy enough to deal with, but I find it odd. Is this a known issue? Perhaps I've misunderstood but decimal.Decimal(0.0) works fine here: $ python2.7 Python 2.7.3 (default, Dec 18 2014, 19:10:20) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import decimal >>> decimal.Decimal(0.0) Decimal('0') Oscar From larry.martell at gmail.com Wed Mar 25 10:36:07 2015 From: larry.martell at gmail.com (Larry Martell) Date: Wed, 25 Mar 2015 08:36:07 -0600 Subject: Python 2.7 issue with decimal value 0.0 In-Reply-To: References: Message-ID: On Wed, Mar 25, 2015 at 8:26 AM, Grant Edwards wrote: > On 2015-03-25, Larry Martell wrote: >> I have an app that works with 2.6, but in 2.7 it is failing. I traced >> it down to an issue with decimal.Decimal being passed a value of 0.0. >> It 2.6 this is fine, but in 2.7 it throws an exception: >> >> TypeError: Cannot convert float to Decimal. First convert the float to a string >> >> This is easy enough to deal with, but I find it odd. Is this a known issue? > > $ python > Python 2.7.9 (default, Jan 2 2015, 09:51:10) > [GCC 4.8.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import decimal >>>> decimal.Decimal(0) > Decimal('0') >>>> decimal.Decimal(0.0) > Decimal('0') >>>> decimal.Decimal('0') I'm sorry, I missed typed. It works in 2.7, but not in 2.6: ]$ python Python 2.6.6 (r266:84292, Jan 22 2014, 09:42:36) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import decimal >>> decimal.Decimal(0.0) Traceback (most recent call last): File "", line 1, in File "/usr/lib64/python2.6/decimal.py", line 649, in __new__ "First convert the float to a string") TypeError: Cannot convert float to Decimal. First convert the float to a string From mail at timgolden.me.uk Wed Mar 25 10:37:51 2015 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 25 Mar 2015 14:37:51 +0000 Subject: Python 2.7 issue with decimal value 0.0 In-Reply-To: References: Message-ID: <5512C83F.3060205@timgolden.me.uk> On 25/03/2015 14:29, Oscar Benjamin wrote: > On 25 March 2015 at 14:20, Larry Martell wrote: >> I have an app that works with 2.6, but in 2.7 it is failing. I traced >> it down to an issue with decimal.Decimal being passed a value of 0.0. >> It 2.6 this is fine, but in 2.7 it throws an exception: >> >> TypeError: Cannot convert float to Decimal. First convert the float to a string >> >> This is easy enough to deal with, but I find it odd. Is this a known issue? > > Perhaps I've misunderstood but decimal.Decimal(0.0) works fine here: > > $ python2.7 > Python 2.7.3 (default, Dec 18 2014, 19:10:20) > [GCC 4.6.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import decimal >>>> decimal.Decimal(0.0) > Decimal('0') I suspect the OP is confusing himself a little: the ability to create a Decimal object directly from a float/int was added in 2.7. In 2.6 you have to create it from a string (and if you don't you get the very error message he posts above). ActivePython 2.6.6.18 (ActiveState Software Inc.) based on Python 2.6.6 (r266:84292, Jan 7 2011, 13:16:36) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import decimal >>> decimal.Decimal(0.0) Traceback (most recent call last): File "", line 1, in File "C:\python26\lib\decimal.py", line 649, in __new__ "First convert the float to a string") TypeError: Cannot convert float to Decimal. First convert the float to a string >>> TJG From ian.g.kelly at gmail.com Wed Mar 25 10:44:02 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 25 Mar 2015 08:44:02 -0600 Subject: Python 2.7 issue with decimal value 0.0 In-Reply-To: References: Message-ID: On Wed, Mar 25, 2015 at 8:36 AM, Larry Martell wrote: > On Wed, Mar 25, 2015 at 8:26 AM, Grant Edwards wrote: >> On 2015-03-25, Larry Martell wrote: >>> I have an app that works with 2.6, but in 2.7 it is failing. I traced >>> it down to an issue with decimal.Decimal being passed a value of 0.0. >>> It 2.6 this is fine, but in 2.7 it throws an exception: >>> >>> TypeError: Cannot convert float to Decimal. First convert the float to a string >>> >>> This is easy enough to deal with, but I find it odd. Is this a known issue? >> >> $ python >> Python 2.7.9 (default, Jan 2 2015, 09:51:10) >> [GCC 4.8.3] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >>>>> import decimal >>>>> decimal.Decimal(0) >> Decimal('0') >>>>> decimal.Decimal(0.0) >> Decimal('0') >>>>> decimal.Decimal('0') > > I'm sorry, I missed typed. It works in 2.7, but not in 2.6: "Changed in version 2.7: The argument to the constructor is now permitted to be a float instance." https://docs.python.org/2/library/decimal.html#decimal.Decimal From larry.martell at gmail.com Wed Mar 25 10:47:26 2015 From: larry.martell at gmail.com (Larry Martell) Date: Wed, 25 Mar 2015 10:47:26 -0400 Subject: Python 2.7 issue with decimal value 0.0 In-Reply-To: References: Message-ID: On Wed, Mar 25, 2015 at 10:44 AM, Ian Kelly wrote: > On Wed, Mar 25, 2015 at 8:36 AM, Larry Martell wrote: >> On Wed, Mar 25, 2015 at 8:26 AM, Grant Edwards wrote: >>> On 2015-03-25, Larry Martell wrote: >>>> I have an app that works with 2.6, but in 2.7 it is failing. I traced >>>> it down to an issue with decimal.Decimal being passed a value of 0.0. >>>> It 2.6 this is fine, but in 2.7 it throws an exception: >>>> >>>> TypeError: Cannot convert float to Decimal. First convert the float to a string >>>> >>>> This is easy enough to deal with, but I find it odd. Is this a known issue? >>> >>> $ python >>> Python 2.7.9 (default, Jan 2 2015, 09:51:10) >>> [GCC 4.8.3] on linux2 >>> Type "help", "copyright", "credits" or "license" for more information. >>>>>> import decimal >>>>>> decimal.Decimal(0) >>> Decimal('0') >>>>>> decimal.Decimal(0.0) >>> Decimal('0') >>>>>> decimal.Decimal('0') >> >> I'm sorry, I missed typed. It works in 2.7, but not in 2.6: > > "Changed in version 2.7: The argument to the constructor is now > permitted to be a float instance." > > https://docs.python.org/2/library/decimal.html#decimal.Decimal Thanks! From gdotoli at gmail.com Wed Mar 25 10:53:24 2015 From: gdotoli at gmail.com (Gregg Dotoli) Date: Wed, 25 Mar 2015 07:53:24 -0700 (PDT) Subject: Regex Python Help In-Reply-To: <551212d1$0$13006$c3e8da3$5496439d@news.astraweb.com> References: <099b0ca2-1f5e-4eb4-a7d0-d8210bcca51a@googlegroups.com> <551212d1$0$13006$c3e8da3$5496439d@news.astraweb.com> Message-ID: <59bd09bc-83f8-4b62-9288-07ba6f901d3d@googlegroups.com> No worries Steven, Thanks to ALL on this thread. Gregg On Tuesday, March 24, 2015 at 9:43:58 PM UTC-4, Steven D'Aprano wrote: > On Wed, 25 Mar 2015 05:13 am, gdotoli at gmail.com wrote: > > > The error is: > > > > SyntaxError: Missing parentheses in call to 'print' > > > I cannot imagine how the message could be more explicit: the call to print > is missing parentheses. If you're not going to read the error messages you > are given, you are truly going to struggle as a programmer. > > Read the error message. If you don't understand the error message, please > say so. > > And choose a relevant subject line: this has nothing to do with regexes. You > might as well have called it "Import Python Help". > > > -- > Steven From random832 at fastmail.us Wed Mar 25 11:10:04 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Wed, 25 Mar 2015 11:10:04 -0400 Subject: Daylight savings time question In-Reply-To: References: Message-ID: <1427296204.2332241.245095289.06209E9B@webmail.messagingengine.com> On Tue, Mar 24, 2015, at 18:24, Dan Stromberg wrote: > Is there a way of "adding" 4 hours and getting a jump of 5 hours on > March 8th, 2015 (due to Daylight Savings Time), without hardcoding > when to spring forward and when to fall back? I'd love it if there's > some library that'll do this for me. If you're adding an extra four hours to your "local" time, then your new offset is going to be -3 hours instead of -7: to do this "properly" you would have to define a new timezone. From sunfish7 at gmail.com Wed Mar 25 11:45:45 2015 From: sunfish7 at gmail.com (=?utf-8?B?z4A=?=) Date: Wed, 25 Mar 2015 15:45:45 +0000 Subject: PiCxx In-Reply-To: <2E1837FF-9A40-40E6-BB27-FB57BA9D8E9C@gmail.com> References: <2E1837FF-9A40-40E6-BB27-FB57BA9D8E9C@gmail.com> Message-ID: Hello Python people, I've made a C++ wrapper for Python. I've called it PiCxx and put it up here: https://github.com/p-i-/PiCxx That project runs out of the box on OS X and should be pretty easy to adapt for other OS. Any help providing demo projects for other platforms is most welcome (especially iOS/Android)! Currently I've only provided support for Python 3.x, is that is all I need in my own work. 2.x would not be too much extra trouble. PiCxx presents a viable alternative to Boost::Python and PyCXX -- I didn't want to use either of those two because I didn't want to introduce a Boost dependency and I found the internals of PyCXX impenetrable, so I set about doing a (C++11) rewrite. I've ditched the idea of splitting off a different C++ class for each PyFoo_Type. Instead I have an Object class to mirror PyObject. Feel free to contact me by email or (even better) webchat.freenode.net #pi Happy spring '15, ? (pi) 25 March 2015 PS Note I haven't subscribed to this mailing list, so I may not catch replies! -------------- next part -------------- An HTML attachment was scrubbed... URL: From ndbecker2 at gmail.com Wed Mar 25 12:00:09 2015 From: ndbecker2 at gmail.com (Neal Becker) Date: Wed, 25 Mar 2015 12:00:09 -0400 Subject: PiCxx References: <2E1837FF-9A40-40E6-BB27-FB57BA9D8E9C@gmail.com> Message-ID: ? wrote: > Hello Python people, > > I've made a C++ wrapper for Python. > I've called it PiCxx and put it up here: https://github.com/p-i-/PiCxx > > > That project runs out of the box on OS X and should be pretty easy to > adapt for other OS. Any help providing demo projects for other platforms > is most welcome (especially iOS/Android)! > > Currently I've only provided support for Python 3.x, is that is all I need > in my own work. 2.x would not be too much extra trouble. > > PiCxx presents a viable alternative to Boost::Python and PyCXX -- I didn't > want to use either of those two because I didn't want to introduce a Boost > dependency and I found the internals of PyCXX impenetrable, so I set about > doing a (C++11) rewrite. > > I've ditched the idea of splitting off a different C++ class for each > PyFoo_Type. Instead I have an Object class to mirror PyObject. > > Feel free to contact me by email or (even better) webchat.freenode.net > #pi > > Happy spring '15, > > ? (pi) > 25 March 2015 > > PS Note I haven't subscribed to this mailing list, so I may not catch > replies! My interest in HPC, and as such, need interoperation between numpy arrays and c++. Does PiCxx offer any help here? -- Those who fail to understand recursion are doomed to repeat it From manuel.graune at koeln.de Wed Mar 25 13:29:38 2015 From: manuel.graune at koeln.de (Manuel Graune) Date: Wed, 25 Mar 2015 18:29:38 +0100 Subject: Supply condition in function call Message-ID: <87bnjhyohp.fsf@uriel.graune.org> Hi, I'm looking for a way to supply a condition to an if-statement inside a function body when calling the function. I can sort of get what I want with using eval (see code below) but I would like to achieve this in a safer way. If there is a solution which is safer while being less flexible, that would be fine. Also, supplying the condition as a string is not necessary. What I want to do is basically like this: def test1(a, b, condition="True"): for i,j in zip(a,b): c=i+j if eval(condition): print("Foo") test1([0,1,2,3],[1,2,3,4],"i+j >4") print("Bar") test1([0,1,2,3],[1,2,3,4],"c >4") print("Bar") test1([0,1,2,3],[1,2,3,4],"a[i] >2") print("Bar") test1([0,1,2,3],[1,2,3,4]) Resulting in Foo Foo Bar Foo Foo Bar Foo Bar Foo Foo Foo Foo Thanks for your help Regards, Manuel -- A hundred men did the rational thing. The sum of those rational choices was called panic. Neal Stephenson -- System of the world http://www.graune.org/GnuPG_pubkey.asc Key fingerprint = 1E44 9CBD DEE4 9E07 5E0A 5828 5476 7E92 2DB4 3C99 From joel.goldstick at gmail.com Wed Mar 25 13:41:02 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Wed, 25 Mar 2015 13:41:02 -0400 Subject: Supply condition in function call In-Reply-To: <87bnjhyohp.fsf@uriel.graune.org> References: <87bnjhyohp.fsf@uriel.graune.org> Message-ID: On Wed, Mar 25, 2015 at 1:29 PM, Manuel Graune wrote: > Hi, > > I'm looking for a way to supply a condition to an if-statement inside a > function body when calling the function. I can sort of get what I want > with using eval (see code below) but I would like to achieve this in a > safer way. If there is a solution which is safer while being > less flexible, that would be fine. Also, supplying the condition as a > string is not necessary. What I want to do is basically like this: > > def test1(a, b, condition="True"): > for i,j in zip(a,b): > c=i+j > if eval(condition): > print("Foo") > I'm not sure I understand your question, but condition will evaluate to True or False regardless, so: if condition: print ("Foo") else: print ("Bar") eval can be dangerous as someone could put some unknown command with side effects in condition > test1([0,1,2,3],[1,2,3,4],"i+j >4") > print("Bar") > test1([0,1,2,3],[1,2,3,4],"c >4") > print("Bar") > test1([0,1,2,3],[1,2,3,4],"a[i] >2") > print("Bar") > test1([0,1,2,3],[1,2,3,4]) > > Resulting in > > Foo > Foo > Bar > Foo > Foo > Bar > Foo > Bar > Foo > Foo > Foo > Foo > > Thanks for your help > > Regards, > > Manuel > > -- > A hundred men did the rational thing. The sum of those rational choices was > called panic. Neal Stephenson -- System of the world > http://www.graune.org/GnuPG_pubkey.asc > Key fingerprint = 1E44 9CBD DEE4 9E07 5E0A 5828 5476 7E92 2DB4 3C99 > -- > https://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick http://joelgoldstick.com From webmailgroups at gmail.com Wed Mar 25 13:43:34 2015 From: webmailgroups at gmail.com (Ivan Evstegneev) Date: Wed, 25 Mar 2015 19:43:34 +0200 Subject: Function Defaults - avoiding unneccerary combinations of arguments at input Message-ID: <009d01d06723$38860d50$a99227f0$@gmail.com> Hello all , Just a little question about function's default arguments. Let's say I have this function: def my_fun(history=False, built=False, current=False, topo=None, full=False, file=None): if currnet and full: do something_1 elif current and file: do something_2 elif history and full and file: do something_3 ...... some code here.............. and so on... I won't cover all the possibilities here (actually I don't use all of them ^_^). The question is about avoiding the response for unnecessary combinations? For instance, if user will call function this way: >>>my_fun(current=True, full=True, topo='some str', file="some_file") That will lead to function's misbehavior. As a particular case it will choose "current and full" condition. What is the common accepted way to deal with such unwanted situations? Thanks a lot in advance, Ivan. From ian.g.kelly at gmail.com Wed Mar 25 13:44:07 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 25 Mar 2015 11:44:07 -0600 Subject: Supply condition in function call In-Reply-To: <87bnjhyohp.fsf@uriel.graune.org> References: <87bnjhyohp.fsf@uriel.graune.org> Message-ID: On Wed, Mar 25, 2015 at 11:29 AM, Manuel Graune wrote: > Hi, > > I'm looking for a way to supply a condition to an if-statement inside a > function body when calling the function. I can sort of get what I want > with using eval (see code below) but I would like to achieve this in a > safer way. If there is a solution which is safer while being > less flexible, that would be fine. Also, supplying the condition as a > string is not necessary. What I want to do is basically like this: > > def test1(a, b, condition="True"): > for i,j in zip(a,b): > c=i+j > if eval(condition): > print("Foo") Pass the condition as a function. def test1(a, b, condition=lambda i, j: True): for i,j in zip(a,b): c=i+j if condition(i, j): print("Foo") test1([0,1,2,3],[1,2,3,4], lambda i, j: i+j > 4) # etc. If you find lambdas confusing and prefer named functions, those will work just as well. def i_plus_j_gt_4(i, j): return i + j > 4 test1([0,1,2,3],[1,2,3,4], i_plus_j_gt_4) From manuel.graune at koeln.de Wed Mar 25 13:51:21 2015 From: manuel.graune at koeln.de (Manuel Graune) Date: Wed, 25 Mar 2015 18:51:21 +0100 Subject: Supply condition in function call References: <87bnjhyohp.fsf@uriel.graune.org> Message-ID: <87sict0xuu.fsf@uriel.graune.org> Joel Goldstick writes: > On Wed, Mar 25, 2015 at 1:29 PM, Manuel Graune wrote: >> >> def test1(a, b, condition="True"): >> for i,j in zip(a,b): >> c=i+j >> if eval(condition): >> print("Foo") >> > I'm not sure I understand your question, but condition will evaluate > to True or False regardless, so: > if condition: > print ("Foo") > else: > print ("Bar") > The point is (see examples below) to specify the condition that is to be evaluated when calling the function (as opposed to when stating the function). > eval can be dangerous as someone could put some unknown command with > side effects in condition > I know that. That's why I'm looking for an alternative. ;-) >> test1([0,1,2,3],[1,2,3,4],"i+j >4") >> print("Bar") >> test1([0,1,2,3],[1,2,3,4],"c >4") >> print("Bar") >> test1([0,1,2,3],[1,2,3,4],"a[i] >2") >> >> Resulting in >> >> Foo >> Foo >> Bar >> Foo >> Foo >> Bar >> Foo Regards, Manuel -- A hundred men did the rational thing. The sum of those rational choices was called panic. Neal Stephenson -- System of the world http://www.graune.org/GnuPG_pubkey.asc Key fingerprint = 1E44 9CBD DEE4 9E07 5E0A 5828 5476 7E92 2DB4 3C99 From ian.g.kelly at gmail.com Wed Mar 25 14:00:02 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 25 Mar 2015 12:00:02 -0600 Subject: Function Defaults - avoiding unneccerary combinations of arguments at input In-Reply-To: <009d01d06723$38860d50$a99227f0$@gmail.com> References: <009d01d06723$38860d50$a99227f0$@gmail.com> Message-ID: On Wed, Mar 25, 2015 at 11:43 AM, Ivan Evstegneev wrote: > Hello all , > > > Just a little question about function's default arguments. > > Let's say I have this function: > > def my_fun(history=False, built=False, current=False, topo=None, > full=False, file=None): > if currnet and full: > do something_1 > elif current and file: > do something_2 > elif history and full and file: > do something_3 > > > ...... some code here.............. > > and so on... > > I won't cover all the possibilities here (actually I don't use all of them > ^_^). > > The question is about avoiding the response for unnecessary combinations? > > For instance, if user will call function this way: > > >>>>my_fun(current=True, full=True, topo='some str', file="some_file") > > That will lead to function's misbehavior. As a particular case it will > choose "current and full" condition. > > > What is the common accepted way to deal with such unwanted situations? Don't try to combine all these into a single function whose behaviour is controlled by a bunch of booleans. Create a separate function instead for each unique intended behavior (possibly sharing a common non-public implementation). From joel.goldstick at gmail.com Wed Mar 25 14:17:06 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Wed, 25 Mar 2015 14:17:06 -0400 Subject: Supply condition in function call In-Reply-To: <87sict0xuu.fsf@uriel.graune.org> References: <87bnjhyohp.fsf@uriel.graune.org> <87sict0xuu.fsf@uriel.graune.org> Message-ID: On Wed, Mar 25, 2015 at 1:51 PM, Manuel Graune wrote: > Joel Goldstick writes: > >> On Wed, Mar 25, 2015 at 1:29 PM, Manuel Graune wrote: >>> >>> def test1(a, b, condition="True"): >>> for i,j in zip(a,b): >>> c=i+j >>> if eval(condition): >>> print("Foo") >>> >> I'm not sure I understand your question, but condition will evaluate >> to True or False regardless, so: >> if condition: >> print ("Foo") >> else: >> print ("Bar") >> > > The point is (see examples below) to specify the condition that is to be > evaluated when calling the function (as opposed to when stating the function). > >> eval can be dangerous as someone could put some unknown command with >> side effects in condition >> > > I know that. That's why I'm looking for an alternative. ;-) Oh, now I see. Do you know about this: https://docs.python.org/2/library/ast.html#ast.literal_eval > >>> test1([0,1,2,3],[1,2,3,4],"i+j >4") >>> print("Bar") >>> test1([0,1,2,3],[1,2,3,4],"c >4") >>> print("Bar") >>> test1([0,1,2,3],[1,2,3,4],"a[i] >2") >>> >>> Resulting in >>> >>> Foo >>> Foo >>> Bar >>> Foo >>> Foo >>> Bar >>> Foo > > Regards, > > Manuel > > -- > A hundred men did the rational thing. The sum of those rational choices was > called panic. Neal Stephenson -- System of the world > http://www.graune.org/GnuPG_pubkey.asc > Key fingerprint = 1E44 9CBD DEE4 9E07 5E0A 5828 5476 7E92 2DB4 3C99 > -- > https://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick http://joelgoldstick.com From ian.g.kelly at gmail.com Wed Mar 25 14:22:23 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 25 Mar 2015 12:22:23 -0600 Subject: Supply condition in function call In-Reply-To: References: <87bnjhyohp.fsf@uriel.graune.org> <87sict0xuu.fsf@uriel.graune.org> Message-ID: On Wed, Mar 25, 2015 at 12:17 PM, Joel Goldstick wrote: > Oh, now I see. Do you know about this: > https://docs.python.org/2/library/ast.html#ast.literal_eval As the name suggests, that only evals literals. It won't work for complex expressions like "i + j > 4" From joel.goldstick at gmail.com Wed Mar 25 14:42:24 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Wed, 25 Mar 2015 14:42:24 -0400 Subject: Supply condition in function call In-Reply-To: References: <87bnjhyohp.fsf@uriel.graune.org> <87sict0xuu.fsf@uriel.graune.org> Message-ID: On Wed, Mar 25, 2015 at 2:22 PM, Ian Kelly wrote: > On Wed, Mar 25, 2015 at 12:17 PM, Joel Goldstick > wrote: >> Oh, now I see. Do you know about this: >> https://docs.python.org/2/library/ast.html#ast.literal_eval > > As the name suggests, that only evals literals. It won't work for > complex expressions like "i + j > 4" > -- Thanks Ian, sorry for the misdirection ... > https://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick http://joelgoldstick.com From tjreedy at udel.edu Wed Mar 25 14:43:06 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 25 Mar 2015 14:43:06 -0400 Subject: Function Defaults - avoiding unneccerary combinations of arguments at input In-Reply-To: <009d01d06723$38860d50$a99227f0$@gmail.com> References: <009d01d06723$38860d50$a99227f0$@gmail.com> Message-ID: On 3/25/2015 1:43 PM, Ivan Evstegneev wrote: > Hello all , > > > Just a little question about function's default arguments. > > Let's say I have this function: > > def my_fun(history=False, built=False, current=False, topo=None, > full=False, file=None): > if currnet and full: > do something_1 > elif current and file: > do something_2 > elif history and full and file: > do something_3 > > > ...... some code here.............. > > and so on... > > I won't cover all the possibilities here (actually I don't use all of them > ^_^). > > The question is about avoiding the response for unnecessary combinations? > > For instance, if user will call function this way: > > >>>> my_fun(current=True, full=True, topo='some str', file="some_file") > > That will lead to function's misbehavior. As a particular case it will > choose "current and full" condition. > > > What is the common accepted way to deal with such unwanted situations? Raise a value error for illegal combinations. There are a few instances in the stdlib where 2 of several options are mutually incompatible. -- Terry Jan Reedy From john_ladasky at sbcglobal.net Wed Mar 25 14:44:59 2015 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Wed, 25 Mar 2015 11:44:59 -0700 (PDT) Subject: Sudoku solver In-Reply-To: <87r3sdnw5t.fsf@elektro.pacujo.net> References: <87r3sdnw5t.fsf@elektro.pacujo.net> Message-ID: <4e81bdb9-52db-46e6-b449-d4241cb2a3f2@googlegroups.com> On Wednesday, March 25, 2015 at 4:39:40 AM UTC-7, Marko Rauhamaa wrote: > I post below a sudoku solver. I eagerly await neater implementations (as > well as bug reports). So, it's a brute-force, recursive solver? The code is nice and short. But I bet it takes a long time to run. I and a student of mine are working on Sudoku solvers which solve puzzles the way that humans would. Smart, pattern-recognition strategies take less time to run... but, obviously, far more time to turn into code! From travisgriggs at gmail.com Wed Mar 25 14:49:56 2015 From: travisgriggs at gmail.com (Travis Griggs) Date: Wed, 25 Mar 2015 11:49:56 -0700 Subject: Newbie looking for elegant solution In-Reply-To: References: Message-ID: > On Mar 24, 2015, at 8:28 PM, Chris Angelico wrote: > > On Wed, Mar 25, 2015 at 2:13 PM, wrote: >> I have a list containing 9600 integer elements - each integer is either 0 or 1. >> >> Starting at the front of the list, I need to combine 8 list elements into 1 by treating them as if they were bits of one byte with 1 and 0 denoting bit on/off (the 8th element would be the rightmost bit of the first byte). >> >> Speed is not of utmost importance - an elegant solution is. Any suggestions? > > Oooh fun! > >>>> l = [1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1] >>>> list(int(''.join(str(i) for i in l),2).to_bytes(len(l)//8,'big')) > [177, 105, 117] > > Convert it into a string, convert the string to an integer > (interpreting it as binary), then convert the integer into a series of > bytes, and interpret those bytes as a list of integers. > > Example works in Python 3. For Python 2, you'll need ord() to get the > integers at the end. > > I'm not sure how elegant this is, but it's a fun trick to play with :) > > Next idea please! I love these kinds of threads. Me too. These are my favorite threads. Here?s my entry: [sum(b << (7 - i) for i, b in enumerate(bits)) for bits in zip(*[l[n::8] for n in range(8)])] I think there has to be a better way to do the left hand part, but I liked the zipped iterators on 8 slices. From tjreedy at udel.edu Wed Mar 25 14:50:19 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 25 Mar 2015 14:50:19 -0400 Subject: Supply condition in function call In-Reply-To: <87bnjhyohp.fsf@uriel.graune.org> References: <87bnjhyohp.fsf@uriel.graune.org> Message-ID: On 3/25/2015 1:29 PM, Manuel Graune wrote: > Hi, > > I'm looking for a way to supply a condition to an if-statement inside a > function body when calling the function. I can sort of get what I want > with using eval (see code below) but I would like to achieve this in a > safer way. If there is a solution which is safer while being > less flexible, that would be fine. Also, supplying the condition as a > string is not necessary. What I want to do is basically like this: > > def test1(a, b, condition="True"): > for i,j in zip(a,b): > c=i+j > if eval(condition): > print("Foo") The standard solution to the above is to have a boolean parameter, such as print_wanted=False. > test1([0,1,2,3],[1,2,3,4],"i+j >4") > print("Bar") For this, follow Ian's suggestion of passing a predicate function. -- Terry Jan Reedy From ian.g.kelly at gmail.com Wed Mar 25 15:05:37 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 25 Mar 2015 13:05:37 -0600 Subject: Sudoku solver In-Reply-To: <4e81bdb9-52db-46e6-b449-d4241cb2a3f2@googlegroups.com> References: <87r3sdnw5t.fsf@elektro.pacujo.net> <4e81bdb9-52db-46e6-b449-d4241cb2a3f2@googlegroups.com> Message-ID: On Wed, Mar 25, 2015 at 12:44 PM, John Ladasky wrote: > On Wednesday, March 25, 2015 at 4:39:40 AM UTC-7, Marko Rauhamaa wrote: > >> I post below a sudoku solver. I eagerly await neater implementations (as >> well as bug reports). > > So, it's a brute-force, recursive solver? The code is nice and short. But I bet it takes a long time to run. > > I and a student of mine are working on Sudoku solvers which solve puzzles the way that humans would. Smart, pattern-recognition strategies take less time to run... but, obviously, far more time to turn into code! I haven't written one myself, but Peter Norvig has a nice example on the web of a Python sudoku solver using constraint propagation to limit the search space. http://norvig.com/sudoku.html I don't know that I would do it much differently if I were going to write one myself. From gherron at digipen.edu Wed Mar 25 15:13:14 2015 From: gherron at digipen.edu (Gary Herron) Date: Wed, 25 Mar 2015 12:13:14 -0700 Subject: Supply condition in function call In-Reply-To: <87bnjhyohp.fsf@uriel.graune.org> References: <87bnjhyohp.fsf@uriel.graune.org> Message-ID: <551308CA.10303@digipen.edu> On 03/25/2015 10:29 AM, Manuel Graune wrote: > Hi, > > I'm looking for a way to supply a condition to an if-statement inside a > function body when calling the function. I can sort of get what I want > with using eval (see code below) but I would like to achieve this in a > safer way. If there is a solution which is safer while being > less flexible, that would be fine. Also, supplying the condition as a > string is not necessary. What I want to do is basically like this: > > def test1(a, b, condition="True"): > for i,j in zip(a,b): > c=i+j > if eval(condition): > print("Foo") > > test1([0,1,2,3],[1,2,3,4],"i+j >4") > print("Bar") > test1([0,1,2,3],[1,2,3,4],"c >4") > print("Bar") > test1([0,1,2,3],[1,2,3,4],"a[i] >2") > print("Bar") > test1([0,1,2,3],[1,2,3,4]) > > This is nicely done with lambda expressions: To pass in a condition as a function: test1([0,1,2,3],[1,2,3,4], lambda i,j: i+j<4) To check the condition in the function: if condition(i,j): To get the full range of conditions, you will need to include all the variables needed by any condition you can imagine. So the above suggestions may need to be expanded to: ... lambda i,j,a,b: ... or whatever and ... condition(i,j,a,b) ... or whatever If any of your conditions gets too long/complex for a lambda (or you just don't like Python's lambda expressions), then just create a function for your condition: def cond1(i,j,a,b): return i+j>4 and do test1(..., cond1) and if condition(i,j,a,b): -- Dr. Gary Herron Department of Computer Science DigiPen Institute of Technology (425) 895-4418 From webmailgroups at gmail.com Wed Mar 25 15:22:52 2015 From: webmailgroups at gmail.com (Ivan Evstegneev) Date: Wed, 25 Mar 2015 21:22:52 +0200 Subject: Function Defaults - avoiding unneccerary combinations of arguments at input In-Reply-To: References: <009d01d06723$38860d50$a99227f0$@gmail.com> Message-ID: <000601d06731$17e97a60$47bc6f20$@gmail.com> Hi Terry, Thanks for answer, I'll google these stdlib instances. Sincerely, Ivan. > -----Original Message----- > From: Python-list [mailto:python-list- > bounces+webmailgroups=gmail.com at python.org] On Behalf Of Terry Reedy > Sent: Wednesday, March 25, 2015 20:43 > To: python-list at python.org > Subject: Re: Function Defaults - avoiding unneccerary combinations of > arguments at input > > On 3/25/2015 1:43 PM, Ivan Evstegneev wrote: > > Hello all , > > > > > > Just a little question about function's default arguments. > > > > Let's say I have this function: > > > > def my_fun(history=False, built=False, current=False, topo=None, > > full=False, file=None): > > if currnet and full: > > do something_1 > > elif current and file: > > do something_2 > > elif history and full and file: > > do something_3 > > > > > > ...... some code here.............. > > > > and so on... > > > > I won't cover all the possibilities here (actually I don't use all of > > them ^_^). > > > > The question is about avoiding the response for unnecessary > combinations? > > > > For instance, if user will call function this way: > > > > > >>>> my_fun(current=True, full=True, topo='some str', file="some_file") > > > > That will lead to function's misbehavior. As a particular case it will > > choose "current and full" condition. > > > > > > What is the common accepted way to deal with such unwanted situations? > > Raise a value error for illegal combinations. There are a few instances in the > stdlib where 2 of several options are mutually incompatible. > > > -- > Terry Jan Reedy > > -- > https://mail.python.org/mailman/listinfo/python-list From marko at pacujo.net Wed Mar 25 15:37:35 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 25 Mar 2015 21:37:35 +0200 Subject: Sudoku solver References: <87r3sdnw5t.fsf@elektro.pacujo.net> <4e81bdb9-52db-46e6-b449-d4241cb2a3f2@googlegroups.com> Message-ID: <87twx8amww.fsf@elektro.pacujo.net> John Ladasky : > On Wednesday, March 25, 2015 at 4:39:40 AM UTC-7, Marko Rauhamaa wrote: > >> I post below a sudoku solver. I eagerly await neater implementations (as >> well as bug reports). > > So, it's a brute-force, recursive solver? The code is nice and short. > But I bet it takes a long time to run. Try it. The C version takes milliseconds to complete (usually). The Python version can take the bigger part of a second. The strategy translates into many analogous problems. For example, I use it for version dependency resolution in a component system. Marko From gdotoli at gmail.com Wed Mar 25 15:43:28 2015 From: gdotoli at gmail.com (Gregg Dotoli) Date: Wed, 25 Mar 2015 12:43:28 -0700 (PDT) Subject: Basic Python V3 Search Tool using RE module Message-ID: This basic script will help to find evidence of CryptoWall on a slave drive. Although it is just a string, more complex regex patterns can be replaced with the string. It is incredible how fast Python is and how easy it has helped in quickly assessing a pool of slave drives. I'm improving it as we speak. Thanks for your help and patience. I'm new with Python. import os import re # From the Root topdir = "." # Regex Pattern pattern="DECRYPT_I" regexp=re.compile(pattern) for dirpath,dirnames, files in os.walk(topdir): for name in files: result=regexp.search(name) print(os.path.join(dirpath,name)) print (result) Gregg Dotoli From tiglathsuriol at gmail.com Wed Mar 25 15:49:47 2015 From: tiglathsuriol at gmail.com (Tiglath Suriol) Date: Wed, 25 Mar 2015 12:49:47 -0700 (PDT) Subject: test1 In-Reply-To: References: <7edc4671-8f96-491a-be30-0ad3f2175e07@googlegroups.com> Message-ID: <62b52eb2-67cc-4075-b6e1-f19700e66bed@googlegroups.com> On Tuesday, March 24, 2015 at 11:04:48 PM UTC-4, Chris Angelico wrote: > On Wed, Mar 25, 2015 at 1:47 PM, Tiglath Suriol wrote: > > {% block title %}{% endblock %} > > Looks to me like you're playing around with a templating system like > Jinja, but may I suggest that you send tests to yourself rather than > to an entire mailing list/newsgroup? :) > > ChrisA Two possibilities: You are a moderator. If you are a moderator you are welcome to delete my tests posts. This is of course improbably because this newsgroup is not moderated. The other possibility is that you are just a guy, who despite the fact that my posts cost you nothing, and you are absolutely free to ignore them, your life is so dull that that you just must intervene and comment on anything you do not comprehend, because appointing yourself net cop is about as exciting as it gets. It's a free country, I know. You have every right to engage in pathetic speech. To that guy I say: <> It's safe, you can't go back to watching grass grow. From webmailgroups at gmail.com Wed Mar 25 15:50:40 2015 From: webmailgroups at gmail.com (Ivan Evstegneev) Date: Wed, 25 Mar 2015 21:50:40 +0200 Subject: Function Defaults - avoiding unneccerary combinations of arguments at input In-Reply-To: References: <009d01d06723$38860d50$a99227f0$@gmail.com> Message-ID: <000801d06734$f9e57830$edb06890$@gmail.com> Hello again ^_^, Googled a bit, and found only one, a "ValueError" exception, but still don't understand how it should be implemented in my case. Should my code look like this one: def my_fun(history=False, built=False, current=False, topo=None, full=False, file=None): try: if currnet and full: do something_1 elif current and file: do something_2 elif history and full and file: do something_3 except ValueError: print("No valid input! Please try again ...") ...... some code here.............. Or I'm just too optimistic ^_^? Thanks in advance, Ivan. > -----Original Message----- > From: Python-list [mailto:python-list- > bounces+webmailgroups=gmail.com at python.org] On Behalf Of Terry Reedy > Sent: Wednesday, March 25, 2015 20:43 > To: python-list at python.org > Subject: Re: Function Defaults - avoiding unneccerary combinations of > arguments at input > > On 3/25/2015 1:43 PM, Ivan Evstegneev wrote: > > Hello all , > > > > > > Just a little question about function's default arguments. > > > > Let's say I have this function: > > > > def my_fun(history=False, built=False, current=False, topo=None, > > full=False, file=None): > > if currnet and full: > > do something_1 > > elif current and file: > > do something_2 > > elif history and full and file: > > do something_3 > > > > > > ...... some code here.............. > > > > and so on... > > > > I won't cover all the possibilities here (actually I don't use all of > > them ^_^). > > > > The question is about avoiding the response for unnecessary > combinations? > > > > For instance, if user will call function this way: > > > > > >>>> my_fun(current=True, full=True, topo='some str', file="some_file") > > > > That will lead to function's misbehavior. As a particular case it will > > choose "current and full" condition. > > > > > > What is the common accepted way to deal with such unwanted situations? > > Raise a value error for illegal combinations. There are a few instances in the > stdlib where 2 of several options are mutually incompatible. > > > -- > Terry Jan Reedy > > -- > https://mail.python.org/mailman/listinfo/python-list From invalid at invalid.invalid Wed Mar 25 15:53:16 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 25 Mar 2015 19:53:16 +0000 (UTC) Subject: Supply condition in function call References: <87bnjhyohp.fsf@uriel.graune.org> Message-ID: On 2015-03-25, Ian Kelly wrote: > On Wed, Mar 25, 2015 at 11:29 AM, Manuel Graune wrote: > >> I'm looking for a way to supply a condition to an if-statement inside a >> function body when calling the function. I can sort of get what I want >> with using eval [...] > > Pass the condition as a function. > > def test1(a, b, condition=lambda i, j: True): > for i,j in zip(a,b): > c=i+j > if condition(i, j): > print("Foo") > > test1([0,1,2,3],[1,2,3,4], lambda i, j: i+j > 4) > # etc. FWIW, back in the day such a function was referred to as a "thunk" (particularly if it was auto-generated by a compiler that used pass-by-name instead of pass-by-value or pass-by-reference): http://en.wikipedia.org/wiki/Thunk Dunno if people still use that term or not. -- Grant Edwards grant.b.edwards Yow! I'm RELIGIOUS!! at I love a man with gmail.com a HAIRPIECE!! Equip me with MISSILES!! From rgaddi at technologyhighland.invalid Wed Mar 25 16:07:10 2015 From: rgaddi at technologyhighland.invalid (Rob Gaddi) Date: Wed, 25 Mar 2015 20:07:10 +0000 (UTC) Subject: Function Defaults - avoiding unneccerary combinations of arguments at input References: <009d01d06723$38860d50$a99227f0$@gmail.com> Message-ID: On Wed, 25 Mar 2015 21:50:40 +0200, Ivan Evstegneev wrote: > Hello again ^_^, > > Googled a bit, and found only one, a "ValueError" exception, but still > don't understand how it should be implemented in my case. > > Should my code look like this one: > > def my_fun(history=False, built=False, current=False, topo=None, > full=False, file=None): > try: > if currnet and full: > do something_1 > elif current and file: > do something_2 > elif history and full and file: > do something_3 > > except ValueError: > print("No valid input! Please try again ...") > > > ...... some code here.............. > > > Or I'm just too optimistic ^_^? > > Thanks in advance, > > Ivan. > A) Please don't top-post. Put your new stuff below previous context, so it flows in readable order. B) You've got the concept backwards. You're not trying to catch a ValueError because one came up below your function. Your function was called incorrectly, and you're kicking the responsibility for dealing with it back to the guy who got it wrong. def my_fun(....): if invalid_argument_combination: raise ValueError('Hey jerk, read the documentation.') # otherwise you do your thing in here. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From alister.nospam.ware at ntlworld.com Wed Mar 25 16:09:20 2015 From: alister.nospam.ware at ntlworld.com (alister) Date: Wed, 25 Mar 2015 20:09:20 +0000 (UTC) Subject: test1 References: <7edc4671-8f96-491a-be30-0ad3f2175e07@googlegroups.com> <62b52eb2-67cc-4075-b6e1-f19700e66bed@googlegroups.com> Message-ID: On Wed, 25 Mar 2015 12:49:47 -0700, Tiglath Suriol wrote: > On Tuesday, March 24, 2015 at 11:04:48 PM UTC-4, Chris Angelico wrote: >> On Wed, Mar 25, 2015 at 1:47 PM, Tiglath Suriol wrote: >> > {% block title %}{% endblock %} >> >> Looks to me like you're playing around with a templating system like >> Jinja, but may I suggest that you send tests to yourself rather than to >> an entire mailing list/newsgroup? :) >> >> ChrisA > > Two possibilities: > > You are a moderator. If you are a moderator you are welcome to delete > my tests posts. This is of course improbably because this newsgroup > is not moderated. > > The other possibility is that you are just a guy, who despite the fact > that my posts cost you nothing, and you are absolutely free to ignore > them, your life is so dull that that you just must intervene and comment > on anything you do not comprehend, because appointing yourself net cop > is about as exciting as it gets. > > It's a free country, I know. You have every right to engage in pathetic > speech. > > To that guy I say: <> > > It's safe, you can't go back to watching grass grow. Of course you are free to continue to behave rudely & post test messages to a public group but you may find that when you do actually ask a question(or even offer an opinion) no one responds because we have al taken you advice to simply ignore your posts ans set our news readers to ignore them As Chris is a respected contributor to this newsgroup that would only be your loss -- The worst part of valor is indiscretion. From ian.g.kelly at gmail.com Wed Mar 25 16:09:59 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 25 Mar 2015 14:09:59 -0600 Subject: Sudoku solver In-Reply-To: <87twx8amww.fsf@elektro.pacujo.net> References: <87r3sdnw5t.fsf@elektro.pacujo.net> <4e81bdb9-52db-46e6-b449-d4241cb2a3f2@googlegroups.com> <87twx8amww.fsf@elektro.pacujo.net> Message-ID: On Wed, Mar 25, 2015 at 1:37 PM, Marko Rauhamaa wrote: > John Ladasky : > >> On Wednesday, March 25, 2015 at 4:39:40 AM UTC-7, Marko Rauhamaa wrote: >> >>> I post below a sudoku solver. I eagerly await neater implementations (as >>> well as bug reports). >> >> So, it's a brute-force, recursive solver? The code is nice and short. >> But I bet it takes a long time to run. > > Try it. > > The C version takes milliseconds to complete (usually). The Python > version can take the bigger part of a second. The test puzzle that you posted has 23 values already filled in. How does it perform on harder puzzles with only 17 clues (the proven minimum)? One would expect it to be around a million times slower. From alister.nospam.ware at ntlworld.com Wed Mar 25 16:10:46 2015 From: alister.nospam.ware at ntlworld.com (alister) Date: Wed, 25 Mar 2015 20:10:46 +0000 (UTC) Subject: test2 References: Message-ID: On Wed, 25 Mar 2015 14:22:23 +1100, Chris Angelico wrote: > On Wed, Mar 25, 2015 at 2:11 PM, Tiglath Suriol > wrote: >> # Make this unique, and don't share it with anybody. >> SECRET_KEY = '42=kv!a-il*!4j&7v+0(@a at vq_3j-+ysatta@l6-h63odj2)75' > > This right here is a reason to send your test messages someplace other > than a huge, high-traffic mailing list! > > ChrisA :-) is Nicos back? -- Any given program will expand to fill available memory. From tjreedy at udel.edu Wed Mar 25 16:19:35 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 25 Mar 2015 16:19:35 -0400 Subject: Function Defaults - avoiding unneccerary combinations of arguments at input In-Reply-To: <000801d06734$f9e57830$edb06890$@gmail.com> References: <009d01d06723$38860d50$a99227f0$@gmail.com> <000801d06734$f9e57830$edb06890$@gmail.com> Message-ID: On 3/25/2015 3:50 PM, Ivan Evstegneev wrote: > Googled a bit, and found only one, a "ValueError" exception, but still don't > understand how it should be implemented in my case. > > Should my code look like this one: > > def my_fun(history=False, built=False, current=False, topo=None, > full=False, file=None): > try: > if currnet and full: > do something_1 > elif current and file: > do something_2 > elif history and full and file: > do something_3 > > except ValueError: > print("No valid input! Please try again ...") You need to raise ValueError, not try to catch one that never occurs. def my_fun(history=False, built=False, current=False, topo=None, full=False, file=None): if current and full: do something_1 elif current and file: do something_2 elif history and full and file: do something_3 else: raise ValueError("not a valid combination of arguments") My answer does not negate the possibility that Ian is correct that you are trying to do too much in one function. But I did want to point out that there are stdlib precedents for excluding invalid argument combinations. However, in those cases, only a small proportion of combinations are invalid and if the function were split, most of the code would be duplicated. Here is an mutually exclusive combo that is *not* flagged: passing both '-' (read from stdin) and 'file.py' to python on the command line. The first wins and the second is ignored. '-i -' is redundant and ignored. -- Terry Jan Reedy From marko at pacujo.net Wed Mar 25 16:31:02 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 25 Mar 2015 22:31:02 +0200 Subject: Sudoku solver References: <87r3sdnw5t.fsf@elektro.pacujo.net> <4e81bdb9-52db-46e6-b449-d4241cb2a3f2@googlegroups.com> <87twx8amww.fsf@elektro.pacujo.net> Message-ID: <87iodoakft.fsf@elektro.pacujo.net> Ian Kelly : > The test puzzle that you posted has 23 values already filled in. How > does it perform on harder puzzles with only 17 clues (the proven > minimum)? One would expect it to be around a million times slower. Just try it. The example had a minimum of clues (drop one clue and you'll get multiple solutions). mentions this puzzle: ======================================================================== 8 . . . . . . . . . . 3 6 . . . . . . 7 . . 9 . 2 . . . 5 . . . 7 . . . . . . . 4 5 7 . . . . . 1 . . . 3 . . . 1 . . . . 6 8 . . 8 5 . . . 1 . . 9 . . . . 4 . . ======================================================================== It takes about 2 seconds for my Python program to find the answer but it spends a total of 110 seconds to exhaust the problem space. The analogous C program finished the whole thing in 200 milliseconds. Marko From denismfmcmahon at gmail.com Wed Mar 25 16:34:56 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Wed, 25 Mar 2015 20:34:56 +0000 (UTC) Subject: Regex Python Help References: <099b0ca2-1f5e-4eb4-a7d0-d8210bcca51a@googlegroups.com> Message-ID: On Tue, 24 Mar 2015 11:13:41 -0700, gdotoli wrote: > I am creating a tool to search a filesystem for one simple string. man grep STOP! REINVENTING! THE! WHEEL! Your new wheel will invariably be slower and less efficient than the old one. -- Denis McMahon, denismfmcmahon at gmail.com From webmailgroups at gmail.com Wed Mar 25 16:43:44 2015 From: webmailgroups at gmail.com (Ivan Evstegneev) Date: Wed, 25 Mar 2015 22:43:44 +0200 Subject: Function Defaults - avoiding unneccerary combinations of arguments at input In-Reply-To: References: <009d01d06723$38860d50$a99227f0$@gmail.com> Message-ID: <000e01d0673c$63a87ef0$2af97cd0$@gmail.com> > -----Original Message----- > From: Python-list [mailto:python-list- > bounces+webmailgroups=gmail.com at python.org] On Behalf Of Rob Gaddi > Sent: Wednesday, March 25, 2015 22:07 > To: python-list at python.org > Subject: Re: Function Defaults - avoiding unneccerary combinations of > arguments at input > > On Wed, 25 Mar 2015 21:50:40 +0200, Ivan Evstegneev wrote: > > > Hello again ^_^, > > > > Googled a bit, and found only one, a "ValueError" exception, but still > > don't understand how it should be implemented in my case. > > > > Should my code look like this one: > > > > def my_fun(history=False, built=False, current=False, topo=None, > > full=False, file=None): > > try: > > if currnet and full: > > do something_1 > > elif current and file: > > do something_2 > > elif history and full and file: > > do something_3 > > > > except ValueError: > > print("No valid input! Please try again ...") > > > > > > ...... some code here.............. > > > > > > Or I'm just too optimistic ^_^? > > > > Thanks in advance, > > > > Ivan. > > > > A) Please don't top-post. Put your new stuff below previous context, so it > flows in readable order. > > B) You've got the concept backwards. You're not trying to catch a ValueError > because one came up below your function. Your function was called > incorrectly, and you're kicking the responsibility for dealing with it back to the > guy who got it wrong. > > def my_fun(....): > if invalid_argument_combination: > raise ValueError('Hey jerk, read the documentation.') > > # otherwise you do your thing in here. > > > -- > 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 Ok thanks fo the answer. Got it. About top-posting... will need to tweak Outlook settings. From ian.g.kelly at gmail.com Wed Mar 25 16:49:08 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 25 Mar 2015 14:49:08 -0600 Subject: Supply condition in function call In-Reply-To: References: <87bnjhyohp.fsf@uriel.graune.org> Message-ID: On Wed, Mar 25, 2015 at 1:53 PM, Grant Edwards wrote: > On 2015-03-25, Ian Kelly wrote: >> On Wed, Mar 25, 2015 at 11:29 AM, Manuel Graune wrote: >> >>> I'm looking for a way to supply a condition to an if-statement inside a >>> function body when calling the function. I can sort of get what I want >>> with using eval [...] >> >> Pass the condition as a function. >> >> def test1(a, b, condition=lambda i, j: True): >> for i,j in zip(a,b): >> c=i+j >> if condition(i, j): >> print("Foo") >> >> test1([0,1,2,3],[1,2,3,4], lambda i, j: i+j > 4) >> # etc. > > FWIW, back in the day such a function was referred to as a "thunk" > (particularly if it was auto-generated by a compiler that used > pass-by-name instead of pass-by-value or pass-by-reference): > > http://en.wikipedia.org/wiki/Thunk > > Dunno if people still use that term or not. I've heard the term (though not since my college days, I think), but I've always understood thunks to be parameterless (hence the use as a form of pass-by-name). From niujinghui at gmail.com Wed Mar 25 17:16:36 2015 From: niujinghui at gmail.com (Jinghui Niu) Date: Wed, 25 Mar 2015 14:16:36 -0700 (PDT) Subject: time module vs. datetime module: plain language for beginners Message-ID: I am learning python programming. One thing that gives me a lot of confusion is the division of labours between the time module and the datetime module. As it turns out to be, time module is not only about time, it's about date too. And datetime doesn't natively support timezone, you have to create one for yourself. Why duplicate datetime module? What is the design rationale between this division? Can't we just have one unified module that deals with dates and times? Could someone please list some situations where the two modules are actually useful in their own ways respectively? Explanation with not too much jargon is highly appreciated. Thanks in advance. From gdotoli at gmail.com Wed Mar 25 17:19:39 2015 From: gdotoli at gmail.com (Gregg Dotoli) Date: Wed, 25 Mar 2015 14:19:39 -0700 (PDT) Subject: Regex Python Help In-Reply-To: References: <099b0ca2-1f5e-4eb4-a7d0-d8210bcca51a@googlegroups.com> Message-ID: <94a16553-1d08-46ca-9290-d024cf408248@googlegroups.com> Grep is regular expressions. If I'm using Python, I'll use the Python modules. Silly Gregg On Wednesday, March 25, 2015 at 4:36:01 PM UTC-4, Denis McMahon wrote: > On Tue, 24 Mar 2015 11:13:41 -0700, gdotoli wrote: > > > I am creating a tool to search a filesystem for one simple string. > > man grep > > STOP! REINVENTING! THE! WHEEL! > > Your new wheel will invariably be slower and less efficient than the old > one. > > -- > Denis McMahon, denismfmcmahon at gmail.com From ciroporuzzo at mail.com Wed Mar 25 17:23:58 2015 From: ciroporuzzo at mail.com (Dieffe Sedici) Date: Wed, 25 Mar 2015 14:23:58 -0700 (PDT) Subject: -- redacted -- Message-ID: <7d471aa5-b6ed-4800-9855-37319ba126ee@googlegroups.com> -- redacted -- From breamoreboy at yahoo.co.uk Wed Mar 25 18:15:41 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 25 Mar 2015 22:15:41 +0000 Subject: Regex Python Help In-Reply-To: <94a16553-1d08-46ca-9290-d024cf408248@googlegroups.com> References: <099b0ca2-1f5e-4eb4-a7d0-d8210bcca51a@googlegroups.com> <94a16553-1d08-46ca-9290-d024cf408248@googlegroups.com> Message-ID: On 25/03/2015 21:19, Gregg Dotoli wrote: > Grep is regular expressions. If I'm using Python, I'll use the Python modules. > Silly > > Gregg > Clear as mud, and please don't top post. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rosuav at gmail.com Wed Mar 25 18:36:10 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 Mar 2015 09:36:10 +1100 Subject: test1 In-Reply-To: <62b52eb2-67cc-4075-b6e1-f19700e66bed@googlegroups.com> References: <7edc4671-8f96-491a-be30-0ad3f2175e07@googlegroups.com> <62b52eb2-67cc-4075-b6e1-f19700e66bed@googlegroups.com> Message-ID: On Thu, Mar 26, 2015 at 6:49 AM, Tiglath Suriol wrote: > Two possibilities: > > You are a moderator. If you are a moderator you are welcome to delete my tests posts. This is of course improbably because this newsgroup is not moderated. You misunderstand newsgroups and mailing lists. Posts do not get deleted after the event. Even on a web forum, where an administrator can delete posts, the information is already out there; the instant any one person has seen your post, you've lost control of it. So think about what you post - especially when (as in your other thread) it contains private information. > The other possibility is that you are just a guy, who despite the fact that my posts cost you nothing, and you are absolutely free to ignore them, your life is so dull that that you just must intervene and comment on anything you do not comprehend, because appointing yourself net cop is about as exciting as it gets. > > It's a free country, I know. You have every right to engage in pathetic speech. You also misunderstand freedom. I suggest you explore all three concepts (freedom, newsgroups, and mailing lists), and learn what you're actually dealing with. You may find the results rewarding. ChrisA From rosuav at gmail.com Wed Mar 25 18:40:32 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 Mar 2015 09:40:32 +1100 Subject: Sudoku solver In-Reply-To: <87iodoakft.fsf@elektro.pacujo.net> References: <87r3sdnw5t.fsf@elektro.pacujo.net> <4e81bdb9-52db-46e6-b449-d4241cb2a3f2@googlegroups.com> <87twx8amww.fsf@elektro.pacujo.net> <87iodoakft.fsf@elektro.pacujo.net> Message-ID: On Thu, Mar 26, 2015 at 7:31 AM, Marko Rauhamaa wrote: > Ian Kelly : > >> The test puzzle that you posted has 23 values already filled in. How >> does it perform on harder puzzles with only 17 clues (the proven >> minimum)? One would expect it to be around a million times slower. > > Just try it. The example had a minimum of clues (drop one clue and > you'll get multiple solutions). That's not quite what Ian meant. You've shown that your particular grid needs every clue to be solvable; Ian is pointing out that it's possible to create a solvable puzzle (one with a unique solution) with only 17 clues. ChrisA From steve+comp.lang.python at pearwood.info Wed Mar 25 18:50:48 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 26 Mar 2015 09:50:48 +1100 Subject: Sudoku solver References: <87r3sdnw5t.fsf@elektro.pacujo.net> Message-ID: <55133bc9$0$12977$c3e8da3$5496439d@news.astraweb.com> On Wed, 25 Mar 2015 10:39 pm, Marko Rauhamaa wrote: > I have yet to find practical use for fibonacci numbers. Many people have failed to find practical uses for many things from mathematics. Doesn't mean they don't exist: http://en.wikipedia.org/wiki/Fibonacci_number#Applications -- Steven From ian.g.kelly at gmail.com Wed Mar 25 18:57:49 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 25 Mar 2015 16:57:49 -0600 Subject: test1 In-Reply-To: <62b52eb2-67cc-4075-b6e1-f19700e66bed@googlegroups.com> References: <7edc4671-8f96-491a-be30-0ad3f2175e07@googlegroups.com> <62b52eb2-67cc-4075-b6e1-f19700e66bed@googlegroups.com> Message-ID: On Wed, Mar 25, 2015 at 1:49 PM, Tiglath Suriol wrote: > Two possibilities: > > You are a moderator. If you are a moderator you are welcome to delete my tests posts. This is of course improbably because this newsgroup is not moderated. > > The other possibility is that you are just a guy, who despite the fact that my posts cost you nothing, and you are absolutely free to ignore them, your life is so dull that that you just must intervene and comment on anything you do not comprehend, because appointing yourself net cop is about as exciting as it gets. > > It's a free country, I know. You have every right to engage in pathetic speech. > > To that guy I say: <> > > It's safe, you can't go back to watching grass grow. *plonk* From breamoreboy at yahoo.co.uk Wed Mar 25 19:04:15 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 25 Mar 2015 23:04:15 +0000 Subject: Sudoku solver In-Reply-To: <55133bc9$0$12977$c3e8da3$5496439d@news.astraweb.com> References: <87r3sdnw5t.fsf@elektro.pacujo.net> <55133bc9$0$12977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 25/03/2015 22:50, Steven D'Aprano wrote: > On Wed, 25 Mar 2015 10:39 pm, Marko Rauhamaa wrote: > >> I have yet to find practical use for fibonacci numbers. > > Many people have failed to find practical uses for many things from > mathematics. Doesn't mean they don't exist: > > http://en.wikipedia.org/wiki/Fibonacci_number#Applications > I've just read "Alan Turing: The Enigma". Apparently he was fascinated by the appearance of Fibonacci numbers in nature, as described here http://en.wikipedia.org/wiki/Fibonacci_number#In_nature -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From steve+comp.lang.python at pearwood.info Wed Mar 25 19:10:03 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 26 Mar 2015 10:10:03 +1100 Subject: Regex Python Help References: <099b0ca2-1f5e-4eb4-a7d0-d8210bcca51a@googlegroups.com> <94a16553-1d08-46ca-9290-d024cf408248@googlegroups.com> Message-ID: <5513404c$0$13000$c3e8da3$5496439d@news.astraweb.com> On Thu, 26 Mar 2015 08:19 am, Gregg Dotoli wrote: > Grep is regular expressions. If I'm using Python, I'll use the Python > modules. Silly It very well may be silly. You're using Python regular expressions because you're using Python. Why are you using Python? Early in this thread you said "Here you go. Windows shell was easier!!!" Does Windows shell have grep? How about Powershell? If grep is available, why mix two different languages? -- Steven From kai.peters at gmail.com Wed Mar 25 19:14:50 2015 From: kai.peters at gmail.com (kai.peters at gmail.com) Date: Wed, 25 Mar 2015 16:14:50 -0700 (PDT) Subject: Newbie looking for elegant solution In-Reply-To: References: Message-ID: <13610033-eed5-4660-aa10-103e8f0c2ec8@googlegroups.com> On Tuesday, 24 March 2015 20:14:06 UTC-7, otaksoft... at gmail.com wrote: > I have a list containing 9600 integer elements - each integer is either 0 or 1. > > Starting at the front of the list, I need to combine 8 list elements into 1 by treating them as if they were bits of one byte with 1 and 0 denoting bit on/off (the 8th element would be the rightmost bit of the first byte). > > The end result should be a new list that is 8 x shorter than the original list containing integers between 0 and 255. > > Speed is not of utmost importance - an elegant solution is. Any suggestions? > > Thanks for all input, > Kai The list comes from PILLOW: getdata # im.getdata() => sequence Returns the contents of an image as a sequence object containing pixel values. The sequence object is flattened, so that values for line one follow directly after the values of line zero, and so on. Note that the sequence object returned by this method is an internal PIL data type, which only supports certain sequence operations, including iteration and basic sequence access. To convert it to an ordinary sequence (e.g. for printing), use list(im.getdata()). From no.email at nospam.invalid Wed Mar 25 19:30:40 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 25 Mar 2015 16:30:40 -0700 Subject: Newbie looking for elegant solution References: <13610033-eed5-4660-aa10-103e8f0c2ec8@googlegroups.com> Message-ID: <87mw303ba7.fsf@jester.gateway.sonic.net> kai.peters at gmail.com writes: > im.getdata() => sequence > Returns the contents of an image as a sequence object containing pixel > values. The sequence object is flattened, so that values for line one > follow directly after the values of line zero, and so on. And this is a list of 1's and 0's, I guess for a bitonal picture? Anyway, the code I posted should be able to take in the sequence directly (lazily) without needing an intermediate list. If you change the outer list comprehension to a generator expression (i.e. in Python 2.x, replace the square brackets with parentheses) it will produce a lazy sequence at the output, that you can then process one line at a time or whatever. Also, on computers these days, a million element list isn't a big problem. What are you going to do with the output? That might also help people find suggestions. From irmen.NOSPAM at xs4all.nl Wed Mar 25 19:34:07 2015 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Thu, 26 Mar 2015 00:34:07 +0100 Subject: Newbie looking for elegant solution In-Reply-To: <13610033-eed5-4660-aa10-103e8f0c2ec8@googlegroups.com> References: <13610033-eed5-4660-aa10-103e8f0c2ec8@googlegroups.com> Message-ID: <551345ed$0$2942$e4fe514c@news.xs4all.nl> On 26-3-2015 0:14, kai.peters at gmail.com wrote: > On Tuesday, 24 March 2015 20:14:06 UTC-7, otaksoft... at gmail.com wrote: >> I have a list containing 9600 integer elements - each integer is either 0 or 1. >> >> Starting at the front of the list, I need to combine 8 list elements into 1 by treating them as if they were bits of one byte with 1 and 0 denoting bit on/off (the 8th element would be the rightmost bit of the first byte). >> >> The end result should be a new list that is 8 x shorter than the original list containing integers between 0 and 255. >> >> Speed is not of utmost importance - an elegant solution is. Any suggestions? >> >> Thanks for all input, >> Kai > > > > The list comes from PILLOW: > > getdata # > > im.getdata() => sequence > Don't you want to use Image.tobytes() instead? Or, Image.save() directly if you want to store the image somewhere else perhaps? In other words, what are you going to do with the -internal- data returned from getdata, perhaps you don't even want to call it, and skip dealing with the raw pixel bits altogether... Irmen From tiglathsuriol at gmail.com Wed Mar 25 19:34:56 2015 From: tiglathsuriol at gmail.com (Tiglath Suriol) Date: Wed, 25 Mar 2015 16:34:56 -0700 (PDT) Subject: test1 In-Reply-To: References: <7edc4671-8f96-491a-be30-0ad3f2175e07@googlegroups.com> <62b52eb2-67cc-4075-b6e1-f19700e66bed@googlegroups.com> Message-ID: <90769224-1895-4f06-89da-4e03c877edc7@googlegroups.com> On Wednesday, March 25, 2015 at 4:09:39 PM UTC-4, alister wrote: > On Wed, 25 Mar 2015 12:49:47 -0700, Tiglath Suriol wrote: > > > On Tuesday, March 24, 2015 at 11:04:48 PM UTC-4, Chris Angelico wrote: > >> On Wed, Mar 25, 2015 at 1:47 PM, Tiglath Suriol wrote: > >> > {% block title %}{% endblock %} > >> > >> Looks to me like you're playing around with a templating system like > >> Jinja, but may I suggest that you send tests to yourself rather than to > >> an entire mailing list/newsgroup? :) > >> > >> ChrisA > > > > Two possibilities: > > > > You are a moderator. If you are a moderator you are welcome to delete > > my tests posts. This is of course improbably because this newsgroup > > is not moderated. > > > > The other possibility is that you are just a guy, who despite the fact > > that my posts cost you nothing, and you are absolutely free to ignore > > them, your life is so dull that that you just must intervene and comment > > on anything you do not comprehend, because appointing yourself net cop > > is about as exciting as it gets. > > > > It's a free country, I know. You have every right to engage in pathetic > > speech. > > > > To that guy I say: <> > > > > It's safe, you can't go back to watching grass grow. > > Of course you are free to continue to behave rudely & post test messages > to a public group but you may find that when you do actually ask a > question(or even offer an opinion) no one responds because we have al > taken you advice to simply ignore your posts ans set our news readers to > ignore them Now would be a very good time to start. From steve+comp.lang.python at pearwood.info Wed Mar 25 19:36:44 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 26 Mar 2015 10:36:44 +1100 Subject: time module vs. datetime module: plain language for beginners References: Message-ID: <5513468e$0$12992$c3e8da3$5496439d@news.astraweb.com> On Thu, 26 Mar 2015 08:16 am, Jinghui Niu wrote: > I am learning python programming. One thing that gives me a lot of > confusion is the division of labours between the time module and the > datetime module. > > As it turns out to be, time module is not only about time, it's about date > too. And datetime doesn't natively support timezone, you have to create > one for yourself. > > Why duplicate datetime module? What is the design rationale between this > division? Can't we just have one unified module that deals with dates and > times? Could someone please list some situations where the two modules are > actually useful in their own ways respectively? > > Explanation with not too much jargon is highly appreciated. Thanks in > advance. The time module is written in C, and is mostly interface to low-level operating system functions. The datetime module is written in Python. It would be painful to write the time module in Python, or the datetime module in C, so they are separate. py> import time py> import datetime py> time.__file__ '/usr/local/lib/python3.3/lib-dynload/time.cpython-33m.so' py> datetime.__file__ '/usr/local/lib/python3.3/datetime.py' There are other designs possible. For example, the datetime module could be written in Python, and it could import an accelerator module for the C parts: from _datetime import * In fact, it already does that! But the private accelerator C datetime doesn't include the contents of time, so there are still two public modules. Why didn't the time functions just get moved into _datetime? As with most of these things, the answer is probably for historical reasons. You would need to look far back in the history of Python to see how those two modules evolved over the years, but my guess is that the very first version of each had no overlap, and the overlap has just developed since then. The oldest version of Python I have is version 1.5, and it has a time module but no datetime module. So my guess is that time was written first, as an interface to the operating system time routines, in C. Then, some versions later, a pure-Python datetime module was added, and then later still an accelerated C _datetime module was added. That's my guess. I cannot remember the last time I have needed to import both time and datetime from the same module. I usually only import one, or the other. For example, I might do: time.sleep(3) which doesn't require the datetime module. -- Steven From tiglathsuriol at gmail.com Wed Mar 25 19:43:18 2015 From: tiglathsuriol at gmail.com (Tiglath Suriol) Date: Wed, 25 Mar 2015 16:43:18 -0700 (PDT) Subject: test1 In-Reply-To: References: <7edc4671-8f96-491a-be30-0ad3f2175e07@googlegroups.com> <62b52eb2-67cc-4075-b6e1-f19700e66bed@googlegroups.com> Message-ID: On Wednesday, March 25, 2015 at 6:38:09 PM UTC-4, Chris Angelico wrote: > On Thu, Mar 26, 2015 at 6:49 AM, wrote: > > Two possibilities: > > > > You are a moderator. If you are a moderator you are welcome to delete my tests posts. This is of course improbably because this newsgroup is not moderated. > > You misunderstand newsgroups and mailing lists. Posts do not get > deleted after the event. Even on a web forum, where an administrator > can delete posts, the information is already out there; the instant > any one person has seen your post, you've lost control of it. So think > about what you post - especially when (as in your other thread) it > contains private information. > > > The other possibility is that you are just a guy, who despite the fact that my posts cost you nothing, and you are absolutely free to ignore them, your life is so dull that that you just must intervene and comment on anything you do not comprehend, because appointing yourself net cop is about as exciting as it gets. > > > > It's a free country, I know. You have every right to engage in pathetic speech. > > You also misunderstand freedom. I suggest you explore all three > concepts (freedom, newsgroups, and mailing lists), and learn what > you're actually dealing with. You may find the results rewarding. > > ChrisA You open my post you see it's some code. No questions. You move on. But no, you NEED to impart advice where not has been solicited. If I had added "Please ignore" to the title of my posts, I would still be writing this to you, and other smartasses. I've dealt with people like you in newsgroups for a long time, you just think you have a mortgage here and there is no pie that does not deserve your finger. In the real world we call you: fishwife. Will you ignore me, please? From steve+comp.lang.python at pearwood.info Wed Mar 25 19:48:51 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 26 Mar 2015 10:48:51 +1100 Subject: Function Defaults - avoiding unneccerary combinations of arguments at input References: Message-ID: <55134964$0$13004$c3e8da3$5496439d@news.astraweb.com> On Thu, 26 Mar 2015 04:43 am, Ivan Evstegneev wrote: > Hello all , > > > Just a little question about function's default arguments. > > Let's say I have this function: > > def my_fun(history=False, built=False, current=False, topo=None, > full=False, file=None): > if currnet and full: > do something_1 > elif current and file: > do something_2 > elif history and full and file: > do something_3 This is an extreme example that shows why Guido's Law "No constant arguments" is a good design principle. (Well, it's not really so much a law as a guideline.) If you have a function that looks like this: def spam(arg, flag=True): if flag: return do_this(arg) else: return do_that(arg) then you should just use do_this and do_that directly and get rid of spam. In your case, its hard to say *exactly* what you should do, since you are only showing a small sketch of "my_fun", but it looks to me that it tries to do too much. You can probably split it into two or four smaller functions, and avoid needing so many (or any!) flags. That will avoid (or at least reduce) the need to check for mutually incompatible sets of arguments. Another useful design principle: if dealing with the combinations of arguments is too hard, that's a sign that you have too many combinations of arguments. If there are combinations which are impossible, there are three basic ways to deal with that. In order from best to worst: (1) Don't let those combinations occur at all. Redesign your function, or split it into multiple functions, so the impossible combinations no longer exist. (2) Raise an error when an impossible combination occurs. (3) Just ignore one or more argument so that what was impossible is now possible. -- Steven From ian.g.kelly at gmail.com Wed Mar 25 19:49:27 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 25 Mar 2015 17:49:27 -0600 Subject: time module vs. datetime module: plain language for beginners In-Reply-To: References: Message-ID: On Wed, Mar 25, 2015 at 3:16 PM, Jinghui Niu wrote: > I am learning python programming. One thing that gives me a lot of confusion is the division of labours between the time module and the datetime module. > > As it turns out to be, time module is not only about time, it's about date too. And datetime doesn't natively support timezone, you have to create one for yourself. > > Why duplicate datetime module? What is the design rationale between this division? Can't we just have one unified module that deals with dates and times? Could someone please list some situations where the two modules are actually useful in their own ways respectively? > > Explanation with not too much jargon is highly appreciated. Thanks in advance. They have fairly different focuses. Notice that in the standard library table of contents, they're not even listed in the same section. datetime is listed under "8.Data Types" whereas time falls under "16. Generic Operating System Services". That pretty much sums it up: the datetime module exists to implement convenient data types for representing dates and times. The time module mostly provides low-level analogues of C APIs and system calls, e.g. stuff that you might expect to find in time.h if you were working in C. From breamoreboy at yahoo.co.uk Wed Mar 25 19:50:12 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 25 Mar 2015 23:50:12 +0000 Subject: Regex Python Help In-Reply-To: <5513404c$0$13000$c3e8da3$5496439d@news.astraweb.com> References: <099b0ca2-1f5e-4eb4-a7d0-d8210bcca51a@googlegroups.com> <94a16553-1d08-46ca-9290-d024cf408248@googlegroups.com> <5513404c$0$13000$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 25/03/2015 23:10, Steven D'Aprano wrote: > On Thu, 26 Mar 2015 08:19 am, Gregg Dotoli wrote: > >> Grep is regular expressions. If I'm using Python, I'll use the Python >> modules. Silly > > It very well may be silly. > > You're using Python regular expressions because you're using Python. Why are > you using Python? Early in this thread you said > > "Here you go. Windows shell was easier!!!" > > Does Windows shell have grep? How about Powershell? If grep is available, > why mix two different languages? > gnuwin32 certainly does. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Wed Mar 25 19:57:11 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 25 Mar 2015 23:57:11 +0000 Subject: test1 In-Reply-To: References: <7edc4671-8f96-491a-be30-0ad3f2175e07@googlegroups.com> <62b52eb2-67cc-4075-b6e1-f19700e66bed@googlegroups.com> Message-ID: On 25/03/2015 23:43, Tiglath Suriol wrote: > On Wednesday, March 25, 2015 at 6:38:09 PM UTC-4, Chris Angelico wrote: >> On Thu, Mar 26, 2015 at 6:49 AM, wrote: >>> Two possibilities: >>> >>> You are a moderator. If you are a moderator you are welcome to delete my tests posts. This is of course improbably because this newsgroup is not moderated. >> >> You misunderstand newsgroups and mailing lists. Posts do not get >> deleted after the event. Even on a web forum, where an administrator >> can delete posts, the information is already out there; the instant >> any one person has seen your post, you've lost control of it. So think >> about what you post - especially when (as in your other thread) it >> contains private information. >> >>> The other possibility is that you are just a guy, who despite the fact that my posts cost you nothing, and you are absolutely free to ignore them, your life is so dull that that you just must intervene and comment on anything you do not comprehend, because appointing yourself net cop is about as exciting as it gets. >>> >>> It's a free country, I know. You have every right to engage in pathetic speech. >> >> You also misunderstand freedom. I suggest you explore all three >> concepts (freedom, newsgroups, and mailing lists), and learn what >> you're actually dealing with. You may find the results rewarding. >> >> ChrisA > > You open my post you see it's some code. No questions. You move on. > > But no, you NEED to impart advice where not has been solicited. > > If I had added "Please ignore" to the title of my posts, I would still be writing this to you, and other smartasses. I've dealt with people like you in newsgroups for a long time, you just think you have a mortgage here and there is no pie that does not deserve your finger. In the real world we call you: fishwife. > > Will you ignore me, please? > You might be used to dealing with other people in other newsgroups. This is the Python main mailing list/newsgroup. There is a rather more civilised way of doing things around here. As for ignoring you, why don't you simply stop posting, then we won't have to? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From tiglathsuriol at gmail.com Wed Mar 25 19:57:26 2015 From: tiglathsuriol at gmail.com (Tiglath Suriol) Date: Wed, 25 Mar 2015 16:57:26 -0700 (PDT) Subject: test1 In-Reply-To: References: <7edc4671-8f96-491a-be30-0ad3f2175e07@googlegroups.com> <62b52eb2-67cc-4075-b6e1-f19700e66bed@googlegroups.com> Message-ID: <29fa2698-2db3-4818-ad8d-d64e3c3dd7bd@googlegroups.com> On Wednesday, March 25, 2015 at 4:09:39 PM UTC-4, alister wrote: > As Chris is a respected contributor to this newsgroup that would only be > your loss > I'll just have to find some way to go on then, won't I? I bounce some code off a newsgroup, and all these fox-terriers start nipping at my heels, amazing... Shoo, shoo > > -- > The worst part of valor is indiscretion. From steve+comp.lang.python at pearwood.info Wed Mar 25 19:59:24 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 26 Mar 2015 10:59:24 +1100 Subject: test1 References: <7edc4671-8f96-491a-be30-0ad3f2175e07@googlegroups.com> <62b52eb2-67cc-4075-b6e1-f19700e66bed@googlegroups.com> Message-ID: <55134bdd$0$12979$c3e8da3$5496439d@news.astraweb.com> On Thu, 26 Mar 2015 10:43 am, Tiglath Suriol wrote: > I've dealt with people like you in newsgroups for a long time So many years, so little learning. It's arseholes like you who make it so important to invent a way to stab people through the internet. Just go away, you're not wanted here. *plonk* -- Steven From breamoreboy at yahoo.co.uk Wed Mar 25 20:01:13 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 26 Mar 2015 00:01:13 +0000 Subject: time module vs. datetime module: plain language for beginners In-Reply-To: References: Message-ID: On 25/03/2015 23:49, Ian Kelly wrote: > On Wed, Mar 25, 2015 at 3:16 PM, Jinghui Niu wrote: >> I am learning python programming. One thing that gives me a lot of confusion is the division of labours between the time module and the datetime module. >> >> As it turns out to be, time module is not only about time, it's about date too. And datetime doesn't natively support timezone, you have to create one for yourself. >> >> Why duplicate datetime module? What is the design rationale between this division? Can't we just have one unified module that deals with dates and times? Could someone please list some situations where the two modules are actually useful in their own ways respectively? >> >> Explanation with not too much jargon is highly appreciated. Thanks in advance. > > They have fairly different focuses. Notice that in the standard > library table of contents, they're not even listed in the same > section. datetime is listed under "8.Data Types" whereas time falls > under "16. Generic Operating System Services". That pretty much sums > it up: the datetime module exists to implement convenient data types > for representing dates and times. The time module mostly provides > low-level analogues of C APIs and system calls, e.g. stuff that you > might expect to find in time.h if you were working in C. > Let's not forget the calendar module, although I've forgotten the last time I used it as that was so many years ago. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From ian.g.kelly at gmail.com Wed Mar 25 20:07:24 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 25 Mar 2015 18:07:24 -0600 Subject: Sudoku solver In-Reply-To: <87iodoakft.fsf@elektro.pacujo.net> References: <87r3sdnw5t.fsf@elektro.pacujo.net> <4e81bdb9-52db-46e6-b449-d4241cb2a3f2@googlegroups.com> <87twx8amww.fsf@elektro.pacujo.net> <87iodoakft.fsf@elektro.pacujo.net> Message-ID: On Wed, Mar 25, 2015 at 2:31 PM, Marko Rauhamaa wrote: > Ian Kelly : > >> The test puzzle that you posted has 23 values already filled in. How >> does it perform on harder puzzles with only 17 clues (the proven >> minimum)? One would expect it to be around a million times slower. > > Just try it. The example had a minimum of clues (drop one clue and > you'll get multiple solutions). > > orlds-hardest-sudoku-can-you-crack-it.html> mentions this puzzle: > > ======================================================================== > 8 . . . . . . . . > . . 3 6 . . . . . > . 7 . . 9 . 2 . . > . 5 . . . 7 . . . > . . . . 4 5 7 . . > . . . 1 . . . 3 . > . . 1 . . . . 6 8 > . . 8 5 . . . 1 . > . 9 . . . . 4 . . > ======================================================================== > > It takes about 2 seconds for my Python program to find the answer but it > spends a total of 110 seconds to exhaust the problem space. > > The analogous C program finished the whole thing in 200 milliseconds. "Hard" for a human doesn't necessarily mean "hard" for a programmatic solver in this case. Try your solver on this one: $ cat sudoku2.dat . . . 7 . . . . . 1 . . . . . . . . . . . 4 3 . 2 . . . . . . . . . . 6 . . . 5 . 9 . . . . . . . . . 4 1 8 . . . . 8 1 . . . . . 2 . . . . 5 . . 4 . . . . 3 . . I tried the first puzzle you posted, and it took about a second. I then started running it on this one before I started typing up this post, and it hasn't finished yet. While that was running, I then tried running Norvig's solver on this puzzle, and it completed in about 0.07 seconds. For the curious, this puzzle was arbitrarily collected from http://theconversation.com/good-at-sudoku-heres-some-youll-never-complete-5234 From python at mrabarnett.plus.com Wed Mar 25 20:17:58 2015 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 26 Mar 2015 00:17:58 +0000 Subject: test1 In-Reply-To: References: <7edc4671-8f96-491a-be30-0ad3f2175e07@googlegroups.com> <62b52eb2-67cc-4075-b6e1-f19700e66bed@googlegroups.com> Message-ID: <55135036.1010607@mrabarnett.plus.com> On 2015-03-25 22:36, Chris Angelico wrote: > On Thu, Mar 26, 2015 at 6:49 AM, Tiglath Suriol wrote: >> Two possibilities: >> >> You are a moderator. If you are a moderator you are welcome to delete my tests posts. This is of course improbably because this newsgroup is not moderated. > > You misunderstand newsgroups and mailing lists. Posts do not get > deleted after the event. Even on a web forum, where an administrator > can delete posts, the information is already out there; the instant > any one person has seen your post, you've lost control of it. So think > about what you post - especially when (as in your other thread) it > contains private information. > >> The other possibility is that you are just a guy, who despite the fact that my posts cost you nothing, and you are absolutely free to ignore them, your life is so dull that that you just must intervene and comment on anything you do not comprehend, because appointing yourself net cop is about as exciting as it gets. >> >> It's a free country, I know. You have every right to engage in pathetic speech. > > You also misunderstand freedom. I suggest you explore all three > concepts (freedom, newsgroups, and mailing lists), and learn what > you're actually dealing with. You may find the results rewarding. > > ChrisA > A quick search suggests that he has prior form. From breamoreboy at yahoo.co.uk Wed Mar 25 20:36:49 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 26 Mar 2015 00:36:49 +0000 Subject: test1 In-Reply-To: <55135036.1010607@mrabarnett.plus.com> References: <7edc4671-8f96-491a-be30-0ad3f2175e07@googlegroups.com> <62b52eb2-67cc-4075-b6e1-f19700e66bed@googlegroups.com> <55135036.1010607@mrabarnett.plus.com> Message-ID: On 26/03/2015 00:17, MRAB wrote: > On 2015-03-25 22:36, Chris Angelico wrote: >> On Thu, Mar 26, 2015 at 6:49 AM, Tiglath Suriol >> wrote: >>> Two possibilities: >>> >>> You are a moderator. If you are a moderator you are welcome to >>> delete my tests posts. This is of course improbably because this >>> newsgroup is not moderated. >> >> You misunderstand newsgroups and mailing lists. Posts do not get >> deleted after the event. Even on a web forum, where an administrator >> can delete posts, the information is already out there; the instant >> any one person has seen your post, you've lost control of it. So think >> about what you post - especially when (as in your other thread) it >> contains private information. >> >>> The other possibility is that you are just a guy, who despite the >>> fact that my posts cost you nothing, and you are absolutely free to >>> ignore them, your life is so dull that that you just must intervene >>> and comment on anything you do not comprehend, because appointing >>> yourself net cop is about as exciting as it gets. >>> >>> It's a free country, I know. You have every right to engage in >>> pathetic speech. >> >> You also misunderstand freedom. I suggest you explore all three >> concepts (freedom, newsgroups, and mailing lists), and learn what >> you're actually dealing with. You may find the results rewarding. >> >> ChrisA >> > A quick search suggests that he has prior form. How many years did he get? Was it PHP or C++ ? :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From kai.peters at gmail.com Wed Mar 25 20:38:36 2015 From: kai.peters at gmail.com (kai.peters at gmail.com) Date: Wed, 25 Mar 2015 17:38:36 -0700 (PDT) Subject: Newbie looking for elegant solution In-Reply-To: References: Message-ID: On Tuesday, 24 March 2015 20:14:06 UTC-7, otaksoft... at gmail.com wrote: > I have a list containing 9600 integer elements - each integer is either 0 or 1. > > Starting at the front of the list, I need to combine 8 list elements into 1 by treating them as if they were bits of one byte with 1 and 0 denoting bit on/off (the 8th element would be the rightmost bit of the first byte). > > The end result should be a new list that is 8 x shorter than the original list containing integers between 0 and 255. > > Speed is not of utmost importance - an elegant solution is. Any suggestions? > > Thanks for all input, > Kai I though that the bytes type is Python 3 only? If so, I cannot use it. Using PILLOW, I am generating images from text and these are then sent to a black & white image rendering device which expects 8 one bit pixels as one byte (as a condensed format I guess). This device then "turns" bits into pixels again and displays the image that way. If that is clear enough for you to suggest a better way to achieve what I am after, I'd like to hear it. Kai From no.email at nospam.invalid Wed Mar 25 21:09:23 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 25 Mar 2015 18:09:23 -0700 Subject: Newbie looking for elegant solution References: Message-ID: <87egoc36po.fsf@jester.gateway.sonic.net> kai.peters at gmail.com writes: > I though that the bytes type is Python 3 only? If so, I cannot use it. In Python 2, the regular string type (str) is a byte vector, though it is immutable. Do you send one scan line at a time to the rendering device, or the whole file all at once, or what? Do you want to dump the output to a disk file and send that to the rendering device as a separate step? Anyway, use the chr function to turn a number like 65 into a character like 'A'. From davea at davea.name Wed Mar 25 21:20:35 2015 From: davea at davea.name (Dave Angel) Date: Wed, 25 Mar 2015 21:20:35 -0400 Subject: Basic Python V3 Search Tool using RE module In-Reply-To: References: Message-ID: <55135EE3.3080809@davea.name> On 03/25/2015 03:43 PM, Gregg Dotoli wrote: > > This basic script will help to find > evidence of CryptoWall on a slave drive. Although it is > just a string, more complex regex patterns can be > replaced with the string. It is incredible how fast Python is and > how easy it has helped in quickly assessing a pool of slave drives. > I'm improving it as we speak. > > > Thanks for your help and patience. I'm new with Python. > > > import os > import re > # From the Root > topdir = "." > > # Regex Pattern > pattern="DECRYPT_I" > regexp=re.compile(pattern) > for dirpath,dirnames, files in os.walk(topdir): > for name in files: > result=regexp.search(name) > print(os.path.join(dirpath,name)) > print (result) Any reason you started a new thread? And I thought (from the other thread) that you were trying to search the contents of the files. Right now you're just looking for a file name containing the pattern. That could explain why it's so fast. -- DaveA From tiglathsuriol at gmail.com Wed Mar 25 21:26:34 2015 From: tiglathsuriol at gmail.com (Tiglath Suriol) Date: Wed, 25 Mar 2015 18:26:34 -0700 (PDT) Subject: test1 In-Reply-To: References: <7edc4671-8f96-491a-be30-0ad3f2175e07@googlegroups.com> <62b52eb2-67cc-4075-b6e1-f19700e66bed@googlegroups.com> Message-ID: <584bbccc-7691-4a32-861e-bd317659533b@googlegroups.com> On Wednesday, March 25, 2015 at 7:58:11 PM UTC-4, Mark Lawrence wrote: > > You might be used to dealing with other people in other newsgroups. > This is the Python main mailing list/newsgroup. There is a rather more > civilised way of doing things around here. What arrogance, So you think you are special. I see the same busybodies here as in other newsgroups. Same shit. Why don't you write some Python instead of minding my business? As for ignoring you, why > don't you simply stop posting, then we won't have to? > e We? Is that the royal we or you speak for some group? You won't have to? Hilarious! I've heard of the tail wagging the dog, but the knee jerking the jerk is quite an admission you just made. There is a good reason why I posted two test messages, but I don't owe you that explanation, so you will have to put up with that uncontrollable knee jerk for as long as I post spitballs at you, minus any explanation. Feel free to mind your business. > -- > My fellow Pythonistas, ask not what our language can do for you, ask > what you can do for our language. > > Mark Lawrence From python.list at tim.thechases.com Wed Mar 25 21:29:06 2015 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 25 Mar 2015 20:29:06 -0500 Subject: Basic Python V3 Search Tool using RE module In-Reply-To: <55135EE3.3080809@davea.name> References: <55135EE3.3080809@davea.name> Message-ID: <20150325202906.504dd415@bigbox.christie.dr> On 2015-03-25 21:20, Dave Angel wrote: >> pattern="DECRYPT_I" >> regexp=re.compile(pattern) > > That could explain why it's so fast. While I might have missed it in the thread, it also seems that regexpen are overkill for this. Why not just test for if pattern in name: ... -tkc From kai.peters at gmail.com Wed Mar 25 21:29:53 2015 From: kai.peters at gmail.com (kai.peters at gmail.com) Date: Wed, 25 Mar 2015 18:29:53 -0700 (PDT) Subject: Newbie looking for elegant solution In-Reply-To: <87egoc36po.fsf@jester.gateway.sonic.net> References: <87egoc36po.fsf@jester.gateway.sonic.net> Message-ID: <4fe3dcfc-3d02-4e13-9dcf-ae7ba58f5533@googlegroups.com> On Wednesday, 25 March 2015 18:10:00 UTC-7, Paul Rubin wrote: > nobody writes: > > I though that the bytes type is Python 3 only? If so, I cannot use it. > > In Python 2, the regular string type (str) is a byte vector, though it > is immutable. Do you send one scan line at a time to the rendering > device, or the whole file all at once, or what? Do you want to dump the > output to a disk file and send that to the rendering device as a > separate step? Anyway, use the chr function to turn a number like 65 > into a character like 'A'. The whole file. The device polls a storage area for incoming files and display them. From tiglathsuriol at gmail.com Wed Mar 25 21:34:45 2015 From: tiglathsuriol at gmail.com (Tiglath Suriol) Date: Wed, 25 Mar 2015 18:34:45 -0700 (PDT) Subject: test1 In-Reply-To: <55134bdd$0$12979$c3e8da3$5496439d@news.astraweb.com> References: <7edc4671-8f96-491a-be30-0ad3f2175e07@googlegroups.com> <62b52eb2-67cc-4075-b6e1-f19700e66bed@googlegroups.com> <55134bdd$0$12979$c3e8da3$5496439d@news.astraweb.com> Message-ID: <6aec1e5f-eeed-46e0-b30a-7cb3e5a601b3@googlegroups.com> On Wednesday, March 25, 2015 at 7:59:34 PM UTC-4, Steven D'Aprano wrote: > On Thu, 26 Mar 2015 10:43 am, Tiglath Suriol wrote: > > > I've dealt with people like you in newsgroups for a long time > > So many years, so little learning. It's arseholes like you who make it so > important to invent a way to stab people through the internet. Just go > away, you're not wanted here. > I may stay a while just to poke you in the eye a little longer. I am beginning to enjoy this. People entering a battle of wits unarmed. It's a joy to watch. You talk as if I wanted you to want me. Pure delusion. I posted at nobody, as I am free to do, and idiots come out of the woodwork as if I had committed some infraction. And you even want to stab me. Sterling. Who raised you. wolves? > > > > -- > Steven From tiglathsuriol at gmail.com Wed Mar 25 21:38:41 2015 From: tiglathsuriol at gmail.com (Tiglath Suriol) Date: Wed, 25 Mar 2015 18:38:41 -0700 (PDT) Subject: test1 In-Reply-To: References: <7edc4671-8f96-491a-be30-0ad3f2175e07@googlegroups.com> <62b52eb2-67cc-4075-b6e1-f19700e66bed@googlegroups.com> Message-ID: <2c04cef7-b072-4206-9933-7177d7256ae4@googlegroups.com> On Wednesday, March 25, 2015 at 8:18:22 PM UTC-4, MRAB wrote: > On 2015-03-25 22:36, Chris Angelico wrote: > > On Thu, Mar 26, 2015 at 6:49 AM, Tiglath Suriolwrote: > >> Two possibilities: > >> > >> You are a moderator. If you are a moderator you are welcome to delete my tests posts. This is of course improbably because this newsgroup is not moderated. > > > > You misunderstand newsgroups and mailing lists. Posts do not get > > deleted after the event. Even on a web forum, where an administrator > > can delete posts, the information is already out there; the instant > > any one person has seen your post, you've lost control of it. So think > > about what you post - especially when (as in your other thread) it > > contains private information. > > > >> The other possibility is that you are just a guy, who despite the fact that my posts cost you nothing, and you are absolutely free to ignore them, your life is so dull that that you just must intervene and comment on anything you do not comprehend, because appointing yourself net cop is about as exciting as it gets. > >> > >> It's a free country, I know. You have every right to engage in pathetic speech. > > > > You also misunderstand freedom. I suggest you explore all three > > concepts (freedom, newsgroups, and mailing lists), and learn what > > you're actually dealing with. You may find the results rewarding. > > > > ChrisA > > > A quick search suggests that he has prior form. Get a life at long last. From no.email at nospam.invalid Wed Mar 25 22:53:22 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 25 Mar 2015 19:53:22 -0700 Subject: Newbie looking for elegant solution References: <87egoc36po.fsf@jester.gateway.sonic.net> <4fe3dcfc-3d02-4e13-9dcf-ae7ba58f5533@googlegroups.com> Message-ID: <87a8z031wd.fsf@jester.gateway.sonic.net> kai.peters at gmail.com writes: > The whole file. The device polls a storage area for incoming files and > display them. If the storage area is on disk and you don't care about speed, then it's enough to convert the bit stream and write it out a character at a time. Some other posters mentioned possible alternative PIL interfaces you could use, to the one that gives you a bit stream. The bit stream interface sounds like a bad choice, but it's the only choice available then go for it. From abhi.darkness at gmail.com Wed Mar 25 22:56:53 2015 From: abhi.darkness at gmail.com (Abhiram R) Date: Thu, 26 Mar 2015 08:26:53 +0530 Subject: Sudoku solver In-Reply-To: References: <87r3sdnw5t.fsf@elektro.pacujo.net> <4e81bdb9-52db-46e6-b449-d4241cb2a3f2@googlegroups.com> <87twx8amww.fsf@elektro.pacujo.net> <87iodoakft.fsf@elektro.pacujo.net> Message-ID: On Mar 26, 2015 5:39 AM, "Ian Kelly" wrote: > > "Hard" for a human doesn't necessarily mean "hard" for a programmatic > solver in this case. Try your solver on this one: > > $ cat sudoku2.dat > . . . 7 . . . . . > 1 . . . . . . . . > . . . 4 3 . 2 . . > . . . . . . . . 6 > . . . 5 . 9 . . . > . . . . . . 4 1 8 > . . . . 8 1 . . . > . . 2 . . . . 5 . > . 4 . . . . 3 . . > > I tried the first puzzle you posted, and it took about a second. I > then started running it on this one before I started typing up this > post, and it hasn't finished yet. Sooooo... Is it done yet? And if yes, how long did it take? -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Wed Mar 25 23:24:11 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 25 Mar 2015 21:24:11 -0600 Subject: Sudoku solver In-Reply-To: References: <87r3sdnw5t.fsf@elektro.pacujo.net> <4e81bdb9-52db-46e6-b449-d4241cb2a3f2@googlegroups.com> <87twx8amww.fsf@elektro.pacujo.net> <87iodoakft.fsf@elektro.pacujo.net> Message-ID: On Wed, Mar 25, 2015 at 8:56 PM, Abhiram R wrote: > > On Mar 26, 2015 5:39 AM, "Ian Kelly" wrote: >> > >> "Hard" for a human doesn't necessarily mean "hard" for a programmatic >> solver in this case. Try your solver on this one: >> >> $ cat sudoku2.dat >> . . . 7 . . . . . >> 1 . . . . . . . . >> . . . 4 3 . 2 . . >> . . . . . . . . 6 >> . . . 5 . 9 . . . >> . . . . . . 4 1 8 >> . . . . 8 1 . . . >> . . 2 . . . . 5 . >> . 4 . . . . 3 . . >> >> I tried the first puzzle you posted, and it took about a second. I >> then started running it on this one before I started typing up this >> post, and it hasn't finished yet. > > Sooooo... Is it done yet? And if yes, how long did it take? I don't know, I killed it at about 16 minutes. From oyljerry at gmail.com Wed Mar 25 23:26:12 2015 From: oyljerry at gmail.com (Jerry OELoo) Date: Thu, 26 Mar 2015 11:26:12 +0800 Subject: What is elegant way to do configuration on server app Message-ID: Hi. I have used python to provide a web service app, it will running 7*24, and it will return some data to client by API. Now I want to add some extra data in return data, ex, "status = 1", and I want this value 1 can be configured, that means I can control that service app return status with 0, 1 or other value, and I want to keep service running always. Currently, I can just think out that I put status into a configure file, and service schedule read this file and get status value, Is there any other elegant way to achieve this? What is standard way in python for this requirement? Thanks! Best Regards Jerry -- Rejoice,I Desire! From abhi.darkness at gmail.com Wed Mar 25 23:28:10 2015 From: abhi.darkness at gmail.com (Abhiram R) Date: Thu, 26 Mar 2015 08:58:10 +0530 Subject: Sudoku solver In-Reply-To: References: <87r3sdnw5t.fsf@elektro.pacujo.net> <4e81bdb9-52db-46e6-b449-d4241cb2a3f2@googlegroups.com> <87twx8amww.fsf@elektro.pacujo.net> <87iodoakft.fsf@elektro.pacujo.net> Message-ID: On Thu, Mar 26, 2015 at 8:54 AM, Ian Kelly wrote: > On Wed, Mar 25, 2015 at 8:56 PM, Abhiram R wrote: >> >> On Mar 26, 2015 5:39 AM, "Ian Kelly" wrote: >>> >> >>> "Hard" for a human doesn't necessarily mean "hard" for a programmatic >>> solver in this case. Try your solver on this one: >>> >>> $ cat sudoku2.dat >>> . . . 7 . . . . . >>> 1 . . . . . . . . >>> . . . 4 3 . 2 . . >>> . . . . . . . . 6 >>> . . . 5 . 9 . . . >>> . . . . . . 4 1 8 >>> . . . . 8 1 . . . >>> . . 2 . . . . 5 . >>> . 4 . . . . 3 . . >>> >>> I tried the first puzzle you posted, and it took about a second. I >>> then started running it on this one before I started typing up this >>> post, and it hasn't finished yet. >> >> Sooooo... Is it done yet? And if yes, how long did it take? > > I don't know, I killed it at about 16 minutes. > -- > https://mail.python.org/mailman/listinfo/python-list :( Too bad. I'll give it a go myself. And then try implementing my own solution. Have a lot of time on my hands today :D -- -Abhiram R From kai.peters at gmail.com Wed Mar 25 23:54:09 2015 From: kai.peters at gmail.com (kai.peters at gmail.com) Date: Wed, 25 Mar 2015 20:54:09 -0700 (PDT) Subject: PIL(LOW) - What am I missing? Message-ID: <7029df19-f6c0-4b3f-be11-8ac45752ac68@googlegroups.com> I create an image as per: img = Image.new('1', (1024, 1280), 1) I then draw on it and do: imagedata = list(img.getdata()) print len(imagedata) This gives me 1228800 instead of the expected 1310720 (1024 * 1280) - any ideas what I am missing? As always, any help much appreciated. Kai From rustompmody at gmail.com Thu Mar 26 00:02:03 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 25 Mar 2015 21:02:03 -0700 (PDT) Subject: Supply condition in function call In-Reply-To: References: <87bnjhyohp.fsf@uriel.graune.org> Message-ID: <9b6f41d0-e27e-4e0b-b04d-d15627667330@googlegroups.com> On Thursday, March 26, 2015 at 12:44:03 AM UTC+5:30, Gary Herron wrote: > On 03/25/2015 10:29 AM, Manuel Graune wrote: > > Hi, > > > > I'm looking for a way to supply a condition to an if-statement inside a > > function body when calling the function. I can sort of get what I want > > with using eval (see code below) but I would like to achieve this in a > > safer way. If there is a solution which is safer while being > > less flexible, that would be fine. Also, supplying the condition as a > > string is not necessary. What I want to do is basically like this: > > > > def test1(a, b, condition="True"): > > for i,j in zip(a,b): > > c=i+j > > if eval(condition): > > print("Foo") > > > > test1([0,1,2,3],[1,2,3,4],"i+j >4") > > print("Bar") > > test1([0,1,2,3],[1,2,3,4],"c >4") > > print("Bar") > > test1([0,1,2,3],[1,2,3,4],"a[i] >2") > > print("Bar") > > test1([0,1,2,3],[1,2,3,4]) > > > > > > This is nicely done with lambda expressions: The builtin function filter is for this (more or less). Comprehensions are usually better than filter. [And BTW help(filter) in python2 is much better documention than in python3 ] From gherron at digipen.edu Thu Mar 26 00:23:54 2015 From: gherron at digipen.edu (Gary Herron) Date: Wed, 25 Mar 2015 21:23:54 -0700 Subject: PIL(LOW) - What am I missing? In-Reply-To: <7029df19-f6c0-4b3f-be11-8ac45752ac68@googlegroups.com> References: <7029df19-f6c0-4b3f-be11-8ac45752ac68@googlegroups.com> Message-ID: <551389DA.4080609@digipen.edu> On 03/25/2015 08:54 PM, kai.peters at gmail.com wrote: > I create an image as per: > > img = Image.new('1', (1024, 1280), 1) > > I then draw on it and do: > > imagedata = list(img.getdata()) > print len(imagedata) > > This gives me 1228800 instead of the expected 1310720 (1024 * 1280) > - any ideas what I am missing? > > As always, any help much appreciated. > > Kai Are you sure? Both Python2 and Python3 give me the expected 1310720, I'm running PILLOW version 2.6.1 on Linux (with both Python 3.4.2 and Python 2.7.8). >>> from PIL import Image >>> img = Image.new('1', (1024, 1280), 1) >>> imagedata = list(img.getdata()) >>> print len(imagedata) 1310720 -- Dr. Gary Herron Department of Computer Science DigiPen Institute of Technology (425) 895-4418 From PointedEars at web.de Thu Mar 26 00:35:46 2015 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Thu, 26 Mar 2015 05:35:46 +0100 Subject: A simple single line, triple-quoted comment is giving syntax error. Why? References: <3533816.ZYnZ2OzjCs@PointedEars.de> <3971951.908YQu3oQO@PointedEars.de> Message-ID: <1504323.jUKfeKbQsP@PointedEars.de> Chris Angelico wrote: > On Sun, Mar 22, 2015 at 2:49 PM, Thomas 'PointedEars' Lahn > wrote: >>> Implicit concatenation is part of the syntax, not part of the expression >>> evaluator. >> Reads like nonsense to me. > > What do you mean? As I showed, string literals and consecutive tokens of string literals (?STRING+?) so as to do implicit concatenation *are* expressions of the Python grammar. Expressions are *part of* the syntax of a programming language. Perhaps you mean that the time when implicit concatenation is evaluated (compile time) differs from the time when other expressions are evaluated (runtime). But a) whether that is true depends on the implementation and b) there can be no doubt that either expression needs to be evaluated. So whatever you mean by ?expression evaluator? has to be able to do those things. Which makes the statement above read like nonsense to me. -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From kai.peters at gmail.com Thu Mar 26 00:46:35 2015 From: kai.peters at gmail.com (kai.peters at gmail.com) Date: Wed, 25 Mar 2015 21:46:35 -0700 (PDT) Subject: PIL(LOW) - What am I missing? In-Reply-To: <7029df19-f6c0-4b3f-be11-8ac45752ac68@googlegroups.com> References: <7029df19-f6c0-4b3f-be11-8ac45752ac68@googlegroups.com> Message-ID: On Wednesday, 25 March 2015 20:54:21 UTC-7, kai.p... at gmail.com wrote: > I create an image as per: > > img = Image.new('1', (1024, 1280), 1) > > I then draw on it and do: > > imagedata = list(img.getdata()) > print len(imagedata) > > This gives me 1228800 instead of the expected 1310720 (1024 * 1280) > - any ideas what I am missing? Please disregard - typo after a long night :( > > As always, any help much appreciated. > > Kai From tjreedy at udel.edu Thu Mar 26 01:00:33 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 26 Mar 2015 01:00:33 -0400 Subject: Regex Python Help In-Reply-To: <5513404c$0$13000$c3e8da3$5496439d@news.astraweb.com> References: <099b0ca2-1f5e-4eb4-a7d0-d8210bcca51a@googlegroups.com> <94a16553-1d08-46ca-9290-d024cf408248@googlegroups.com> <5513404c$0$13000$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/25/2015 7:10 PM, Steven D'Aprano wrote: > Does Windows shell have grep? How about Powershell? No. I just use Idle's grep (Find in Files). And I generally would even if Command Prompt did have grep. Idle's has the nice feature that output goes in an Output Window, with each line found prefaced with filename and line number. One can then right click on a line and open the file at that line in an Idle editor. One can also save the list to a file if so inclined. -- Terry Jan Reedy From ian.g.kelly at gmail.com Thu Mar 26 01:09:45 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 25 Mar 2015 23:09:45 -0600 Subject: A simple single line, triple-quoted comment is giving syntax error. Why? In-Reply-To: <1504323.jUKfeKbQsP@PointedEars.de> References: <3533816.ZYnZ2OzjCs@PointedEars.de> <3971951.908YQu3oQO@PointedEars.de> <1504323.jUKfeKbQsP@PointedEars.de> Message-ID: On Wed, Mar 25, 2015 at 10:35 PM, Thomas 'PointedEars' Lahn wrote: > Chris Angelico wrote: > >> On Sun, Mar 22, 2015 at 2:49 PM, Thomas 'PointedEars' Lahn >> wrote: >>>> Implicit concatenation is part of the syntax, not part of the expression >>>> evaluator. >>> Reads like nonsense to me. >> >> What do you mean? > > As I showed, string literals and consecutive tokens of string literals > (?STRING+?) so as to do implicit concatenation *are* expressions of the > Python grammar. Expressions are *part of* the syntax of a programming > language. > > Perhaps you mean that the time when implicit concatenation is evaluated > (compile time) differs from the time when other expressions are evaluated > (runtime). But a) whether that is true depends on the implementation and > b) there can be no doubt that either expression needs to be evaluated. So > whatever you mean by ?expression evaluator? has to be able to do those > things. > > Which makes the statement above read like nonsense to me. What the grammar that you quoted from shows is that STRING+ is an expression. The individual STRINGs of a STRING+ are not expressions, except to the extent that they can be parsed in isolation as a STRING+. By the same token, a STRING+ is a single string literal, not an aggregate of several. Ancillary data point: >>> help(ast.literal_eval) Safely evaluate an expression node or a string containing a Python expression. The string or node provided may only consist of the following Python literal structures: strings, bytes, numbers, tuples, lists, dicts, sets, booleans, and None. >>> ast.literal_eval('"foo" "bar"') 'foobar' So the ast.literal_eval also treats this as one literal expression. From davea at davea.name Thu Mar 26 01:23:23 2015 From: davea at davea.name (Dave Angel) Date: Thu, 26 Mar 2015 01:23:23 -0400 Subject: A simple single line, triple-quoted comment is giving syntax error. Why? In-Reply-To: References: <3533816.ZYnZ2OzjCs@PointedEars.de> <3971951.908YQu3oQO@PointedEars.de> <1504323.jUKfeKbQsP@PointedEars.de> Message-ID: <551397CB.6070000@davea.name> On 03/26/2015 01:09 AM, Ian Kelly wrote: > > >>>>> https://docs.python.org/3/reference/lexical_analysis.html#string-literal-concatenation > > What the grammar that you quoted from shows is that STRING+ is an > expression. The individual STRINGs of a STRING+ are not expressions, > except to the extent that they can be parsed in isolation as a > STRING+. By the same token, a STRING+ is a single string literal, not > an aggregate of several. > That's the way I also read the BNF. But something I cannot find in that chapter of the reference is the definition of STRING+ Naturally searching for 'string' finds way too many spurious refs. -- DaveA From rosuav at gmail.com Thu Mar 26 02:00:33 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 Mar 2015 17:00:33 +1100 Subject: Supply condition in function call In-Reply-To: <9b6f41d0-e27e-4e0b-b04d-d15627667330@googlegroups.com> References: <87bnjhyohp.fsf@uriel.graune.org> <9b6f41d0-e27e-4e0b-b04d-d15627667330@googlegroups.com> Message-ID: On Thu, Mar 26, 2015 at 3:02 PM, Rustom Mody wrote: > [And BTW > help(filter) in python2 is much better documention than in python3 > ] Python 2.7.3 (default, Mar 13 2014, 11:03:55) [GCC 4.7.2] on linux2 filter(...) filter(function or None, sequence) -> list, tuple, or string Return those items of sequence for which function(item) is true. If function is None, return the items that are true. If sequence is a tuple or string, return the same type, else return a list. Python 3.5.0a0 (default:4709290253e3, Jan 20 2015, 21:48:07) [GCC 4.7.2] on linux class filter(object) | filter(function or None, iterable) --> filter object | | Return an iterator yielding those items of iterable for which function(item) | is true. If function is None, return the items that are true. | | Methods defined here: (chomp a handful of method details) Looks pretty comparable to me. Py2 clearly stipulates that it's a function that returns a tuple, string, or list. Py3 defines it as a class, and then describes what it does (it's an iterator) and then its methods. ChrisA From manuel.graune at koeln.de Thu Mar 26 02:27:39 2015 From: manuel.graune at koeln.de (Manuel Graune) Date: Thu, 26 Mar 2015 07:27:39 +0100 Subject: Supply condition in function call References: <87bnjhyohp.fsf@uriel.graune.org> Message-ID: <87r3sc9stg.fsf@uriel.graune.org> Gary Herron writes: > On 03/25/2015 10:29 AM, Manuel Graune wrote: >> >> def test1(a, b, condition="True"): >> for i,j in zip(a,b): >> c=i+j >> if eval(condition): >> print("Foo") >> >> test1([0,1,2,3],[1,2,3,4],"i+j >4") >> print("Bar") >> test1([0,1,2,3],[1,2,3,4],"c >4") >> print("Bar") >> test1([0,1,2,3],[1,2,3,4],"a[i] >2") >> > > This is nicely done with lambda expressions: > > To pass in a condition as a function: > test1([0,1,2,3],[1,2,3,4], lambda i,j: i+j<4) > > To check the condition in the function: > if condition(i,j): This seems to be the right direction and a good solution for simple cases. Unfortunately this: > To get the full range of conditions, you will need to include all the variables needed by any condition you can imagine. So the above suggestions may need to be expanded to: > ... lambda i,j,a,b: ... or whatever > > and > ... condition(i,j,a,b) ... or whatever > is not as concise as I had hoped for. Is there a possibility to do (maybe with a helper function inside the main function's body) solve this more elegantly? I'm thinking of some combination of e. g. **kwargs, dir() and introspection. Regards, Manuel -- A hundred men did the rational thing. The sum of those rational choices was called panic. Neal Stephenson -- System of the world http://www.graune.org/GnuPG_pubkey.asc Key fingerprint = 1E44 9CBD DEE4 9E07 5E0A 5828 5476 7E92 2DB4 3C99 From cs at zip.com.au Thu Mar 26 03:06:00 2015 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 26 Mar 2015 18:06:00 +1100 Subject: Supply condition in function call In-Reply-To: <87r3sc9stg.fsf@uriel.graune.org> References: <87r3sc9stg.fsf@uriel.graune.org> Message-ID: <20150326070600.GA2199@cskk.homeip.net> On 26Mar2015 07:27, Manuel Graune wrote: >Gary Herron writes: >> On 03/25/2015 10:29 AM, Manuel Graune wrote: >>> def test1(a, b, condition="True"): >>> for i,j in zip(a,b): >>> c=i+j >>> if eval(condition): >>> print("Foo") >>> >>> test1([0,1,2,3],[1,2,3,4],"i+j >4") >>> print("Bar") >>> test1([0,1,2,3],[1,2,3,4],"c >4") >>> print("Bar") >>> test1([0,1,2,3],[1,2,3,4],"a[i] >2") >> >> This is nicely done with lambda expressions: >> >> To pass in a condition as a function: >> test1([0,1,2,3],[1,2,3,4], lambda i,j: i+j<4) >> >> To check the condition in the function: >> if condition(i,j): > >This seems to be the right direction and a good solution for simple >cases. Unfortunately this: > >> To get the full range of conditions, you will need to include all the variables needed by any condition you can imagine. So the above suggestions may need to be expanded to: >> ... lambda i,j,a,b: ... or whatever >> >> and >> ... condition(i,j,a,b) ... or whatever >> > >is not as concise as I had hoped for. Is there a possibility to do >(maybe with a helper function inside the main function's body) solve >this more elegantly? I'm thinking of some combination of e. g. **kwargs, >dir() and introspection. Yes. Consider locals(): https://docs.python.org/3/library/functions.html#locals which is a built in function returning a copy of the current local variables in a dict. Example: condition_test = lambda vars: vars['i'] + vars[j'] > 4 def test1(a, b, condition): for i, j in zip(a,b): c = i + j if condition(locals()): print("Foo") test1([0,1,2,3], [1,2,3,4], condition_test) This passes the local variables inside test1() to "condition" as a single parameter. Now, I grant that vars['i'] is a miracle of tediousness. So consider this elaboration: from collections import namedtuple condition_test = lambda vars: vars.i + vars.j > 4 def test1(a, b, condition): for i, j in zip(a,b): c = i + j vars = locals() varnames = list(vars.keys()) varstupletype = namedtuple("locals", varnames) varstuple = varstupletype(*[ vars[k] for k in varnames ]) if condition(varstuple): print("Foo") Here, the condition_test function/lambda uses "vars.i" and "vars.j", which i think you'll agree is easier to read and write. The price is the construction of a "namedtuple" to hold the variable name values. See: https://docs.python.org/3/library/collections.html#collections.namedtuple So the (untested) code above: - get the locals() as before - get the names of the variables; it is important to have this in a array because we need to access the values in the same order when we make the tuple - make a new namedtuple class "varstupletype", which is used to make the named tuple - make the named tuple itself with the values of the variables in order If you're writing a lot of test functions like test1 you can push the namedtuple stuff off into a helper function: def vartuple(vars): varnames = list(vars.keys()) varstupletype = namedtuple("locals", varnames) varstuple = varstupletype(*[ vars[k] for k in varnames ]) return varstuple and then "test1()" can look like this: def test1(a, b, condition): for i, j in zip(a,b): c = i + j if condition(vartuple(locals())): print("Foo") which makes it much easier to write test2 and so on later. Does this help? Cheers, Cameron Simpson Your reality is lies and balderdash, and I'm glad to say that I have no grasp of it. - Baron Munchausen From frank at chagford.com Thu Mar 26 04:19:48 2015 From: frank at chagford.com (Frank Millman) Date: Thu, 26 Mar 2015 10:19:48 +0200 Subject: Sudoku solver References: <87r3sdnw5t.fsf@elektro.pacujo.net> Message-ID: "Marko Rauhamaa" wrote in message news:87r3sdnw5t.fsf at elektro.pacujo.net... > > > I post below a sudoku solver. I eagerly await neater implementations (as > well as bug reports). > Here is another python-based sudoku solver - http://www.ics.uci.edu/~eppstein/PADS/Sudoku.py >From its docstring - "A proper Sudoku puzzle must have a unique solution, and it should be possible to reach that solution by a sequence of logical deductions without trial and error. To the extent possible, we strive to keep the same ethic in our automated solver, by mimicking human rule-based reasoning, rather than resorting to brute force backtracking search." A neat feature is that, having printed the solution, it then lists every step it took in its reasoning process to arrive at the solution. It solved Marko's original puzzle and Ian's puzzle in less than a second. It could not solve Marko's second one, returning "impossible" immediately. Here is another one that does not use python, but uses SQL - https://www.sqlite.org/lang_with.html You will find it at the bottom of the page, under the heading "Outlandish Recursive Query Examples". Frank Millman From ben+python at benfinney.id.au Thu Mar 26 04:59:13 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 26 Mar 2015 19:59:13 +1100 Subject: What is elegant way to do configuration on server app References: Message-ID: <85sics5e3i.fsf@benfinney.id.au> Jerry OELoo writes: > Currently, I can just think out that I put status into a configure > file, and service schedule read this file and get status value, That sounds like a fine start. Some advice: * You may be tempted to make the configuration file executable (e.g. Python code). Resist that temptation; keep it *much* simpler, a non-executable data format. Python's standard library has the ?configparser? module to parse and provide the values from a very common configuration file format. Use that unless you have a good reason not to. * Your program can ?poll? the configuration file to see whether it has changed. At startup, read the config file's modification timestamp . Make a part of your event loop (assuming your server runs an event loop) that wakes up every N seconds (e.g. every 60 seconds) and checkes the file's modification timestamp again; if it's newer, record that value for future comparisons, then re-read the file for its values. Hope that helps. -- \ ?For your convenience we recommend courteous, efficient | `\ self-service.? ?supermarket, Hong Kong | _o__) | Ben Finney From __peter__ at web.de Thu Mar 26 05:03:27 2015 From: __peter__ at web.de (Peter Otten) Date: Thu, 26 Mar 2015 10:03:27 +0100 Subject: Supply condition in function call References: <87r3sc9stg.fsf@uriel.graune.org> <20150326070600.GA2199@cskk.homeip.net> Message-ID: Cameron Simpson wrote: > On 26Mar2015 07:27, Manuel Graune wrote: >>Gary Herron writes: >>> On 03/25/2015 10:29 AM, Manuel Graune wrote: >>>> def test1(a, b, condition="True"): >>>> for i,j in zip(a,b): >>>> c=i+j >>>> if eval(condition): >>>> print("Foo") >>>> >>>> test1([0,1,2,3],[1,2,3,4],"i+j >4") >>>> print("Bar") >>>> test1([0,1,2,3],[1,2,3,4],"c >4") >>>> print("Bar") >>>> test1([0,1,2,3],[1,2,3,4],"a[i] >2") >>> >>> This is nicely done with lambda expressions: >>> >>> To pass in a condition as a function: >>> test1([0,1,2,3],[1,2,3,4], lambda i,j: i+j<4) >>> >>> To check the condition in the function: >>> if condition(i,j): >> >>This seems to be the right direction and a good solution for simple >>cases. Unfortunately this: >> >>> To get the full range of conditions, you will need to include all the >>> variables needed by any condition you can imagine. So the above >>> suggestions may need to be expanded to: >>> ... lambda i,j,a,b: ... or whatever >>> >>> and >>> ... condition(i,j,a,b) ... or whatever >>> >> >>is not as concise as I had hoped for. Is there a possibility to do >>(maybe with a helper function inside the main function's body) solve >>this more elegantly? I'm thinking of some combination of e. g. **kwargs, >>dir() and introspection. > > Yes. > > Consider locals(): > > https://docs.python.org/3/library/functions.html#locals > > which is a built in function returning a copy of the current local > variables in a dict. Example: > > condition_test = lambda vars: vars['i'] + vars[j'] > 4 > > def test1(a, b, condition): > for i, j in zip(a,b): > c = i + j > if condition(locals()): > print("Foo") > > test1([0,1,2,3], [1,2,3,4], condition_test) > > This passes the local variables inside test1() to "condition" as a single > parameter. Now, I grant that vars['i'] is a miracle of tediousness. So > consider this elaboration: > > from collections import namedtuple > > condition_test = lambda vars: vars.i + vars.j > 4 > > def test1(a, b, condition): > for i, j in zip(a,b): > c = i + j > vars = locals() > varnames = list(vars.keys()) That leaves varnames in undefined order. Consider varnames = sorted(vars) instead or pass the list of arguments explicitly, optionally with some inspect fallback: $ cat pass_condition_inspect.py import inspect def test3(a, b, condition, args=None): if args is None: args = inspect.getargspec(condition).args for i, j in zip(a,b): c = i + j _locals = locals() if condition(*[_locals[name] for name in args]): print("Foo", i, j) def condition(c, i): return i * i > c test3([1, 2, 3], [2, 3, 4], condition) print("---") # note reverse order of argument names test3([1, 2, 3], [2, 3, 4], condition, ["i", "c"]) $ python3 pass_condition_inspect.py Foo 3 4 --- Foo 1 2 Foo 2 3 Foo 3 4 A simpler alternative is changing the signature of condition() and passing keyword arguments: $ cat pass_condition.py def test2(a, b, condition): for i, j in zip(a,b): c = i + j if condition(**locals()): print("Foo", i, j) def condition(c, i, **unused): return i * i > c test2([1, 2, 3], [2, 3, 4], condition) $ python3 pass_condition.py Foo 3 4 Creating a locals() dict on every iteration is still costly, and personally I would prefer the tighter interface where you pass a limited set of arguments explicitly. > varstupletype = namedtuple("locals", varnames) > varstuple = varstupletype(*[ vars[k] for k in varnames ]) > if condition(varstuple): > print("Foo") > > Here, the condition_test function/lambda uses "vars.i" and "vars.j", which > i think you'll agree is easier to read and write. The price is the > construction of a "namedtuple" to hold the variable name values. See: > > https://docs.python.org/3/library/collections.html#collections.namedtuple > > So the (untested) code above: > > - get the locals() as before > - get the names of the variables; it is important to have this in a > array because we need to access the values in the same order when we > make the tuple - make a new namedtuple class "varstupletype", which is > used to make the named tuple - make the named tuple itself with the > values of the variables in order > > If you're writing a lot of test functions like test1 you can push the > namedtuple stuff off into a helper function: > > def vartuple(vars): > varnames = list(vars.keys()) > varstupletype = namedtuple("locals", varnames) > varstuple = varstupletype(*[ vars[k] for k in varnames ]) > return varstuple > > and then "test1()" can look like this: > > def test1(a, b, condition): > for i, j in zip(a,b): > c = i + j > if condition(vartuple(locals())): > print("Foo") > > which makes it much easier to write test2 and so on later. From webmailgroups at gmail.com Thu Mar 26 05:47:54 2015 From: webmailgroups at gmail.com (Ivan Evstegneev) Date: Thu, 26 Mar 2015 11:47:54 +0200 Subject: Function Defaults - avoiding unneccerary combinations of arguments at input In-Reply-To: <55134964$0$13004$c3e8da3$5496439d@news.astraweb.com> References: <55134964$0$13004$c3e8da3$5496439d@news.astraweb.com> Message-ID: <001e01d067a9$f009ea60$d01dbf20$@gmail.com> > -----Original Message----- > From: Python-list [mailto:python-list- > bounces+webmailgroups=gmail.com at python.org] On Behalf Of Steven > D'Aprano > Sent: Thursday, March 26, 2015 01:49 > To: python-list at python.org > Subject: Re: Function Defaults - avoiding unneccerary combinations of > arguments at input > > On Thu, 26 Mar 2015 04:43 am, Ivan Evstegneev wrote: > > > Hello all , > > > > > > Just a little question about function's default arguments. > > > > Let's say I have this function: > > > > def my_fun(history=False, built=False, current=False, topo=None, > > full=False, file=None): > > if currnet and full: > > do something_1 > > elif current and file: > > do something_2 > > elif history and full and file: > > do something_3 > > > This is an extreme example that shows why Guido's Law "No constant > arguments" is a good design principle. (Well, it's not really so much a law as a > guideline.) > > If you have a function that looks like this: > > def spam(arg, flag=True): > if flag: > return do_this(arg) > else: > return do_that(arg) > > > then you should just use do_this and do_that directly and get rid of spam. > > In your case, its hard to say *exactly* what you should do, since you are only > showing a small sketch of "my_fun", but it looks to me that it tries to do too > much. You can probably split it into two or four smaller functions, and avoid > needing so many (or any!) flags. > > That will avoid (or at least reduce) the need to check for mutually > incompatible sets of arguments. > > Another useful design principle: if dealing with the combinations of > arguments is too hard, that's a sign that you have too many combinations of > arguments. > > If there are combinations which are impossible, there are three basic ways to > deal with that. In order from best to worst: > > > (1) Don't let those combinations occur at all. Redesign your function, or split > it into multiple functions, so the impossible combinations no longer exist. > > (2) Raise an error when an impossible combination occurs. > > (3) Just ignore one or more argument so that what was impossible is now > possible. > > > > > -- > Steven > > -- > https://mail.python.org/mailman/listinfo/python-list Hello Steven, As I said in a previous mail, main purpose of this arguments is to define what path should be chose. It is actually one xls file that could be placed into various placed within my folder tree. For instance, I have following folder tree: data_lib/ current/ history/ built/ Say I have "test.xls" that could be in one of those three folders. I wrote a function that reads it out, and its input arguments just define where it should be read. So all those "ifs" related to path definition. Still now I'm thinking to really split it out... I'll have a separate function for path definition and then it will call a common reader_fun() in order to read this file. Sincerely, Ivan From marfig at gmail.com Thu Mar 26 05:48:44 2015 From: marfig at gmail.com (Mario Figueiredo) Date: Thu, 26 Mar 2015 10:48:44 +0100 Subject: module attributes and docstrings References: <55114f5e$0$12991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Sorry for the late reply. We experienced a 3 day blackout following one of the most amazing thunderstorms I've witnessed in my life. On Tue, 24 Mar 2015 22:49:49 +1100, Steven D'Aprano wrote: >On Tue, 24 Mar 2015 07:55 pm, Mario Figueiredo wrote: > >> Reading PEP 257 and 258 I got the impression that I could document >> module attributes and these would be available in the __doc__ >> attribute of the object. > >PEP 258 is rejected, so you can't take that as definitive. Ah! That explains it then. Thank you. (Also learned to start paying more attention to the status field). > >PEP 257 has this definition very early in the document: > > A docstring is a string literal that occurs as the first > statement in a module, function, class, or method definition. > > >Nothing there about documenting arbitrary attributes. That did get me a little confused. But since PEP 258 required PEP 257, I just assumed the former would redefine the latter and didn't make much of the apparent contradiction. > >Even if there was support from the compiler to extract the docstring, where >would it be stored? Consider: > >spam = None >"""Spammy goodness.""" >eggs = None >"""Scrambled, not fried.""" > >There's only one None object, and even if it could take a docstring (and it >can't), which docstring would it get? Presumably the second, which would >make help(spam) confusing, but when we say eggs = 23 the docstring would >disappear too. This is a byproduct of me still thinking in terms of C variables. When I first read that paragraph of yours, it didn't make sense to me -- "What is he talking about? I'm documenting the spam and eggs identifiers, not the None object". But when I was trying to reply to you by mounting a case around writing directly to the __doc__ attribute of the spam and eggs identifiers, the python shell was quick to make me realized my foolishness, and I remembered about Python variables not being the same as C variables. From marfig at gmail.com Thu Mar 26 05:53:48 2015 From: marfig at gmail.com (Mario Figueiredo) Date: Thu, 26 Mar 2015 10:53:48 +0100 Subject: module attributes and docstrings References: Message-ID: On Tue, 24 Mar 2015 15:33:41 -0400, Terry Reedy wrote: > >You have discovered one of advantages of a def statement over a >name=lambda assignment statement. In Python, there is no good reason to >use the latter form and PEP 8 specifically discourages it: "Always use a >def statement instead of an assignment statement that binds a lambda >expression directly to an identifier." Chris also suggested me this. And frankly, I don't see why I shouldn't follow that advise. It's good advice. However, lambda functions do read well in my mind and I find it hard to spot where they obscure the code more than a function. So the explicit vs. implicit part of the argument doesn't translate well with me. I however agree that a function declaration brings other benefits, like the ability to decorate or document. I will reserve the use of lambdas to only where they are necessary. Thanks. From cs at zip.com.au Thu Mar 26 06:06:29 2015 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 26 Mar 2015 21:06:29 +1100 Subject: Supply condition in function call In-Reply-To: References: Message-ID: <20150326100629.GA7173@cskk.homeip.net> On 26Mar2015 10:03, Peter Otten <__peter__ at web.de> wrote: >Cameron Simpson wrote: >> vars = locals() >> varnames = list(vars.keys()) > >That leaves varnames in undefined order. Consider > >varnames = sorted(vars) Actually, not necessary. I started with sorted, but it is irrelevant, so I backed off to "list" to avoid introducing an unwarranted implication, in fact precisely the implicaion you are making. The only requirement, which I mentioned, is that the values used to initialise the namedtuple are supplied in the same order as the tuple field names, so all that is needed is to suck the .keys() out once and use them in the same order when we construct the namedtuple. Hence just a list. Cheers, Cameron Simpson From rosuav at gmail.com Thu Mar 26 06:27:45 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 Mar 2015 21:27:45 +1100 Subject: module attributes and docstrings In-Reply-To: References: Message-ID: On Thu, Mar 26, 2015 at 8:53 PM, Mario Figueiredo wrote: > However, lambda functions do read well in my mind and I find it hard > to spot where they obscure the code more than a function. So the > explicit vs. implicit part of the argument doesn't translate well with > me. I however agree that a function declaration brings other benefits, > like the ability to decorate or document. A function is a function is a function, so really, it's just a question of whether you create them with a statement (def) or an expression (lambda). Two basic rules of thumb: 1) If you're assigning a lambda function to a simple name, then you don't need it to be an expression, so use def. 2) If you're warping your function body to make it an expression, use def. Basically, look at the outside and look at the inside. In some cases, it's obvious that it's all expressions: # Sort a list of widget objects by name widgets.sort(key=lambda w: w.name) Other times, it's pretty obvious that you should be using statements: delete_name_if_blank = lambda w: delattr(w, "name") if w.name == "" else None list(map(delete_name_if_blank, widgets)) In between, there's a lot of room to call it either way. ChrisA From __peter__ at web.de Thu Mar 26 06:37:48 2015 From: __peter__ at web.de (Peter Otten) Date: Thu, 26 Mar 2015 11:37:48 +0100 Subject: Supply condition in function call References: <20150326100629.GA7173@cskk.homeip.net> Message-ID: Cameron Simpson wrote: > On 26Mar2015 10:03, Peter Otten <__peter__ at web.de> wrote: >>Cameron Simpson wrote: >>> vars = locals() >>> varnames = list(vars.keys()) >> >>That leaves varnames in undefined order. Consider >> >>varnames = sorted(vars) > > Actually, not necessary. > > I started with sorted, but it is irrelevant, so I backed off to "list" to > avoid introducing an unwarranted implication, in fact precisely the > implicaion you are making. > > The only requirement, which I mentioned, is that the values used to > initialise the namedtuple are supplied in the same order as the tuple > field names, so all that is needed is to suck the .keys() out once and use > them in the same order when we construct the namedtuple. Hence just a > list. You are right. Once I spotted the "error" I failed to notice that you pass the named tuple as a single argument, i. e. condition(nt), not condition(*nt) :( By the way, in this case you don't need the list at all: def vartuple(vars): return namedtuple("locals", vars)._make(vars.values()) From steve+comp.lang.python at pearwood.info Thu Mar 26 06:51:01 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 26 Mar 2015 21:51:01 +1100 Subject: Function Defaults - avoiding unneccerary combinations of arguments at input References: <55134964$0$13004$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5513e495$0$12983$c3e8da3$5496439d@news.astraweb.com> On Thu, 26 Mar 2015 08:47 pm, Ivan Evstegneev wrote: > > >> -----Original Message----- >> From: Python-list [mailto:python-list- >> bounces+webmailgroups=gmail.com at python.org] On Behalf Of Steven >> D'Aprano >> Sent: Thursday, March 26, 2015 01:49 >> To: python-list at python.org >> Subject: Re: Function Defaults - avoiding unneccerary combinations of >> arguments at input >> >> On Thu, 26 Mar 2015 04:43 am, Ivan Evstegneev wrote: >> >> > Hello all , >> > >> > >> > Just a little question about function's default arguments. >> > >> > Let's say I have this function: >> > >> > def my_fun(history=False, built=False, current=False, topo=None, >> > full=False, file=None): >> > if currnet and full: >> > do something_1 >> > elif current and file: >> > do something_2 >> > elif history and full and file: >> > do something_3 [...] > As I said in a previous mail, main purpose of this arguments is to define > what path should be chose. It is actually one xls file that could be > placed into various placed within my folder tree. > > For instance, I have following folder tree: > > data_lib/ > current/ > history/ > built/ > > Say I have "test.xls" that could be in one of those three folders. > I wrote a function that reads it out, and its input arguments just define > where it should be read. So all those "ifs" related to path definition. Perhaps something like this? def my_func(subdir): if subdir not in ("current", "history", "built"): raise ValueError("invalid sub-directory") # Better to use os.path.join, but I'm feeling lazy. path = "path/to/data_lib/" + subdir + "/test.xls" process(path) -- Steven From denismfmcmahon at gmail.com Thu Mar 26 08:04:02 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Thu, 26 Mar 2015 12:04:02 +0000 (UTC) Subject: Regex Python Help References: <099b0ca2-1f5e-4eb4-a7d0-d8210bcca51a@googlegroups.com> <94a16553-1d08-46ca-9290-d024cf408248@googlegroups.com> Message-ID: On Wed, 25 Mar 2015 14:19:39 -0700, Gregg Dotoli wrote: > On Wednesday, March 25, 2015 at 4:36:01 PM UTC-4, Denis McMahon wrote: >> On Tue, 24 Mar 2015 11:13:41 -0700, gdotoli wrote: >> >> > I am creating a tool to search a filesystem for one simple string. >> >> man grep >> >> STOP! REINVENTING! THE! WHEEL! >> >> Your new wheel will invariably be slower and less efficient than the >> old one. > Grep is regular expressions. If I'm using Python, I'll use the Python > modules. > Silly 1. Please don't top post, this is usenet, we don't top post, comments go after the text they comment on soi we can read down the page and it makes sense. 2. You gave the thread the title of "regex python help". 3. Your initial comment was "I am creating a tool to search a filesystem for one simple string." 4. The tool (see 3) already exists, it's called grep, it uses regular expressions (see 2). It's also going to be a lot faster than using python. 5. According to your post, grep seems to be the tool you are looking for. 6. Reinventing grep in python seems much more silly to me, by the time you've finished writing and testing the python code (especially if you need to seek help from a newsgroup in the process) grep would have found and identified every file containing your "one simple string". -- Denis McMahon, denismfmcmahon at gmail.com From marko at pacujo.net Thu Mar 26 08:13:42 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 26 Mar 2015 14:13:42 +0200 Subject: Sudoku solver References: <87r3sdnw5t.fsf@elektro.pacujo.net> <4e81bdb9-52db-46e6-b449-d4241cb2a3f2@googlegroups.com> <87twx8amww.fsf@elektro.pacujo.net> <87iodoakft.fsf@elektro.pacujo.net> Message-ID: <87k2y4neh5.fsf@elektro.pacujo.net> Abhiram R : > On Thu, Mar 26, 2015 at 8:54 AM, Ian Kelly wrote: >> On Wed, Mar 25, 2015 at 8:56 PM, Abhiram R wrote: >>> On Mar 26, 2015 5:39 AM, "Ian Kelly" wrote: >>>> $ cat sudoku2.dat >>>> . . . 7 . . . . . >>>> 1 . . . . . . . . >>>> . . . 4 3 . 2 . . >>>> . . . . . . . . 6 >>>> . . . 5 . 9 . . . >>>> . . . . . . 4 1 8 >>>> . . . . 8 1 . . . >>>> . . 2 . . . . 5 . >>>> . 4 . . . . 3 . . >>>> >>>> I tried the first puzzle you posted, and it took about a second. I >>>> then started running it on this one before I started typing up this >>>> post, and it hasn't finished yet. >>> >>> Sooooo... Is it done yet? And if yes, how long did it take? >> >> I don't know, I killed it at about 16 minutes. > > :( Too bad. I'll give it a go myself. And then try implementing my own > solution. Have a lot of time on my hands today :D Early optimization and so on and so forth... I have optimized my solution slightly: 1. precalculated integer division operations (big savings) 2. interned integers (little savings) The example above now finishes in 41 minutes on my computer. (The C version finishes in 13 seconds). The program runs single-threaded. Taking the trouble to parallelize the algorithm is out of scope for the purposes of this discussion; it would necessarily destroy the compactness of the solution. ======================================================================== #!/usr/bin/env python3 import sys M = 3 N = M * M P = M * N Q = M * P buddies = [ [ buddy for buddy in range(Q) if buddy != slot and (buddy % N == slot % N or buddy // N == slot // N or buddy // P == slot // P and buddy % N // M == slot % N // M) ] for slot in range(Q) ] interned = { n : n for n in range(1, N + 1) } candidates = list(interned.values()) def main(): board = [] for n in sys.stdin.read().split(): try: board.append(int(n)) except ValueError: board.append(None) solve(board) def solve(board, slot=0): if slot == Q: report(board) elif board[slot] is None: for candidate in candidates: if not any(board[buddy] is candidate for buddy in buddies[slot]): board[slot] = candidate solve(board, slot + 1) board[slot] = None else: solve(board, slot + 1) def report(board): print("\n".join( " ".join(str(board[row * N + col]) for col in range(N)) for row in range(N))) print() if __name__ == '__main__': main() ======================================================================== Marko From marko at pacujo.net Thu Mar 26 08:26:22 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 26 Mar 2015 14:26:22 +0200 Subject: Sudoku solver References: <87r3sdnw5t.fsf@elektro.pacujo.net> Message-ID: <87fv8sndw1.fsf@elektro.pacujo.net> "Frank Millman" : > Here is another python-based sudoku solver - > > http://www.ics.uci.edu/~eppstein/PADS/Sudoku.py > >>From its docstring - > > "A proper Sudoku puzzle must have a unique solution, and it should be > possible to reach that solution by a sequence of logical deductions > without trial and error. I don't think that statement holds water. Trial-and-error is at the basis of deduction (reductio ad absurdum). The human solver employs it in their head. The question is, what is the difference between pen-and-paper and in-your-head for a computer program? (Question: Are computers good at blindfold chess?) > To the extent possible, we strive to keep the same ethic in our > automated solver, by mimicking human rule-based reasoning, rather than > resorting to brute force backtracking search." That's cool... > A neat feature is that, having printed the solution, it then lists > every step it took in its reasoning process to arrive at the solution. > > It solved Marko's original puzzle and Ian's puzzle in less than a > second. It could not solve Marko's second one, returning "impossible" > immediately. ... but that realization greatly reduces the value of the solver. I brought up sudoku solving as a "real-world" example of the usefulness of exhaustive recursion. The concerns on astronomical execution times must be considered but at the same time, one should realize things aren't as bad as they would seem: exhaustion is a practical way to solve sudoku puzzles and analogous programming challenges. The compactness of a working sudoku solver should demonstrate something about (1) the usefulness of recursion and (2) the expressive power of Python. Marko From rosuav at gmail.com Thu Mar 26 08:37:10 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 Mar 2015 23:37:10 +1100 Subject: Sudoku solver In-Reply-To: <87fv8sndw1.fsf@elektro.pacujo.net> References: <87r3sdnw5t.fsf@elektro.pacujo.net> <87fv8sndw1.fsf@elektro.pacujo.net> Message-ID: On Thu, Mar 26, 2015 at 11:26 PM, Marko Rauhamaa wrote: > "Frank Millman" : > >> Here is another python-based sudoku solver - >> >> http://www.ics.uci.edu/~eppstein/PADS/Sudoku.py >> >>>From its docstring - >> >> "A proper Sudoku puzzle must have a unique solution, and it should be >> possible to reach that solution by a sequence of logical deductions >> without trial and error. > > I don't think that statement holds water. Trial-and-error is at the > basis of deduction (reductio ad absurdum). The human solver employs it > in their head. The question is, what is the difference between > pen-and-paper and in-your-head for a computer program? Nothing. And solving a Sudoku puzzle - or any other puzzle - should require no guessing. It should be possible to solve purely by logic. Same goes for every other kind of puzzle out there; it's highly unsatisfying to play Minesweeper and get to the end with a block of four squares in a corner, two mines left, and no way of knowing which diagonal has the mines and which is clear. No trial-and-error, thanks. ChrisA From ralph.heinkel at web.de Thu Mar 26 08:37:45 2015 From: ralph.heinkel at web.de (Ralph Heinkel) Date: Thu, 26 Mar 2015 05:37:45 -0700 (PDT) Subject: sys.exec_prefix doesn't seem to reflect --exec-prefix path Message-ID: <548dcac1-fa00-4fc1-81d1-ccae28cafcbc@googlegroups.com> Hi, on my linux box there is a python version 2.7.5 installed in /usr/local. Now I want to install the newer version 2.7.9, but in a different directory to avoid clashes with the current installation. What I did was: ./configure --prefix /usr/local/Python-2.7.9 --exec-prefix /usr/local/Python-2.7.9 make make install Everything looks fine, Python is installed in the proper directory. BUT: When I run /usr/local/Python-2.7.9/bin/python and do 'print sys.exec_prefix' it prints '/usr/local' instead of '/usr/local/Python-2.7.9'. This has the effect that the old libraries of version 2.7.5 are used instead of the 2.7.9 ones. The docs in https://docs.python.org/2/library/sys.html state that sys.exec_prefix will reflect the value given to option --exec-prefix at configuration time. Any idea what I did wrong? Thanks for your help, Ralph From dihedral88888 at gmail.com Thu Mar 26 09:01:07 2015 From: dihedral88888 at gmail.com (CHIN Dihedral) Date: Thu, 26 Mar 2015 06:01:07 -0700 (PDT) Subject: Basic Python V3 Search Tool using RE module In-Reply-To: References: Message-ID: > Gregg Dotoli Are you reminding everyone who had a PC running DOS2.X-3X in 1990. It was really a pain at that time that a hard disk of an intel-MS based PC was sold hundreds of dollars, and another pain was that the buyer had to use the disabled dir in DOS after buying a HD. From alister.nospam.ware at ntlworld.com Thu Mar 26 09:01:09 2015 From: alister.nospam.ware at ntlworld.com (alister) Date: Thu, 26 Mar 2015 13:01:09 +0000 (UTC) Subject: test1 References: <7edc4671-8f96-491a-be30-0ad3f2175e07@googlegroups.com> <62b52eb2-67cc-4075-b6e1-f19700e66bed@googlegroups.com> <55135036.1010607@mrabarnett.plus.com> Message-ID: On Thu, 26 Mar 2015 00:36:49 +0000, Mark Lawrence wrote: > On 26/03/2015 00:17, MRAB wrote: >> On 2015-03-25 22:36, Chris Angelico wrote: >>> On Thu, Mar 26, 2015 at 6:49 AM, Tiglath Suriol >>> wrote: >>>> Two possibilities: >>>> >>>> You are a moderator. If you are a moderator you are welcome to >>>> delete my tests posts. This is of course improbably because this >>>> newsgroup is not moderated. >>> >>> You misunderstand newsgroups and mailing lists. Posts do not get >>> deleted after the event. Even on a web forum, where an administrator >>> can delete posts, the information is already out there; the instant >>> any one person has seen your post, you've lost control of it. So think >>> about what you post - especially when (as in your other thread) it >>> contains private information. >>> >>>> The other possibility is that you are just a guy, who despite the >>>> fact that my posts cost you nothing, and you are absolutely free to >>>> ignore them, your life is so dull that that you just must intervene >>>> and comment on anything you do not comprehend, because appointing >>>> yourself net cop is about as exciting as it gets. >>>> >>>> It's a free country, I know. You have every right to engage in >>>> pathetic speech. >>> >>> You also misunderstand freedom. I suggest you explore all three >>> concepts (freedom, newsgroups, and mailing lists), and learn what >>> you're actually dealing with. You may find the results rewarding. >>> >>> ChrisA >>> >> A quick search suggests that he has prior form. > > How many years did he get? Was it PHP or C++ ? :) i hope he has a good spam filter as I am about to sign him up for everything :-) -- Violence in reality is quite different from theory. -- Spock, "The Cloud Minders", stardate 5818.4 From ian.g.kelly at gmail.com Thu Mar 26 09:15:55 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 26 Mar 2015 07:15:55 -0600 Subject: Sudoku solver In-Reply-To: <87fv8sndw1.fsf@elektro.pacujo.net> References: <87r3sdnw5t.fsf@elektro.pacujo.net> <87fv8sndw1.fsf@elektro.pacujo.net> Message-ID: On Mar 26, 2015 6:31 AM, "Marko Rauhamaa" wrote: > > "Frank Millman" : > > > Here is another python-based sudoku solver - > > > > http://www.ics.uci.edu/~eppstein/PADS/Sudoku.py > > > >>From its docstring - > > > > "A proper Sudoku puzzle must have a unique solution, and it should be > > possible to reach that solution by a sequence of logical deductions > > without trial and error. > > I don't think that statement holds water. Trial-and-error is at the > basis of deduction (reductio ad absurdum). The human solver employs it > in their head. The question is, what is the difference between > pen-and-paper and in-your-head for a computer program? It's an accurate characterization of the sort of puzzles that are typically presented as sudoku. I don't think that I have used trial and error, in my head or otherwise, in any sudoku I have ever solved. > > It solved Marko's original puzzle and Ian's puzzle in less than a > > second. It could not solve Marko's second one, returning "impossible" > > immediately. Perhaps this is why that puzzle was described as being so difficult: it required steps that human solvers don't usually take. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ikorot01 at gmail.com Thu Mar 26 09:33:21 2015 From: ikorot01 at gmail.com (Igor Korot) Date: Thu, 26 Mar 2015 09:33:21 -0400 Subject: Fwd: test1 In-Reply-To: References: <7edc4671-8f96-491a-be30-0ad3f2175e07@googlegroups.com> <62b52eb2-67cc-4075-b6e1-f19700e66bed@googlegroups.com> <55135036.1010607@mrabarnett.plus.com> Message-ID: On Thu, Mar 26, 2015 at 9:01 AM, alister wrote: > On Thu, 26 Mar 2015 00:36:49 +0000, Mark Lawrence wrote: > >> On 26/03/2015 00:17, MRAB wrote: >>> On 2015-03-25 22:36, Chris Angelico wrote: >>>> On Thu, Mar 26, 2015 at 6:49 AM, Tiglath Suriol >>>> wrote: >>>>> Two possibilities: >>>>> >>>>> You are a moderator. If you are a moderator you are welcome to >>>>> delete my tests posts. This is of course improbably because this >>>>> newsgroup is not moderated. >>>> >>>> You misunderstand newsgroups and mailing lists. Posts do not get >>>> deleted after the event. Even on a web forum, where an administrator >>>> can delete posts, the information is already out there; the instant >>>> any one person has seen your post, you've lost control of it. So think >>>> about what you post - especially when (as in your other thread) it >>>> contains private information. >>>> >>>>> The other possibility is that you are just a guy, who despite the >>>>> fact that my posts cost you nothing, and you are absolutely free to >>>>> ignore them, your life is so dull that that you just must intervene >>>>> and comment on anything you do not comprehend, because appointing >>>>> yourself net cop is about as exciting as it gets. >>>>> >>>>> It's a free country, I know. You have every right to engage in >>>>> pathetic speech. >>>> >>>> You also misunderstand freedom. I suggest you explore all three >>>> concepts (freedom, newsgroups, and mailing lists), and learn what >>>> you're actually dealing with. You may find the results rewarding. >>>> >>>> ChrisA >>>> >>> A quick search suggests that he has prior form. >> >> How many years did he get? Was it PHP or C++ ? :) > > i hope he has a good spam filter as I am about to sign him up for > everything :-) Well he did gave out his private key to the public in an ASCII format. I wonder what people can do with it? ;-) > > > > > -- > Violence in reality is quite different from theory. > -- Spock, "The Cloud Minders", stardate 5818.4 > -- > https://mail.python.org/mailman/listinfo/python-list From ian.g.kelly at gmail.com Thu Mar 26 09:51:53 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 26 Mar 2015 07:51:53 -0600 Subject: Fwd: test1 In-Reply-To: References: <7edc4671-8f96-491a-be30-0ad3f2175e07@googlegroups.com> <62b52eb2-67cc-4075-b6e1-f19700e66bed@googlegroups.com> <55135036.1010607@mrabarnett.plus.com> Message-ID: On Mar 26, 2015 7:35 AM, "Igor Korot" wrote: > > On Thu, Mar 26, 2015 at 9:01 AM, alister > wrote: > > i hope he has a good spam filter as I am about to sign him up for > > everything :-) > > Well he did gave out his private key to the public in an ASCII format. > I wonder what people can do with it? ;-) Spamming someone as a response to being spammed is reasonable, in an eye-for-an-eye kind of way (though a bit childish). Hacking their site is not. Besides, it would be a lot more work for you to do anything untoward with it than it would be for him to just change it. -------------- next part -------------- An HTML attachment was scrubbed... URL: From joel.goldstick at gmail.com Thu Mar 26 09:53:34 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Thu, 26 Mar 2015 09:53:34 -0400 Subject: test1 In-Reply-To: <6aec1e5f-eeed-46e0-b30a-7cb3e5a601b3@googlegroups.com> References: <7edc4671-8f96-491a-be30-0ad3f2175e07@googlegroups.com> <62b52eb2-67cc-4075-b6e1-f19700e66bed@googlegroups.com> <55134bdd$0$12979$c3e8da3$5496439d@news.astraweb.com> <6aec1e5f-eeed-46e0-b30a-7cb3e5a601b3@googlegroups.com> Message-ID: Your first message was not python related. Your subsequent messages were rude. You've never been here before it seems. This is an interesting group, open to all with interest in python. How do you fit in? Not On Wed, Mar 25, 2015 at 9:34 PM, Tiglath Suriol wrote: > On Wednesday, March 25, 2015 at 7:59:34 PM UTC-4, Steven D'Aprano wrote: >> On Thu, 26 Mar 2015 10:43 am, Tiglath Suriol wrote: >> >> > I've dealt with people like you in newsgroups for a long time >> >> So many years, so little learning. It's arseholes like you who make it so >> important to invent a way to stab people through the internet. Just go >> away, you're not wanted here. >> > > I may stay a while just to poke you in the eye a little longer. I am beginning to enjoy this. People entering a battle of wits unarmed. It's a joy to watch. > > > You talk as if I wanted you to want me. Pure delusion. I posted at nobody, as I am free to do, and idiots come out of the woodwork as if I had committed some infraction. > > And you even want to stab me. Sterling. Who raised you. wolves? > > >> >> >> >> -- >> Steven > > -- > https://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick http://joelgoldstick.com From joel.goldstick at gmail.com Thu Mar 26 09:57:05 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Thu, 26 Mar 2015 09:57:05 -0400 Subject: Fwd: test1 In-Reply-To: References: <7edc4671-8f96-491a-be30-0ad3f2175e07@googlegroups.com> <62b52eb2-67cc-4075-b6e1-f19700e66bed@googlegroups.com> <55135036.1010607@mrabarnett.plus.com> Message-ID: Apparently Tiglath is a troll: see this: http://www.science-bbs.com/121-math/6b7f8c793e31402e.htm On Thu, Mar 26, 2015 at 9:51 AM, Ian Kelly wrote: > On Mar 26, 2015 7:35 AM, "Igor Korot" wrote: >> >> On Thu, Mar 26, 2015 at 9:01 AM, alister >> wrote: >> > i hope he has a good spam filter as I am about to sign him up for >> > everything :-) >> >> Well he did gave out his private key to the public in an ASCII format. >> I wonder what people can do with it? ;-) > > Spamming someone as a response to being spammed is reasonable, in an > eye-for-an-eye kind of way (though a bit childish). Hacking their site is > not. > > Besides, it would be a lot more work for you to do anything untoward with it > than it would be for him to just change it. > > > -- > https://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com From davea at davea.name Thu Mar 26 10:14:33 2015 From: davea at davea.name (Dave Angel) Date: Thu, 26 Mar 2015 10:14:33 -0400 Subject: Sudoku solver In-Reply-To: References: <87r3sdnw5t.fsf@elektro.pacujo.net> <87fv8sndw1.fsf@elektro.pacujo.net> Message-ID: <55141449.1030600@davea.name> On 03/26/2015 08:37 AM, Chris Angelico wrote: > On Thu, Mar 26, 2015 at 11:26 PM, Marko Rauhamaa wrote: >> "Frank Millman" : >> >>> Here is another python-based sudoku solver - >>> >>> http://www.ics.uci.edu/~eppstein/PADS/Sudoku.py >>> >>> >From its docstring - >>> >>> "A proper Sudoku puzzle must have a unique solution, and it should be >>> possible to reach that solution by a sequence of logical deductions >>> without trial and error. >> >> I don't think that statement holds water. Trial-and-error is at the >> basis of deduction (reductio ad absurdum). The human solver employs it >> in their head. The question is, what is the difference between >> pen-and-paper and in-your-head for a computer program? > > Nothing. And solving a Sudoku puzzle - or any other puzzle - should > require no guessing. It should be possible to solve purely by logic. > Same goes for every other kind of puzzle out there; it's highly > unsatisfying to play Minesweeper and get to the end with a block of > four squares in a corner, two mines left, and no way of knowing which > diagonal has the mines and which is clear. > > No trial-and-error, thanks. I think you're making an unwarranted assumption here. Your Minesweeper example has two solutions, so there's no way of telling which is the "correct" one. But I'd claim that there are puzzles which have exactly one solution, but which need trial and error at some point to find that solution. I'm not sure how to prove it, since somebody could claim that I just haven't tried all the non-trial-and-error rules. I did write a Sudoku-solver many years ago, in C++, and it solved the typical Sudoku I fed it in about 2ms. But it was deliberately written to apply only rules that humans could readily apply. No backtracking. I did not at that time have any electronic source for puzzles, and I got bored with manually entering them in from puzzle books. So I never actually encountered a puzzle it couldn't solve. I mostly used it to determine that a puzzle I couldn't manually solve was in fact uniquely solvable, and that I'd just messed up somehow. I wish I still had that source code, as it probably sounds like I'm blowing smoke here. The general approach I used was to make objects of each of the cells, which tracked its neighbors to decide whether its value was determined. And when it was determined, it notified its other neighbors. In turn, if that decided a value for any of the neighbors, that cell notified its neighbors. Likewise each row or column or box kept track of its state and notified the appropriate cells whenever something interesting was discovered. Then the outer loop just tickled each cell in turn, and the solution rippled out. Maybe I'm misinterpreting your phrase "No trial and error, thanks". Perhaps you're saying that puzzles that require trial and error are no fun to solve for humans. And that's a different matter entirely. I do the daily KenKen puzzles in my local paper, and they're just hard enough to be fun, seldom taking longer than I'm willing to take in the mornings. -- DaveA From marko at pacujo.net Thu Mar 26 10:15:58 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 26 Mar 2015 16:15:58 +0200 Subject: Sudoku solver References: <87r3sdnw5t.fsf@elektro.pacujo.net> <4e81bdb9-52db-46e6-b449-d4241cb2a3f2@googlegroups.com> <87twx8amww.fsf@elektro.pacujo.net> <87iodoakft.fsf@elektro.pacujo.net> <87k2y4neh5.fsf@elektro.pacujo.net> Message-ID: <878uejondt.fsf@elektro.pacujo.net> Marko Rauhamaa : > I have optimized my solution slightly: > > 1. precalculated integer division operations (big savings) > > 2. interned integers (little savings) > > The example above now finishes in 41 minutes on my computer. (The C > version finishes in 13 seconds). Any considered harmfull. Changing an "any" test to a loop shortens the solving time from 41 minutes to 14 minutes. Object creation overhead seems to be the killer. The program still has a prominent integer incrementation... ======================================================================== #!/usr/bin/env python3 import sys M = 3 N = M * M P = M * N Q = M * P buddies = [ [ buddy for buddy in range(Q) if buddy != slot and (buddy % N == slot % N or buddy // N == slot // N or buddy // P == slot // P and buddy % N // M == slot % N // M) ] for slot in range(Q) ] interned = { n : n for n in range(1, N + 1) } candidates = list(interned.values()) def main(): board = [] for n in sys.stdin.read().split(): try: board.append(int(n)) except ValueError: board.append(None) solve(board) def solve(board, slot=0): if slot == Q: report(board) elif board[slot] is None: for candidate in candidates: for buddy in buddies[slot]: if board[buddy] is candidate: break else: board[slot] = candidate solve(board, slot + 1) board[slot] = None else: solve(board, slot + 1) def report(board): print("\n".join( " ".join(str(board[row * N + col]) for col in range(N)) for row in range(N))) print() if __name__ == '__main__': main() ======================================================================== Marko From marko at pacujo.net Thu Mar 26 10:23:36 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 26 Mar 2015 16:23:36 +0200 Subject: Sudoku solver References: <87r3sdnw5t.fsf@elektro.pacujo.net> <87fv8sndw1.fsf@elektro.pacujo.net> Message-ID: <874mp7on13.fsf@elektro.pacujo.net> Ian Kelly : > I don't think that I have used trial and error, in my head or > otherwise, in any sudoku I have ever solved. Of course you have. "This here can't be a 2 because if it were a 2, that there would have to be a 5, which is impossible. Thus, the only remaining alternative is 3, so I mark that down." That's trial and error, aka, reductio ad absurdum. (Additionally, sudoku solvers are known to pencil all kinds of markings on the sudoku sheets to help the deduction work.) Marko From rosuav at gmail.com Thu Mar 26 10:41:09 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 27 Mar 2015 01:41:09 +1100 Subject: Sudoku solver In-Reply-To: <55141449.1030600@davea.name> References: <87r3sdnw5t.fsf@elektro.pacujo.net> <87fv8sndw1.fsf@elektro.pacujo.net> <55141449.1030600@davea.name> Message-ID: On Fri, Mar 27, 2015 at 1:14 AM, Dave Angel wrote: > On 03/26/2015 08:37 AM, Chris Angelico wrote: >> Nothing. And solving a Sudoku puzzle - or any other puzzle - should >> require no guessing. It should be possible to solve purely by logic. >> Same goes for every other kind of puzzle out there; it's highly >> unsatisfying to play Minesweeper and get to the end with a block of >> four squares in a corner, two mines left, and no way of knowing which >> diagonal has the mines and which is clear. >> >> No trial-and-error, thanks. > > > I think you're making an unwarranted assumption here. Your Minesweeper > example has two solutions, so there's no way of telling which is the > "correct" one. But I'd claim that there are puzzles which have exactly one > solution, but which need trial and error at some point to find that > solution. Only one can possibly be correct; if you dig one cell, you'll die, and if you dig the other, you'll win. But you have no way of knowing which is which, without dying, using some kind of "undo" feature (orange smoke comes to mind), and trying the other. Or, of course, guessing right, in which case you win. > I'm not sure how to prove it, since somebody could claim that I just haven't > tried all the non-trial-and-error rules. With Sudoku, there are some pretty complicated rules and patterns. Minesweeper is much simpler to prove. But there are still rules and patterns, and at some point, you simply have to say that a puzzle is "beyond the logic of this set of rules". It might not be beyond a more comprehensive set of rules, but that doesn't matter; you've proven the puzzle to be unsolvable *with your (program's) skill set*. > I did write a Sudoku-solver many years ago, in C++, and it solved the > typical Sudoku I fed it in about 2ms. But it was deliberately written to > apply only rules that humans could readily apply. No backtracking. I did > not at that time have any electronic source for puzzles, and I got bored > with manually entering them in from puzzle books. So I never actually > encountered a puzzle it couldn't solve. I mostly used it to determine that > a puzzle I couldn't manually solve was in fact uniquely solvable, and that > I'd just messed up somehow. > > I wish I still had that source code, as it probably sounds like I'm blowing > smoke here. > > The general approach I used was to make objects of each of the cells, which > tracked its neighbors to decide whether its value was determined. And when > it was determined, it notified its other neighbors. In turn, if that > decided a value for any of the neighbors, that cell notified its neighbors. > Likewise each row or column or box kept track of its state and notified the > appropriate cells whenever something interesting was discovered. Then the > outer loop just tickled each cell in turn, and the solution rippled out. Not entirely sure I have this correct, but it sounds like you have a basic solver that uses one rule: If there is no other value that can be in this cell, you can write this one down. It's certainly possible to add a lot more sophistication to a solver; for instance, in this grid, it's possible to place a 4 with certainty: . . . | . . . | . . . . . . | 4 . . | . . . . . . | . . . | . . 4 ------+-------+------ . . . | . . . | . . . . . . | . . . | . . . . . . | . . . | . 4 . ------+-------+------ . . . | . . . | . . . . . . | . 1 2 | . . . 4 . . | . . . | . . . An examination of the bottom-center block shows that the 4 in it must be on its top row (even though you don't know which of two possibilities has it), ergo the bottom-right block must have its 4 on the center row. The more of these kinds of rules you have, the more puzzles you can solve - but I would still code the solver to avoid guessing. > Maybe I'm misinterpreting your phrase "No trial and error, thanks". Perhaps > you're saying that puzzles that require trial and error are no fun to solve > for humans. And that's a different matter entirely. I do the daily KenKen > puzzles in my local paper, and they're just hard enough to be fun, seldom > taking longer than I'm willing to take in the mornings. I agree that they're no fun for humans. That's part of the point, but not the whole point. Since we're talking about puzzles, here, the primary purpose of a machine solver is (or should be!) to prove that a puzzle is solvable, and thus worthy of being given to a human. So the solver should restrict itself to what's considered worth working with - and in some cases, might restrict itself even further ("generate an easy puzzle, please"), by cutting out some forms of logic. Now, if your humans are happy with puzzles that they have to guess, then sure, incorporate guessing in your solver. But if the humans aren't, then what do you prove by having an electronic solver that can do the puzzle? There's a small mathematical curiosity to finding out just how few clues can carry sufficient information to uniquely define a grid, but that's already been proven. So, that's why I would avoid guessing. I've written a lot of solvers for various puzzles. Minesweeper, Sudoku, a binary Sudoku-like puzzle that I don't really have a good name for, several others. Every time, I've tried to prove the puzzles solvable by humans, and sometimes that means rejecting ones that could technically be solved by brute force. ChrisA From davea at davea.name Thu Mar 26 11:03:16 2015 From: davea at davea.name (Dave Angel) Date: Thu, 26 Mar 2015 11:03:16 -0400 Subject: Sudoku solver In-Reply-To: References: <87r3sdnw5t.fsf@elektro.pacujo.net> <87fv8sndw1.fsf@elektro.pacujo.net> <55141449.1030600@davea.name> Message-ID: <55141FB4.4040900@davea.name> On 03/26/2015 10:41 AM, Chris Angelico wrote: that's already been proven. So, that's why I would avoid guessing. > > I've written a lot of solvers for various puzzles. Minesweeper, > Sudoku, a binary Sudoku-like puzzle that I don't really have a good > name for, several others. Every time, I've tried to prove the puzzles > solvable by humans, and sometimes that means rejecting ones that could > technically be solved by brute force. OK, we're on the same page. I would use different terminology for some of it, but that's okay. The purist in me would like to write a solver which (within a few seconds) could solve any unique puzzle, and identify puzzles which don't have a unique solution. One reason I never got back to writing one was I also wanted a difficulty-ranker, which would identify how hard a human was likely to consider the puzzle. Had I been writing it in Python, I'd probably have pursued adding brute force, and then used some of the code to write a puzzle-generator. But even then, the problem of ranking was one that had me buffaloed. It's clearly not enough to count the starting clues (eg. easyness = (clues - 17) * pi ) And writing an efficient program that generates a non-trivial puzzle would seem to be quite hard. I've heard it said that Sudoku puzzles generated by machines are much less satisfying than those generated by a human. When in a playful mood, I wonder if all the Sudoku puzzles out there are just permutations of a few hundred written by Will Shortz. Swap around rows, columns, boxes, and cryptogram the digit mapping. Voila, a new puzzle. i read a short story about the purpose of jokes, in which it said there were only a few hundred of them, the rest were just minor variants, and that they were an experiment being run on human beings. And once we realized it, they'd shut off our sense of humor. -- DaveA From ian.g.kelly at gmail.com Thu Mar 26 11:06:42 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 26 Mar 2015 09:06:42 -0600 Subject: Sudoku solver In-Reply-To: <874mp7on13.fsf@elektro.pacujo.net> References: <87r3sdnw5t.fsf@elektro.pacujo.net> <87fv8sndw1.fsf@elektro.pacujo.net> <874mp7on13.fsf@elektro.pacujo.net> Message-ID: On Thu, Mar 26, 2015 at 8:23 AM, Marko Rauhamaa wrote: > Ian Kelly : > >> I don't think that I have used trial and error, in my head or >> otherwise, in any sudoku I have ever solved. > > Of course you have. "This here can't be a 2 because if it were a 2, that > there would have to be a 5, which is impossible. Thus, the only > remaining alternative is 3, so I mark that down." > > That's trial and error, aka, reductio ad absurdum. > > (Additionally, sudoku solvers are known to pencil all kinds of markings > on the sudoku sheets to help the deduction work.) Okay, I've probably used single-lookahead trial and error in my reasoning at some point. But the example you give is equivalent to the deductive process "That can't be a 5, so I remove it as a candidate. The only place left for a 5 is here, so I remove the 2 as a candidate and fill in the 5." From breamoreboy at yahoo.co.uk Thu Mar 26 11:13:28 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 26 Mar 2015 15:13:28 +0000 Subject: test1 In-Reply-To: <584bbccc-7691-4a32-861e-bd317659533b@googlegroups.com> References: <7edc4671-8f96-491a-be30-0ad3f2175e07@googlegroups.com> <62b52eb2-67cc-4075-b6e1-f19700e66bed@googlegroups.com> <584bbccc-7691-4a32-861e-bd317659533b@googlegroups.com> Message-ID: On 26/03/2015 01:26, Tiglath Suriol wrote: > On Wednesday, March 25, 2015 at 7:58:11 PM UTC-4, Mark Lawrence wrote: >> >> You might be used to dealing with other people in other newsgroups. >> This is the Python main mailing list/newsgroup. There is a rather more >> civilised way of doing things around here. > > What arrogance, So you think you are special. I see the same busybodies here as in other newsgroups. Same shit. Why don't you write some Python instead of minding my business? > > > As for ignoring you, why >> don't you simply stop posting, then we won't have to? >> e > > We? Is that the royal we or you speak for some group? > > You won't have to? Hilarious! > > I've heard of the tail wagging the dog, but the knee jerking the jerk is quite an admission you just made. > > There is a good reason why I posted two test messages, but I don't owe you that explanation, so you will have to put up with that uncontrollable knee jerk for as long as I post spitballs at you, minus any explanation. Feel free to mind your business. > >> -- >> My fellow Pythonistas, ask not what our language can do for you, ask >> what you can do for our language. >> >> Mark Lawrence > Everything reported as abuse on google groups and marked as spam on gmane. What else is there to do? Ah yes. *plonk* -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From tiglathsuriol at gmail.com Thu Mar 26 11:16:27 2015 From: tiglathsuriol at gmail.com (Tiglath Suriol) Date: Thu, 26 Mar 2015 08:16:27 -0700 (PDT) Subject: test1 In-Reply-To: References: <7edc4671-8f96-491a-be30-0ad3f2175e07@googlegroups.com> <62b52eb2-67cc-4075-b6e1-f19700e66bed@googlegroups.com> <55135036.1010607@mrabarnett.plus.com> Message-ID: <82435d80-68b0-4fed-860b-a2ad228c1b7a@googlegroups.com> On Thursday, March 26, 2015 at 9:01:23 AM UTC-4, alister wrote: > On Thu, 26 Mar 2015 00:36:49 +0000, Mark Lawrence wrote: > > > On 26/03/2015 00:17, MRAB wrote: > >> On 2015-03-25 22:36, Chris Angelico wrote: > >>> On Thu, Mar 26, 2015 at 6:49 AM, Tiglath Suriol > >>> wrote: > >>>> Two possibilities: > >>>> > >>>> You are a moderator. If you are a moderator you are welcome to > >>>> delete my tests posts. This is of course improbably because this > >>>> newsgroup is not moderated. > >>> > >>> You misunderstand newsgroups and mailing lists. Posts do not get > >>> deleted after the event. Even on a web forum, where an administrator > >>> can delete posts, the information is already out there; the instant > >>> any one person has seen your post, you've lost control of it. So think > >>> about what you post - especially when (as in your other thread) it > >>> contains private information. > >>> > >>>> The other possibility is that you are just a guy, who despite the > >>>> fact that my posts cost you nothing, and you are absolutely free to > >>>> ignore them, your life is so dull that that you just must intervene > >>>> and comment on anything you do not comprehend, because appointing > >>>> yourself net cop is about as exciting as it gets. > >>>> > >>>> It's a free country, I know. You have every right to engage in > >>>> pathetic speech. > >>> > >>> You also misunderstand freedom. I suggest you explore all three > >>> concepts (freedom, newsgroups, and mailing lists), and learn what > >>> you're actually dealing with. You may find the results rewarding. > >>> > >>> ChrisA > >>> > >> A quick search suggests that he has prior form. > > > > How many years did he get? Was it PHP or C++ ? :) > > i hope he has a good spam filter as I am about to sign him up for > everything :-) > You are all booster and no warhead, mental midgets. As if I would use my regular email to visit this place. > > > > -- > Violence in reality is quite different from theory. > -- Spock, "The Cloud Minders", stardate 5818.4 From tiglathsuriol at gmail.com Thu Mar 26 11:18:02 2015 From: tiglathsuriol at gmail.com (Tiglath Suriol) Date: Thu, 26 Mar 2015 08:18:02 -0700 (PDT) Subject: test1 In-Reply-To: References: <7edc4671-8f96-491a-be30-0ad3f2175e07@googlegroups.com> <62b52eb2-67cc-4075-b6e1-f19700e66bed@googlegroups.com> <55135036.1010607@mrabarnett.plus.com> Message-ID: <0ffd2492-0e4c-40b7-818b-dfeeca2893b2@googlegroups.com> On Thursday, March 26, 2015 at 9:33:43 AM UTC-4, Igor Korot wrote: > On Thu, Mar 26, 2015 at 9:01 AM, alister > wrote: > > On Thu, 26 Mar 2015 00:36:49 +0000, Mark Lawrence wrote: > > > >> On 26/03/2015 00:17, MRAB wrote: > >>> On 2015-03-25 22:36, Chris Angelico wrote: > >>>> On Thu, Mar 26, 2015 at 6:49 AM, Tiglath Suriol > >>>> wrote: > >>>>> Two possibilities: > >>>>> > >>>>> You are a moderator. If you are a moderator you are welcome to > >>>>> delete my tests posts. This is of course improbably because this > >>>>> newsgroup is not moderated. > >>>> > >>>> You misunderstand newsgroups and mailing lists. Posts do not get > >>>> deleted after the event. Even on a web forum, where an administrator > >>>> can delete posts, the information is already out there; the instant > >>>> any one person has seen your post, you've lost control of it. So think > >>>> about what you post - especially when (as in your other thread) it > >>>> contains private information. > >>>> > >>>>> The other possibility is that you are just a guy, who despite the > >>>>> fact that my posts cost you nothing, and you are absolutely free to > >>>>> ignore them, your life is so dull that that you just must intervene > >>>>> and comment on anything you do not comprehend, because appointing > >>>>> yourself net cop is about as exciting as it gets. > >>>>> > >>>>> It's a free country, I know. You have every right to engage in > >>>>> pathetic speech. > >>>> > >>>> You also misunderstand freedom. I suggest you explore all three > >>>> concepts (freedom, newsgroups, and mailing lists), and learn what > >>>> you're actually dealing with. You may find the results rewarding. > >>>> > >>>> ChrisA > >>>> > >>> A quick search suggests that he has prior form. > >> > >> How many years did he get? Was it PHP or C++ ? :) > > > > i hope he has a good spam filter as I am about to sign him up for > > everything :-) > > Well he did gave out his private key to the public in an ASCII format. > I wonder what people can do with it? ;-) You got me there. Dang! From rosuav at gmail.com Thu Mar 26 11:21:15 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 27 Mar 2015 02:21:15 +1100 Subject: Sudoku solver In-Reply-To: <55141FB4.4040900@davea.name> References: <87r3sdnw5t.fsf@elektro.pacujo.net> <87fv8sndw1.fsf@elektro.pacujo.net> <55141449.1030600@davea.name> <55141FB4.4040900@davea.name> Message-ID: On Fri, Mar 27, 2015 at 2:03 AM, Dave Angel wrote: > On 03/26/2015 10:41 AM, Chris Angelico wrote: > that's already been proven. So, that's why I would avoid guessing. >> >> >> I've written a lot of solvers for various puzzles. Minesweeper, >> Sudoku, a binary Sudoku-like puzzle that I don't really have a good >> name for, several others. Every time, I've tried to prove the puzzles >> solvable by humans, and sometimes that means rejecting ones that could >> technically be solved by brute force. > > > OK, we're on the same page. I would use different terminology for some of > it, but that's okay. Good, I thought we were in agreement. And yeah, terminology is tricky. > The purist in me would like to write a solver which (within a few seconds) > could solve any unique puzzle, and identify puzzles which don't have a > unique solution. One reason I never got back to writing one was I also > wanted a difficulty-ranker, which would identify how hard a human was likely > to consider the puzzle. It'd be pretty straight-forward. You simply define a number of rule-difficulty-categories, something like this: EASY * If eight digits are "locked off" from a cell by already existing in its neighbours, the remaining digit must be the one. * If eight cells in a {row, column, square} have a given digit locked off, then the remaining cell must contain that digit. MEDIUM * Construct "possibility regions" for digits in squares (ie all the possible cells that that digit could be in). Any such region which sits within a single row/column is equivalent to an actual digit in that row/column for the purposes of exclusions. * Likewise the converse - if both possible places for the 7 in this row are in this square, we can depend on the 7 being in one of those, and not anywhere else in the square. HARD * Any complex rule that you feel like coding up. There are plenty of "Sudoku help" web sites out there that can provide rule definitions. IMPOSSIBLE * Brute force. Attempt to put a digit in a cell, then see if you can solve the puzzle thereafter. If you prove the puzzle to have no solutions, that digit cannot be in that cell. Then, in your solver, you use EASY rules until they provide you with no more material, and only then move on to MEDIUM rules, etc. The highest difficulty class that you had to use in solving the puzzle is the puzzle's difficulty class. This isn't a perfect system, of course, but it's a decent start. It also deals with the terminology problem: you can declare a puzzle "solvable, but IMPOSSIBLE class difficulty", which means you have to guess. Though I would strongly suggest disabling brute-forcing most of the time, as it'll kill your CPU... especially if you have a puzzle generation algorithm that looks like this: Start with a blank grid. While puzzle not solvable: Add random clue digit For each clue digit: Remove clue If puzzle not solvable: Reinstate clue With IMPOSSIBLE deactivated, this is a reasonably straight-forward way to generate puzzles (and you can deactivate HARD to require a medium-difficulty puzzle, etc). Otherwise... kerchug, kerchug, kerchug.... ChrisA From tiglathsuriol at gmail.com Thu Mar 26 11:25:03 2015 From: tiglathsuriol at gmail.com (Tiglath Suriol) Date: Thu, 26 Mar 2015 08:25:03 -0700 (PDT) Subject: test1 In-Reply-To: References: <7edc4671-8f96-491a-be30-0ad3f2175e07@googlegroups.com> <62b52eb2-67cc-4075-b6e1-f19700e66bed@googlegroups.com> <55134bdd$0$12979$c3e8da3$5496439d@news.astraweb.com> <6aec1e5f-eeed-46e0-b30a-7cb3e5a601b3@googlegroups.com> Message-ID: <85b79d54-f608-4b17-bd6d-46daf1b5d47b@googlegroups.com> On Thursday, March 26, 2015 at 9:53:48 AM UTC-4, Joel Goldstick wrote: > Your first message was not python related. Your subsequent messages > were rude. You've never been here before it seems. This is an > interesting group, open to all with interest in python. How do you > fit in? Not > > On Wed, Mar 25, 2015 at 9:34 PM, Tiglath Suriol wrote: > > On Wednesday, March 25, 2015 at 7:59:34 PM UTC-4, Steven D'Aprano wrote: > >> On Thu, 26 Mar 2015 10:43 am, Tiglath Suriol wrote: > >> > >> > I've dealt with people like you in newsgroups for a long time > >> > >> So many years, so little learning. It's arseholes like you who make it so > >> important to invent a way to stab people through the internet. Just go > >> away, you're not wanted here. > >> > > > > I may stay a while just to poke you in the eye a little longer. I am beginning to enjoy this. People entering a battle of wits unarmed. It's a joy to watch. > > > > > > You talk as if I wanted you to want me. Pure delusion. I posted at nobody, as I am free to do, and idiots come out of the woodwork as if I had committed some infraction. > > > > And you even want to stab me. Sterling. Who raised you. wolves? > > > > > >> > >> > >> > >> -- > >> Steven > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > > -- > Joel Goldstick > http://joelgoldstick.com Rather... I came here because I can and may. but I did no provoke anyone. Then the Central Scrutinizer chimed in followed by his Seven Dwarves and his bitches. Now you, in which group do you fit? Had you all minded your business I wouldn't be here. Saving yourselves all those inane s, and even more inane retorts. Now be sincere, you write at me because this is like gawking at an accident on the road, it's a disturbance in your otherwise Pythonic, catatonic day. I did not intend to, but since you appeared, I don't mind kicking your asses for laughs. So please write more. From tiglathsuriol at gmail.com Thu Mar 26 11:33:50 2015 From: tiglathsuriol at gmail.com (Tiglath Suriol) Date: Thu, 26 Mar 2015 08:33:50 -0700 (PDT) Subject: test1 In-Reply-To: References: <7edc4671-8f96-491a-be30-0ad3f2175e07@googlegroups.com> <62b52eb2-67cc-4075-b6e1-f19700e66bed@googlegroups.com> <584bbccc-7691-4a32-861e-bd317659533b@googlegroups.com> Message-ID: On Thursday, March 26, 2015 at 11:14:06 AM UTC-4, Mark Lawrence wrote: > On 26/03/2015 01:26, Tiglath Suriol wrote: > > On Wednesday, March 25, 2015 at 7:58:11 PM UTC-4, Mark Lawrence wrote: > >> > >> You might be used to dealing with other people in other newsgroups. > >> This is the Python main mailing list/newsgroup. There is a rather more > >> civilised way of doing things around here. > > > > What arrogance, So you think you are special. I see the same busybodies here as in other newsgroups. Same shit. Why don't you write some Python instead of minding my business? > > > > > > As for ignoring you, why > >> don't you simply stop posting, then we won't have to? > >> e > > > > We? Is that the royal we or you speak for some group? > > > > You won't have to? Hilarious! > > > > I've heard of the tail wagging the dog, but the knee jerking the jerk is quite an admission you just made. > > > > There is a good reason why I posted two test messages, but I don't owe you that explanation, so you will have to put up with that uncontrollable knee jerk for as long as I post spitballs at you, minus any explanation. Feel free to mind your business. > > > >> -- > >> My fellow Pythonistas, ask not what our language can do for you, ask > >> what you can do for our language. > >> > >> Mark Lawrence > > > > Everything reported as abuse on google groups and marked as spam on > gmane. What else is there to do? Ah yes. > > *plonk* > > -- > My fellow Pythonistas, ask not what our language can do for you, ask > what you can do for our language. > > Mark Lawrence I don't remember addressing his guy, HE addressed me FIRST, as all of you did, now you complaint you don't like my replies. That is what happens to nosy fishwives. The sooner you all "plonk" me the sooner you can go back to your ordinary lives. From joel.goldstick at gmail.com Thu Mar 26 11:33:57 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Thu, 26 Mar 2015 11:33:57 -0400 Subject: test1 In-Reply-To: <85b79d54-f608-4b17-bd6d-46daf1b5d47b@googlegroups.com> References: <7edc4671-8f96-491a-be30-0ad3f2175e07@googlegroups.com> <62b52eb2-67cc-4075-b6e1-f19700e66bed@googlegroups.com> <55134bdd$0$12979$c3e8da3$5496439d@news.astraweb.com> <6aec1e5f-eeed-46e0-b30a-7cb3e5a601b3@googlegroups.com> <85b79d54-f608-4b17-bd6d-46daf1b5d47b@googlegroups.com> Message-ID: On Thu, Mar 26, 2015 at 11:25 AM, Tiglath Suriol wrote: > On Thursday, March 26, 2015 at 9:53:48 AM UTC-4, Joel Goldstick wrote: >> Your first message was not python related. Your subsequent messages >> were rude. You've never been here before it seems. This is an >> interesting group, open to all with interest in python. How do you >> fit in? Not >> >> On Wed, Mar 25, 2015 at 9:34 PM, Tiglath Suriol wrote: >> > On Wednesday, March 25, 2015 at 7:59:34 PM UTC-4, Steven D'Aprano wrote: >> >> On Thu, 26 Mar 2015 10:43 am, Tiglath Suriol wrote: >> >> >> >> > I've dealt with people like you in newsgroups for a long time >> >> >> >> So many years, so little learning. It's arseholes like you who make it so >> >> important to invent a way to stab people through the internet. Just go >> >> away, you're not wanted here. >> >> >> > >> > I may stay a while just to poke you in the eye a little longer. I am beginning to enjoy this. People entering a battle of wits unarmed. It's a joy to watch. >> > >> > >> > You talk as if I wanted you to want me. Pure delusion. I posted at nobody, as I am free to do, and idiots come out of the woodwork as if I had committed some infraction. >> > >> > And you even want to stab me. Sterling. Who raised you. wolves? >> > >> > >> >> >> >> >> >> >> >> -- >> >> Steven >> > >> > -- >> > https://mail.python.org/mailman/listinfo/python-list >> >> >> >> -- >> Joel Goldstick >> http://joelgoldstick.com > > Rather... > > I came here because I can and may. but I did no provoke anyone. > > Then the Central Scrutinizer chimed in followed by his Seven Dwarves and his bitches. Now you, in which group do you fit? > > Had you all minded your business I wouldn't be here. Saving yourselves all those inane s, and even more inane retorts. > > Now be sincere, you write at me because this is like gawking at an accident on the road, it's a disturbance in your otherwise Pythonic, catatonic day. > > I did not intend to, but since you appeared, I don't mind kicking your asses for laughs. So please write more. > > -- > https://mail.python.org/mailman/listinfo/python-list You came here to be on display since you have some sort of warped sense of self. Show your mother what you write online. Maybe she can get you help -- Joel Goldstick http://joelgoldstick.com From tiglathsuriol at gmail.com Thu Mar 26 11:35:36 2015 From: tiglathsuriol at gmail.com (Tiglath Suriol) Date: Thu, 26 Mar 2015 08:35:36 -0700 (PDT) Subject: test1 In-Reply-To: References: <7edc4671-8f96-491a-be30-0ad3f2175e07@googlegroups.com> <62b52eb2-67cc-4075-b6e1-f19700e66bed@googlegroups.com> <584bbccc-7691-4a32-861e-bd317659533b@googlegroups.com> Message-ID: <21f89535-eda0-4119-aea6-4c53a372d8c0@googlegroups.com> On Thursday, March 26, 2015 at 11:14:06 AM UTC-4, Mark Lawrence wrote: > On 26/03/2015 01:26, Tiglath Suriol wrote: > > On Wednesday, March 25, 2015 at 7:58:11 PM UTC-4, Mark Lawrence wrote: > >> > >> You might be used to dealing with other people in other newsgroups. > >> This is the Python main mailing list/newsgroup. There is a rather more > >> civilised way of doing things around here. > > > > What arrogance, So you think you are special. I see the same busybodies here as in other newsgroups. Same shit. Why don't you write some Python instead of minding my business? > > > > > > As for ignoring you, why > >> don't you simply stop posting, then we won't have to? > >> e > > > > We? Is that the royal we or you speak for some group? > > > > You won't have to? Hilarious! > > > > I've heard of the tail wagging the dog, but the knee jerking the jerk is quite an admission you just made. > > > > There is a good reason why I posted two test messages, but I don't owe you that explanation, so you will have to put up with that uncontrollable knee jerk for as long as I post spitballs at you, minus any explanation. Feel free to mind your business. > > > >> -- > >> My fellow Pythonistas, ask not what our language can do for you, ask > >> what you can do for our language. > >> > >> Mark Lawrence > > > > Everything reported as abuse on google groups How brave. He starts an argument and not goes to tell the teacher because got a bloody nose. Plonk and run to hide under the bed as fast as your little legs will carry you, Mark. From tiglathsuriol at gmail.com Thu Mar 26 11:38:54 2015 From: tiglathsuriol at gmail.com (Tiglath Suriol) Date: Thu, 26 Mar 2015 08:38:54 -0700 (PDT) Subject: Fwd: test1 In-Reply-To: References: <7edc4671-8f96-491a-be30-0ad3f2175e07@googlegroups.com> <62b52eb2-67cc-4075-b6e1-f19700e66bed@googlegroups.com> <55135036.1010607@mrabarnett.plus.com> Message-ID: <59fcf2e2-6640-488c-b216-2d840c947d99@googlegroups.com> On Thursday, March 26, 2015 at 9:52:36 AM UTC-4, Ian wrote: > On Mar 26, 2015 7:35 AM, "Igor Korot" wrote: > > > > > > ?On Thu, Mar 26, 2015 at 9:01 AM, alister > > > wrote: > > > > i hope he has a good spam filter as I am about to sign him up for > > > > everything :-) > > > > > > Well he did gave out his private key to the public in an ASCII format. > > > I wonder what people can do with it? ;-) > > Spamming someone as a response to being spammed is reasonable, in an eye-for-an-eye kind of way (though a bit childish). Hacking their site is not. > > Besides, it would be a lot more work for you to do anything untoward with it than it would be for him to just change it. Get your facts right, Sherlock. I did not spam anyone. I posted to an open public newsgroup. Just some code, nothing offensive or even directed to anyone. Then people started to get cute, and now that returned fire is a bucket a drop they complaints like bitches on the rag. Not surprised, but not SPAM either. If anyone pull a newsgroup into his email that's his doing, not mine. Hack me all you want. I dare you. From invalid at invalid.invalid Thu Mar 26 11:41:22 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 26 Mar 2015 15:41:22 +0000 (UTC) Subject: Supply condition in function call References: <87bnjhyohp.fsf@uriel.graune.org> Message-ID: On 2015-03-25, Ian Kelly wrote: > On Wed, Mar 25, 2015 at 1:53 PM, Grant Edwards wrote: >> On 2015-03-25, Ian Kelly wrote: >>> On Wed, Mar 25, 2015 at 11:29 AM, Manuel Graune wrote: >>> >>>> I'm looking for a way to supply a condition to an if-statement inside a >>>> function body when calling the function. I can sort of get what I want >>>> with using eval [...] >>> >>> Pass the condition as a function. >>> >>> def test1(a, b, condition=lambda i, j: True): >>> for i,j in zip(a,b): >>> c=i+j >>> if condition(i, j): >>> print("Foo") >>> >>> test1([0,1,2,3],[1,2,3,4], lambda i, j: i+j > 4) >>> # etc. >> >> FWIW, back in the day such a function was referred to as a "thunk" >> (particularly if it was auto-generated by a compiler that used >> pass-by-name instead of pass-by-value or pass-by-reference): >> >> http://en.wikipedia.org/wiki/Thunk >> >> Dunno if people still use that term or not. > > I've heard the term (though not since my college days, I think), but > I've always understood thunks to be parameterless (hence the use as a > form of pass-by-name). You're right -- I misread the example. Somehow I skipped the "for i,j" line completely, and was thinking that i and j were defined in the caller's context. Thus the OP was trying to implment something akin to call by name. -- Grant Edwards grant.b.edwards Yow! Here I am in the at POSTERIOR OLFACTORY LOBULE gmail.com but I don't see CARL SAGAN anywhere!! From marko at pacujo.net Thu Mar 26 11:42:05 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 26 Mar 2015 17:42:05 +0200 Subject: Sudoku solver References: <87r3sdnw5t.fsf@elektro.pacujo.net> <87fv8sndw1.fsf@elektro.pacujo.net> <55141449.1030600@davea.name> Message-ID: <87zj6zn4tu.fsf@elektro.pacujo.net> Dave Angel : > When in a playful mood, I wonder if all the Sudoku puzzles out there > are just permutations of a few hundred written by Will Shortz. A sudoku solver can be trivially turned into a puzzle generator: ======================================================================== $ ./sudoku.py --generate >puzzle.dat $ cat puzzle.dat 3 . 2 . 4 . . . . 4 5 . . . 6 . . . 6 . . . 9 . . 8 . . . . . . . 5 . . . 6 4 . . 9 . 3 . . 7 3 5 . . . 4 8 . . . . . . 8 . . . 8 . . 7 . . . 3 . . . . 1 . . . 2 $ ./sudoku.py 1 and sys.argv[1] == "--generate": generate() return board = [] for n in sys.stdin.read().split(): try: board.append(int(n)) except ValueError: board.append(EMPTY) for solution in solve(board): report(solution) def generate(): report(minimize(next(solve([ EMPTY ] * Q)))) def solve(board, slot=0): if slot == Q: yield board[:] elif board[slot] is EMPTY: shuffled = candidates[:] random.shuffle(shuffled) for candidate in shuffled: for buddy in buddies[slot]: if board[buddy] is candidate: break else: board[slot] = candidate yield from solve(board, slot + 1) board[slot] = EMPTY else: yield from solve(board, slot + 1) def minimize(board): while True: nonempty_slots = [ slot for slot in range(Q) if board[slot] is not EMPTY ] random.shuffle(nonempty_slots) for slot in nonempty_slots: removed, board[slot] = board[slot], EMPTY if uniquely_solvable(board): break board[slot] = removed else: return board def uniquely_solvable(board): it = solve(board[:]) next(it) try: next(it) except StopIteration: return True return False def report(board): print("\n".join( " ".join(str(board[row * N + col]) for col in range(N)) for row in range(N))) print() if __name__ == '__main__': main() ======================================================================== Marko From marko at pacujo.net Thu Mar 26 11:48:06 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 26 Mar 2015 17:48:06 +0200 Subject: Sudoku solver References: <87r3sdnw5t.fsf@elektro.pacujo.net> <87fv8sndw1.fsf@elektro.pacujo.net> <874mp7on13.fsf@elektro.pacujo.net> Message-ID: <87vbhnn4jt.fsf@elektro.pacujo.net> Ian Kelly : > On Thu, Mar 26, 2015 at 8:23 AM, Marko Rauhamaa wrote: >> That's trial and error, aka, reductio ad absurdum. > > Okay, I've probably used single-lookahead trial and error in my > reasoning at some point. But the example you give is equivalent to the > deductive process "That can't be a 5, so I remove it as a candidate. > The only place left for a 5 is here, so I remove the 2 as a candidate > and fill in the 5." In fact, the "trial-and-error" technique is used in automated theorem proving: Lean provers are generally implemented in Prolog, and make proficient use of the backtracking engine and logic variables of that language. Marko From invalid at invalid.invalid Thu Mar 26 11:49:30 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 26 Mar 2015 15:49:30 +0000 (UTC) Subject: What is elegant way to do configuration on server app References: Message-ID: On 2015-03-26, Ben Finney wrote: > Jerry OELoo writes: > >> Currently, I can just think out that I put status into a configure >> file, and service schedule read this file and get status value, > > That sounds like a fine start. Some advice: > > * You may be tempted to make the configuration file executable (e.g. > Python code). Resist that temptation; keep it *much* simpler, a > non-executable data format. > > Python's standard library has the ?configparser? module > to parse and > provide the values from a very common configuration file format. > Use that unless you have a good reason not to. I second the recommendation for configparser for stuff of simple to moderate complexity. If it gets too complex for configparser, you may want to consider JSON, or for even more complex stuff just use plain Python code in your config file (this can be very powerful and expressive, but can also be diffucult to implement safely). > * Your program can ?poll? the configuration file to see whether it has > changed. At startup, read the config file's modification timestamp > . > > Make a part of your event loop (assuming your server runs an event > loop) that wakes up every N seconds (e.g. every 60 seconds) and > checkes the file's modification timestamp again; if it's newer, record > that value for future comparisons, then re-read the file for its > values. That sounds rather Windowsesque. The more-or-less standard way to do handle the situation on Unix is to reread the config file when you get a SIGHUP. -- Grant Edwards grant.b.edwards Yow! ONE LIFE TO LIVE for at ALL MY CHILDREN in ANOTHER gmail.com WORLD all THE DAYS OF OUR LIVES. From ian.g.kelly at gmail.com Thu Mar 26 12:20:10 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 26 Mar 2015 10:20:10 -0600 Subject: Sudoku solver In-Reply-To: <87vbhnn4jt.fsf@elektro.pacujo.net> References: <87r3sdnw5t.fsf@elektro.pacujo.net> <87fv8sndw1.fsf@elektro.pacujo.net> <874mp7on13.fsf@elektro.pacujo.net> <87vbhnn4jt.fsf@elektro.pacujo.net> Message-ID: On Thu, Mar 26, 2015 at 9:48 AM, Marko Rauhamaa wrote: > Ian Kelly : > >> On Thu, Mar 26, 2015 at 8:23 AM, Marko Rauhamaa wrote: >>> That's trial and error, aka, reductio ad absurdum. >> >> Okay, I've probably used single-lookahead trial and error in my >> reasoning at some point. But the example you give is equivalent to the >> deductive process "That can't be a 5, so I remove it as a candidate. >> The only place left for a 5 is here, so I remove the 2 as a candidate >> and fill in the 5." > > In fact, the "trial-and-error" technique is used in automated theorem > proving: > > Lean provers are generally implemented in Prolog, and make proficient > use of the backtracking engine and logic variables of that language. > > Sure, but what has this to do with the statement that *sudoku* should not require trial and error to solve? From python.list at tim.thechases.com Thu Mar 26 12:26:48 2015 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 26 Mar 2015 11:26:48 -0500 Subject: test1 In-Reply-To: References: <7edc4671-8f96-491a-be30-0ad3f2175e07@googlegroups.com> <62b52eb2-67cc-4075-b6e1-f19700e66bed@googlegroups.com> <584bbccc-7691-4a32-861e-bd317659533b@googlegroups.com> Message-ID: <20150326112648.0e4615de@bigbox.christie.dr> On 2015-03-26 08:33, Tiglath Suriol wrote: > > Mark Lawrence > > I don't remember addressing his guy, HE addressed me FIRST, as all > of you did, Hmmm...To what then has he been replying? *You* posted/broadcast the FIRST message which addressed every member of the list. If you don't want to address every member of a list, try not posting. Or at least expect replies. > now you complaint you don't like my replies. Mostly it's your uncivil tone that people seem to be complaining about. Reading over the messages in the thread, it's mostly *you* complaining about replies. And you that keeps fanning the flame. > I came here because I can and may. And folks here replied. Because they can and may. And you're not kidding anybody: your bravado and insults against a plurality of respected community members only amplifies your own appearance of folly. -tkc From PointedEars at web.de Thu Mar 26 12:45:48 2015 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Thu, 26 Mar 2015 17:45:48 +0100 Subject: A simple single line, triple-quoted comment is giving syntax error. Why? References: <3533816.ZYnZ2OzjCs@PointedEars.de> <3971951.908YQu3oQO@PointedEars.de> <1504323.jUKfeKbQsP@PointedEars.de> Message-ID: <2362875.FIK8ImHTJA@PointedEars.de> Ian Kelly wrote: > [?] Thomas 'PointedEars' Lahn [?] wrote: >> Chris Angelico wrote: >>> [?] Thomas 'PointedEars' Lahn [?] wrote: >>>>> Implicit concatenation is part of the syntax, not part of the >>>>> expression evaluator. >>>> Reads like nonsense to me. >>> What do you mean? >> As I showed, string literals and consecutive tokens of string literals >> (?STRING+?) so as to do implicit concatenation *are* expressions of the >> Python grammar. Expressions are *part of* the syntax of a programming >> language. >> >> Perhaps you mean that the time when implicit concatenation is evaluated >> (compile time) differs from the time when other expressions are evaluated >> (runtime). But a) whether that is true depends on the implementation and >> b) there can be no doubt that either expression needs to be evaluated. >> So whatever you mean by ?expression evaluator? has to be able to do those >> things. >> >> Which makes the statement above read like nonsense to me. > > What the grammar that you quoted from shows is that STRING+ is an > expression. The individual STRINGs of a STRING+ are not expressions, > except to the extent that they can be parsed in isolation as a > STRING+. How did you get that idea? STRING+ means one or more consecutive STRING tokens (ignoring whitespace in-between), which means one or more consecutive string literals. A (single) string literal definitely is an expression as it can be produced with the ?expr? goal symbol of the Python grammar (given there in a flavor of EBNF). > By the same token, a STRING+ is a single string literal, not > an aggregate of several. No, in the used flavour of EBNF the unquoted ?+? following a goal symbol clearly means the occurrence of *at least one* of the immediately preceding symbol, meaning either one *or more than one*. pp. > Ancillary data point: > > >>> help(ast.literal_eval) > Safely evaluate an expression node or a string containing a Python > expression. The string or node provided may only consist of the > following Python literal structures: strings, bytes, numbers, tuples, > lists, dicts, sets, booleans, and None. > >>> ast.literal_eval('"foo" "bar"') > 'foobar' > > So the ast.literal_eval also treats this as one literal expression. What do you mean? ast.literal_eval() sees a single string value resulting from the evaluation of one string literal, by the Python compiler, that contains the representation of two consecutive string literals: '"foo" "bar"' It then does exactly what the Python compiler would do in such a case: parse this as if it were one string literal (the ?implicit concatenation? I am talking about). "foo" "bar" ? "foobar" This was not debated. -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From marko at pacujo.net Thu Mar 26 12:47:31 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 26 Mar 2015 18:47:31 +0200 Subject: Sudoku solver References: <87r3sdnw5t.fsf@elektro.pacujo.net> <87fv8sndw1.fsf@elektro.pacujo.net> <874mp7on13.fsf@elektro.pacujo.net> <87vbhnn4jt.fsf@elektro.pacujo.net> Message-ID: <874mp7aeos.fsf@elektro.pacujo.net> Ian Kelly : > On Thu, Mar 26, 2015 at 9:48 AM, Marko Rauhamaa wrote: >> In fact, the "trial-and-error" technique is used in automated theorem >> proving: >> >> Lean provers are generally implemented in Prolog, and make proficient >> use of the backtracking engine and logic variables of that language. >> >> > > Sure, but what has this to do with the statement that *sudoku* should > not require trial and error to solve? Trial-and-error was presented in opposition to logical deduction, while really trial-and-error *is* logical deduction. Marko From tiglathsuriol at gmail.com Thu Mar 26 13:00:56 2015 From: tiglathsuriol at gmail.com (Tiglath Suriol) Date: Thu, 26 Mar 2015 10:00:56 -0700 (PDT) Subject: test1 In-Reply-To: References: <7edc4671-8f96-491a-be30-0ad3f2175e07@googlegroups.com> <62b52eb2-67cc-4075-b6e1-f19700e66bed@googlegroups.com> <55134bdd$0$12979$c3e8da3$5496439d@news.astraweb.com> <6aec1e5f-eeed-46e0-b30a-7cb3e5a601b3@googlegroups.com> <85b79d54-f608-4b17-bd6d-46daf1b5d47b@googlegroups.com> Message-ID: <28f04e93-f40b-4822-855f-f1d95482585b@googlegroups.com> On Thursday, March 26, 2015 at 11:34:11 AM UTC-4, Joel Goldstick wrote: > On Thu, Mar 26, 2015 at 11:25 AM, Tiglath Suriol > wrote: > > On Thursday, March 26, 2015 at 9:53:48 AM UTC-4, Joel Goldstick wrote: > >> Your first message was not python related. Your subsequent messages > >> were rude. You've never been here before it seems. This is an > >> interesting group, open to all with interest in python. How do you > >> fit in? Not > >> > >> On Wed, Mar 25, 2015 at 9:34 PM, Tiglath Suriol wrote: > >> > On Wednesday, March 25, 2015 at 7:59:34 PM UTC-4, Steven D'Aprano wrote: > >> >> On Thu, 26 Mar 2015 10:43 am, Tiglath Suriol wrote: > >> >> > >> >> > I've dealt with people like you in newsgroups for a long time > >> >> > >> >> So many years, so little learning. It's arseholes like you who make it so > >> >> important to invent a way to stab people through the internet. Just go > >> >> away, you're not wanted here. > >> >> > >> > > >> > I may stay a while just to poke you in the eye a little longer. I am beginning to enjoy this. People entering a battle of wits unarmed. It's a joy to watch. > >> > > >> > > >> > You talk as if I wanted you to want me. Pure delusion. I posted at nobody, as I am free to do, and idiots come out of the woodwork as if I had committed some infraction. > >> > > >> > And you even want to stab me. Sterling. Who raised you. wolves? > >> > > >> > > >> >> > >> >> > >> >> > >> >> -- > >> >> Steven > >> > > >> > -- > >> > https://mail.python.org/mailman/listinfo/python-list > >> > >> > >> > >> -- > >> Joel Goldstick > >> http://joelgoldstick.com > > > > Rather... > > > > I came here because I can and may. but I did no provoke anyone. > > > > Then the Central Scrutinizer chimed in followed by his Seven Dwarves and his bitches. Now you, in which group do you fit? > > > > Had you all minded your business I wouldn't be here. Saving yourselves all those inane s, and even more inane retorts. > > > > Now be sincere, you write at me because this is like gawking at an accident on the road, it's a disturbance in your otherwise Pythonic, catatonic day. > > > > I did not intend to, but since you appeared, I don't mind kicking your asses for laughs. So please write more. > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > > You came here to be on display since you have some sort of warped > sense of self. Show your mother what you write online. Maybe she can > get you help > Look at the facts, Harpo. I posted two test messages containing code. I did not address anyone, I did not ask anything, I made no comment. Said nothing about me or anyone. Posts are still there. See them. All large groups have the type of lame people who like those on the road cause a jam to look at some disturbance. Same here, it was just code, idiots. But you could not let it go. Had to poke your long noses in it. Now that you've found little pleasure in your endevour, you are plonking and whining like stuck pigs. Serves you right. You are free to ignore any post you object to. You also have the power to killfile anyone, so if you are still here stinking my thread is because either you are as thick as a brick, or you want a pissing contest. Which one is it? Bring it on or buzz off, but for fuck's sake stop whining. From gdotoli at gmail.com Thu Mar 26 13:11:49 2015 From: gdotoli at gmail.com (Gregg Dotoli) Date: Thu, 26 Mar 2015 10:11:49 -0700 (PDT) Subject: Basic Python V3 Search Tool using RE module In-Reply-To: References: Message-ID: On Wednesday, March 25, 2015 at 3:43:38 PM UTC-4, Gregg Dotoli wrote: > This basic script will help to find > evidence of CryptoWall on a slave drive. Although it is > just a string, more complex regex patterns can be > replaced with the string. It is incredible how fast Python is and > how easy it has helped in quickly assessing a pool of slave drives. > I'm improving it as we speak. > > > Thanks for your help and patience. I'm new with Python. > > > import os > import re > # From the Root > topdir = "." > > # Regex Pattern > pattern="DECRYPT_I" > regexp=re.compile(pattern) > for dirpath,dirnames, files in os.walk(topdir): > for name in files: > result=regexp.search(name) > print(os.path.join(dirpath,name)) > print (result) > > > > > > Gregg Dotoli I posted this because I thought it may be of help to others. This does grep through all the files and is very fast because the regex is compiled in Python , rather than sitting in some directory as an external command. That is where the optimization comes in. Let's close this thread. Gregg From davea at davea.name Thu Mar 26 13:23:56 2015 From: davea at davea.name (Dave Angel) Date: Thu, 26 Mar 2015 13:23:56 -0400 Subject: Basic Python V3 Search Tool using RE module In-Reply-To: References: Message-ID: <551440AC.9030005@davea.name> On 03/26/2015 01:11 PM, Gregg Dotoli wrote: > On Wednesday, March 25, 2015 at 3:43:38 PM UTC-4, Gregg Dotoli wrote: >> This basic script will help to find >> evidence of CryptoWall on a slave drive. Although it is >> just a string, more complex regex patterns can be >> replaced with the string. It is incredible how fast Python is and >> how easy it has helped in quickly assessing a pool of slave drives. >> I'm improving it as we speak. >> >> >> Thanks for your help and patience. I'm new with Python. >> >> >> import os >> import re >> # From the Root >> topdir = "." >> >> # Regex Pattern >> pattern="DECRYPT_I" >> regexp=re.compile(pattern) >> for dirpath,dirnames, files in os.walk(topdir): >> for name in files: >> result=regexp.search(name) >> print(os.path.join(dirpath,name)) >> print (result) >> >> >> >> >> >> Gregg Dotoli > > I posted this because I thought it may be of help to others. This does grep through all the files and is very fast because the regex is compiled in Python , rather than sitting in some directory as an external command. > That is where the optimization comes in. > > Let's close this thread. > > It "grep"s through all the filenames, but there's no open() call or equivalent there at all. it does not look inside a single file. We can stop posting to the thread, but that won't fix the bug in the code. -- DaveA From PointedEars at web.de Thu Mar 26 13:25:47 2015 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Thu, 26 Mar 2015 18:25:47 +0100 Subject: A simple single line, triple-quoted comment is giving syntax error. Why? References: <3533816.ZYnZ2OzjCs@PointedEars.de> <3971951.908YQu3oQO@PointedEars.de> <1504323.jUKfeKbQsP@PointedEars.de> Message-ID: <1481542.1Cq4f6zJTR@PointedEars.de> Dave Angel wrote: [Fixed quotation] > On 03/26/2015 01:09 AM, Ian Kelly wrote: >>>>> Thomas 'PointedEars' Lahn wrote: >>>>>> >>>>> literal-concatenation> >> >> What the grammar that you quoted from shows is that STRING+ is an >> expression. The individual STRINGs of a STRING+ are not expressions, >> except to the extent that they can be parsed in isolation as a >> STRING+. By the same token, a STRING+ is a single string literal, not >> an aggregate of several. > > That's the way I also read the BNF. Then I am afraid you need to refresh your knowledge of formal grammars. > But something I cannot find in that chapter of the reference is the > definition of STRING+ You *definitely* need to refresh your knowledge of formal grammars. ?STRING+? in this flavor of _E_BNF is ? rather obviously ? equivalent to ::= * ::= '"' * '"' | "'" * "'" | '"""' * '"""' | "'''" * "'''" in BNF and multiple-string = STRING *STRING STRING = '"' *no-unescaped-doublequote '"' / "'" *no-unescaped-singlequote '"' / '"""' *no-unescaped-triple-doublequote '"""' / "'''" *no-unescaped-triple-singlequote "'''" in ABNF. I suspect that in this flavor of EBNF the definition of STRING looks similar to the following: STRING: ('"' no_unescaped_doublequote* '"' | "'" no_unescaped_singlequote* "'" | '"""' no_unescaped_triple_doublequote* '"""' | "'''" no_unescaped_triple_singlequote* "'''") Definition of the still undefined goal symbols is left as an exercise to the reader. -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From PointedEars at web.de Thu Mar 26 13:30:01 2015 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Thu, 26 Mar 2015 18:30:01 +0100 Subject: A simple single line, triple-quoted comment is giving syntax error. Why? References: <3533816.ZYnZ2OzjCs@PointedEars.de> <3971951.908YQu3oQO@PointedEars.de> <1504323.jUKfeKbQsP@PointedEars.de> <1481542.1Cq4f6zJTR@PointedEars.de> Message-ID: <4370855.BVeLXS55tK@PointedEars.de> Thomas 'PointedEars' Lahn wrote: > multiple-string = STRING *STRING > [?] > in ABNF. JFTR: ABNF allows for multiple-string = 1*STRING to be equivalent to the above. pp. -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From ian.g.kelly at gmail.com Thu Mar 26 14:29:02 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 26 Mar 2015 12:29:02 -0600 Subject: A simple single line, triple-quoted comment is giving syntax error. Why? In-Reply-To: <2362875.FIK8ImHTJA@PointedEars.de> References: <3533816.ZYnZ2OzjCs@PointedEars.de> <3971951.908YQu3oQO@PointedEars.de> <1504323.jUKfeKbQsP@PointedEars.de> <2362875.FIK8ImHTJA@PointedEars.de> Message-ID: On Thu, Mar 26, 2015 at 10:45 AM, Thomas 'PointedEars' Lahn wrote: > Ian Kelly wrote: >> What the grammar that you quoted from shows is that STRING+ is an >> expression. The individual STRINGs of a STRING+ are not expressions, >> except to the extent that they can be parsed in isolation as a >> STRING+. > > How did you get that idea? STRING+ means one or more consecutive STRING > tokens (ignoring whitespace in-between), which means one or more consecutive > string literals. A (single) string literal definitely is an expression as > it can be produced with the ?expr? goal symbol of the Python grammar (given > there in a flavor of EBNF). Yes, that's what I was referring to in my parenthetical "except..." above. What I mean is that if you construct a parse tree of "foo" "bar" using that grammar, it looks like this: expr | STRING+ / \ STRING STRING Not like this: expr | STRING+ / \ expr expr | | STRING STRING There is only one expr node, and it contains both STRING tokens. >> By the same token, a STRING+ is a single string literal, not >> an aggregate of several. > > No, in the used flavour of EBNF the unquoted ?+? following a goal symbol > clearly means the occurrence of *at least one* of the immediately preceding > symbol, meaning either one *or more than one*. It means one or more *tokens*, not one or more literals. From ian.g.kelly at gmail.com Thu Mar 26 14:32:11 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 26 Mar 2015 12:32:11 -0600 Subject: A simple single line, triple-quoted comment is giving syntax error. Why? In-Reply-To: References: <3533816.ZYnZ2OzjCs@PointedEars.de> <3971951.908YQu3oQO@PointedEars.de> <1504323.jUKfeKbQsP@PointedEars.de> <2362875.FIK8ImHTJA@PointedEars.de> Message-ID: On Thu, Mar 26, 2015 at 12:29 PM, Ian Kelly wrote: > On Thu, Mar 26, 2015 at 10:45 AM, Thomas 'PointedEars' Lahn >> No, in the used flavour of EBNF the unquoted ?+? following a goal symbol >> clearly means the occurrence of *at least one* of the immediately preceding >> symbol, meaning either one *or more than one*. > > It means one or more *tokens*, not one or more literals. Although reading the documentation, it seems that it also conflates string literals with tokens, so on that I'll have to concede the point. https://docs.python.org/3.4/reference/lexical_analysis.html#string-and-bytes-literals From PointedEars at web.de Thu Mar 26 14:54:36 2015 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Thu, 26 Mar 2015 19:54:36 +0100 Subject: A simple single line, triple-quoted comment is giving syntax error. Why? References: <3533816.ZYnZ2OzjCs@PointedEars.de> <3971951.908YQu3oQO@PointedEars.de> <1504323.jUKfeKbQsP@PointedEars.de> <2362875.FIK8ImHTJA@PointedEars.de> Message-ID: <1823599.Pr2V0MPR6q@PointedEars.de> Ian Kelly wrote: > [?] Thomas 'PointedEars' Lahn [?] wrote: >> Ian Kelly wrote: >>> What the grammar that you quoted from shows is that STRING+ is an >>> expression. The individual STRINGs of a STRING+ are not expressions, >>> except to the extent that they can be parsed in isolation as a >>> STRING+. >> How did you get that idea? STRING+ means one or more consecutive STRING >> tokens (ignoring whitespace in-between), which means one or more >> consecutive string literals. A (single) string literal definitely is an >> expression as it can be produced with the ?expr? goal symbol of the >> Python grammar (given there in a flavor of EBNF). > > Yes, that's what I was referring to in my parenthetical "except..." above. Your ?except? is contradictory to the rest of what you said, at best. > What I mean is that if you construct a parse tree of "foo" "bar" using > that grammar, it looks like this: > > expr > | > STRING+ > / \ > STRING STRING > [?] > > There is only one expr node, and it contains both STRING tokens. Prove it. But be warned: Neither would prove that a string literal is not an expression. Because you did not consider the most simple variant of an AST (or subtree) according to this grammar: expr | STRING Again, ?STRING+? does _not_ mean ?STRING STRING STRING*?; it means ?STRING STRING*?. The second and following STRINGs are *optional*. >> [?] in the used flavour of EBNF the unquoted ?+? following a goal symbol >> clearly means the occurrence of *at least one* of the immediately >> preceding symbol, meaning either one *or more than one*. > > It means one or more *tokens*, not one or more literals. Utter nonsense. Have you ever written a parser? (I have.) A literal *is* a token. Whether two consecutive tokens end up as the same *node* in an AST is a *different* issue (that, again, was _not_ debated). -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From PointedEars at web.de Thu Mar 26 14:56:09 2015 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Thu, 26 Mar 2015 19:56:09 +0100 Subject: A simple single line, triple-quoted comment is giving syntax error. Why? References: <3533816.ZYnZ2OzjCs@PointedEars.de> <3971951.908YQu3oQO@PointedEars.de> <1504323.jUKfeKbQsP@PointedEars.de> <2362875.FIK8ImHTJA@PointedEars.de> Message-ID: <1582467.9xuzSGXesM@PointedEars.de> Ian Kelly wrote: > On Thu, Mar 26, 2015 at 12:29 PM, Ian Kelly wrote: >> On Thu, Mar 26, 2015 at 10:45 AM, Thomas 'PointedEars' Lahn >>> No, in the used flavour of EBNF the unquoted ?+? following a goal symbol >>> clearly means the occurrence of *at least one* of the immediately >>> preceding symbol, meaning either one *or more than one*. >> >> It means one or more *tokens*, not one or more literals. > > Although reading the documentation, it seems that it also conflates > string literals with tokens, There is nothing to conflate here. String literals *are* tokens. > so on that I'll have to concede the point. Too late, the rebuttal is already underway :-p -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From bc at freeuk.com Thu Mar 26 16:00:40 2015 From: bc at freeuk.com (BartC) Date: Thu, 26 Mar 2015 20:00:40 +0000 Subject: Fwd: test1 In-Reply-To: <59fcf2e2-6640-488c-b216-2d840c947d99@googlegroups.com> References: <7edc4671-8f96-491a-be30-0ad3f2175e07@googlegroups.com> <62b52eb2-67cc-4075-b6e1-f19700e66bed@googlegroups.com> <55135036.1010607@mrabarnett.plus.com> <59fcf2e2-6640-488c-b216-2d840c947d99@googlegroups.com> Message-ID: On 26/03/2015 15:38, Tiglath Suriol wrote: > I did not spam anyone. I posted to an open public newsgroup. Just some code, nothing offensive or even directed to anyone. Then people started to get cute, and now that returned fire is a bucket a drop they complaints like bitches on the rag. Not surprised, but not SPAM either. If anyone pull a newsgroup into his email that's his doing, not mine. There are 100,000 different public newsgroups for a reason: they are all about different subjects. Your post had nothing to do with Python that I could see. To post test messages, try alt.test. Otherwise the newsgroup would get swamped if everyone posted irrelevant random stuff. BTW why /did/ you choose this newsgroup? -- Bartc From denismfmcmahon at gmail.com Thu Mar 26 16:02:54 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Thu, 26 Mar 2015 20:02:54 +0000 (UTC) Subject: test1 References: <7edc4671-8f96-491a-be30-0ad3f2175e07@googlegroups.com> <62b52eb2-67cc-4075-b6e1-f19700e66bed@googlegroups.com> <55134bdd$0$12979$c3e8da3$5496439d@news.astraweb.com> <6aec1e5f-eeed-46e0-b30a-7cb3e5a601b3@googlegroups.com> <85b79d54-f608-4b17-bd6d-46daf1b5d47b@googlegroups.com> <28f04e93-f40b-4822-855f-f1d95482585b@googlegroups.com> Message-ID: On Thu, 26 Mar 2015 10:00:56 -0700, Tiglath Suriol wrote: > I posted two test messages containing code. No, you excreted a pile of steaming excrement and have continued to do so. Your original post in this thread had no relevance to the newsgroup or the gated mailing list, it was purely internet vandalism, and your ongoing posts are simply trolling. -- Denis McMahon, denismfmcmahon at gmail.com From emile at fenx.com Thu Mar 26 16:37:10 2015 From: emile at fenx.com (Emile van Sebille) Date: Thu, 26 Mar 2015 13:37:10 -0700 Subject: test1 In-Reply-To: <62b52eb2-67cc-4075-b6e1-f19700e66bed@googlegroups.com> References: <7edc4671-8f96-491a-be30-0ad3f2175e07@googlegroups.com> <62b52eb2-67cc-4075-b6e1-f19700e66bed@googlegroups.com> Message-ID: On 3/25/2015 12:49 PM, Tiglath Suriol wrote: > On Tuesday, March 24, 2015 at 11:04:48 PM UTC-4, Chris Angelico wrote: >> On Wed, Mar 25, 2015 at 1:47 PM, Tiglath Suriol wrote: >PLONK< From emile at fenx.com Thu Mar 26 16:48:05 2015 From: emile at fenx.com (Emile van Sebille) Date: Thu, 26 Mar 2015 13:48:05 -0700 Subject: Best way to calculate fraction part of x? In-Reply-To: References: <55100c7a$0$13004$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/24/2015 6:39 PM, Jason Swails wrote: > > > On Mon, Mar 23, 2015 at 8:38 PM, Emile van Sebille > float (("%6.3f" % x)[-4:]) > > > ?In general you lose a lot of precision this way...? > Even more if you use %6.1 -- but feel free to flavor to taste. :) Emile From marcuslom101 at gmail.com Thu Mar 26 16:58:36 2015 From: marcuslom101 at gmail.com (marcuslom101 at gmail.com) Date: Thu, 26 Mar 2015 13:58:36 -0700 (PDT) Subject: Fwd: test1 In-Reply-To: References: <7edc4671-8f96-491a-be30-0ad3f2175e07@googlegroups.com> <62b52eb2-67cc-4075-b6e1-f19700e66bed@googlegroups.com> <55135036.1010607@mrabarnett.plus.com> <59fcf2e2-6640-488c-b216-2d840c947d99@googlegroups.com> Message-ID: On Thursday, March 26, 2015 at 4:01:08 PM UTC-4, BartC wrote: > On 26/03/2015 15:38, Tiglath Suriol wrote: > > > I did not spam anyone. I posted to an open public newsgroup. Just some code, nothing offensive or even directed to anyone. Then people started to get cute, and now that returned fire is a bucket a drop they complaints like bitches on the rag. Not surprised, but not SPAM either. If anyone pull a newsgroup into his email that's his doing, not mine. > > There are 100,000 different public newsgroups for a reason: they are all > about different subjects. > > Your post had nothing to do with Python that I could see. A polite post at last. How refreshing. That would be two off-topic posts I submitted. All the replies to it were also off-topic, so it can't possibly be such a big crime. > > To post test messages, try alt.test. Otherwise the newsgroup would get > swamped if everyone posted irrelevant random stuff. Say that too to the imbeciles who jumped from the woodwork and made any swamping I may have caused much worst. The reaction has been far worse than my action. This stems from regular posters of a newsgroup developing a sense of entitlement and turf, which is purely imaginary. This is a public place and everyone has the tools to ignore posts and posters. They just wanted to play and mock and got burned. > > BTW why /did/ you choose this newsgroup? > I just needed to save some code and there was no email at hand, I use this because it's a group I am familiar with, alt.test sounds like a better option. Thanks > -- > Bartc From joel.goldstick at gmail.com Thu Mar 26 17:03:29 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Thu, 26 Mar 2015 17:03:29 -0400 Subject: Fwd: test1 In-Reply-To: References: <7edc4671-8f96-491a-be30-0ad3f2175e07@googlegroups.com> <62b52eb2-67cc-4075-b6e1-f19700e66bed@googlegroups.com> <55135036.1010607@mrabarnett.plus.com> <59fcf2e2-6640-488c-b216-2d840c947d99@googlegroups.com> Message-ID: post to yourself funny how you have a new email address On Thu, Mar 26, 2015 at 4:58 PM, wrote: > On Thursday, March 26, 2015 at 4:01:08 PM UTC-4, BartC wrote: >> On 26/03/2015 15:38, Tiglath Suriol wrote: >> >> > I did not spam anyone. I posted to an open public newsgroup. Just some code, nothing offensive or even directed to anyone. Then people started to get cute, and now that returned fire is a bucket a drop they complaints like bitches on the rag. Not surprised, but not SPAM either. If anyone pull a newsgroup into his email that's his doing, not mine. >> >> There are 100,000 different public newsgroups for a reason: they are all >> about different subjects. >> >> Your post had nothing to do with Python that I could see. > > > A polite post at last. How refreshing. > > That would be two off-topic posts I submitted. All the replies to it were also off-topic, so it can't possibly be such a big crime. > > >> >> To post test messages, try alt.test. Otherwise the newsgroup would get >> swamped if everyone posted irrelevant random stuff. > > Say that too to the imbeciles who jumped from the woodwork and made any swamping I may have caused much worst. > > The reaction has been far worse than my action. This stems from regular posters of a newsgroup developing a sense of entitlement and turf, which is purely imaginary. This is a public place and everyone has the tools to ignore posts and posters. They just wanted to play and mock and got burned. > > >> >> BTW why /did/ you choose this newsgroup? >> > > I just needed to save some code and there was no email at hand, I use this because it's a group I am familiar with, alt.test sounds like a better option. > > Thanks > > >> -- >> Bartc > > -- > https://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick http://joelgoldstick.com From marcuslom101 at gmail.com Thu Mar 26 17:06:28 2015 From: marcuslom101 at gmail.com (marcuslom101 at gmail.com) Date: Thu, 26 Mar 2015 14:06:28 -0700 (PDT) Subject: test1 In-Reply-To: References: <7edc4671-8f96-491a-be30-0ad3f2175e07@googlegroups.com> <62b52eb2-67cc-4075-b6e1-f19700e66bed@googlegroups.com> <55134bdd$0$12979$c3e8da3$5496439d@news.astraweb.com> <6aec1e5f-eeed-46e0-b30a-7cb3e5a601b3@googlegroups.com> <85b79d54-f608-4b17-bd6d-46daf1b5d47b@googlegroups.com> <28f04e93-f40b-4822-855f-f1d95482585b@googlegroups.com> Message-ID: <0ee4a088-987b-48e6-b337-3ee0f3b58f73@googlegroups.com> On Thursday, March 26, 2015 at 4:03:57 PM UTC-4, Denis McMahon wrote: > On Thu, 26 Mar 2015 10:00:56 -0700, Tiglath Suriol wrote: > > > I posted two test messages containing code. > > No, you excreted a pile of steaming excrement and have continued to do > so. Your original post in this thread had no relevance to the newsgroup > or the gated mailing list, it was purely internet vandalism, and your > ongoing posts are simply trolling. > > -- > Denis McMahon, denismfmcmahon at gmail.com I posted two test messages containing code. They are still there, are you blind as well as dumb? Your post is also off-topic, so what are you whining about, girl? You can ignore my posts almost effortlessly, the fact that you prefer to inveigh in your rant means that you want to be part of this. I'll be happy to oblige, bozo. Make my day. From marfig at gmail.com Thu Mar 26 17:11:49 2015 From: marfig at gmail.com (Mario Figueiredo) Date: Thu, 26 Mar 2015 22:11:49 +0100 Subject: Fwd: test1 References: <55135036.1010607@mrabarnett.plus.com> <59fcf2e2-6640-488c-b216-2d840c947d99@googlegroups.com> Message-ID: <33t8hahid205r5ngmi2su9284roj8kn1an@4ax.com> On Thu, 26 Mar 2015 13:58:36 -0700 (PDT), marcuslom101 at gmail.com wrote: >I just needed to save some code and there was no email at hand > LOL. What an imbecile. You gotta love trolls sometimes. They exist with the sole purpose to make you feel good about yourself. From marfig at gmail.com Thu Mar 26 17:19:45 2015 From: marfig at gmail.com (Mario Figueiredo) Date: Thu, 26 Mar 2015 22:19:45 +0100 Subject: test1 References: <55134bdd$0$12979$c3e8da3$5496439d@news.astraweb.com> <6aec1e5f-eeed-46e0-b30a-7cb3e5a601b3@googlegroups.com> <85b79d54-f608-4b17-bd6d-46daf1b5d47b@googlegroups.com> <28f04e93-f40b-4822-855f-f1d95482585b@googlegroups.com> <0ee4a088-987b-48e6-b337-3ee0f3b58f73@googlegroups.com> Message-ID: On Thu, 26 Mar 2015 14:06:28 -0700 (PDT), marcuslom101 at gmail.com wrote: > >I posted two test messages containing code. They are still there, > are you blind as well as dumb? > >Your post is also off-topic, so what are you whining about, girl? > >You can ignore my posts almost effortlessly, the fact that you >prefer to inveigh in your rant means that you want to be part of >this. I'll be happy to oblige, bozo. Make my day. > Hush now, little baby troll. Don't get all teary on us. Calm down. Just a little while ago you were saying you didn't care about what people said. So don't care about what people say. BTW, you are as stupid as you are an ignorant little trapped troll. You purportedly spammed this place and now we are having fun telling you all about it. Boo hoo! Now, remember what you said... From sohcahtoa82 at gmail.com Thu Mar 26 17:23:56 2015 From: sohcahtoa82 at gmail.com (sohcahtoa82 at gmail.com) Date: Thu, 26 Mar 2015 14:23:56 -0700 (PDT) Subject: test1 In-Reply-To: <7edc4671-8f96-491a-be30-0ad3f2175e07@googlegroups.com> References: <7edc4671-8f96-491a-be30-0ad3f2175e07@googlegroups.com> Message-ID: <7affeafc-cb76-42cc-8aa8-75f655a23c05@googlegroups.com> On Tuesday, March 24, 2015 at 7:48:05 PM UTC-7, Tiglath Suriol wrote: > > NetworkChangeAPI Web Service

    NetworkChangeAPI


    The following operations are supported. For a formal definition, please review the Service Description.

    ################################################################## ##################################################################### I tired to authenticate with SOAPpy and failed. ################################################################## ##################################################################### Python 2.7.6 (default, Apr 28 2014, 19:01:47) [GCC 4.2.2 20070831 prerelease [FreeBSD]] on freebsd8 Type "help", "copyright", "credits" or "license" for more information. >>> import SOAPpy >>> from SOAPpy import SOAPProxy >>> username, password, instance = 'domain\\user', 'abc123', 'demo' >>> proxy, namespace = 'http://username:password at networkchange/NetworkChangeAPI.asmx'+instance+'/incident.do?SOAP', 'http://networkchange/webservices/' >>> server = SOAPProxy(proxy,namespace) >>> server.config.debug = 1 >>> response = server.GetBlankRfc() In build. *** Outgoing HTTP headers ********************************************** POST /NetworkChangeAPI.asmxdemo/incident.do?SOAP HTTP/1.0 Host: networkchange User-agent: SOAPpy 0.12.22 (http://pywebsvcs.sf.net) Content-type: text/xml; charset=UTF-8 Content-length: 401 SOAPAction: "GetBlankRfc" ************************************************************************ *** Outgoing SOAP ****************************************************** ************************************************************************ code= 401 msg= Unauthorized headers= Content-Type: text/html Server: MediumCo-IIS/7.5 WWW-Authenticate: Negotiate WWW-Authenticate: NTLM X-Powered-By: ASP.NET Host: WBA02 X-UA-Compatible: IE=9 Date: Sat, 28 Mar 2015 22:03:17 GMT Connection: close Content-Length: 1293 content-type= text/html data= 401 - Unauthorized: Access is denied due to invalid credentials.

    401 - Unauthorized: Access is denied due to invalid credentials.

    You do not have permission to view this directory or page using the credentials that you supplied.

    *** Incoming HTTP headers ********************************************** HTTP/1.? 401 Unauthorized Content-Type: text/html Server: MediumCo-IIS/7.5 WWW-Authenticate: Negotiate WWW-Authenticate: NTLM X-Powered-By: ASP.NET Host: WBA02 X-UA-Compatible: IE=9 Date: Sat, 28 Mar 2015 22:03:17 GMT Connection: close Content-Length: 1293 ************************************************************************ *** Incoming SOAP ****************************************************** 401 - Unauthorized: Access is denied due to invalid credentials.

    401 - Unauthorized: Access is denied due to invalid credentials.

    You do not have permission to view this directory or page using the credentials that you supplied.

    ************************************************************************ Traceback (most recent call last): File "", line 1, in File "/home/chpfaff/python/sandbox/SOAPpy-0.12.22/build/lib/SOAPpy/Client.py", line 547, in __call__ return self.__r_call(*args, **kw) File "/home/chpfaff/python/sandbox/SOAPpy-0.12.22/build/lib/SOAPpy/Client.py", line 569, in __r_call self.__hd, self.__ma) File "/home/chpfaff/python/sandbox/SOAPpy-0.12.22/build/lib/SOAPpy/Client.py", line 432, in __call timeout = self.timeout) File "/home/chpfaff/python/sandbox/SOAPpy-0.12.22/build/lib/SOAPpy/Client.py", line 331, in call raise HTTPError(code, msg) SOAPpy.Errors.HTTPError: ################################################################## ##################################################################### Below is a example of one of the methods i am trying to call. ################################################################## ##################################################################### POST /NetworkChangeAPI.asmx HTTP/1.1 Host: ppeNetworkchange Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "http://Networkchange/webservices/GetBlankRfc" HTTP/1.1 200 OK Content-Type: text/xml; charset=utf-8 Content-Length: length int int int string int string _None or Status or PropertyDimension or PropertyGroup or Priority or Environment or Risk or Complexity or Datacenter or AssignedResource or PotentiallyAffectedProperty or PeerReviewTeam or CreatedBy or ChangeManager or ChangeType or ChangeSubType or OnHoldJustification or ChangeResultCategory or ChangeResultIssue or Market or TimeTrackingRole or IssueType or ProcessPhase or LinkType or PropertyOwner or AwarenessNotificationFrequency or EventType or Regions or LockdownStatus or LockdownType or CabRole or DiaryType or LockdownAffectedProperties or LockdownDatacentes string int string _None or Status or PropertyDimension or PropertyGroup or Priority or Environment or Risk or Complexity or Datacenter or AssignedResource or PotentiallyAffectedProperty or PeerReviewTeam or CreatedBy or ChangeManager or ChangeType or ChangeSubType or OnHoldJustification or ChangeResultCategory or ChangeResultIssue or Market or TimeTrackingRole or IssueType or ProcessPhase or LinkType or PropertyOwner or AwarenessNotificationFrequency or EventType or Regions or LockdownStatus or LockdownType or CabRole or DiaryType or LockdownAffectedProperties or LockdownDatacentes boolean string int string _None or Status or PropertyDimension or PropertyGroup or Priority or Environment or Risk or Complexity or Datacenter or AssignedResource or PotentiallyAffectedProperty or PeerReviewTeam or CreatedBy or ChangeManager or ChangeType or ChangeSubType or OnHoldJustification or ChangeResultCategory or ChangeResultIssue or Market or TimeTrackingRole or IssueType or ProcessPhase or LinkType or PropertyOwner or AwarenessNotificationFrequency or EventType or Regions or LockdownStatus or LockdownType or CabRole or DiaryType or LockdownAffectedProperties or LockdownDatacentes boolean string string string dateTime string string string dateTime string string int string string dateTime string int string _None or Status or PropertyDimension or PropertyGroup or Priority or Environment or Risk or Complexity or Datacenter or AssignedResource or PotentiallyAffectedProperty or PeerReviewTeam or CreatedBy or ChangeManager or ChangeType or ChangeSubType or OnHoldJustification or ChangeResultCategory or ChangeResultIssue or Market or TimeTrackingRole or IssueType or ProcessPhase or LinkType or PropertyOwner or AwarenessNotificationFrequency or EventType or Regions or LockdownStatus or LockdownType or CabRole or DiaryType or LockdownAffectedProperties or LockdownDatacentes boolean string string string string dateTime boolean dateTime boolean <Value>string</Value> _None or Status or PropertyDimension or PropertyGroup or Priority or Environment or Risk or Complexity or Datacenter or AssignedResource or PotentiallyAffectedProperty or PeerReviewTeam or CreatedBy or ChangeManager or ChangeType or ChangeSubType or OnHoldJustification or ChangeResultCategory or ChangeResultIssue or Market or TimeTrackingRole or IssueType or ProcessPhase or LinkType or PropertyOwner or AwarenessNotificationFrequency or EventType or Regions or LockdownStatus or LockdownType or CabRole or DiaryType or LockdownAffectedProperties or LockdownDatacentes _None or Status or PropertyDimension or PropertyGroup or Priority or Environment or Risk or Complexity or Datacenter or AssignedResource or PotentiallyAffectedProperty or PeerReviewTeam or CreatedBy or ChangeManager or ChangeType or ChangeSubType or OnHoldJustification or ChangeResultCategory or ChangeResultIssue or Market or TimeTrackingRole or IssueType or ProcessPhase or LinkType or PropertyOwner or AwarenessNotificationFrequency or EventType or Regions or LockdownStatus or LockdownType or CabRole or DiaryType or LockdownAffectedProperties or LockdownDatacentes _None or Status or PropertyDimension or PropertyGroup or Priority or Environment or Risk or Complexity or Datacenter or AssignedResource or PotentiallyAffectedProperty or PeerReviewTeam or CreatedBy or ChangeManager or ChangeType or ChangeSubType or OnHoldJustification or ChangeResultCategory or ChangeResultIssue or Market or TimeTrackingRole or IssueType or ProcessPhase or LinkType or PropertyOwner or AwarenessNotificationFrequency or EventType or Regions or LockdownStatus or LockdownType or CabRole or DiaryType or LockdownAffectedProperties or LockdownDatacentes _None or Status or PropertyDimension or PropertyGroup or Priority or Environment or Risk or Complexity or Datacenter or AssignedResource or PotentiallyAffectedProperty or PeerReviewTeam or CreatedBy or ChangeManager or ChangeType or ChangeSubType or OnHoldJustification or ChangeResultCategory or ChangeResultIssue or Market or TimeTrackingRole or IssueType or ProcessPhase or LinkType or PropertyOwner or AwarenessNotificationFrequency or EventType or Regions or LockdownStatus or LockdownType or CabRole or DiaryType or LockdownAffectedProperties or LockdownDatacentes _None or Status or PropertyDimension or PropertyGroup or Priority or Environment or Risk or Complexity or Datacenter or AssignedResource or PotentiallyAffectedProperty or PeerReviewTeam or CreatedBy or ChangeManager or ChangeType or ChangeSubType or OnHoldJustification or ChangeResultCategory or ChangeResultIssue or Market or TimeTrackingRole or IssueType or ProcessPhase or LinkType or PropertyOwner or AwarenessNotificationFrequency or EventType or Regions or LockdownStatus or LockdownType or CabRole or DiaryType or LockdownAffectedProperties or LockdownDatacentes _None or Status or PropertyDimension or PropertyGroup or Priority or Environment or Risk or Complexity or Datacenter or AssignedResource or PotentiallyAffectedProperty or PeerReviewTeam or CreatedBy or ChangeManager or ChangeType or ChangeSubType or OnHoldJustification or ChangeResultCategory or ChangeResultIssue or Market or TimeTrackingRole or IssueType or ProcessPhase or LinkType or PropertyOwner or AwarenessNotificationFrequency or EventType or Regions or LockdownStatus or LockdownType or CabRole or DiaryType or LockdownAffectedProperties or LockdownDatacentes string string _None or Status or PropertyDimension or PropertyGroup or Priority or Environment or Risk or Complexity or Datacenter or AssignedResource or PotentiallyAffectedProperty or PeerReviewTeam or CreatedBy or ChangeManager or ChangeType or ChangeSubType or OnHoldJustification or ChangeResultCategory or ChangeResultIssue or Market or TimeTrackingRole or IssueType or ProcessPhase or LinkType or PropertyOwner or AwarenessNotificationFrequency or EventType or Regions or LockdownStatus or LockdownType or CabRole or DiaryType or LockdownAffectedProperties or LockdownDatacentes _None or Status or PropertyDimension or PropertyGroup or Priority or Environment or Risk or Complexity or Datacenter or AssignedResource or PotentiallyAffectedProperty or PeerReviewTeam or CreatedBy or ChangeManager or ChangeType or ChangeSubType or OnHoldJustification or ChangeResultCategory or ChangeResultIssue or Market or TimeTrackingRole or IssueType or ProcessPhase or LinkType or PropertyOwner or AwarenessNotificationFrequency or EventType or Regions or LockdownStatus or LockdownType or CabRole or DiaryType or LockdownAffectedProperties or LockdownDatacentes _None or Status or PropertyDimension or PropertyGroup or Priority or Environment or Risk or Complexity or Datacenter or AssignedResource or PotentiallyAffectedProperty or PeerReviewTeam or CreatedBy or ChangeManager or ChangeType or ChangeSubType or OnHoldJustification or ChangeResultCategory or ChangeResultIssue or Market or TimeTrackingRole or IssueType or ProcessPhase or LinkType or PropertyOwner or AwarenessNotificationFrequency or EventType or Regions or LockdownStatus or LockdownType or CabRole or DiaryType or LockdownAffectedProperties or LockdownDatacentes boolean string string boolean string boolean string string string string string string string string string string string string boolean _None or Status or PropertyDimension or PropertyGroup or Priority or Environment or Risk or Complexity or Datacenter or AssignedResource or PotentiallyAffectedProperty or PeerReviewTeam or CreatedBy or ChangeManager or ChangeType or ChangeSubType or OnHoldJustification or ChangeResultCategory or ChangeResultIssue or Market or TimeTrackingRole or IssueType or ProcessPhase or LinkType or PropertyOwner or AwarenessNotificationFrequency or EventType or Regions or LockdownStatus or LockdownType or CabRole or DiaryType or LockdownAffectedProperties or LockdownDatacentes _None or Status or PropertyDimension or PropertyGroup or Priority or Environment or Risk or Complexity or Datacenter or AssignedResource or PotentiallyAffectedProperty or PeerReviewTeam or CreatedBy or ChangeManager or ChangeType or ChangeSubType or OnHoldJustification or ChangeResultCategory or ChangeResultIssue or Market or TimeTrackingRole or IssueType or ProcessPhase or LinkType or PropertyOwner or AwarenessNotificationFrequency or EventType or Regions or LockdownStatus or LockdownType or CabRole or DiaryType or LockdownAffectedProperties or LockdownDatacentes boolean int boolean int dateTime dateTime dateTime int _None or Status or PropertyDimension or PropertyGroup or Priority or Environment or Risk or Complexity or Datacenter or AssignedResource or PotentiallyAffectedProperty or PeerReviewTeam or CreatedBy or ChangeManager or ChangeType or ChangeSubType or OnHoldJustification or ChangeResultCategory or ChangeResultIssue or Market or TimeTrackingRole or IssueType or ProcessPhase or LinkType or PropertyOwner or AwarenessNotificationFrequency or EventType or Regions or LockdownStatus or LockdownType or CabRole or DiaryType or LockdownAffectedProperties or LockdownDatacentes string string string string string string string boolean boolean boolean boolean boolean boolean boolean boolean boolean boolean boolean boolean boolean boolean boolean boolean boolean boolean boolean boolean boolean boolean boolean boolean boolean boolean boolean boolean boolean boolean boolean boolean int int int int int boolean boolean string boolean boolean string boolean boolean int string string boolean string int int int int int string thank you!!!!!!! :) From timr at probo.com Sat Mar 28 19:34:51 2015 From: timr at probo.com (Tim Roberts) Date: Sat, 28 Mar 2015 16:34:51 -0700 Subject: A simple single line, triple-quoted comment is giving syntax error. Why? References: <5509be2c$0$3027$426a74cc@news.free.fr> <8908fd12-9069-4230-8b1c-3f88e74bdabf@googlegroups.com> Message-ID: Aditya Raj Bhatt wrote: >On Wednesday, March 18, 2015 at 1:04:39 PM UTC-5, Laurent Pointal wrote: >> > Can someone also provide a sort of a 'guide' to triple-quoted >> > comments in general? >> >> A triple ' or " string is a Python string, allowing line-return in >> string. > >What do you mean by line-return in string? Is it newline? Does it mean I >can write - > >'''first part >second part''' > >? > >> If it is in an expression (like a = 5 '''a comment'''), then it must >> be a >> valid expression (and here it is not). > >What is not a valid expression here? Were you ever able to extract the Real Answer to your original question from the froth that resulted? Your basic misunderstanding is that the triple-quote thing is NOT a comment marker. It is a string literal, exactly like a single-quoted string, except that it allows embedded newlines. So, your statement a = 5 '''a comment''' is invalid for exactly the same reason that the statement a = 5 "a comment" is invalid. Neither one of those statement have any comments. There is a CONVENTION to embed a literal string as the first line in a function, to allow for automatic documentation. Whether the literal string is single-quoted or triple-quoted is irrelevant. That is, these two things are equivalent: def func(a): "This is a function" return a*2 def func(a): """This is a function""" return a*2 -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From bc at freeuk.com Sat Mar 28 19:50:03 2015 From: bc at freeuk.com (BartC) Date: Sat, 28 Mar 2015 23:50:03 +0000 Subject: Sudoku solver In-Reply-To: <82e7c5b9-2f0f-405b-859c-b74916c475e0@googlegroups.com> References: <87r3sdnw5t.fsf@elektro.pacujo.net> <4e81bdb9-52db-46e6-b449-d4241cb2a3f2@googlegroups.com> <87twx8amww.fsf@elektro.pacujo.net> <82e7c5b9-2f0f-405b-859c-b74916c475e0@googlegroups.com> Message-ID: On 28/03/2015 03:39, Sayth wrote: > Good test for pypy to see where it's speed sits between C and Python. I've spent the last hour or so doing such tests. Using the OP's algorithm, and testing with the 'hard' puzzle posted by Ian Kelly, I got these approximate results: Python 3.1: 1700 seconds (normal Python interpreter) PyPy: 93 seconds C unoptimised: 17 seconds (gcc -O0 32-bit) C optimised: 3.3 seconds (gcc -O3 32-bit) (X: 170 seconds) All running on Windows on x64. (X is my own interpreted language, which is where my interest in this is. This had been generally faster than Python until PyPy came along. It does however use a pure byte-code interpreter, so the result is not too bad. But using X *and* my own brute-force algorithm, the same puzzle took 2 seconds to solve - faster than C! However it doesn't matter that the OP's algorithm is not great, as it makes an interesting new benchmark.) -- Bartc From rosuav at gmail.com Sat Mar 28 20:12:28 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 29 Mar 2015 11:12:28 +1100 Subject: Sudoku solver In-Reply-To: References: <87r3sdnw5t.fsf@elektro.pacujo.net> <4e81bdb9-52db-46e6-b449-d4241cb2a3f2@googlegroups.com> <87twx8amww.fsf@elektro.pacujo.net> <82e7c5b9-2f0f-405b-859c-b74916c475e0@googlegroups.com> Message-ID: On Sun, Mar 29, 2015 at 10:50 AM, BartC wrote: > Using the OP's algorithm, and testing with the 'hard' puzzle posted by Ian > Kelly, I got these approximate results: > > Python 3.1: 1700 seconds (normal Python interpreter) > PyPy: 93 seconds > C unoptimised: 17 seconds (gcc -O0 32-bit) > C optimised: 3.3 seconds (gcc -O3 32-bit) > (X: 170 seconds) Nice stats. Any chance you can add CPython 3.4 or 3.5 to that? That's a pretty old CPython you're using. ChrisA From flebber.crue at gmail.com Sat Mar 28 22:57:27 2015 From: flebber.crue at gmail.com (Sayth) Date: Sat, 28 Mar 2015 19:57:27 -0700 (PDT) Subject: Python 2/3 versus Perl 5/6 In-Reply-To: References: <55168340$0$12999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <35890a6a-1eef-43cd-8baa-e61a3aa191f4@googlegroups.com> Perl 6 tried to acheive to much, and by delay and confusion lost the enthusiasm of the community behind it Perl 6 and the at that time robust Perl 5 community who saw it as the future, when that future waned so did their's. Perl 6 should have just done what the community wanted at that time, introduce class::mop for a proper oop implementation abs tidy a few edge cases and pull in a few key modules into core. They would now be talking Perl 7 and how to implement functional design into the new release with a larger community. It would be interesting to see how Ruby would have progressed of Perl hadn't stuffed progress up so badly. To me Ruby has always looked like a tidy Perl. From steve+comp.lang.python at pearwood.info Sat Mar 28 23:06:19 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 29 Mar 2015 14:06:19 +1100 Subject: Sudoku solver References: <87r3sdnw5t.fsf@elektro.pacujo.net> <4e81bdb9-52db-46e6-b449-d4241cb2a3f2@googlegroups.com> <87twx8amww.fsf@elektro.pacujo.net> <82e7c5b9-2f0f-405b-859c-b74916c475e0@googlegroups.com> Message-ID: <55176c2c$0$13009$c3e8da3$5496439d@news.astraweb.com> On Sun, 29 Mar 2015 10:50 am, BartC wrote: > (X is my own interpreted language, which is where my interest in this > is. This had been generally faster than Python until PyPy came along. It > does however use a pure byte-code interpreter, so the result is not too > bad. > > But using X *and* my own brute-force algorithm, the same puzzle took 2 > seconds to solve - faster than C! I'm not one of those people who think that C is by definition the fastest language conceivable. (People who believe this sometimes make an exception for hand-crafted assembly, which is ironic since these days the best C optimizing compilers can generate faster, tighter code than human assembly programmers.) I know that program speed depends on the implementation of the language, not necessarily the language itself. I know that Fortran can beat C for numeric work, and that with a tiny fraction of the work put into optimization that C has seen, modern languages like Scala, Eiffel, Haskell and D can get to a factor of 2-6 times as slow as C. And I know that PyPy has managed to beat C in some (quite restrictive, but not completely unrealistic) benchmarks: http://morepypy.blogspot.com.au/2011/02/pypy-faster-than-c-on-carefully-crafted.html http://morepypy.blogspot.com.au/2011/08/pypy-is-faster-than-c-again-string.html So beating C is not impossible. But, when you tell me that your very own personal interpreted language, which I assume nobody else has worked on, is 40% faster than optimized C, my first reaction is to expect that you've probably made a mistake somewhere. I would have the same reaction if somebody casually dropped into a conversation that they happened to beat Usain Bolt's 100m personal best of 9.58 seconds by almost four seconds. While carrying a 20kg backpack. -- Steven From flebber.crue at gmail.com Sat Mar 28 23:13:25 2015 From: flebber.crue at gmail.com (Sayth) Date: Sat, 28 Mar 2015 20:13:25 -0700 (PDT) Subject: Proposal for new minor syntax In-Reply-To: References: Message-ID: <28edb3c6-e6ae-42c8-8b99-e3c172e262e5@googlegroups.com> Sounds like you want to implement nim special dot syntax in python. http://nim-lang.org/manual.html#special-operators From rosuav at gmail.com Sun Mar 29 00:10:46 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 29 Mar 2015 15:10:46 +1100 Subject: Sudoku solver In-Reply-To: <55176c2c$0$13009$c3e8da3$5496439d@news.astraweb.com> References: <87r3sdnw5t.fsf@elektro.pacujo.net> <4e81bdb9-52db-46e6-b449-d4241cb2a3f2@googlegroups.com> <87twx8amww.fsf@elektro.pacujo.net> <82e7c5b9-2f0f-405b-859c-b74916c475e0@googlegroups.com> <55176c2c$0$13009$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Mar 29, 2015 at 2:06 PM, Steven D'Aprano wrote: > On Sun, 29 Mar 2015 10:50 am, BartC wrote: > >> (X is my own interpreted language, which is where my interest in this >> is. This had been generally faster than Python until PyPy came along. It >> does however use a pure byte-code interpreter, so the result is not too >> bad. >> >> But using X *and* my own brute-force algorithm, the same puzzle took 2 >> seconds to solve - faster than C! > > But, when you tell me that your very own personal interpreted language, > which I assume nobody else has worked on, is 40% faster than optimized C, > my first reaction is to expect that you've probably made a mistake > somewhere. I would have the same reaction if somebody casually dropped into > a conversation that they happened to beat Usain Bolt's 100m personal best > of 9.58 seconds by almost four seconds. While carrying a 20kg backpack. I think you're misreading the stats. The first table compares languages, all using the same algorithm, and in that, C beat X ten to one, unoptimized. The second figure, when X took only 2 seconds, was demonstrating the massive improvement that the algorithmic change (from "the OP's algorithm" to "[BartC's] own brute-force algorithm") achieved. For comparison, that's like casually dropping into conversation that you happened to drive a car faster than Usain Bolt's personal best. :) ChrisA From ian.g.kelly at gmail.com Sun Mar 29 00:15:53 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 28 Mar 2015 22:15:53 -0600 Subject: Proposal for new minor syntax In-Reply-To: References: <55167a22$0$13013$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Mar 28, 2015 at 9:05 AM, Mario Figueiredo wrote: > Neiter the language. The dot symbol is a delimiter in the python > grammar. Not an operator. And also defined as a delimiter in the > official documentation, right after operators. What does it matter? How '.' is lexed when it appears on its own should make no difference to the lexing of '.='. > Meanwhile augmented assignment is governed by the `augassign` > nonterminal. An addition to its list would result in a non backwards > compatible new syntactic sugar feature. This would mabe not be a big > issue between 3.X and 2.X, but would, I reckon, be against the > compatibility rules between 3.X versions. How would it not be backwards compatible? I'm not able to come up with any situation where the character sequence '.=' is currently legal outside of string literals and comments. The counter-proposed '=.' could be an issue, since this is currently legal Python: x=.3 But I believe even that is still unambiguous since you couldn't currently follow the =. with an identifier. From rustompmody at gmail.com Sun Mar 29 00:50:52 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 28 Mar 2015 21:50:52 -0700 (PDT) Subject: Proposal for new minor syntax In-Reply-To: References: <55167a22$0$13013$c3e8da3$5496439d@news.astraweb.com> Message-ID: <78e0fb5b-1b2d-4150-a970-9fb5dc93a1f7@googlegroups.com> On Sunday, March 29, 2015 at 9:47:00 AM UTC+5:30, Ian wrote: > On Sat, Mar 28, 2015 at 9:05 AM, Mario Figueiredo wrote: > > Neiter the language. The dot symbol is a delimiter in the python > > grammar. Not an operator. And also defined as a delimiter in the > > official documentation, right after operators. > > What does it matter? How '.' is lexed when it appears on its own > should make no difference to the lexing of '.='. Some circularity here: "How sth is lexed" "sth appears on its own" [except for 1-char/1-token programs!!] From gandalf at shopzeus.com Sun Mar 29 03:12:28 2015 From: gandalf at shopzeus.com (=?ISO-8859-2?Q?Nagy_L=E1szl=F3_Zsolt?=) Date: Sun, 29 Mar 2015 09:12:28 +0200 Subject: pycurl.error: (55, 'select/poll returned error') In-Reply-To: <87fv8pwrk0.fsf@handshake.de> References: <5514FFEE.4030204@shopzeus.com> <87fv8pwrk0.fsf@handshake.de> Message-ID: <5517A5DC.6060001@shopzeus.com> 2015.03.28. 7:43 keltez?ssel, dieter ?rta: > Nagy L?szl? Zsolt writes: > >> When calling curl.perform() on a curl instance I get this: >> >> pycurl.error: (55, 'select/poll returned error') >> .... >> This error happens only if the file to be POST-ed is big enough. Last >> week files were under 1GB and everything went fine. Files above about >> 1GB cannot be sent over with curl. > Web services sometimes have limits about the allowed size of uploaded > files. I know about one web server application framework (Zope/ZServer) > that simply shuts down its communication channel when it receives > a too large file - such a behaviour can confuse the client. > Maybe, in your case, the server side, too, does something unexpected > when it receives large files? The same server is happily accepting files over 4GB from other clients. Those other clients are exactly the same client programs, but they are running on Windows. Only the one on this FreeBSD box is throwing the error. > > "select/poll" by itself has nothing to do with the size of files. > It is used to get informed when one out a set of communication channels > is ready (again) for interaction. In principle, it should not fail -- > unless something strange happens to the communication channels. Yes, I know... But somehow this is related to the file size, because small files are going through. -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. From ian.g.kelly at gmail.com Sun Mar 29 03:56:24 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 29 Mar 2015 01:56:24 -0600 Subject: A simple single line, triple-quoted comment is giving syntax error. Why? In-Reply-To: <9781856.5cutuNVPEq@PointedEars.de> References: <3533816.ZYnZ2OzjCs@PointedEars.de> <3971951.908YQu3oQO@PointedEars.de> <1504323.jUKfeKbQsP@PointedEars.de> <2362875.FIK8ImHTJA@PointedEars.de> <1823599.Pr2V0MPR6q@PointedEars.de> <9781856.5cutuNVPEq@PointedEars.de> Message-ID: On Sat, Mar 28, 2015 at 12:20 PM, Thomas 'PointedEars' Lahn wrote: > Ian Kelly wrote: > >> [?] Thomas 'PointedEars' Lahn [?] wrote: >>> Ian Kelly wrote: >>>> What I mean is that if you construct a parse tree of "foo" "bar" using >>>> that grammar, it looks like this: >>>> >>>> expr >>>> | >>>> STRING+ >>>> / \ >>>> STRING STRING >>>> [?] >>>> >>>> There is only one expr node, and it contains both STRING tokens. >>> Prove it. >> >> I'm not going to expend the effort that would be required to go >> through the entire Python grammar step-by-step and exhaustively prove >> that "foo" "bar" can unambiguously only be produced as a single expr. > > And why should you? That is not what you claimed. Of course it is. I claimed that there was only one expr node in the parse tree of "foo" "bar". You asked me to prove it. That would require two things: first, showing that the complete expansion of the parse tree above does not include any further expr nodes (which I contend is obvious enough that it should not need to be explicitly spelled out in this thread), and second, showing that no other parse tree will generate "foo" "bar". >> If you believe otherwise, show a parse tree that parses these as >> separate expressions. > > Fallacies: Straw man, shifting the burden of proof. If there is a straw man here, it is only the result of one or both of us failing to communicate. Are you now saying that you agree that there is only one expr node in the parse of "foo" "bar"? If so, then why did you ask me to prove it? Why should the burden of proof be on me in the first place? I made the request because demonstrating the positive (such a parse tree exists) would, as usual, be much simpler than proving the negative (no such parse tree exists). In any case, it sounds to me like we're probably in agreement at this point. >>> But be warned: Neither would prove that a string literal is not an >>> expression. >> >> I've not claimed that a string literal is not an expression. > > Yes, you did. You debated my statement which says that. Let me refresh > your memory. I said: You are correct. I was reading "string literal" as STRING+ when I wrote that. I was perhaps confused because your statement "Neither would prove that a string literal is not an expression" did not make sense to me at the time. Within a grammar, the question of "is an X a Y" is nonsensical in isolation. It can only be answered in relation to a parse tree. Consider the simple grammar: S -> A | B A -> x B -> x Is x an A? It depends. If the tree that generates the x produces it from an A node, then yes. Otherwise, no. So when I write that the "foo" in "foo" "bar" is not an expression, I am only speaking in relation to the parse tree that generates "foo" "bar". I am not speaking about the parse tree that generates only "foo", because it is irrelevant, even though in that context it would be an expression. > | As I showed, string literals and consecutive tokens of string literals > | (?STRING+?) so as to do implicit concatenation *are* expressions of the > | Python grammar. > > To which you replied: > > | What the grammar that you quoted from shows is that STRING+ is an > | expression. The individual STRINGs of a STRING+ are not expressions, [?] > ^^^^^^^ ^^^^^^^^^^^^^^^^^^^ > You continued with > > | except to the extent that they can be parsed in isolation as a STRING+. > > but that is nothing more than a backdoor, contradictory to what you said > before (and, as it has been showed, nonsensical). I don't know what you mean by a "backdoor". The purpose of that parenthetical was to explicitly acknowledge that the single STRING could be viewed as an expression when taken out of context, and to disclaim that I was excluding that case from the preceding statement. I still stand by that statement; The "foo" in "foo" "bar" is not an expression in the same sense that the "42" is not an expression in "hucr,.@#%c|42ptqc$". >> My claim is that a literal consisting of the implicit concatenation of >> more than one string token is can only be parsed as one expression, not >> several. > > Then you must have fundamentally misunderstood my statement and this whole > discussion. Quite possibly. Rereading the thread at the point where I jumped in, it's not clear to me now what it was in your post that I was responding to. >> Parsing "foo" "bar" >> >>> Because you did not consider the most simple variant of an AST >>> (or subtree) according to this grammar: >>> >>> expr >>> | >>> STRING >> >> Of course I did. This is again *exactly* what I was talking about in >> reference to parsing the individual strings in isolation. > > Actually, you were arguing against my statement that string literals are > expressions (that a string literal is an expression). You claimed, rather > explicitly, that they were not. See above. I have no idea what point you're trying to convey here. >> I'm quite familiar with basic concepts of EBNF. > > But apparently not logic. Are you intentionally trying to be inflammatory? I think that I have misunderstood your writing in places and that you have likewise misunderstood mine in others. Can we leave it at that? From auriocus at gmx.de Sun Mar 29 03:57:02 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sun, 29 Mar 2015 09:57:02 +0200 Subject: Sudoku solver In-Reply-To: <55176c2c$0$13009$c3e8da3$5496439d@news.astraweb.com> References: <87r3sdnw5t.fsf@elektro.pacujo.net> <4e81bdb9-52db-46e6-b449-d4241cb2a3f2@googlegroups.com> <87twx8amww.fsf@elektro.pacujo.net> <82e7c5b9-2f0f-405b-859c-b74916c475e0@googlegroups.com> <55176c2c$0$13009$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 29.03.15 um 05:06 schrieb Steven D'Aprano: > I'm not one of those people who think that C is by definition the fastest > language conceivable. (People who believe this sometimes make an exception > for hand-crafted assembly, which is ironic since these days the best C > optimizing compilers can generate faster, tighter code than human assembly > programmers.) I know that program speed depends on the implementation of > the language, not necessarily the language itself. I know that Fortran can > beat C for numeric work, and that with a tiny fraction of the work put into > optimization that C has seen, modern languages like Scala, Eiffel, Haskell > and D can get to a factor of 2-6 times as slow as C. And I know that PyPy > has managed to beat C in some (quite restrictive, but not completely > unrealistic) benchmarks: > > http://morepypy.blogspot.com.au/2011/02/pypy-faster-than-c-on-carefully-crafted.html > http://morepypy.blogspot.com.au/2011/08/pypy-is-faster-than-c-again-string.html > > > So beating C is not impossible. Beating C is not impossible, but it is really hard. The compilation is usually excluded from such benchmarks. Then any langugage could in principle compile to the same instructions as the equivalent C program, and hence achieve the same speed. The reason that C is such a tough competitor is 1) the tools have been optimized over 40 years - just compare the sourcecode of gcc with a minimalistic compiler such as tcc, and then compare the execution speed of the programs compiled by it 2) the langugage is very easy to compile, since the programmer is forced to annotate the sourcecode with data types that usually map 1:1 into registers If you can do type deduction for your variables that lead to the same result as the C program, then you can also compile to the same efficient code. In most cases the hand-crafted C program is more restricted, because the programmer does not make a promise to the compiler that things will never overflow (e.g., int is restricted to 32 bits instead of arbitrary integers). Defeating a C compiler is possible in (rare) cases, I wouldn't really count the examples you've posted, since they don't actually compute anything useful. However, for instance the Intel C compiler is able to replace a loop like this: for (int i=0; i > But, when you tell me that your very own personal interpreted language, > which I assume nobody else has worked on, is 40% faster than optimized C, > my first reaction is to expect that you've probably made a mistake I agree with Chris that this was a misunderstanding. Christian From thorsten at thorstenkampe.de Sun Mar 29 04:11:47 2015 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Sun, 29 Mar 2015 10:11:47 +0200 Subject: Run two processes in parallel Message-ID: Hi, I'd like to run two processes concurrently (either through a builtin module or a third-party). One is a "background" task and the other is displaying a spinner (for which I already found good packages). The two processes do not have to communicate with each other; only the second should be able to know when the first has terminated. To make it clear, this is the pseudo-code: ``` import time, PARALLEL, spinner process1 = PARALLEL.start(time.sleep(60)) while process1.isrunning spinner.update() time.sleep(1) print('done') ``` >From what I see, Python modules threading and multiprocessing seem either not suited for that or to be too complicated (though I don't have any experience with these and could be wrong). A search on PyPi for parallel, background, and concurrent found too many. What would you do? Which technique or module would you suggest? Thorsten From anudeepsm at gmail.com Sun Mar 29 04:57:40 2015 From: anudeepsm at gmail.com (bobbydeep) Date: Sun, 29 Mar 2015 01:57:40 -0700 (PDT) Subject: TCP sockets python timeout public IP adresss Message-ID: I am trying to communicate between a server and client using TCP sockets. Server code: import socket import sys # Create a TCP/IP socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Bind the socket to the port server_address = ('my-server-ipadress', 1999) print >>sys.stderr, 'starting up on %s port %s' % server_address sock.bind(server_address) sock.listen(1) try: print >>sys.stderr, 'connection from', client_address # Receive the data in small chunks and retransmit it while True: data = connection.recv(16) print >>sys.stderr, 'received "%s"' % data if data: print >>sys.stderr, 'sending data back to the client' connection.sendall(data) else: print >>sys.stderr, 'no more data from', client_address break finally: # Clean up the connection connection.close() Client code: from socket import * clientsocket = socket(AF_INET,SOCK_STREAM) clientsocket.connect(("my-server-ip-address",1999)) recv = clientsocket.recv(1024) print(recv) It is working fine on a local connection. The problem I am facing is when I run the client code on my laptop (using my home wifi network)and try to communicate with the remote server, it is not able connect to the server. What could be the problem ? Any changes in the code required, or do I need to disable firewall on my laptop ? The error I get is, error: [Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond From ian.g.kelly at gmail.com Sun Mar 29 05:13:31 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 29 Mar 2015 03:13:31 -0600 Subject: Run two processes in parallel In-Reply-To: References: Message-ID: On Sun, Mar 29, 2015 at 2:11 AM, Thorsten Kampe wrote: > Hi, > > I'd like to run two processes concurrently (either through a builtin > module or a third-party). One is a "background" task and the other is > displaying a spinner (for which I already found good packages). > > The two processes do not have to communicate with each other; only > the second should be able to know when the first has terminated. To > make it clear, this is the pseudo-code: > > ``` > import time, PARALLEL, spinner > process1 = PARALLEL.start(time.sleep(60)) > > while process1.isrunning > spinner.update() > time.sleep(1) > > print('done') > ``` > > From what I see, Python modules threading and multiprocessing seem > either not suited for that or to be too complicated (though I don't > have any experience with these and could be wrong). A search on PyPi > for parallel, background, and concurrent found too many. > > What would you do? Which technique or module would you suggest? It shouldn't be all that complicated: import time, multiprocessing, spinner process1 = multiprocessing.Process(target=time.sleep, args=(60,)) process1.start() while process1.is_alive(): spinner.update() time.sleep(1) # join is called implicitly by is_alive, but # calling it explicitly is good practice. process1.join() print('done') Threading should also work fine as long as your background thread doesn't hold the GIL for long periods of time, which would freeze out your spinner update loop. I would tend to prefer threading over multiprocessing for this since the spinner thread is not CPU-bound. From anudeepsm at gmail.com Sun Mar 29 06:03:56 2015 From: anudeepsm at gmail.com (bobbdeep) Date: Sun, 29 Mar 2015 03:03:56 -0700 (PDT) Subject: TCP sockets python timeout public IP adresss In-Reply-To: References: Message-ID: Changed server code to the following, from socket import * HOST = '' PORT = 8080 serversocket = socket(AF_INET,SOCK_STREAM) serversocket.bind((HOST,PORT)) serversocket.listen(5) while True: (clientsocket, address) = serversocket.accept() print ("Got client request from",address) clientsocket.send("Thank You for connecting") clientsocket.close() Still getting same error. From none at mailinator.com Sun Mar 29 06:14:29 2015 From: none at mailinator.com (mm0fmf) Date: Sun, 29 Mar 2015 11:14:29 +0100 Subject: TCP sockets python timeout public IP adresss In-Reply-To: References: Message-ID: On 29/03/2015 09:57, bobbydeep wrote: From the error (10060) it looks like Windows but it would be nice if you could say which Python and OS you were using. I haven't looked at your code but just taking at face value that it does work internally. > server_address = ('my-server-ipadress', 1999) Next thing to check is whether you have permission to open arbitrary ports on the server and whether they are firewalled off. For example, I have a shell account on the server that hosts my webpages and I can run ftp / scp to move files across the internet. However, I cannot open say port 54321 to the internet and accept connections on it. From robert.kern at gmail.com Sun Mar 29 06:20:07 2015 From: robert.kern at gmail.com (Robert Kern) Date: Sun, 29 Mar 2015 11:20:07 +0100 Subject: PiCxx In-Reply-To: References: <2E1837FF-9A40-40E6-BB27-FB57BA9D8E9C@gmail.com> Message-ID: On 2015-03-25 15:45, ? wrote: > Hello Python people, > > I've made a C++ wrapper for Python. > I've called it PiCxx and put it up here: https://github.com/p-i-/PiCxx Please consider using a recognized open source license. Your project looks interesting, but I won't touch it with the current license. http://opensource.org/licenses -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From steve+comp.lang.python at pearwood.info Sun Mar 29 06:35:59 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 29 Mar 2015 21:35:59 +1100 Subject: Sudoku solver References: <87r3sdnw5t.fsf@elektro.pacujo.net> <4e81bdb9-52db-46e6-b449-d4241cb2a3f2@googlegroups.com> <87twx8amww.fsf@elektro.pacujo.net> <82e7c5b9-2f0f-405b-859c-b74916c475e0@googlegroups.com> <55176c2c$0$13009$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5517d590$0$12982$c3e8da3$5496439d@news.astraweb.com> On Sun, 29 Mar 2015 03:10 pm, Chris Angelico wrote: > On Sun, Mar 29, 2015 at 2:06 PM, Steven D'Aprano > wrote: >> On Sun, 29 Mar 2015 10:50 am, BartC wrote: >> >>> (X is my own interpreted language, which is where my interest in this >>> is. This had been generally faster than Python until PyPy came along. It >>> does however use a pure byte-code interpreter, so the result is not too >>> bad. >>> >>> But using X *and* my own brute-force algorithm, the same puzzle took 2 >>> seconds to solve - faster than C! >> >> But, when you tell me that your very own personal interpreted language, >> which I assume nobody else has worked on, is 40% faster than optimized C, >> my first reaction is to expect that you've probably made a mistake >> somewhere. I would have the same reaction if somebody casually dropped >> into a conversation that they happened to beat Usain Bolt's 100m personal >> best of 9.58 seconds by almost four seconds. While carrying a 20kg >> backpack. > > I think you're misreading the stats. The first table compares > languages, all using the same algorithm, and in that, C beat X ten to > one, unoptimized. The second figure, when X took only 2 seconds, was > demonstrating the massive improvement that the algorithmic change > (from "the OP's algorithm" to "[BartC's] own brute-force algorithm") > achieved. For comparison, that's like casually dropping into > conversation that you happened to drive a car faster than Usain Bolt's > personal best. :) Swapping from a clever algorithm to a brute force algorithm is not what I would describe as swapping from running to driving a car. I would describe it as swapping from running down the street to running through quicksand while carrying a grand piano. I don't what sort of algorithm you think is going to be *slower* than brute force. Wait, I have one... randomly generate a grid of numbers. Is it a valid sudoko that matches the clues given? If so, we're done, if not, generate another random grid. Brute force will beat that. That's why I can't help but feel that, *given the description we've seen*, perhaps Bart's brute force code doesn't actually solve the problem, and that's why it is so fast. I'm reminded of the recent thread where somebody claimed to have a significant speed-up over Timsort by using a binary search instead of linear search. Tim Peters investigated, and noticed that the code wasn't actually sorting. It's easy to beat the performance of any sort algorithm if you don't actually sort... Anyway, we don't really know where the confusion lies. Perhaps the description is misleading, or I'm just confused, or Bart's idea of brute force is not the same as my idea of brute force, or perhaps he really is a super-genius who has casually relegated C to the dust bin of historic languages... -- Steven From PointedEars at web.de Sun Mar 29 06:41:26 2015 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Sun, 29 Mar 2015 12:41:26 +0200 Subject: A simple single line, triple-quoted comment is giving syntax error. Why? References: <3533816.ZYnZ2OzjCs@PointedEars.de> <3971951.908YQu3oQO@PointedEars.de> <1504323.jUKfeKbQsP@PointedEars.de> <2362875.FIK8ImHTJA@PointedEars.de> <1823599.Pr2V0MPR6q@PointedEars.de> <9781856.5cutuNVPEq@PointedEars.de> Message-ID: <3894022.plrvF2nHWu@PointedEars.de> Ian Kelly wrote: > [?] Thomas 'PointedEars' Lahn [?] wrote: >> Ian Kelly wrote: >>> [?] Thomas 'PointedEars' Lahn [?] wrote: >>>> Ian Kelly wrote: >>>>> What I mean is that if you construct a parse tree of "foo" "bar" using >>>>> that grammar, it looks like this: >>>>> >>>>> expr >>>>> | >>>>> STRING+ >>>>> / \ >>>>> STRING STRING >>>>> [?] >>>>> >>>>> There is only one expr node, and it contains both STRING tokens. >>>> Prove it. >>> >>> I'm not going to expend the effort that would be required to go >>> through the entire Python grammar step-by-step and exhaustively prove >>> that "foo" "bar" can unambiguously only be produced as a single expr. >> >> And why should you? That is not what you claimed. > > Of course it is. I claimed that there was only one expr node in the > parse tree of "foo" "bar". Which is something else. > That would require two things: [?] What I asked you would require only a real-life representation of the parse tree above. >>> If you believe otherwise, show a parse tree that parses these as >>> separate expressions. >> Fallacies: Straw man, shifting the burden of proof. > > If there is a straw man here, it is only the result of one or both of > us failing to communicate. I agree. > If so, then why did you ask me to prove it? See above. > Why should the burden of proof be on me in the first place? Because *you* made the claim that ?STRING+? could be part of an AST in this way. > In any case, it sounds to me like we're probably in agreement at this > point. I do not think so. > Within a grammar, the question of "is an X a Y" is nonsensical in > isolation. It can only be answered in relation to a parse tree. > Consider the simple grammar: > > S -> A | B > A -> x > B -> x > > Is x an A? It depends. No, by the definition 2 below, that we all accepted implicitly up to this point, x is *definitely* an A. > If the tree that generates the x produces it from an A node, then yes. > Otherwise, no. Fallacy. First, two definitions, so that we are clear what we are talking about: (1) Let a *production chain* be the repeated application of the production rules of a formal grammar such that C ? D ? x is a production chain if there are production rules C ? D D ? x. [Note the difference between ??? and ???.] (2) Let the statement ?x is an A? be true if x can be produced in a production chain starting with or including the non-terminal A left-hand side ? x ? A ? ?A (? ? A ? ? ? x). Now, according to these definitions, in the offered grammar x is *both* an A and a B. Because what matters is _not_ the practical result of production chains (the actual parse tree), but the certainty of the theoretical possibility of it. However, in the interest of disambiguity in their parsers, programming languages do not have such a set of production rules in their grammar that lead to ambiguous productions. In particular, you will not find in the Python grammar another production rule that leads to ?STRING? being producable by a production chain not containing ?expr?. So, if we accept these definitions, we can and have to extend the classification of STRING( literals) to say that they are ?atom?s, ?arith(metic)_expr?(ession)s (as strange as that may sound), and so on, ?expr?(ession)s, ?comparison?s and so on (as strange as that may sound), and finally ?st(ate)m(en)t?s (this fact started the whole discussion), and ?single_input?s, and not anything else. > So when I write that the "foo" in "foo" "bar" is not an expression, I > am only speaking in relation to the parse tree that generates "foo" > "bar". But it has been indicated by others that the parse tree that you presented is wrong, based on a misconception about the syntax of the formal grammar, and you have not yet substantiated your claim that it is correct. > I am not speaking about the parse tree that generates only > "foo", because it is irrelevant, even though in that context it would > be an expression. Same fallacy as above. > I don't know what you mean by a "backdoor". Appending a statement that is contradictory to what was stated just before, or at least ambiguous, so that the possibility arises for one to say ?I did not mean that? when that/a contradiction to the former statement is pointed out later. > The purpose of that parenthetical was to explicitly acknowledge that the > single STRING could be viewed as an expression when taken out of context, Yes, your fallacy is mainly based on ignoring the context. Context is important; you cannot just ignore it and still make correct arguments. > and to disclaim that I was excluding that case from the preceding > statement. I still stand by that statement; The "foo" in "foo" "bar" is > not an expression in the same sense that the "42" is not an expression in > "hucr,.@#%c|42ptqc$". False analogy. The ?42? in there cannot be produced by ?expr? *in that context* (it can only be produced by ?STRING?). >> Actually, you were arguing against my statement that string literals are >> expressions (that a string literal is an expression). You claimed, >> rather explicitly, that they were not. See above. > > I have no idea what point you're trying to convey here. Is the ?See above? not enough a reference? >>> I'm quite familiar with basic concepts of EBNF. >> But apparently not logic. > > Are you intentionally trying to be inflammatory? I am merely stating my observations. There is no offense where none is taken. > I think that I have misunderstood your writing in places and that you have > likewise misunderstood mine in others. Can we leave it at that? No, because misunderstandings need to be clarified and fallacies need to be exposed if we are to arrive at the truth. -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From rosuav at gmail.com Sun Mar 29 06:54:04 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 29 Mar 2015 21:54:04 +1100 Subject: Sudoku solver In-Reply-To: <5517d590$0$12982$c3e8da3$5496439d@news.astraweb.com> References: <87r3sdnw5t.fsf@elektro.pacujo.net> <4e81bdb9-52db-46e6-b449-d4241cb2a3f2@googlegroups.com> <87twx8amww.fsf@elektro.pacujo.net> <82e7c5b9-2f0f-405b-859c-b74916c475e0@googlegroups.com> <55176c2c$0$13009$c3e8da3$5496439d@news.astraweb.com> <5517d590$0$12982$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Mar 29, 2015 at 9:35 PM, Steven D'Aprano wrote: > Anyway, we don't really know where the confusion lies. Perhaps the > description is misleading, or I'm just confused, or Bart's idea of brute > force is not the same as my idea of brute force, or perhaps he really is a > super-genius who has casually relegated C to the dust bin of historic > languages... Ah, I see what you mean. I tend to describe an algorithm as "brute force" even if it has a few simplifications and early cut-offs. A brute-force primality test, for instance, might divide the target number by every counting number since 1, looking for a remainder; does it cease to be brute-force if you check only 2 and odd numbers? only those up to its square root? Either of those tiny optimizations will give a dramatic speed improvement, without representing a flaw; and I would still consider them brute force. The purest form is a barbarian trying to lift a gate; the slightly-optimized is a wizard trying to lift the same gate; but neither algorithm is using a Knock spell to open it by magic. And if you've seen "The Gamers", you'll know that brute force is as fickle as a roll of the dice..... Point is, "brute force" isn't a pure absolute from which there can be no variation. ChrisA From anudeepsm at gmail.com Sun Mar 29 07:20:09 2015 From: anudeepsm at gmail.com (bobbdeep) Date: Sun, 29 Mar 2015 04:20:09 -0700 (PDT) Subject: TCP sockets python timeout public IP adresss In-Reply-To: References: Message-ID: <98896311-5b4c-4242-a7ec-080cbe2462dd@googlegroups.com> On Sunday, March 29, 2015 at 3:44:43 PM UTC+5:30, mm0fmf wrote: > On 29/03/2015 09:57, bobbydeep wrote: > > From the error (10060) it looks like Windows but it would be nice if > you could say which Python and OS you were using. > > I haven't looked at your code but just taking at face value that it does > work internally. > > > server_address = ('my-server-ipadress', 1999) > > Next thing to check is whether you have permission to open arbitrary > ports on the server and whether they are firewalled off. For example, I > have a shell account on the server that hosts my webpages and I can run > ftp / scp to move files across the internet. However, I cannot open say > port 54321 to the internet and accept connections on it. I am using windows 8 and python 2.7.7. I did an nmap to my server to identify the list of open ports on my server. I found out that only three ports are open. How do I add a port to the list of open ports on my server ? server version: Linux hostname 3.13.0-48-generic #80-Ubuntu SMP Thu Mar 12 11:16:15 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux From bc at freeuk.com Sun Mar 29 07:25:20 2015 From: bc at freeuk.com (BartC) Date: Sun, 29 Mar 2015 12:25:20 +0100 Subject: Sudoku solver In-Reply-To: <55176c2c$0$13009$c3e8da3$5496439d@news.astraweb.com> References: <87r3sdnw5t.fsf@elektro.pacujo.net> <4e81bdb9-52db-46e6-b449-d4241cb2a3f2@googlegroups.com> <87twx8amww.fsf@elektro.pacujo.net> <82e7c5b9-2f0f-405b-859c-b74916c475e0@googlegroups.com> <55176c2c$0$13009$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 29/03/2015 04:06, Steven D'Aprano wrote: > On Sun, 29 Mar 2015 10:50 am, BartC wrote: >> But using X *and* my own brute-force algorithm, the same puzzle took 2 >> seconds to solve - faster than C! > But, when you tell me that your very own personal interpreted language, > which I assume nobody else has worked on, is 40% faster than optimized C, > my first reaction is to expect that you've probably made a mistake > somewhere. I would have the same reaction if somebody casually dropped into > a conversation that they happened to beat Usain Bolt's 100m personal best > of 9.58 seconds by almost four seconds. While carrying a 20kg backpack. As Chris mentioned, when I say 'faster than C', I mean X running my algorithm was faster then C running Marko's algoritim (on Ian's data). This was just an illustration of algorithm being more important than language. (As it happens, C using gcc was particularly good at this benchmark. Looking only at optimised code, Clang took 4.5 seconds, while a trio of lesser C compilers took from 14 to 22 seconds. This is why I also showed the unoptimised figure, which indicates what raw native code could do, without taking account of the super-optimisations that gcc is capable of applying. Because after all such optimisations could also be applied to the Python code, such as unrolling those nested loops in good(). And theoretically, a clever enough C compiler could have solved it in 0 seconds since I'd hard-coded the board values within the source! See: http://pastebin.com/RZE67TLy ) -- Bartc From ahlusar.ahluwalia at gmail.com Sun Mar 29 07:26:46 2015 From: ahlusar.ahluwalia at gmail.com (Saran Ahluwalia) Date: Sun, 29 Mar 2015 04:26:46 -0700 (PDT) Subject: Second Pair of eyes for Correctly writing out XML from DataFrame (Pandas)? Message-ID: <575b458c-6022-4adf-8cd6-3a66f750dbb0@googlegroups.com> I would appreciate feedback on whether I correctly exported my DataFrame and wrote into XML. I used the ElementTree library. My DataFrame has 11 rows and 8 columns (excluding the index column) For your convenience here it is: #My schema assumption: # #[ #Some number row #Sample text #] # document = ET.Element("list") def make_message(document, row): msg = ET.SubElement(document, "message") for field in row.index: field_element = ET.SubElement(msg, field) field_element.text = row[field] return msg def add_to_document(row): return make_message(document, row) #df.apply(add_to_document, axis=0) ---> if I were to import a Dataframe stored in the variable #"df", I would simply APPLY the add_to_document function and COMBINE this into a document ET.dump(document) Thank you, in advance for your help. From ahlusar.ahluwalia at gmail.com Sun Mar 29 07:32:48 2015 From: ahlusar.ahluwalia at gmail.com (Saran Ahluwalia) Date: Sun, 29 Mar 2015 04:32:48 -0700 (PDT) Subject: Strategy/ Advice for How to Best Attack this Problem? Message-ID: Below are the function's requirements. I am torn between using the OS module or some other quick and dirty module. In addition, my ideal assumption that this could be cross-platform. "Records" refers to contents in a file. What are some suggestions from the Pythonistas? * Monitors a folder for files that are dropped throughout the day * When a file is dropped in the folder the program should scan the file o IF all the records in the file have the same length o THEN the file should be moved to a "success" folder and a text file written indicating the total number of records processed o IF the file is empty OR the records are not all of the same length o THEN the file should be moved to a "failure" folder and a text file written indicating the cause for failure (for example: Empty file or line 100 was not the same length as the rest). From ahlusar.ahluwalia at gmail.com Sun Mar 29 07:37:05 2015 From: ahlusar.ahluwalia at gmail.com (Saran Ahluwalia) Date: Sun, 29 Mar 2015 04:37:05 -0700 (PDT) Subject: Addendum to Strategy/ Advice for How to Best Attack this Problem? In-Reply-To: References: Message-ID: On Sunday, March 29, 2015 at 7:33:04 AM UTC-4, Saran Ahluwalia wrote: > Below are the function's requirements. I am torn between using the OS module or some other quick and dirty module. In addition, my ideal assumption that this could be cross-platform. "Records" refers to contents in a file. What are some suggestions from the Pythonistas? > > * Monitors a folder for files that are dropped throughout the day > > * When a file is dropped in the folder the program should scan the file > > o IF all the records in the file have the same length > > o THEN the file should be moved to a "success" folder and a text file written indicating the total number of records processed > > o IF the file is empty OR the records are not all of the same length > > o THEN the file should be moved to a "failure" folder and a text file written indicating the cause for failure (for example: Empty file or line 100 was not the same length as the rest). Below are some functions that I have been playing around with. I am not sure how to create a functional program from each of these constituent parts. I could use decorators or simply pass a function within another function. [code] import time import fnmatch import os import shutil #If you want to write to a file, and if it doesn't exist, do this: if not os.path.exists(filepath): f = open(filepath, 'w') #If you want to read a file, and if it exists, do the following: try: f = open(filepath) except IOError: print 'I will be moving this to the ' #Changing a directory to "/home/newdir" os.chdir("/home/newdir") def move(src, dest): shutil.move(src, dest) def fileinfo(file): filename = os.path.basename(file) rootdir = os.path.dirname(file) lastmod = time.ctime(os.path.getmtime(file)) creation = time.ctime(os.path.getctime(file)) filesize = os.path.getsize(file) print "%s**\t%s\t%s\t%s\t%s" % (rootdir, filename, lastmod, creation, filesize) searchdir = r'D:\Your\Directory\Root' matches = [] def search for root, dirnames, filenames in os.walk(searchdir): ## for filename in fnmatch.filter(filenames, '*.c'): for filename in filenames: ## matches.append(os.path.join(root, filename)) ##print matches fileinfo(os.path.join(root, filename)) def get_files(src_dir): # traverse root directory, and list directories as dirs and files as files for root, dirs, files in os.walk(src_dir): path = root.split('/') for file in files: process(os.path.join(root, file)) os.remove(os.path.join(root, file)) def del_dirs(src_dir): for dirpath, _, _ in os.walk(src_dir, topdown=False): # Listing the files if dirpath == src_dir: break try: os.rmdir(dirpath) except OSError as ex: print(ex) def main(): get_files(src_dir) del_dirs(src_dir) if __name__ == "__main__": main() [/code] From thorsten at thorstenkampe.de Sun Mar 29 07:39:52 2015 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Sun, 29 Mar 2015 13:39:52 +0200 Subject: Run two processes in parallel References: Message-ID: * Ian Kelly (Sun, 29 Mar 2015 03:13:31 -0600) > > On Sun, Mar 29, 2015 at 2:11 AM, Thorsten Kampe > wrote: > > > > I'd like to run two processes concurrently (either through a builtin > > module or a third-party). One is a "background" task and the other is > > displaying a spinner (for which I already found good packages). > > [...] > > It shouldn't be all that complicated: > > import time, multiprocessing, spinner > process1 = multiprocessing.Process(target=time.sleep, args=(60,)) > process1.start() > [...] Thanks, I missed the example in the long documentation for multiprocessing. From Python 3.2 there is also `concurrent.futures` which does the same thing - but also allows you to use a thread. Thorsten From steve+comp.lang.python at pearwood.info Sun Mar 29 07:59:04 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 29 Mar 2015 22:59:04 +1100 Subject: Python 2/3 versus Perl 5/6 References: <55168340$0$12999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5517e909$0$13001$c3e8da3$5496439d@news.astraweb.com> On Sun, 29 Mar 2015 06:36 am, Mario Figueiredo wrote: > On Sat, 28 Mar 2015 21:32:31 +1100, Steven D'Aprano > wrote: > >>The famous Perl coder Allison Randal writes about why Perl is not dead >>(it's just pining for the fjords *wink* ) and contrasts the Perl 5/6 split >>to Python 2/3: > > A shame Allison doesn't frequent these groups. I would have a few > questions for her. > > Perl 6 is in fact a bit like Python 3. Perl 6 is an attempt to > recreate the language, addressing (by throwing away or heavily > changing) all the things that gave an indication the language would > stiffle and die and bring in new ideas to address the demands of > modern software design and implementation... > > But that's not the thing that confuses me most about Allison's post. > The whole conversation about Rakudo not being Perl was. > > Perl 6 is Perl. It is part of the Perl family. "Perl family" is not the same as Perl. The Perl documentation is clear that they consider Perl 6 to be not just a mere new version, but a completely different language: http://perldoc.perl.org/perlfaq1.html#What-is-Perl-6%3f My understanding is that Perl 6 is related to Perl 5 in a similar way to (say) Pascal to Algol, Objective-C to C, or Scheme to Lisp. > And Perl 6 has been > developed exclusively as a language specification. Which means it is > not a language implementation. Rakudo is one such implementation, for > the JVM, of the language specification known as Perl 6. Therefore > Rakudo is Perl 6, which means Rakudo is also Perl. > > I mean, we can all agree Jython is Python. Maybe not CPython, but > Python. Maybe not pythonic in all its body, but Python. Rakudo is no > different. The Perl core developers think it is. I have no reason to disagree with them. That's exactly the point that Allison Randal is making: Perl 6 has split with the Perl community, despite Larry Wall's interest in it. That's not the case with Python 3. Although take-up of Python 3 has been slow, it has also been steady, and it is still the same language. > It's a shame(?) it is gaining no traction (and I think > Alisson optimism is either misplaced of whishful thinking). But Rakudo > is a reminder to everyone about the design principles and motivations > behind Perl 6. For good or bad, because no other implementation of > Perl 6 exists yet that can produce working code, which after all this > years can only mean that Perl 6 is in deep trouble. I don't know about that. Is Perl 6 in danger of running out of developers? Could you wipe out the entire Perl 6 development team with one out of control bus? I don't think so. A language like Cobra is, I think, maintained by one person. Frink is even worse: not only is it maintained by a single person, but it isn't even open source, so if he is hit by a bus, Frink dies. (Which is terribly sad, because Frink is amazing.) What is the minimum number of users that a language needs to survive long term? Ten? Ten million? Somewhere in between? If you define "not in the TIOBE top 10" as "in deep trouble", then sure, Perl 6 is in deep trouble. But I think languages can survive for decades or longer in small and not-so-small niches, and continue to be influential long after the language has ceased to be maintained. There are still people using PL/I and APL and Tcl/Tk, even if they aren't being used for new major projects. -- Steven From bc at freeuk.com Sun Mar 29 08:01:58 2015 From: bc at freeuk.com (BartC) Date: Sun, 29 Mar 2015 13:01:58 +0100 Subject: Sudoku solver In-Reply-To: <5517d590$0$12982$c3e8da3$5496439d@news.astraweb.com> References: <87r3sdnw5t.fsf@elektro.pacujo.net> <4e81bdb9-52db-46e6-b449-d4241cb2a3f2@googlegroups.com> <87twx8amww.fsf@elektro.pacujo.net> <82e7c5b9-2f0f-405b-859c-b74916c475e0@googlegroups.com> <55176c2c$0$13009$c3e8da3$5496439d@news.astraweb.com> <5517d590$0$12982$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 29/03/2015 11:35, Steven D'Aprano wrote: > That's why I can't help but feel that, *given the description we've seen*, > perhaps Bart's brute force code doesn't actually solve the problem, and > that's why it is so fast. I'm reminded of the recent thread where somebody > claimed to have a significant speed-up over Timsort by using a binary > search instead of linear search. Tim Peters investigated, and noticed that > the code wasn't actually sorting. It's easy to beat the performance of any > sort algorithm if you don't actually sort... > > Anyway, we don't really know where the confusion lies. Perhaps the > description is misleading, or I'm just confused, or Bart's idea of brute > force is not the same as my idea of brute force, or perhaps he really is a > super-genius who has casually relegated C to the dust bin of historic > languages... My solver definitely works, as the solutions produced by the two algorithms are identical. I'm not clever enough to produce a properly analytical solver, but perhaps it is not quite as brute force as the Python one. I've looked at my code and I don't really understand it (it's from a long time ago), and it would take quite a while to convert it to Python and post it. (Most of it seems to be preoccupied with multiple ways of indexing the board or grid.) (If it's of any interest, this non-Python code is here: http://pastebin.com/5cXd2Pef ) -- Bartc From __peter__ at web.de Sun Mar 29 08:33:05 2015 From: __peter__ at web.de (Peter Otten) Date: Sun, 29 Mar 2015 14:33:05 +0200 Subject: Addendum to Strategy/ Advice for How to Best Attack this Problem? References: Message-ID: Saran Ahluwalia wrote: > On Sunday, March 29, 2015 at 7:33:04 AM UTC-4, Saran Ahluwalia wrote: >> Below are the function's requirements. I am torn between using the OS >> module or some other quick and dirty module. In addition, my ideal >> assumption that this could be cross-platform. "Records" refers to >> contents in a file. What are some suggestions from the Pythonistas? >> >> * Monitors a folder for files that are dropped throughout the day >> >> * When a file is dropped in the folder the program should scan the file >> >> o IF all the records in the file have the same length >> >> o THEN the file should be moved to a "success" folder and a text file >> written indicating the total number of records processed >> >> o IF the file is empty OR the records are not all of the same length >> >> o THEN the file should be moved to a "failure" folder and a text file >> written indicating the cause for failure (for example: Empty file or line >> 100 was not the same length as the rest). > > Below are some functions that I have been playing around with. I am not > sure how to create a functional program from each of these constituent > parts. I could use decorators or simply pass a function within another > function. Throwing arbitrary code at a task in the hope that something sticks is not a good approach. You already have given a clear description of the problem, so start with that and try to "pythonize" it. Example: def main(): while True: files_to_check = get_files_in_monitored_folder() for file in files_to_check: if is_good(file): move_to_success_folder(file) else: move_to_failure_folder(file) wait_a_minute() if __name__ == "__main__": main() Then write bogus implementations for the building blocks: def get_files_in_monitored_folder(): return ["/foo/bar/ham", "/foo/bar/spam"] def is_good(file): return file.endswith("/ham") def move_to_failure_folder(file): print("failure", file) def move_to_success_folder(file): print("success", file) def wait_a_minute(): raise SystemExit("bye") # we don't want to enter the loop while developing Now successively replace the dummy function with functions that do the right thing. Test them individually (preferrably using unit tests) so that when you have completed them all and your program does not work like it should you can be sure that there is a flaw in the main function. > [code] > import time > import fnmatch > import os > import shutil > > > #If you want to write to a file, and if it doesn't exist, do this: Hm, are these your personal notes or is it an actual script? > if not os.path.exists(filepath): > f = open(filepath, 'w') > #If you want to read a file, and if it exists, do the following: > > try: > f = open(filepath) > except IOError: > print 'I will be moving this to the ' > > > #Changing a directory to "/home/newdir" > os.chdir("/home/newdir") Never using os.chdir() is a good habit to get into. > def move(src, dest): > shutil.move(src, dest) > > def fileinfo(file): > filename = os.path.basename(file) > rootdir = os.path.dirname(file) > lastmod = time.ctime(os.path.getmtime(file)) > creation = time.ctime(os.path.getctime(file)) > filesize = os.path.getsize(file) > > print "%s**\t%s\t%s\t%s\t%s" % (rootdir, filename, lastmod, creation, > filesize) > > searchdir = r'D:\Your\Directory\Root' > matches = [] > > def search Everytime you post code that doesn't even compile you lose some goodwill. In a few lines of code meant to demonstrate a problem a typo may be acceptable, but for something that you probably composed in an editor you should take the time to run it and fix at least the syntax errors. > for root, dirnames, filenames in os.walk(searchdir): > ## for filename in fnmatch.filter(filenames, '*.c'): > for filename in filenames: > ## matches.append(os.path.join(root, filename)) > ##print matches > fileinfo(os.path.join(root, filename)) > > > def get_files(src_dir): > # traverse root directory, and list directories as dirs and files as files > for root, dirs, files in os.walk(src_dir): > path = root.split('/') > for file in files: > process(os.path.join(root, file)) > os.remove(os.path.join(root, file)) > > def del_dirs(src_dir): > for dirpath, _, _ in os.walk(src_dir, topdown=False): # Listing the > files > if dirpath == src_dir: > break > try: > os.rmdir(dirpath) > except OSError as ex: > print(ex) > > > def main(): > get_files(src_dir) > del_dirs(src_dir) > > > if __name__ == "__main__": > main() > > > [/code] From ahlusar.ahluwalia at gmail.com Sun Mar 29 08:41:12 2015 From: ahlusar.ahluwalia at gmail.com (Saran A) Date: Sun, 29 Mar 2015 05:41:12 -0700 (PDT) Subject: Addendum to Strategy/ Advice for How to Best Attack this Problem? In-Reply-To: References: Message-ID: <03e661d2-db49-4d2b-8524-3f5b3a07d1b8@googlegroups.com> Thank you for the feedback - I have only been programming for 8 months now and am fairly new to best practice and what is considered acceptable in public forums. I appreciate the feedback on how to best address this problem. On Sunday, March 29, 2015 at 8:33:43 AM UTC-4, Peter Otten wrote: > Saran Ahluwalia wrote: > > > On Sunday, March 29, 2015 at 7:33:04 AM UTC-4, Saran Ahluwalia wrote: > >> Below are the function's requirements. I am torn between using the OS > >> module or some other quick and dirty module. In addition, my ideal > >> assumption that this could be cross-platform. "Records" refers to > >> contents in a file. What are some suggestions from the Pythonistas? > >> > >> * Monitors a folder for files that are dropped throughout the day > >> > >> * When a file is dropped in the folder the program should scan the file > >> > >> o IF all the records in the file have the same length > >> > >> o THEN the file should be moved to a "success" folder and a text file > >> written indicating the total number of records processed > >> > >> o IF the file is empty OR the records are not all of the same length > >> > >> o THEN the file should be moved to a "failure" folder and a text file > >> written indicating the cause for failure (for example: Empty file or line > >> 100 was not the same length as the rest). > > > > Below are some functions that I have been playing around with. I am not > > sure how to create a functional program from each of these constituent > > parts. I could use decorators or simply pass a function within another > > function. > > Throwing arbitrary code at a task in the hope that something sticks is not a > good approach. You already have given a clear description of the problem, so > start with that and try to "pythonize" it. Example: > > def main(): > while True: > files_to_check = get_files_in_monitored_folder() > for file in files_to_check: > if is_good(file): > move_to_success_folder(file) > else: > move_to_failure_folder(file) > wait_a_minute() > > if __name__ == "__main__": > main() > > Then write bogus implementations for the building blocks: > > def get_files_in_monitored_folder(): > return ["/foo/bar/ham", "/foo/bar/spam"] > > def is_good(file): > return file.endswith("/ham") > > def move_to_failure_folder(file): > print("failure", file) > > def move_to_success_folder(file): > print("success", file) > > def wait_a_minute(): > raise SystemExit("bye") # we don't want to enter the loop while > developing > > Now successively replace the dummy function with functions that do the right > thing. Test them individually (preferrably using unit tests) so that when > you have completed them all and your program does not work like it should > you can be sure that there is a flaw in the main function. > > > [code] > > import time > > import fnmatch > > import os > > import shutil > > > > > > #If you want to write to a file, and if it doesn't exist, do this: > > Hm, are these your personal notes or is it an actual script? > > > if not os.path.exists(filepath): > > f = open(filepath, 'w') > > #If you want to read a file, and if it exists, do the following: > > > > try: > > f = open(filepath) > > except IOError: > > print 'I will be moving this to the ' > > > > > > #Changing a directory to "/home/newdir" > > os.chdir("/home/newdir") > > Never using os.chdir() is a good habit to get into. > > > def move(src, dest): > > shutil.move(src, dest) > > > > def fileinfo(file): > > filename = os.path.basename(file) > > rootdir = os.path.dirname(file) > > lastmod = time.ctime(os.path.getmtime(file)) > > creation = time.ctime(os.path.getctime(file)) > > filesize = os.path.getsize(file) > > > > print "%s**\t%s\t%s\t%s\t%s" % (rootdir, filename, lastmod, creation, > > filesize) > > > > searchdir = r'D:\Your\Directory\Root' > > matches = [] > > > > def search > > Everytime you post code that doesn't even compile you lose some goodwill. > In a few lines of code meant to demonstrate a problem a typo may be > acceptable, but for something that you probably composed in an editor you > should take the time to run it and fix at least the syntax errors. > > > for root, dirnames, filenames in os.walk(searchdir): > > ## for filename in fnmatch.filter(filenames, '*.c'): > > for filename in filenames: > > ## matches.append(os.path.join(root, filename)) > > ##print matches > > fileinfo(os.path.join(root, filename)) > > > > > > def get_files(src_dir): > > # traverse root directory, and list directories as dirs and files as files > > for root, dirs, files in os.walk(src_dir): > > path = root.split('/') > > for file in files: > > process(os.path.join(root, file)) > > os.remove(os.path.join(root, file)) > > > > def del_dirs(src_dir): > > for dirpath, _, _ in os.walk(src_dir, topdown=False): # Listing the > > files > > if dirpath == src_dir: > > break > > try: > > os.rmdir(dirpath) > > except OSError as ex: > > print(ex) > > > > > > def main(): > > get_files(src_dir) > > del_dirs(src_dir) > > > > > > if __name__ == "__main__": > > main() > > > > > > [/code] From davea at davea.name Sun Mar 29 09:27:33 2015 From: davea at davea.name (Dave Angel) Date: Sun, 29 Mar 2015 09:27:33 -0400 Subject: Addendum to Strategy/ Advice for How to Best Attack this Problem? In-Reply-To: References: Message-ID: <5517FDC5.6030402@davea.name> On 03/29/2015 07:37 AM, Saran Ahluwalia wrote: > On Sunday, March 29, 2015 at 7:33:04 AM UTC-4, Saran Ahluwalia wrote: >> Below are the function's requirements. I am torn between using the OS module or some other quick and dirty module. In addition, my ideal assumption that this could be cross-platform. "Records" refers to contents in a file. What are some suggestions from the Pythonistas? >> >> * Monitors a folder for files that are dropped throughout the day >> >> * When a file is dropped in the folder the program should scan the file >> >> o IF all the records in the file have the same length >> >> o THEN the file should be moved to a "success" folder and a text file written indicating the total number of records processed >> >> o IF the file is empty OR the records are not all of the same length >> >> o THEN the file should be moved to a "failure" folder and a text file written indicating the cause for failure (for example: Empty file or line 100 was not the same length as the rest). > > Below are some functions that I have been playing around with. I am not sure how to create a functional program from each of these constituent parts. I could use decorators or simply pass a function within another function. Your problem isn't complicated enough to either need function objects or decorators. You might want to write a generator function, but even that seems overkill for the problem as stated. Just write the code, top-down, with dummy bodies containing stub code. Then fill it in from bottom up, with unit tests for each completed function. More complex problems can justify a different approach, but you don't need to use every trick in the arsenal. > > [code] > import time > import fnmatch > import os > import shutil > If you have code fragments that aren't going to be used, don't write them as top-level code. Either move them to another file, or at least enclose them in a function with a name like dummy_do_not_use() My own convention for that is to suffix the function name with a bunch of uppercase ZZZ's That way the name jumps out at me so I'll recognize it, and I can be sure I'll never actually call it. > > #If you want to write to a file, and if it doesn't exist, do this: > > if not os.path.exists(filepath): > f = open(filepath, 'w') > > #If you want to read a file, and if it exists, do the following: > > try: > f = open(filepath) > except IOError: > print 'I will be moving this to the ' > > > #Changing a directory to "/home/newdir" > os.chdir("/home/newdir") As Peter said, chdir can be very troublesome. Avoid at almost all costs. As you've done elsewhere, use os.path.join() to combine directory paths with relative filenames. > > def move(src, dest): > shutil.move(src, dest) > > def fileinfo(file): > filename = os.path.basename(file) > rootdir = os.path.dirname(file) > lastmod = time.ctime(os.path.getmtime(file)) > creation = time.ctime(os.path.getctime(file)) > filesize = os.path.getsize(file) > > print "%s**\t%s\t%s\t%s\t%s" % (rootdir, filename, lastmod, creation, filesize) > > searchdir = r'D:\Your\Directory\Root' > matches = [] > > def search > for root, dirnames, filenames in os.walk(searchdir): Why are you using a directory tree when your "spec" said the files would be in a specific directory? > ## for filename in fnmatch.filter(filenames, '*.c'): > for filename in filenames: > ## matches.append(os.path.join(root, filename)) > ##print matches > fileinfo(os.path.join(root, filename)) > > > def get_files(src_dir): > # traverse root directory, and list directories as dirs and files as files > for root, dirs, files in os.walk(src_dir): > path = root.split('/') > for file in files: > process(os.path.join(root, file)) > os.remove(os.path.join(root, file)) Probably you shouldn't have os.remove in the code till the stuff around it has been carefully tested. Besides, nothing in the spec says you're going to remove any files. > > def del_dirs(src_dir): > for dirpath, _, _ in os.walk(src_dir, topdown=False): # Listing the files > if dirpath == src_dir: > break > try: > os.rmdir(dirpath) > except OSError as ex: > print(ex) > > > def main(): > get_files(src_dir) > del_dirs(src_dir) > Your description says "monitor". That implies to me an ongoing process, or a loop. You probably want something like: def main(): while True: process_files(directory_name) sleep(10000) > > if __name__ == "__main__": > main() > > > [/code] > -- DaveA From bc at freeuk.com Sun Mar 29 11:23:19 2015 From: bc at freeuk.com (BartC) Date: Sun, 29 Mar 2015 16:23:19 +0100 Subject: Sudoku solver In-Reply-To: References: <87r3sdnw5t.fsf@elektro.pacujo.net> <4e81bdb9-52db-46e6-b449-d4241cb2a3f2@googlegroups.com> <87twx8amww.fsf@elektro.pacujo.net> <82e7c5b9-2f0f-405b-859c-b74916c475e0@googlegroups.com> <55176c2c$0$13009$c3e8da3$5496439d@news.astraweb.com> <5517d590$0$12982$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 29/03/2015 13:01, BartC wrote: > On 29/03/2015 11:35, Steven D'Aprano wrote: >> Anyway, we don't really know where the confusion lies. Perhaps the >> description is misleading, or I'm just confused, or Bart's idea of brute >> force is not the same as my idea of brute force, or perhaps he really >> is a >> super-genius who has casually relegated C to the dust bin of historic >> languages... > > My solver definitely works, as the solutions produced by the two > algorithms are identical. > > I'm not clever enough to produce a properly analytical solver, but > perhaps it is not quite as brute force as the Python one. > > I've looked at my code and I don't really understand it (it's from a > long time ago), and it would take quite a while to convert it to Python > and post it. (Most of it seems to be preoccupied with multiple ways of > indexing the board or grid.) > > (If it's of any interest, this non-Python code is here: > > http://pastebin.com/5cXd2Pef ) I've managed to create a Python version of my 'brute force' sudoku solver: http://pastebin.com/CKmHmBKm It was hard going as I don't normally write Python. But it worked practically first time, after building it bottom-up and then putting the solvepuzzle() routine in place. The data for the 'hard' puzzle is hard-coded into it, so you just run it. Python 3.1 (normal CPython) took 13 or 14 seconds to solve (previously 1700 seconds with the OP's code). PyPy took 1.3 seconds (previously 93 seconds). (Annoyingly, faster than the 1.7 seconds of my language...) (The original code in my language that I posted has been simplified - which also made it faster, and the Python code was based on that version. The Pastebin code has been updated.) I won't bother to test a C version of this, as it's a bit more awkward to translate (making use of strings and deep copies of arrays). -- Bartc From torriem at gmail.com Sun Mar 29 11:54:59 2015 From: torriem at gmail.com (Michael Torrie) Date: Sun, 29 Mar 2015 09:54:59 -0600 Subject: PiCxx In-Reply-To: References: <2E1837FF-9A40-40E6-BB27-FB57BA9D8E9C@gmail.com> Message-ID: <55182053.1070803@gmail.com> On 03/29/2015 04:20 AM, Robert Kern wrote: > On 2015-03-25 15:45, ? wrote: >> Hello Python people, >> >> I've made a C++ wrapper for Python. >> I've called it PiCxx and put it up here: https://github.com/p-i-/PiCxx > > Please consider using a recognized open source license. Your project looks > interesting, but I won't touch it with the current license. > > http://opensource.org/licenses I definitely would not consider sending a pull request with a license like that. Furthermore, a proper source-code license protects your ability to make money on commercial use of your code in the future, depending on what license you choose. And you can license your code under multiple licenses if you choose. And as long as you own the copyright exclusively, you can change or add licenses at any time. Looks like you have contributions from one other person, so you'll need to get his permission to relicense, or else remove his commit. Most developers seem to think of source code licensing as an afterthought (some don't list any license at all on github, so technically everyone who clones their repo is violating copyright). It need not be complicated or hard, but deserves a bit of thought. And, as I said, if you own the exclusive copyright you can change up the license at will. But start somewhere. From dotancohen at gmail.com Sun Mar 29 12:13:20 2015 From: dotancohen at gmail.com (Dotan Cohen) Date: Sun, 29 Mar 2015 19:13:20 +0300 Subject: PiCxx In-Reply-To: References: <2E1837FF-9A40-40E6-BB27-FB57BA9D8E9C@gmail.com> Message-ID: On Sun, Mar 29, 2015 at 1:20 PM, Robert Kern wrote: > Please consider using a recognized open source license. Your project looks > interesting, but I won't touch it with the current license. > > http://opensource.org/licenses > I agree about the licensing. Many devs won't even evaluate the code for technical merits with an unestablished, unclear, and unfamiliar license like that. The "donate anything" concept is a cute idea, but put the idea in either an informal request if you BSD license the code, or as a condition for a commercial license if you GPL the code. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com From marko at pacujo.net Sun Mar 29 14:03:01 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 29 Mar 2015 21:03:01 +0300 Subject: Sudoku solver References: <87r3sdnw5t.fsf@elektro.pacujo.net> <4e81bdb9-52db-46e6-b449-d4241cb2a3f2@googlegroups.com> <87twx8amww.fsf@elektro.pacujo.net> <82e7c5b9-2f0f-405b-859c-b74916c475e0@googlegroups.com> <55176c2c$0$13009$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87619j7kbu.fsf@elektro.pacujo.net> BartC : > As Chris mentioned, when I say 'faster than C', I mean X running my > algorithm was faster then C running Marko's algoritim (on Ian's data). > This was just an illustration of algorithm being more important than > language. Be careful with the benchmark comparisons. Ian's example can be solved with the identical algorithm in eight different ways (four corners, left or right). I ran the example with my recent Python solver and got these times in the eight cases: 884 s 2.5 s 13 s 499 s 5.9 s 128 s 1360 s 36 s (That suggests a slight modification to the original strategy: solve it in each of the eight ways "in parallel" and the worst case should be significantly alleviated.) I'm actually fascinated by the Python modifications that were conceptually insignificant but dramatically speeded up the execution (7880 seconds to 884 seconds). That's something I'll have to keep in mind in the future. Marko From breamoreboy at yahoo.co.uk Sun Mar 29 14:26:26 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 29 Mar 2015 19:26:26 +0100 Subject: Sudoku solver In-Reply-To: <87619j7kbu.fsf@elektro.pacujo.net> References: <87r3sdnw5t.fsf@elektro.pacujo.net> <4e81bdb9-52db-46e6-b449-d4241cb2a3f2@googlegroups.com> <87twx8amww.fsf@elektro.pacujo.net> <82e7c5b9-2f0f-405b-859c-b74916c475e0@googlegroups.com> <55176c2c$0$13009$c3e8da3$5496439d@news.astraweb.com> <87619j7kbu.fsf@elektro.pacujo.net> Message-ID: On 29/03/2015 19:03, Marko Rauhamaa wrote: > BartC : > >> As Chris mentioned, when I say 'faster than C', I mean X running my >> algorithm was faster then C running Marko's algoritim (on Ian's data). >> This was just an illustration of algorithm being more important than >> language. > > Be careful with the benchmark comparisons. Ian's example can be solved > with the identical algorithm in eight different ways (four corners, left > or right). I ran the example with my recent Python solver and got these > times in the eight cases: > > 884 s > 2.5 s > 13 s > 499 s > 5.9 s > 128 s > 1360 s > 36 s > > (That suggests a slight modification to the original strategy: solve it > in each of the eight ways "in parallel" and the worst case should be > significantly alleviated.) > > I'm actually fascinated by the Python modifications that were > conceptually insignificant but dramatically speeded up the execution > (7880 seconds to 884 seconds). That's something I'll have to keep in > mind in the future. > > > Marko > One thing I have come to rely on over the years is never, ever trust your gut instincts about Python performance, you're almost inevitably wrong. When I first came across the Norvig solver I made a change, purely for fun, to replace two calls to len() with a single call and save the result. The run time to solve each puzzle dropped by around 5%. I believe this meets your "conceptually insignificant". -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From marko at pacujo.net Sun Mar 29 14:33:33 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 29 Mar 2015 21:33:33 +0300 Subject: Sudoku solver References: <87r3sdnw5t.fsf@elektro.pacujo.net> <4e81bdb9-52db-46e6-b449-d4241cb2a3f2@googlegroups.com> <87twx8amww.fsf@elektro.pacujo.net> <82e7c5b9-2f0f-405b-859c-b74916c475e0@googlegroups.com> <55176c2c$0$13009$c3e8da3$5496439d@news.astraweb.com> <87619j7kbu.fsf@elektro.pacujo.net> Message-ID: <87zj6v64ci.fsf@elektro.pacujo.net> Mark Lawrence : > One thing I have come to rely on over the years is never, ever trust > your gut instincts about Python performance, you're almost inevitably > wrong. When I first came across the Norvig solver I made a change, > purely for fun, to replace two calls to len() with a single call and > save the result. The run time to solve each puzzle dropped by around > 5%. I believe this meets your "conceptually insignificant". Yes. It's kinda sad when you have to resort to such low-brow optimizations. Mostly you don't have to, though. You mainly want to keep the expression elegant. Marko From nagle at animats.com Sun Mar 29 14:57:54 2015 From: nagle at animats.com (John Nagle) Date: Sun, 29 Mar 2015 11:57:54 -0700 Subject: Python 3 lack of support for fcgi/wsgi. Message-ID: The Python 2 module "fcgi" is gone in Python 3. The Python 3 documentation at https://docs.python.org/3/howto/webservers.html recommends "flup" and links here: https://pypi.python.org/pypi/flup/1.0 That hasn't been updated since 2007, and the SVN repository linked there is gone. The recommended version is abandoned. pip3 tries to install version 1.0.2, from 2009. That's here: https://pypi.python.org/pypi/flup/1.0.2 That version is supported only for Python 2.5 and 2.6. There's a later version on Github: https://github.com/Pyha/flup-py3.3 But that's not what "pip3" is installing. I get the feeling, again, that nobody actually uses this stuff. "pip3" seems perfectly happy to install modules that don't work with Python 3. Try "pip3 install dnspython", for example. You need "dnspython3", but pip3 doesn't know that. There's "wsgiref", which looks more promising, but has a different interface. That's not what the Python documentation recommends as the first choice, but it's a standard module. I keep thinking I'm almost done with Python 3 hell, but then I get screwed by Python 3 again. John Nagle From aberg010 at my.hennepintech.edu Sun Mar 29 15:06:59 2015 From: aberg010 at my.hennepintech.edu (Andrew Berg) Date: Sun, 29 Mar 2015 14:06:59 -0500 Subject: Python 3 lack of support for fcgi/wsgi. In-Reply-To: References: Message-ID: <55184D53.8050902@my.hennepintech.edu> On 2015.03.29 13:57, John Nagle wrote: > There's "wsgiref", which looks more promising, but has a different > interface. That's not what the Python documentation recommends as > the first choice, but it's a standard module. Oh? > These days, FastCGI is never used directly. Just like mod_python, it is only used for the deployment of WSGI applications. > ... > The Web Server Gateway Interface, or WSGI for short, is defined in PEP 333 and is currently the best way to do Python web programming. It seems to me that FastCGI isn't well supported in the Python world because WSGI is by far the recommended choice. From ben+python at benfinney.id.au Sun Mar 29 15:11:22 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 30 Mar 2015 06:11:22 +1100 Subject: Python 3 lack of support for fcgi/wsgi. References: Message-ID: <85twx34o11.fsf@benfinney.id.au> John Nagle writes: > The Python 3 documentation at > https://docs.python.org/3/howto/webservers.html > > recommends "flup" I disagree. In a section where it describes FastCGI, it presents a tiny example as a way to test the packages installed. The example happens to use ?flup?. That's quite different from a recommendation. > I get the feeling, again, that nobody actually uses this stuff. > [?] > I keep thinking I'm almost done with Python 3 hell, but then I > get screwed by Python 3 again. You have found yet another poorly-maintained package which is not at all the responsibility of Python 3. Why are you discussing it as though Python 3 is at fault? What do you expect to change *about Python 3* that would address the perceived problem? Whose responsibility is it to do that? -- \ ?Oh, I love your magazine. My favorite section is ?How To | `\ Increase Your Word Power?. That thing is really, really, | _o__) really... good.? ?Homer, _The Simpsons_ | Ben Finney From marko at pacujo.net Sun Mar 29 15:42:25 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 29 Mar 2015 22:42:25 +0300 Subject: Python 3 lack of support for fcgi/wsgi. References: Message-ID: <87vbhj615q.fsf@elektro.pacujo.net> John Nagle : > There's "wsgiref", which looks more promising, but has a different > interface. That's not what the Python documentation recommends as the > first choice, but it's a standard module. > > I keep thinking I'm almost done with Python 3 hell, but then I get > screwed by Python 3 again. I sympathize but Python 3 is the victim here, wsgi is the culprit. Some years ago I had to write wsgi client code. I found it easiest to write the XML messages by hand and have a tiny Python script ("lather") supply the SOAP envelope handle the message interchange. I found the support libraries didn't really add any value on top of raw XML (in my case, anyway). Marko From none at mailinator.com Sun Mar 29 16:01:24 2015 From: none at mailinator.com (mm0fmf) Date: Sun, 29 Mar 2015 21:01:24 +0100 Subject: TCP sockets python timeout public IP adresss In-Reply-To: <98896311-5b4c-4242-a7ec-080cbe2462dd@googlegroups.com> References: <98896311-5b4c-4242-a7ec-080cbe2462dd@googlegroups.com> Message-ID: On 29/03/2015 12:20, bobbdeep wrote: > How do I add a port to the list of open ports on my server ? Ask the system administrator. From bc at freeuk.com Sun Mar 29 16:59:21 2015 From: bc at freeuk.com (BartC) Date: Sun, 29 Mar 2015 21:59:21 +0100 Subject: Sudoku solver In-Reply-To: References: <87r3sdnw5t.fsf@elektro.pacujo.net> <4e81bdb9-52db-46e6-b449-d4241cb2a3f2@googlegroups.com> <87twx8amww.fsf@elektro.pacujo.net> <82e7c5b9-2f0f-405b-859c-b74916c475e0@googlegroups.com> Message-ID: On 29/03/2015 00:12, Chris Angelico wrote: > On Sun, Mar 29, 2015 at 10:50 AM, BartC wrote: >> Using the OP's algorithm, and testing with the 'hard' puzzle posted by Ian >> Kelly, I got these approximate results: >> >> Python 3.1: 1700 seconds (normal Python interpreter) >> PyPy: 93 seconds >> C unoptimised: 17 seconds (gcc -O0 32-bit) >> C optimised: 3.3 seconds (gcc -O3 32-bit) >> (X: 170 seconds) > > Nice stats. Any chance you can add CPython 3.4 or 3.5 to that? That's > a pretty old CPython you're using. I've tried 3.4.3 and it's nearer 1900 seconds! Which wasn't too surprising as you don't expect new releases to be faster, they tend to be slower. -- Bartc From bc at freeuk.com Sun Mar 29 17:11:45 2015 From: bc at freeuk.com (BartC) Date: Sun, 29 Mar 2015 22:11:45 +0100 Subject: Sudoku solver In-Reply-To: <87619j7kbu.fsf@elektro.pacujo.net> References: <87r3sdnw5t.fsf@elektro.pacujo.net> <4e81bdb9-52db-46e6-b449-d4241cb2a3f2@googlegroups.com> <87twx8amww.fsf@elektro.pacujo.net> <82e7c5b9-2f0f-405b-859c-b74916c475e0@googlegroups.com> <55176c2c$0$13009$c3e8da3$5496439d@news.astraweb.com> <87619j7kbu.fsf@elektro.pacujo.net> Message-ID: On 29/03/2015 19:03, Marko Rauhamaa wrote: > BartC : > >> As Chris mentioned, when I say 'faster than C', I mean X running my >> algorithm was faster then C running Marko's algoritim (on Ian's data). >> This was just an illustration of algorithm being more important than >> language. > > Be careful with the benchmark comparisons. Ian's example can be solved > with the identical algorithm in eight different ways (four corners, left > or right). I ran the example with my recent Python solver and got these > times in the eight cases: > > 884 s > 2.5 s > 13 s > 499 s > 5.9 s > 128 s > 1360 s > 36 s > > (That suggests a slight modification to the original strategy: solve it > in each of the eight ways "in parallel" and the worst case should be > significantly alleviated.) Well, in this case all the benchmarks ran the same algorithm on the same data, which makes them a better test of the implementations than of the algorithm. I've mentioned a (possibly) significantly faster algorithm which I believe to be still brute-force (now in Python here: http://pastebin.com/CKmHmBKm). But I realise it could just be luck in approaching the solution from a literally different angle and encountering the answer sooner. (I think both stop as soon as they find any valid solution.) What I've done is try it on 3 rotations as well as the original (+90, +180, +270 degrees, but haven't bothered with flips and reflections). While the original took 13 seconds (using my algorithm in Python), the rotations took 18, 49 and 87 seconds respectively. Since the original time in PyPy took 90-odd seconds, I was about to acknowledge that mine might not be that much faster after all. Then I realised I was using Python 3.1 not PyPy! Python 3.1 took 28 minutes on original hard puzzle using your code, and 13-87 seconds with mine. So I think this other algorithm is still much faster. I've no idea why, especially since it messes about concatenating strings and converting them to and from integers. -- Bartc From breamoreboy at yahoo.co.uk Sun Mar 29 17:19:56 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 29 Mar 2015 22:19:56 +0100 Subject: Sudoku solver In-Reply-To: References: <87r3sdnw5t.fsf@elektro.pacujo.net> <4e81bdb9-52db-46e6-b449-d4241cb2a3f2@googlegroups.com> <87twx8amww.fsf@elektro.pacujo.net> <82e7c5b9-2f0f-405b-859c-b74916c475e0@googlegroups.com> Message-ID: On 29/03/2015 21:59, BartC wrote: > On 29/03/2015 00:12, Chris Angelico wrote: >> On Sun, Mar 29, 2015 at 10:50 AM, BartC wrote: >>> Using the OP's algorithm, and testing with the 'hard' puzzle posted >>> by Ian >>> Kelly, I got these approximate results: >>> >>> Python 3.1: 1700 seconds (normal Python interpreter) >>> PyPy: 93 seconds >>> C unoptimised: 17 seconds (gcc -O0 32-bit) >>> C optimised: 3.3 seconds (gcc -O3 32-bit) >>> (X: 170 seconds) >> >> Nice stats. Any chance you can add CPython 3.4 or 3.5 to that? That's >> a pretty old CPython you're using. > > I've tried 3.4.3 and it's nearer 1900 seconds! > > Which wasn't too surprising as you don't expect new releases to be > faster, they tend to be slower. > I simply do not believe those figures, that's roughly 12% slower. If that happened in the real world you'd be able to hear the screams of anguish around the world. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Sun Mar 29 17:21:11 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 29 Mar 2015 22:21:11 +0100 Subject: Sudoku solver In-Reply-To: References: <87r3sdnw5t.fsf@elektro.pacujo.net> <4e81bdb9-52db-46e6-b449-d4241cb2a3f2@googlegroups.com> <87twx8amww.fsf@elektro.pacujo.net> <82e7c5b9-2f0f-405b-859c-b74916c475e0@googlegroups.com> Message-ID: On 28/03/2015 23:50, BartC wrote: > On 28/03/2015 03:39, Sayth wrote: >> Good test for pypy to see where it's speed sits between C and Python. > > I've spent the last hour or so doing such tests. > > Using the OP's algorithm, and testing with the 'hard' puzzle posted by > Ian Kelly, I got these approximate results: > > Python 3.1: 1700 seconds (normal Python interpreter) > PyPy: 93 seconds > C unoptimised: 17 seconds (gcc -O0 32-bit) > C optimised: 3.3 seconds (gcc -O3 32-bit) > (X: 170 seconds) > > All running on Windows on x64. > > (X is my own interpreted language, which is where my interest in this > is. This had been generally faster than Python until PyPy came along. It > does however use a pure byte-code interpreter, so the result is not too > bad. > > But using X *and* my own brute-force algorithm, the same puzzle took 2 > seconds to solve - faster than C! > > However it doesn't matter that the OP's algorithm is not great, as it > makes an interesting new benchmark.) > https://attractivechaos.wordpress.com/2011/06/19/an-incomplete-review-of-sudoku-solver-implementations/ -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Sun Mar 29 17:30:49 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 29 Mar 2015 22:30:49 +0100 Subject: cgi parse_qs still exists? Message-ID: This has been marked for deprecation since at least 2.6 but is still in the 3.5 code base. Does anybody know if this is by accident or design? If the former I'll happily raise an issue to get it removed unless somebody beats me to it. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From steve+comp.lang.python at pearwood.info Sun Mar 29 17:40:28 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 30 Mar 2015 08:40:28 +1100 Subject: Python 3 lack of support for fcgi/wsgi. References: Message-ID: <5518714d$0$12985$c3e8da3$5496439d@news.astraweb.com> On Mon, 30 Mar 2015 05:57 am, John Nagle wrote: > https://pypi.python.org/pypi/flup/1.0 > > That hasn't been updated since 2007, and the SVN repository linked there > is gone. The recommended version is abandoned. Welcome to the Internet. Links die and documentation gets outdated. If only things stayed like the Good Old Days when documentation was always 100% accurate and up to date, before Python 3 ruined it for everybody! -- Steven From bc at freeuk.com Sun Mar 29 17:59:47 2015 From: bc at freeuk.com (BartC) Date: Sun, 29 Mar 2015 22:59:47 +0100 Subject: Sudoku solver In-Reply-To: References: <87r3sdnw5t.fsf@elektro.pacujo.net> <4e81bdb9-52db-46e6-b449-d4241cb2a3f2@googlegroups.com> <87twx8amww.fsf@elektro.pacujo.net> <82e7c5b9-2f0f-405b-859c-b74916c475e0@googlegroups.com> Message-ID: On 29/03/2015 22:19, Mark Lawrence wrote: > On 29/03/2015 21:59, BartC wrote: >> On 29/03/2015 00:12, Chris Angelico wrote: >>> On Sun, Mar 29, 2015 at 10:50 AM, BartC wrote: >>>> Using the OP's algorithm, and testing with the 'hard' puzzle posted >>>> by Ian >>>> Kelly, I got these approximate results: >>>> >>>> Python 3.1: 1700 seconds (normal Python interpreter) >>>> PyPy: 93 seconds >>>> C unoptimised: 17 seconds (gcc -O0 32-bit) >>>> C optimised: 3.3 seconds (gcc -O3 32-bit) >>>> (X: 170 seconds) >>> >>> Nice stats. Any chance you can add CPython 3.4 or 3.5 to that? That's >>> a pretty old CPython you're using. >> >> I've tried 3.4.3 and it's nearer 1900 seconds! >> >> Which wasn't too surprising as you don't expect new releases to be >> faster, they tend to be slower. > I simply do not believe those figures, that's roughly 12% slower. If > that happened in the real world you'd be able to hear the screams of > anguish around the world. You're right, it's wasn't 12% slower. It was 16%! I didn't have time to run this very long benchmark so ran a different algorithm using 3.1, averaging 14.1 seconds for 3 runs. And ran the same code with 3.4.3, average 16.4 seconds. Maybe most people don't run intensively computational benchmarks like these. -- Bartc From breamoreboy at yahoo.co.uk Sun Mar 29 18:04:35 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 29 Mar 2015 23:04:35 +0100 Subject: Python 3 lack of support for fcgi/wsgi. In-Reply-To: <5518714d$0$12985$c3e8da3$5496439d@news.astraweb.com> References: <5518714d$0$12985$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 29/03/2015 22:40, Steven D'Aprano wrote: > On Mon, 30 Mar 2015 05:57 am, John Nagle wrote: > >> https://pypi.python.org/pypi/flup/1.0 >> >> That hasn't been updated since 2007, and the SVN repository linked there >> is gone. The recommended version is abandoned. > > Welcome to the Internet. Links die and documentation gets outdated. If only > things stayed like the Good Old Days when documentation was always 100% > accurate and up to date, before Python 3 ruined it for everybody! > I have to agree, Python 3 has caused no end of problems, with documentation being no exception. The issue was made worse by the unicode FSR, which was released in, I think, 3.3. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From bc at freeuk.com Sun Mar 29 18:17:23 2015 From: bc at freeuk.com (BartC) Date: Sun, 29 Mar 2015 23:17:23 +0100 Subject: Sudoku solver In-Reply-To: References: <87r3sdnw5t.fsf@elektro.pacujo.net> <4e81bdb9-52db-46e6-b449-d4241cb2a3f2@googlegroups.com> <87twx8amww.fsf@elektro.pacujo.net> <82e7c5b9-2f0f-405b-859c-b74916c475e0@googlegroups.com> Message-ID: On 29/03/2015 22:21, Mark Lawrence wrote: > On 28/03/2015 23:50, BartC wrote: >> On 28/03/2015 03:39, Sayth wrote: >>> Good test for pypy to see where it's speed sits between C and Python. >> Python 3.1: 1700 seconds (normal Python interpreter) >> PyPy: 93 seconds >> C unoptimised: 17 seconds (gcc -O0 32-bit) >> C optimised: 3.3 seconds (gcc -O3 32-bit) > https://attractivechaos.wordpress.com/2011/06/19/an-incomplete-review-of-sudoku-solver-implementations/ "The fastest Sudoku solver can solve even the hardest Sudoku in about 1 millisecond and solve most others in 0.1 millisecond." Blimey, we might as well pack up and go home then! Actually I didn't realise people took these things so seriously. I came into the thread when I thought it was being suggested that brute-force approaches to this problem were not viable. I think to be useful, it needs to work in a reasonable amount of time, and a few seconds would be more than reasonable; it doesn't need to be 100 microseconds. Unless somehow somebody's got millions of the things to get through. But I guess people aren't interested in actually solving the daily sudoku in the paper** (that would be very dull); maybe there is more sport in finding a faster machine solution than anyone else. (I'm more interested now in getting my own dynamic language to compete with PyPy, and in getting own static language to compete with C/gcc, as the timing for this benchmark was pretty bad.) (** Although I did come across a prize 16x16 sudoku in the paper a few years back. I adapted my code to 16x16 in 10 minutes or so, which took a further couple of minutes to solve the given puzzle, and sent it in. But I didn't win...) -- Bartc From cs at zip.com.au Sun Mar 29 18:35:20 2015 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 30 Mar 2015 09:35:20 +1100 Subject: Supply condition in function call In-Reply-To: <55167b09$0$13013$c3e8da3$5496439d@news.astraweb.com> References: <55167b09$0$13013$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20150329223520.GA60529@cskk.homeip.net> On 28Mar2015 20:57, Steven D'Aprano wrote: >On Sat, 28 Mar 2015 08:19 pm, Ian Kelly wrote: >> I've never been a fan of the primary selection style anyway. Copying >> text is conceptually an action. Selecting text is how one indicates >> the target of an action; conceptually it is not an action itself and >> shouldn't cause an action to be performed. It leads to muddled >> processes like "highlight this text, paste it there, highlight that >> text, delete it, paste in the replacement text from before -- oops, I >> accidentally pasted back in the text that I just deleted instead." > >Everything you say is absolutely correct. And yet middle-click paste is so >convenient when it works that I all but cry from frustration when I find an >application that doesn't support it. In xterm and I think several other X11 terminals, Shift-Insert pastes. I found that _way_ more convenient than middle click. The mouse is not your friend. Cheers, Cameron Simpson Unix is user-friendly. It's just picky about who its friends are. From nagle at animats.com Sun Mar 29 18:37:06 2015 From: nagle at animats.com (John Nagle) Date: Sun, 29 Mar 2015 15:37:06 -0700 Subject: Python 3 lack of support for fcgi/wsgi. In-Reply-To: <55185E5D.5080604@animats.com> References: <55185E5D.5080604@animats.com> Message-ID: On 3/29/2015 1:19 PM, John Nagle wrote: > On 3/29/2015 12:11 PM, Ben Finney wrote: >> John Nagle writes: >> >>> The Python 3 documentation at >>> https://docs.python.org/3/howto/webservers.html >>> >>> recommends "flup" >> >> I disagree. In a section where it describes FastCGI, it presents a tiny >> example as a way to test the packages installed. The example happens to >> use ?flup?. >> >> That's quite different from a recommendation. >> >>> I get the feeling, again, that nobody actually uses this stuff. > > So do others. See "http://www.slideshare.net/mitsuhiko/wsgi-on-python-3" > > "A talk about the current state of WSGI on Python 3. Warning: > depressing. But it does not have to stay that way" > > "wsgiref on Python 3 is just broken." > > "Python 3 that is supposed to make unicode easier is causing a lot more > problems than unicode environments on Python 2" > > "The Python 3 stdlib is currently incredible broken but because there > are so few users, these bugs stay under the radar." > > That was written in 2010. Most of that stuff is still broken. > Here's his detailed critique: > > http://lucumr.pocoo.org/2010/5/25/wsgi-on-python-3/ > >> You have found yet another poorly-maintained package which is not at all >> the responsibility of Python 3. >> Why are you discussing it as though Python 3 is at fault? > > That's a denial problem. Uncritical fanboys are part of the problem, > not part of the solution. > > Practical problems: the version of "flup" on PyPi is so out of date > as to be useless. The original author abandoned the software. There > are at least six forks of "flup" on Github: > > https://github.com/Pyha/flup-py3.3 > https://github.com/Janno/flup-py3.3 > https://github.com/pquentin/flup-py3 > https://github.com/SmartReceipt/flup-server > https://github.com/dnephin/TreeOrg/tree/master/app-root/flup > https://github.com/noxan/flup > > The first three look reasonably promising; the last three look > abandoned. But why are there so many, and what are the > differences between the first three? Probably nobody > was able to fix all the Python 3 related problems documented by > Ronacher in 2010. None of the versions have much usage. Nobody > thought their version was good enough to push it to Pypi. > > All those people had to struggle to try to get a basic capability for > web development using Python to work. To use WSGI with Python 3, you > need to do a lot of work. Or stay with Python 2. > > Python 3 still isn't ready for prime time. > > John Nagle > From manuel.graune at koeln.de Sun Mar 29 18:46:37 2015 From: manuel.graune at koeln.de (Manuel Graune) Date: Mon, 30 Mar 2015 00:46:37 +0200 Subject: Supply condition in function call References: <55167b09$0$13013$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87iodjifqq.fsf@uriel.graune.org> Cameron Simpson writes: > > In xterm and I think several other X11 terminals, Shift-Insert > pastes. I found that _way_ more convenient than middle click. The > mouse is not your friend. > This information might prove as useful as your answer to my original question. ;-) Thanks for both! -- A hundred men did the rational thing. The sum of those rational choices was called panic. Neal Stephenson -- System of the world http://www.graune.org/GnuPG_pubkey.asc Key fingerprint = 1E44 9CBD DEE4 9E07 5E0A 5828 5476 7E92 2DB4 3C99 From ben+python at benfinney.id.au Sun Mar 29 18:58:03 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 30 Mar 2015 09:58:03 +1100 Subject: Python 3 lack of support for fcgi/wsgi. References: <55185E5D.5080604@animats.com> Message-ID: <85pp7r4dj8.fsf@benfinney.id.au> John Nagle writes: (for some reason quoting himself extensively without further comment) > On 3/29/2015 1:19 PM, John Nagle wrote: > > On 3/29/2015 12:11 PM, Ben Finney wrote: > >> John Nagle writes: > >>> The Python 3 documentation at > >>> https://docs.python.org/3/howto/webservers.html > >>> > >>> recommends "flup" > >> > >> I disagree. In a section where it describes FastCGI, it presents a tiny > >> example as a way to test the packages installed. The example happens to > >> use ?flup?. > >> > >> That's quite different from a recommendation. You don't respond to that. So I take it that you won't be claiming any more that the documentation ?recommends? use of ?flup?? > >> You have found yet another poorly-maintained package which is not > >> at all the responsibility of Python 3. > >> Why are you discussing it as though Python 3 is at fault? > > > > That's a denial problem. Uncritical fanboys are part of the > > problem, not part of the solution. To be critical entails rejecting an assertion presented without supporting evidence. You have provided none for your assertion that an unmaintained third-party library is somehow a special failure of Python 3. You removed relevant critical questions without responding to them. Let me continue to ask these critical questions, in hope of getting a pertinent response this time: Why are you discussing it as though Python 3 is at fault? What do you expect to change *about Python 3* that would address the perceived problem? Whose responsibility is it to do that? In the absence of good answers to those questions, the proper critical response would be to dismiss your unsupported claims. -- \ ?Guaranteed to work throughout its useful life.? ?packaging for | `\ clockwork toy, Hong Kong | _o__) | Ben Finney From mr.smittye at gmail.com Sun Mar 29 19:39:49 2015 From: mr.smittye at gmail.com (mr.smittye at gmail.com) Date: Sun, 29 Mar 2015 16:39:49 -0700 (PDT) Subject: Sudoku solver In-Reply-To: <87r3sdnw5t.fsf@elektro.pacujo.net> References: <87r3sdnw5t.fsf@elektro.pacujo.net> Message-ID: On Wednesday, March 25, 2015 at 4:39:40 AM UTC-7, Marko Rauhamaa wrote: > A lot of discussion was generated by the good, old fibonacci sequence. I > have yet to find practical use for fibonacci numbers. However, the > technique behind a sudoku solver come up every now and again in > practical situations. > > I post below a sudoku solver. I eagerly await neater implementations (as > well as bug reports). > > Usage: > ======================================================================== > ./sudoku.py ======================================================================== > > sudoku.dat: > ======================================================================== > 7 . . . . . 6 . . > . 2 . 8 . 6 . 7 . > . . . 4 3 . . 9 . > 5 1 . . . . 4 . 3 > . . 9 . . . . 1 . > . . . . 4 2 . . 5 > . . . 9 . . . . 8 > . . 6 . . . . 5 . > . . . . . . . 6 . > ======================================================================== > > output: > ======================================================================== > 7 8 4 2 9 5 6 3 1 > 9 2 3 8 1 6 5 7 4 > 6 5 1 4 3 7 8 9 2 > 5 1 8 6 7 9 4 2 3 > 2 4 9 3 5 8 7 1 6 > 3 6 7 1 4 2 9 8 5 > 1 7 5 9 6 3 2 4 8 > 8 3 6 7 2 4 1 5 9 > 4 9 2 5 8 1 3 6 7 > > ======================================================================== > > sudoku.py: > ======================================================================== > #!/usr/bin/env python3 > > import sys > > M = 3 > N = M * M > Q = N * N > > candidates = list(range(1, N + 1)) > > def main(): > board = [] > for n in sys.stdin.read().split(): > try: > board.append(int(n)) > except ValueError: > board.append(None) > solve(board) > > def solve(board, slot=0): > if slot == Q: > report(board) > elif board[slot] is None: > for candidate in candidates: > if good(board, slot, candidate): > board[slot] = candidate > solve(board, slot + 1) > board[slot] = None > else: > solve(board, slot + 1) > > def good(board, slot, candidate): > (shelf, row), (stack, col) = (divmod(x, M) for x in divmod(slot, N)) > for i in range(M): > for j in range(M): > if candidate in (board[(i * M + j) * N + stack * M + col], > board[(shelf * M + row) * N + i * M + j], > board[(shelf * M + i) * N + stack * M + j]): > return False > return True > > def report(board): > print("\n".join( > " ".join(str(board[row * N + col]) > for col in range(N)) > for row in range(N))) > print() > > if __name__ == '__main__': > main() > ======================================================================== > > > Marko You say "neater implementation" I'll send you to the code-golf site: http://codegolf.stackexchange.com/a/446/38632 this is brute force. There are some really good implementations in other languages that arent brute force. From jon+usenet at unequivocal.co.uk Sun Mar 29 20:56:55 2015 From: jon+usenet at unequivocal.co.uk (Jon Ribbens) Date: Mon, 30 Mar 2015 00:56:55 +0000 (UTC) Subject: Python 3 lack of support for fcgi/wsgi. References: Message-ID: On 2015-03-29, John Nagle wrote: > The Python 2 module "fcgi" is gone in Python 3. > The Python 3 documentation at > > https://docs.python.org/3/howto/webservers.html > > recommends "flup" and links here: > > https://pypi.python.org/pypi/flup/1.0 > > That hasn't been updated since 2007, and the SVN repository linked there > is gone. The recommended version is abandoned. pip3 > tries to install version 1.0.2, from 2009. That's here: > https://pypi.python.org/pypi/flup/1.0.2 That version is supported > only for Python 2.5 and 2.6. jonpy supports fastcgi and wsgi. I'm not sure if it supports Python 3 but I'm prepared to check and make it so, if anyone wants me to. From no.email at nospam.invalid Sun Mar 29 21:03:15 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 29 Mar 2015 18:03:15 -0700 Subject: Python 3 lack of support for fcgi/wsgi. References: <55185E5D.5080604@animats.com> Message-ID: <87ego7s3e4.fsf@jester.gateway.pace.com> Ben Finney writes: > Why are you discussing it as though Python 3 is at fault? What do you > expect to change *about Python 3* that would address the perceived > problem? Whose responsibility is it to do that? Those questions seem unfair to me. Nagle posted an experience report about a real-world project to migrate a Python 2 codebase to Python 3. He reported hitting more snags than some of us might expect purely from the Python 3 propaganda ("oh, just run the 2to3 utility and it does everything for you"). The report presented info worth considering for anyone thinking of doing a 2-to-3 migration of their own, or maybe even choosing between 2 and 3 for a new project. I find reports like that to be valuable whether or not they suggest fixes for the snags. Meanwhile here's a very well informed post about headaches with Python 3's treatment of Unicode. I had always thought Python 3's main benefit was to fix the headaches of Python 2's somewhat accidental treatment of Unicode. But it looks like Python 3 introduces its own Unicode headaches. http://lucumr.pocoo.org/2014/5/12/everything-about-unicode/ From no.email at nospam.invalid Sun Mar 29 21:08:49 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 29 Mar 2015 18:08:49 -0700 Subject: Strategy/ Advice for How to Best Attack this Problem? References: Message-ID: <87a8yvs34u.fsf@jester.gateway.pace.com> Saran Ahluwalia writes: > cross-platform... > * Monitors a folder for files that are dropped throughout the day I don't see a cross-platform way to do that other than by waking up and scanning the folder every so often (once a minute, say). The Linux way is with inotify and there's a Python module for it (search terms: python inotify). There might be comparable but non-identical interfaces for other platforms. From ben+python at benfinney.id.au Sun Mar 29 21:22:39 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 30 Mar 2015 12:22:39 +1100 Subject: Python 3 lack of support for fcgi/wsgi. References: <55185E5D.5080604@animats.com> <87ego7s3e4.fsf@jester.gateway.pace.com> Message-ID: <85lhif46u8.fsf@benfinney.id.au> Paul Rubin writes: > Ben Finney writes: > > Why are you discussing it as though Python 3 is at fault? What do you > > expect to change *about Python 3* that would address the perceived > > problem? Whose responsibility is it to do that? > > Those questions seem unfair to me. Nagle posted an experience report > about a real-world project to migrate a Python 2 codebase to Python 3. He presented it explicitly in support of the claim that he is ?screwed by Python 3?: I keep thinking I'm almost done with Python 3 hell, but then I get screwed by Python 3 again. The story, though, gives no support that this is specially Python 3's fault. I am asking questions to get John Nagle to explain how Python 3 in particular has caused this problem. > He reported hitting more snags than some of us might expect purely > from the Python 3 propaganda ("oh, just run the 2to3 utility and it > does everything for you"). Propaganda? Are you referring to the official guidelines for migrating from Python 2 to Python 3? The official guide at doesn't support that assertion. The ?2to3? program is presented as a tool to assist. I don't know of anything official saying ?it does everything for you?. Even when it was first introduced it was only ever presented as a *start* to the porting effort. Or are you referring, by ?propaganda?, to some unofficial line that contradicts the official statements of the Python developers? If someone follows unofficial advice directly contradicting the advice explicitly given in the Python 3 porting guide, and then feels they ?get screwed by? following that advice, that sounds more like uncritical flailing. > The report presented info worth considering for anyone thinking of > doing a 2-to-3 migration of their own, or maybe even choosing between > 2 and 3 for a new project. I find reports like that to be valuable > whether or not they suggest fixes for the snags. I agree. It points to the need for improvement in areas where third-party libraries are still lacking. Which doesn't address the assertion that this is somehow a special responsibility of ?Python 3?, which I asked critical questions about. Can we expect those claims, still unsupported, to cease? -- \ ?Facts are meaningless. You could use facts to prove anything | `\ that's even remotely true!? ?Homer, _The Simpsons_ | _o__) | Ben Finney From Seymore4Head at Hotmail.invalid Sun Mar 29 21:40:41 2015 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Sun, 29 Mar 2015 21:40:41 -0400 Subject: Sudoku solver References: <87r3sdnw5t.fsf@elektro.pacujo.net> <4e81bdb9-52db-46e6-b449-d4241cb2a3f2@googlegroups.com> <87twx8amww.fsf@elektro.pacujo.net> <82e7c5b9-2f0f-405b-859c-b74916c475e0@googlegroups.com> Message-ID: <4aahhalj5vd1vnpl1aamh6ri943qnutt3v@4ax.com> On Sun, 29 Mar 2015 23:17:23 +0100, BartC wrote: >On 29/03/2015 22:21, Mark Lawrence wrote: >> On 28/03/2015 23:50, BartC wrote: >>> On 28/03/2015 03:39, Sayth wrote: >>>> Good test for pypy to see where it's speed sits between C and Python. > >>> Python 3.1: 1700 seconds (normal Python interpreter) >>> PyPy: 93 seconds >>> C unoptimised: 17 seconds (gcc -O0 32-bit) >>> C optimised: 3.3 seconds (gcc -O3 32-bit) > >> https://attractivechaos.wordpress.com/2011/06/19/an-incomplete-review-of-sudoku-solver-implementations/ > >"The fastest Sudoku solver can solve even the hardest Sudoku in about 1 >millisecond and solve most others in 0.1 millisecond." > >Blimey, we might as well pack up and go home then! > >Actually I didn't realise people took these things so seriously. I came >into the thread when I thought it was being suggested that brute-force >approaches to this problem were not viable. > >I think to be useful, it needs to work in a reasonable amount of time, >and a few seconds would be more than reasonable; it doesn't need to be >100 microseconds. Unless somehow somebody's got millions of the things >to get through. > >But I guess people aren't interested in actually solving the daily >sudoku in the paper** (that would be very dull); maybe there is more >sport in finding a faster machine solution than anyone else. > The technical term for that is "a pissing contest" >(I'm more interested now in getting my own dynamic language to compete >with PyPy, and in getting own static language to compete with C/gcc, as >the timing for this benchmark was pretty bad.) > >(** Although I did come across a prize 16x16 sudoku in the paper a few >years back. I adapted my code to 16x16 in 10 minutes or so, which took a >further couple of minutes to solve the given puzzle, and sent it in. But >I didn't win...) From rosuav at gmail.com Sun Mar 29 22:04:22 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 Mar 2015 13:04:22 +1100 Subject: Strategy/ Advice for How to Best Attack this Problem? In-Reply-To: <87a8yvs34u.fsf@jester.gateway.pace.com> References: <87a8yvs34u.fsf@jester.gateway.pace.com> Message-ID: On Mon, Mar 30, 2015 at 12:08 PM, Paul Rubin wrote: > Saran Ahluwalia writes: >> cross-platform... >> * Monitors a folder for files that are dropped throughout the day > > I don't see a cross-platform way to do that other than by waking up and > scanning the folder every so often (once a minute, say). The Linux way > is with inotify and there's a Python module for it (search terms: python > inotify). There might be comparable but non-identical interfaces for > other platforms. All too often, "cross-platform" means probing for one option, then another, then another, and using whichever one you can. On Windows, there's FindFirstChangeNotification and ReadDirectoryChanges, which Tim Golden wrote about, and which I coded up into a teleporter for getting files out of a VM automatically: http://timgolden.me.uk/python/win32_how_do_i/watch_directory_for_changes.html https://github.com/Rosuav/shed/blob/master/senddir.py ChrisA From nagle at animats.com Sun Mar 29 22:11:24 2015 From: nagle at animats.com (John Nagle) Date: Sun, 29 Mar 2015 19:11:24 -0700 Subject: Python 3 lack of support for fcgi/wsgi. In-Reply-To: <87ego7s3e4.fsf@jester.gateway.pace.com> References: <55185E5D.5080604@animats.com> <87ego7s3e4.fsf@jester.gateway.pace.com> Message-ID: On 3/29/2015 6:03 PM, Paul Rubin wrote: > Those questions seem unfair to me. Nagle posted an experience report > about a real-world project to migrate a Python 2 codebase to Python 3. > He reported hitting more snags than some of us might expect purely from > the Python 3 propaganda ("oh, just run the 2to3 utility and it does > everything for you"). The report presented info worth considering for > anyone thinking of doing a 2-to-3 migration of their own, or maybe even > choosing between 2 and 3 for a new project. I find reports like that to > be valuable whether or not they suggest fixes for the snags. Thanks. Meanwhile, I've found two more variants on "flup" https://pypi.python.org/pypi/flipflop https://pypi.python.org/pypi/flup6 All of these are descended from the original "flup" code base. PyPi also has fcgi-python (Python 2.6, Windows only.) fcgiapp (circa 2005) superfcgi (circa 2009) Those can probably be ignored. One of the "flup" variants may do the job, but since there are so many, and no single version has won out, testing is necessary. "flipflop" looks promising, simply because the author took all the code out that you don't need on a server. CPAN, the Perl module archive, has some curation and testing. PyPi lacks that, which is how we end up with situations like this, where there are 11 ways to do something, most of which don't work. Incidentally, in my last report, I reported problems with BS4, PyMySQL, and Pickle. I now have workarounds for all of those, but not fixes. The bug reports I listed last time contain the workaround code. John Nagle From no.email at nospam.invalid Sun Mar 29 22:16:09 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 29 Mar 2015 19:16:09 -0700 Subject: Python 3 lack of support for fcgi/wsgi. References: <55185E5D.5080604@animats.com> <87ego7s3e4.fsf@jester.gateway.pace.com> Message-ID: <871tk7s00m.fsf@jester.gateway.pace.com> Ben Finney writes: > Which doesn't address the assertion that this is somehow a special > responsibility of ?Python 3?, which I asked critical questions about. "Python 3" in those sorts of contexts refers to the whole ecosystem including the 3rd party libs. I don't know that I'd say that the language or ecosystem is "responsible". It's just there, with its good and bad points, and people who choose to engage with it find themselves engaging with those points further into the weeds than they might have expected. One of the attractions of Python 2 has traditionally been the existence of a solid library codebase to build on. John is telling us that the Python 3 experience still has dark alleys. From ben+python at benfinney.id.au Sun Mar 29 22:28:25 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 30 Mar 2015 13:28:25 +1100 Subject: Python 3 lack of support for fcgi/wsgi. References: <55185E5D.5080604@animats.com> <87ego7s3e4.fsf@jester.gateway.pace.com> Message-ID: <85bnjb43sm.fsf@benfinney.id.au> John Nagle writes: > CPAN, the Perl module archive, has some curation and testing. PyPi > lacks that, which is how we end up with situations like this, where > there are 11 ways to do something, most of which don't work. That is a valid criticism of PyPI, and more broadly of the Python distribution ecosystem. (Uncritical fanatics would deny that, but I'm not one.) You're quite right that Python's third-party library distribution landscape lags behind that for some other platforms. There has been a great deal of progress in recent years, but contrariwise the progress is in fixing a legacy backlog of terrible third-party distribution support. This is true for code targetting Python 2 as much, if not more so, as of code targetting Python 3. So I'll thank you to direct the frustration where it belongs: at the state of distribution support, which is not a special Python 3 problem but is common to all versions of Python. > Incidentally, in my last report, I reported problems with BS4, > PyMySQL, and Pickle. I now have workarounds for all of those, but not > fixes. The bug reports I listed last time contain the workaround code. Thanks for your persistence. It is good to know progress can be made by focussing on problems where they are. -- \ ?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 ben+python at benfinney.id.au Sun Mar 29 22:30:49 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 30 Mar 2015 13:30:49 +1100 Subject: Python 3 lack of support for fcgi/wsgi. References: <55185E5D.5080604@animats.com> <87ego7s3e4.fsf@jester.gateway.pace.com> <871tk7s00m.fsf@jester.gateway.pace.com> Message-ID: <857ftz43om.fsf@benfinney.id.au> Paul Rubin writes: > I don't know that I'd say that the language or ecosystem is > "responsible". Then you're not in a position to defend the claim. I'm addressing my critical inquiry to the person who made the claim that they ?get screwed by Python 3?. -- \ ?Fox News gives you both sides of every story: the President's | `\ side and the Vice President's side.? ?Steven Colbert, 2006-04-29 | _o__) | Ben Finney From no.email at nospam.invalid Sun Mar 29 22:51:18 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 29 Mar 2015 19:51:18 -0700 Subject: Python 3 lack of support for fcgi/wsgi. References: <55185E5D.5080604@animats.com> <87ego7s3e4.fsf@jester.gateway.pace.com> <871tk7s00m.fsf@jester.gateway.pace.com> Message-ID: <87wq1zqjtl.fsf@jester.gateway.pace.com> Ben Finney writes: > Then you're not in a position to defend the claim. I'm addressing my > critical inquiry to the person who made the claim that they ?get screwed > by Python 3?. I'd say that the screw was expecting the migration to be easier than it actually was. This might result from there not being sufficiently revealing info out there. And that shortage might come from too much stifling of dissent from Python 3 dogma by Python 3 proponents and defenders. In that way, the proponents created or fostered unrealistic expectations for users. You asked for concrete suggestions how to fix that. One way is take reports like John's seriously and receive them with thanks, instead of attacking the messenger. From rosuav at gmail.com Sun Mar 29 23:06:53 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 Mar 2015 14:06:53 +1100 Subject: Python 3 lack of support for fcgi/wsgi. In-Reply-To: <87wq1zqjtl.fsf@jester.gateway.pace.com> References: <55185E5D.5080604@animats.com> <87ego7s3e4.fsf@jester.gateway.pace.com> <871tk7s00m.fsf@jester.gateway.pace.com> <87wq1zqjtl.fsf@jester.gateway.pace.com> Message-ID: On Mon, Mar 30, 2015 at 1:51 PM, Paul Rubin wrote: > One way is take reports like John's seriously and receive them > with thanks, instead of attacking the messenger. If a messenger wants to be thanked, he should start by not attacking the recipients. Respect goes both ways. Make your post with a hostile attitude of "Python 3 is the cause of all my problems", and you'll find hostility coming back at you. One of my sisters keeps on doing this to me. Not with Python, but with computers generally. She complains that computers never work properly for her, and she's hostile to *the machine* even before she starts doing anything. Well, no wonder the computer gets angry with you, and refuses to work! Of course, the moment I come along, the computer sits up and takes notice, because he respects my authority (as the network admin for the house, I'm in command of all computers, to at least some extent - and they know that), but she still complains loudly. It does tend to make the assistance somewhat more caustic in delivery. ChrisA From rustompmody at gmail.com Sun Mar 29 23:20:47 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 29 Mar 2015 20:20:47 -0700 (PDT) Subject: Python 3 lack of support for fcgi/wsgi. In-Reply-To: References: <55185E5D.5080604@animats.com> <87ego7s3e4.fsf@jester.gateway.pace.com> <871tk7s00m.fsf@jester.gateway.pace.com> <87wq1zqjtl.fsf@jester.gateway.pace.com> Message-ID: <1004e48b-138c-443b-8028-4b17a02ab70f@googlegroups.com> On Monday, March 30, 2015 at 8:37:13 AM UTC+5:30, Chris Angelico wrote: > On Mon, Mar 30, 2015 at 1:51 PM, Paul Rubin wrote: > > One way is take reports like John's seriously and receive them > > with thanks, instead of attacking the messenger. > > If a messenger wants to be thanked, he should start by not attacking > the recipients. Respect goes both ways. Make your post with a hostile > attitude of "Python 3 is the cause of all my problems", and you'll > find hostility coming back at you. John : Messenger Paul : ?? Paul is asking for John (et al) to be thanked [And +1 from me on that] On a more serious note you can (and IMHO should) orthogonalize: 1. John I dont appreciate your tone 2. John thank your for the bug-report > > One of my sisters keeps on doing this to me. Not with Python, but with > computers generally. She complains that computers never work properly > for her, and she's hostile to *the machine* even before she starts > doing anything. Well, no wonder the computer gets angry with you, and > refuses to work! Of course, the moment I come along, the computer sits > up and takes notice, because he respects my authority (as the network > admin for the house, I'm in command of all computers, to at least some > extent - and they know that), but she still complains loudly. It does > tend to make the assistance somewhat more caustic in delivery. heh dont I know! I send my mom a file and occasionally she complains: "Why do you spell your file-names funny?" Wedontwritesentenceslikethisdowe? More often she just quietly corrects this stupid boy's spelling. [Unix is one habit that dies hard...] From ben+python at benfinney.id.au Sun Mar 29 23:22:56 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 30 Mar 2015 14:22:56 +1100 Subject: Python 3 lack of support for fcgi/wsgi. References: <55185E5D.5080604@animats.com> <87ego7s3e4.fsf@jester.gateway.pace.com> <871tk7s00m.fsf@jester.gateway.pace.com> <87wq1zqjtl.fsf@jester.gateway.pace.com> Message-ID: <85384n419r.fsf@benfinney.id.au> Chris Angelico writes: > On Mon, Mar 30, 2015 at 1:51 PM, Paul Rubin wrote: > > One way is take reports like John's seriously and receive them > > with thanks, instead of attacking the messenger. Please note that, where John Nagle has made supportible criticisms, I have thanked him for them. They are indeed useful to be aware of. It's also important to note, of course, that those specific criticisms are already well known and are being publicly addressed. It is his claims that there are un-addressed problems which I was focussing on, trying to get specific information. > If a messenger wants to be thanked, he should start by not attacking > the recipients. Respect goes both ways. Make your post with a hostile > attitude of "Python 3 is the cause of all my problems", and you'll > find hostility coming back at you. If my responses seemed hostile, that was not my intent. I asked John Nagle (and have still not seen in this forum his answers to) questions asking for support of his claims. My request for specific supporting information ? that is, this critical inquiry ? was met not with answers, but with allegations of a ?denial problem? and ?uncritical fanboys?. So I've continued to be especially critical in this thread, since John Nagle expressed opposition to uncritical acceptance of claims. Critical inquiry is often mistaken for hostility. If that happened here, I apologise. But so far it's all been a distraction, and I still have nothing from Nagle supporting his assertions Your broader point remains true: readers are safe in dismissing claims about being ?screwed by Python 3? or ?Python 3 not ready for prime time? unsupported by specific evidence. Frustration is understandable. Expressing anger is regrettable, especially if it is misdirected. Persisting in blaming ?Python 3? when the only reported problems are clearly not particular to Python 3, is disingenuous and harmful. -- \ ?If history and science have taught us anything, it is that | `\ passion and desire are not the same as truth.? ?E. O. Wilson, | _o__) _Consilience_, 1998 | Ben Finney From torriem at gmail.com Sun Mar 29 23:30:10 2015 From: torriem at gmail.com (Michael Torrie) Date: Sun, 29 Mar 2015 21:30:10 -0600 Subject: Python 3 lack of support for fcgi/wsgi. In-Reply-To: <85pp7r4dj8.fsf@benfinney.id.au> References: <55185E5D.5080604@animats.com> <85pp7r4dj8.fsf@benfinney.id.au> Message-ID: <5518C342.9010504@gmail.com> On 03/29/2015 04:58 PM, Ben Finney wrote: > You have provided none for your assertion that an unmaintained > third-party library is somehow a special failure of Python 3. A language is only as good as its libraries, either the standard library that ships with the language, or third-party libraries. It is true that third-party library has nothing to do with Python 3's technical completeness as a language, the lack of third party libraries does make Python 3 "not ready for the prime time" for certain tasks. It certainly sounds like Python 3 has turned out to not be a good fit for John's project, and maybe that has nothing to do with Python 3 itself as a language, but more as an ecosystem. What does this have to do with Python itself? I'm not completely sure, but maybe it's about the Python community. What's the way forward? I have no idea. At the very least John is frustrated by the community's lack of apparent interest in fixing problems in the greater python ecosystem when it comes to Python 3. From carl at oddbird.net Sun Mar 29 23:50:59 2015 From: carl at oddbird.net (Carl Meyer) Date: Sun, 29 Mar 2015 21:50:59 -0600 Subject: Python 3 lack of support for fcgi/wsgi. In-Reply-To: <5518C342.9010504@gmail.com> References: <55185E5D.5080604@animats.com> <85pp7r4dj8.fsf@benfinney.id.au> <5518C342.9010504@gmail.com> Message-ID: <5518C823.5020004@oddbird.net> On 03/29/2015 09:30 PM, Michael Torrie wrote: > What does this have to do with Python itself? I'm not completely sure, > but maybe it's about the Python community. What's the way forward? I > have no idea. At the very least John is frustrated by the community's > lack of apparent interest in fixing problems in the greater python > ecosystem when it comes to Python 3. I think one could easily draw far too broad a conclusion from John's report here. The title of the thread says "lack of support for fcgi/wsgi", but AFAICT the content of the report, and the thread, is entirely about FCGI. In my experience, WSGI under Python 3 works very well these days, and all of the popular WSGI servers (gunicorn, mod_wsgi, uwsgi, waitress, ...) run just fine under Python 3. I've deployed several Django applications into production on Python 3 (using WSGI) with no issues. FastCGI is a different story. I do some Django support on #django and on django-users, and I see very few people deploying with FastCGI anymore; almost everyone uses WSGI (and when we see someone using FastCGI, we encourage them to switch to WSGI). In fact, the FastCGI support in Django itself is deprecated and will be removed in Django 1.9. So I am not at all surprised to hear that the Python FastCGI libraries are relatively poorly maintained. And it is true and unsurprising that when a particular library is no longer maintained, it will probably be in better shape on Python 2 than on Python 3, because Python 2 is older. So when it comes to "the community's interest in fixing problems" or John's assertion that "nobody uses this stuff," in both cases I think it's far more about FastCGI vs WSGI than it's about Python 2 vs 3. 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 no.email at nospam.invalid Mon Mar 30 00:35:05 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 29 Mar 2015 21:35:05 -0700 Subject: Python 3 lack of support for fcgi/wsgi. References: <55185E5D.5080604@animats.com> <87ego7s3e4.fsf@jester.gateway.pace.com> <871tk7s00m.fsf@jester.gateway.pace.com> <87wq1zqjtl.fsf@jester.gateway.pace.com> <1004e48b-138c-443b-8028-4b17a02ab70f@googlegroups.com> Message-ID: <87sicnqf0m.fsf@jester.gateway.pace.com> Rustom Mody writes: > On a more serious note you can (and IMHO should) orthogonalize: > 1. John I dont appreciate your tone > 2. John thank your for the bug-report Fair enough, but I'd split #2 into 2a. John, thank you for the bug report describing specific problems we can fix, bringing Python 3 another few little steps closer to maturity. 2b. John, thank you for describing your experience and making the community's picture of the current overall state of Python 3 more accurate. It was apparently a bit too rosy before, and we should avoid fostering unrealistic expectations in the future. From songofacandy at gmail.com Mon Mar 30 00:45:23 2015 From: songofacandy at gmail.com (INADA Naoki) Date: Mon, 30 Mar 2015 13:45:23 +0900 Subject: Python 3 lack of support for fcgi/wsgi. In-Reply-To: <5518C823.5020004@oddbird.net> References: <55185E5D.5080604@animats.com> <85pp7r4dj8.fsf@benfinney.id.au> <5518C342.9010504@gmail.com> <5518C823.5020004@oddbird.net> Message-ID: I agree with you. Web programmers should use maintained libraries. In web world, most common libraries maintained are support Python 3. I (maintainer of PyMySQL and mysqlclient) uses Python 3 for daily job, and use Python 2 only for test my libraries. On Mon, Mar 30, 2015 at 12:50 PM, Carl Meyer wrote: > On 03/29/2015 09:30 PM, Michael Torrie wrote: >> What does this have to do with Python itself? I'm not completely sure, >> but maybe it's about the Python community. What's the way forward? I >> have no idea. At the very least John is frustrated by the community's >> lack of apparent interest in fixing problems in the greater python >> ecosystem when it comes to Python 3. > > I think one could easily draw far too broad a conclusion from John's > report here. The title of the thread says "lack of support for > fcgi/wsgi", but AFAICT the content of the report, and the thread, is > entirely about FCGI. In my experience, WSGI under Python 3 works very > well these days, and all of the popular WSGI servers (gunicorn, > mod_wsgi, uwsgi, waitress, ...) run just fine under Python 3. I've > deployed several Django applications into production on Python 3 (using > WSGI) with no issues. > > FastCGI is a different story. I do some Django support on #django and on > django-users, and I see very few people deploying with FastCGI anymore; > almost everyone uses WSGI (and when we see someone using FastCGI, we > encourage them to switch to WSGI). In fact, the FastCGI support in > Django itself is deprecated and will be removed in Django 1.9. So I am > not at all surprised to hear that the Python FastCGI libraries are > relatively poorly maintained. > > And it is true and unsurprising that when a particular library is no > longer maintained, it will probably be in better shape on Python 2 than > on Python 3, because Python 2 is older. > > So when it comes to "the community's interest in fixing problems" or > John's assertion that "nobody uses this stuff," in both cases I think > it's far more about FastCGI vs WSGI than it's about Python 2 vs 3. > > Carl > > > -- > https://mail.python.org/mailman/listinfo/python-list > -- INADA Naoki From rosuav at gmail.com Mon Mar 30 00:47:23 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 Mar 2015 15:47:23 +1100 Subject: Python 3 lack of support for fcgi/wsgi. In-Reply-To: <87sicnqf0m.fsf@jester.gateway.pace.com> References: <55185E5D.5080604@animats.com> <87ego7s3e4.fsf@jester.gateway.pace.com> <871tk7s00m.fsf@jester.gateway.pace.com> <87wq1zqjtl.fsf@jester.gateway.pace.com> <1004e48b-138c-443b-8028-4b17a02ab70f@googlegroups.com> <87sicnqf0m.fsf@jester.gateway.pace.com> Message-ID: On Mon, Mar 30, 2015 at 3:35 PM, Paul Rubin wrote: > 2b. John, thank you for describing your experience and making the > community's picture of the current overall state of Python 3 more > accurate. It was apparently a bit too rosy before, and we should avoid > fostering unrealistic expectations in the future. Not without some evidence of where this "a bit too rosy" picture came from. So far, we've had rebuttals of vaguenesses, which pretty much amount to FUD. ChrisA From rustompmody at gmail.com Mon Mar 30 01:03:21 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 29 Mar 2015 22:03:21 -0700 (PDT) Subject: Python 3 lack of support for fcgi/wsgi. In-Reply-To: <87sicnqf0m.fsf@jester.gateway.pace.com> References: <55185E5D.5080604@animats.com> <87ego7s3e4.fsf@jester.gateway.pace.com> <871tk7s00m.fsf@jester.gateway.pace.com> <87wq1zqjtl.fsf@jester.gateway.pace.com> <1004e48b-138c-443b-8028-4b17a02ab70f@googlegroups.com> <87sicnqf0m.fsf@jester.gateway.pace.com> Message-ID: On Monday, March 30, 2015 at 10:05:37 AM UTC+5:30, Paul Rubin wrote: > 2b. John, thank you for describing your experience and making the > community's picture of the current overall state of Python 3 more > accurate. It was apparently a bit too rosy before, and we should avoid > fostering unrealistic expectations in the future. Now who's being unrealistic? From dieter at handshake.de Mon Mar 30 02:44:55 2015 From: dieter at handshake.de (dieter) Date: Mon, 30 Mar 2015 08:44:55 +0200 Subject: pycurl.error: (55, 'select/poll returned error') References: <5514FFEE.4030204@shopzeus.com> <87fv8pwrk0.fsf@handshake.de> <5517A5DC.6060001@shopzeus.com> Message-ID: <871tk756hk.fsf@handshake.de> Nagy L?szl? Zsolt writes: > 2015.03.28. 7:43 keltez?ssel, dieter ?rta: >> Nagy L?szl? Zsolt writes: >> >>> When calling curl.perform() on a curl instance I get this: >>> >>> pycurl.error: (55, 'select/poll returned error') >>> .... > The same server is happily accepting files over 4GB from other > clients. Those other clients are exactly the same client programs, but > they are running on Windows. Only the one on this FreeBSD box is > throwing the error. Maybe, you can find out what was the real error reported by "select/poll" (the "55" above might be the "errno" and in you OS header files, you may find what it means). *nix* derivatives have a peculiarity (missing under Windows). There waiting system calls may prematurely return with the error "interrupted system call". Likely, this should give waiting applications a chance to reassess the state after a signal interrupt and decide for themselves whether the waiting should be continued. In most contexts, "interrupted system call" should not be considered an error and the interrupted call should be restartet. Maybe, "pycurl" misses to do that. From dieter at handshake.de Mon Mar 30 02:48:17 2015 From: dieter at handshake.de (dieter) Date: Mon, 30 Mar 2015 08:48:17 +0200 Subject: cgi parse_qs still exists? References: Message-ID: <87wq1z3rri.fsf@handshake.de> Mark Lawrence writes: > This has been marked for deprecation since at least 2.6 but is still > in the 3.5 code base. Does anybody know if this is by accident or > design? If the former I'll happily raise an issue to get it removed > unless somebody beats me to it. I am using "cgi.parse_qs" - and I find it very helpful. Thus, I would be sad if it went away -- unless the library would provide an alternative. From ian.g.kelly at gmail.com Mon Mar 30 02:50:01 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 30 Mar 2015 00:50:01 -0600 Subject: Sudoku solver In-Reply-To: <87619j7kbu.fsf@elektro.pacujo.net> References: <87r3sdnw5t.fsf@elektro.pacujo.net> <4e81bdb9-52db-46e6-b449-d4241cb2a3f2@googlegroups.com> <87twx8amww.fsf@elektro.pacujo.net> <82e7c5b9-2f0f-405b-859c-b74916c475e0@googlegroups.com> <55176c2c$0$13009$c3e8da3$5496439d@news.astraweb.com> <87619j7kbu.fsf@elektro.pacujo.net> Message-ID: On Sun, Mar 29, 2015 at 12:03 PM, Marko Rauhamaa wrote: > BartC : > >> As Chris mentioned, when I say 'faster than C', I mean X running my >> algorithm was faster then C running Marko's algoritim (on Ian's data). >> This was just an illustration of algorithm being more important than >> language. > > Be careful with the benchmark comparisons. Ian's example can be solved > with the identical algorithm in eight different ways (four corners, left > or right). I ran the example with my recent Python solver and got these > times in the eight cases: > > 884 s > 2.5 s > 13 s > 499 s > 5.9 s > 128 s > 1360 s > 36 s That sounds to me like either a transcription error was made to the puzzle at some point, or there's something wrong with your solver. The whole point of that example was that it was a puzzle with the minimum number of clues to specify a unique solution. I tried entering that puzzle into the solver at http://www.sudoku-solutions.com/. It confirms that there is a unique solution, and the solution it gives matches the one given in the article as well as the solution that I got from Norvig's solver. Also, Frank Millman successfully ran the Eppstein solver on it upthread, which purportedly should complain if the puzzle does not have a unique solution. From auriocus at gmx.de Mon Mar 30 03:13:29 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Mon, 30 Mar 2015 09:13:29 +0200 Subject: Sudoku solver In-Reply-To: References: <87r3sdnw5t.fsf@elektro.pacujo.net> <4e81bdb9-52db-46e6-b449-d4241cb2a3f2@googlegroups.com> <87twx8amww.fsf@elektro.pacujo.net> <82e7c5b9-2f0f-405b-859c-b74916c475e0@googlegroups.com> <55176c2c$0$13009$c3e8da3$5496439d@news.astraweb.com> <87619j7kbu.fsf@elektro.pacujo.net> Message-ID: Am 30.03.15 um 08:50 schrieb Ian Kelly: > On Sun, Mar 29, 2015 at 12:03 PM, Marko Rauhamaa wrote: >> Be careful with the benchmark comparisons. Ian's example can be solved >> with the identical algorithm in eight different ways (four corners, left >> or right). I ran the example with my recent Python solver and got these >> times in the eight cases: >> >> 884 s >> 2.5 s >> 13 s >> 499 s >> 5.9 s >> 128 s >> 1360 s >> 36 s > > That sounds to me like either a transcription error was made to the > puzzle at some point, or there's something wrong with your solver. The > whole point of that example was that it was a puzzle with the minimum > number of clues to specify a unique solution. I think Marko meant, that if he creates symmetrically equivalent puzzles by rotating / mirroring the grid, he gets vastly different execution times, but ends up with the same solution. This is not surprising. The brute force algorithm branches into different solutions first, then, because it fills the grid always in the same order. To compare different solvers, it would indeed make sense to average over all symmetric solutions to make sure that no solver wins the competition by sheer luck, i.e. choosing the right path immediately. Christian From ian.g.kelly at gmail.com Mon Mar 30 03:29:42 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 30 Mar 2015 01:29:42 -0600 Subject: Sudoku solver In-Reply-To: References: <87r3sdnw5t.fsf@elektro.pacujo.net> <4e81bdb9-52db-46e6-b449-d4241cb2a3f2@googlegroups.com> <87twx8amww.fsf@elektro.pacujo.net> <82e7c5b9-2f0f-405b-859c-b74916c475e0@googlegroups.com> <55176c2c$0$13009$c3e8da3$5496439d@news.astraweb.com> <87619j7kbu.fsf@elektro.pacujo.net> Message-ID: On Mon, Mar 30, 2015 at 1:13 AM, Christian Gollwitzer wrote: > Am 30.03.15 um 08:50 schrieb Ian Kelly: >> >> On Sun, Mar 29, 2015 at 12:03 PM, Marko Rauhamaa wrote: >>> >>> Be careful with the benchmark comparisons. Ian's example can be solved >>> with the identical algorithm in eight different ways (four corners, left >>> or right). I ran the example with my recent Python solver and got these >>> times in the eight cases: >>> >>> 884 s >>> 2.5 s >>> 13 s >>> 499 s >>> 5.9 s >>> 128 s >>> 1360 s >>> 36 s >> >> >> That sounds to me like either a transcription error was made to the >> puzzle at some point, or there's something wrong with your solver. The >> whole point of that example was that it was a puzzle with the minimum >> number of clues to specify a unique solution. > > I think Marko meant, that if he creates symmetrically equivalent puzzles by > rotating / mirroring the grid, he gets vastly different execution times, but > ends up with the same solution. That makes sense, but it is true for all puzzles that there are eight possible orientations (since it's impossible for a puzzle solution to be symmetric), and the wording made it sound like he was describing a property specific to the puzzle that I posted. From breamoreboy at yahoo.co.uk Mon Mar 30 03:52:07 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 30 Mar 2015 08:52:07 +0100 Subject: cgi parse_qs still exists? In-Reply-To: <87wq1z3rri.fsf@handshake.de> References: <87wq1z3rri.fsf@handshake.de> Message-ID: On 30/03/2015 07:48, dieter wrote: > Mark Lawrence writes: > >> This has been marked for deprecation since at least 2.6 but is still >> in the 3.5 code base. Does anybody know if this is by accident or >> design? If the former I'll happily raise an issue to get it removed >> unless somebody beats me to it. > > I am using "cgi.parse_qs" - and I find it very helpful. > > Thus, I would be sad if it went away -- unless the library would > provide an alternative. > From https://docs.python.org/3/library/cgi.html "This function is deprecated in this module. Use urllib.parse.parse_qs() instead. It is maintained here only for backward compatibility." -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From davea at davea.name Mon Mar 30 04:16:58 2015 From: davea at davea.name (Dave Angel) Date: Mon, 30 Mar 2015 04:16:58 -0400 Subject: Sudoku solver In-Reply-To: References: <87r3sdnw5t.fsf@elektro.pacujo.net> <4e81bdb9-52db-46e6-b449-d4241cb2a3f2@googlegroups.com> <87twx8amww.fsf@elektro.pacujo.net> <82e7c5b9-2f0f-405b-859c-b74916c475e0@googlegroups.com> <55176c2c$0$13009$c3e8da3$5496439d@news.astraweb.com> <87619j7kbu.fsf@elektro.pacujo.net> Message-ID: <5519067A.6040607@davea.name> On 03/30/2015 03:29 AM, Ian Kelly wrote: > On Mon, Mar 30, 2015 at 1:13 AM, Christian Gollwitzer wrote: >> Am 30.03.15 um 08:50 schrieb Ian Kelly: >>> >>> On Sun, Mar 29, 2015 at 12:03 PM, Marko Rauhamaa wrote: >>>> >>>> Be careful with the benchmark comparisons. Ian's example can be solved >>>> with the identical algorithm in eight different ways (four corners, left >>>> or right). I ran the example with my recent Python solver and got these >>>> times in the eight cases: >>>> >>>> 884 s >>>> 2.5 s >>>> 13 s >>>> 499 s >>>> 5.9 s >>>> 128 s >>>> 1360 s >>>> 36 s >>> >>> >>> That sounds to me like either a transcription error was made to the >>> puzzle at some point, or there's something wrong with your solver. The >>> whole point of that example was that it was a puzzle with the minimum >>> number of clues to specify a unique solution. >> >> I think Marko meant, that if he creates symmetrically equivalent puzzles by >> rotating / mirroring the grid, he gets vastly different execution times, but >> ends up with the same solution. > > That makes sense, but it is true for all puzzles that there are eight > possible orientations (since it's impossible for a puzzle solution to > be symmetric), and the wording made it sound like he was describing a > property specific to the puzzle that I posted. > But for some puzzles, the 8 timings may be much closer. Or maybe even further apart. Incidentally, there are many other variants of the same puzzle that might matter, beyond those 8. The digits can all be crypto'ed Like replace all 4 with 8, etc. Probably won't matter for any realistic algorithm. The columns can be reordered, in at least some ways. For example, if the first and second columns are swapped, it's a new puzzle, equivalent. Likewise certain rows. The relationship between row, column and box can be rearranged. Some of these are already covered by the rotations proposed earlier, where for a 90 degree rotate, row becomes column and column becomes row. But in a similar way each box could become a column, and so on. All of these rearrangeements will change the order that an algorithm might choose to examine things, and thus affect timings (but not the solution). When I made my own solver years ago, I considered the puzzle to have 9 columns, 9 rows, and 9 boxes. So these 27 lists of 9 could be analyzed. I just came up with a fast way to map those 243 cells back and forth with the original 81. At that point, it no longer mattered which things were rows and which were columns or boxes. -- DaveA From anudeepsm at gmail.com Mon Mar 30 04:42:28 2015 From: anudeepsm at gmail.com (bobbdeep) Date: Mon, 30 Mar 2015 01:42:28 -0700 (PDT) Subject: TCP sockets python timeout public IP adresss In-Reply-To: References: Message-ID: <71606603-0f84-4677-96c0-71c88982a56f@googlegroups.com> On Sunday, March 29, 2015 at 2:27:59 PM UTC+5:30, bobbdeep wrote: > I am trying to communicate between a server and client using TCP sockets. > > Server code: > > import socket > import sys > > # Create a TCP/IP socket > sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > # Bind the socket to the port > server_address = ('my-server-ipadress', 1999) > print >>sys.stderr, 'starting up on %s port %s' % server_address > sock.bind(server_address) > sock.listen(1) > try: > print >>sys.stderr, 'connection from', client_address > > # Receive the data in small chunks and retransmit it > while True: > data = connection.recv(16) > print >>sys.stderr, 'received "%s"' % data > if data: > print >>sys.stderr, 'sending data back to the client' > connection.sendall(data) > else: > print >>sys.stderr, 'no more data from', client_address > break > > finally: > # Clean up the connection > connection.close() > > Client code: > > from socket import * > > clientsocket = socket(AF_INET,SOCK_STREAM) > > clientsocket.connect(("my-server-ip-address",1999)) > > recv = clientsocket.recv(1024) > > print(recv) > > It is working fine on a local connection. The problem I am facing is when I run the client code on my laptop (using my home wifi network)and try to communicate with the remote server, it is not able connect to the server. What could be the problem ? Any changes in the code required, or do I need to disable firewall on my laptop ? > > The error I get is, error: [Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond Thanks guys everything worksfine. From anudeepsm at gmail.com Mon Mar 30 04:43:56 2015 From: anudeepsm at gmail.com (bobbdeep) Date: Mon, 30 Mar 2015 01:43:56 -0700 (PDT) Subject: Communicating with multiple clients using one TCP socket pyt Message-ID: I am using TCP sockets to communicate between my server and clients. The server code and socket code are as below: server: from socket import * HOST = 'xx.xx.xx.xx' PORT = 1999 serversocket = socket(AF_INET,SOCK_STREAM) serversocket.bind((HOST,PORT)) print 'bind success' serversocket.listen(5) print 'listening' while True: (clientsocket, address) = serversocket.accept() print ("Got client request from",address) #clientsocket.send('True') data = clientsocket.recv(1024) print data clientsocket.send('True') clientsocket.close() client: import socket import sys # Create a TCP/IP socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Connect the socket to the port on the server given by the caller server_address = ('xx.xx.xx.xx', 1999) print >>sys.stderr, 'connecting to %s port %s' % server_address sock.connect(server_address) try: message = 'This is the message. It will be repeated.' print >>sys.stderr, 'sending' for x in range (0,1): name=raw_input ('what is ur name') print type(name) sock.send(name) print sock.recv(1024) finally: sock.close() I am able to communicate with the server from client and able to send and receive data. But the problem I am facing is that I am not able to send and receive data continuously from the server. I have to restart my client code on my laptop to send and receive data again from the server. The way the above client code is working is that when I give a keyboard input, then the socket sends data to server and server responds back. But in the client code, in the for loop if I do two iterations, for the second iteration the data I enter from keyboard is not reaching server. I need to restart my client code to send data again. How do I fix this ? Also, when once client is connected to the server, the other cannot connect to the server. Any ideas on how to do this ? From larry at hastings.org Mon Mar 30 04:46:38 2015 From: larry at hastings.org (Larry Hastings) Date: Mon, 30 Mar 2015 01:46:38 -0700 Subject: [RELEASED] Python 3.5.0a3 is now available Message-ID: <55190D6E.8030300@hastings.org> On behalf of the Python development community and the Python 3.5 release team, I'm thrilled to announce the availability of Python 3.5.0a3. Python 3.5.0a3 is the third alpha release of Python 3.5, which will be the next major release of Python. Python 3.5 is still under heavy development, and is far from complete. This is a preview release, and its use is not recommended for production settings. Two important notes for Windows users about Python 3.5.0a3: * If you have previously installed Python 3.5.0a1, you may need to manually uninstall it before installing Python 3.5.0a3 (issue23612). * If installing Python 3.5.0a3 as a non-privileged user, you may need to escalate to administrator privileges to install an update to your C runtime libraries. You can find Python 3.5.0a3 here: https://www.python.org/downloads/release/python-350a3/ Happy hacking, //arry/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Mon Mar 30 04:57:40 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 30 Mar 2015 02:57:40 -0600 Subject: Sudoku solver In-Reply-To: <5519067A.6040607@davea.name> References: <87r3sdnw5t.fsf@elektro.pacujo.net> <4e81bdb9-52db-46e6-b449-d4241cb2a3f2@googlegroups.com> <87twx8amww.fsf@elektro.pacujo.net> <82e7c5b9-2f0f-405b-859c-b74916c475e0@googlegroups.com> <55176c2c$0$13009$c3e8da3$5496439d@news.astraweb.com> <87619j7kbu.fsf@elektro.pacujo.net> <5519067A.6040607@davea.name> Message-ID: On Mon, Mar 30, 2015 at 2:16 AM, Dave Angel wrote: > The relationship between row, column and box can be rearranged. Some of > these are already covered by the rotations proposed earlier, where for a 90 > degree rotate, row becomes column and column becomes row. But in a similar > way each box could become a column, and so on. I don't think this one is valid. The intersection of a row and a column is one cell. The intersection of a row and a box is three cells. If you swap a column with a box, you're changing the relationships between the squares and the result will not be isomorphic to the original. From rosuav at gmail.com Mon Mar 30 05:13:22 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 Mar 2015 20:13:22 +1100 Subject: Sudoku solver In-Reply-To: References: <87r3sdnw5t.fsf@elektro.pacujo.net> <4e81bdb9-52db-46e6-b449-d4241cb2a3f2@googlegroups.com> <87twx8amww.fsf@elektro.pacujo.net> <82e7c5b9-2f0f-405b-859c-b74916c475e0@googlegroups.com> <55176c2c$0$13009$c3e8da3$5496439d@news.astraweb.com> <87619j7kbu.fsf@elektro.pacujo.net> <5519067A.6040607@davea.name> Message-ID: On Mon, Mar 30, 2015 at 7:57 PM, Ian Kelly wrote: > On Mon, Mar 30, 2015 at 2:16 AM, Dave Angel wrote: >> The relationship between row, column and box can be rearranged. Some of >> these are already covered by the rotations proposed earlier, where for a 90 >> degree rotate, row becomes column and column becomes row. But in a similar >> way each box could become a column, and so on. > > I don't think this one is valid. The intersection of a row and a > column is one cell. The intersection of a row and a box is three > cells. If you swap a column with a box, you're changing the > relationships between the squares and the result will not be > isomorphic to the original. But if you swap *every* column with *every* box? ChrisA From marko at pacujo.net Mon Mar 30 05:16:29 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 30 Mar 2015 12:16:29 +0300 Subject: Sudoku solver References: <87r3sdnw5t.fsf@elektro.pacujo.net> <4e81bdb9-52db-46e6-b449-d4241cb2a3f2@googlegroups.com> <87twx8amww.fsf@elektro.pacujo.net> <82e7c5b9-2f0f-405b-859c-b74916c475e0@googlegroups.com> <55176c2c$0$13009$c3e8da3$5496439d@news.astraweb.com> <87619j7kbu.fsf@elektro.pacujo.net> Message-ID: <87lhiergk2.fsf@elektro.pacujo.net> Ian Kelly : > On Mon, Mar 30, 2015 at 1:13 AM, Christian Gollwitzer > wrote: >> Am 30.03.15 um 08:50 schrieb Ian Kelly: >>> >>> On Sun, Mar 29, 2015 at 12:03 PM, Marko Rauhamaa >>> wrote: >>>> >>>> Be careful with the benchmark comparisons. Ian's example can be >>>> solved with the identical algorithm in eight different ways (four >>>> corners, left or right). I ran the example with my recent Python >>>> solver and got these times in the eight cases: >>>> >>>> 884 s >>>> 2.5 s >>>> 13 s >>>> 499 s >>>> 5.9 s >>>> 128 s >>>> 1360 s >>>> 36 s >>> >>> >>> That sounds to me like either a transcription error was made to the >>> puzzle at some point, or there's something wrong with your solver. >>> The whole point of that example was that it was a puzzle with the >>> minimum number of clues to specify a unique solution. >> >> I think Marko meant, that if he creates symmetrically equivalent >> puzzles by rotating / mirroring the grid, he gets vastly different >> execution times, but ends up with the same solution. > > That makes sense, but it is true for all puzzles that there are eight > possible orientations (since it's impossible for a puzzle solution to > be symmetric), and the wording made it sound like he was describing a > property specific to the puzzle that I posted. Thing is, if you are not careful in your comparisons, you might easily get a good-looking time from one implementation and a lousy time from another implementation because of a different traversal order. That is why brute-force sudoku might not be as good for benchmark testing as BertC was hoping. Marko From marko at pacujo.net Mon Mar 30 05:24:37 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 30 Mar 2015 12:24:37 +0300 Subject: Sudoku solver References: <87r3sdnw5t.fsf@elektro.pacujo.net> Message-ID: <87bnjarg6i.fsf@elektro.pacujo.net> mr.smittye at gmail.com: > You say "neater implementation" > I'll send you to the code-golf site: > http://codegolf.stackexchange.com/a/446/38632 this is brute force. > There are some really good implementations in other languages that > arent brute force. It ain't neater if it don't fit in your posting like mine did. Marko From breamoreboy at yahoo.co.uk Mon Mar 30 06:29:58 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 30 Mar 2015 11:29:58 +0100 Subject: Python 3 lack of support for fcgi/wsgi. In-Reply-To: <85lhif46u8.fsf@benfinney.id.au> References: <55185E5D.5080604@animats.com> <87ego7s3e4.fsf@jester.gateway.pace.com> <85lhif46u8.fsf@benfinney.id.au> Message-ID: On 30/03/2015 02:22, Ben Finney wrote: > Paul Rubin writes: > >> He reported hitting more snags than some of us might expect purely >> from the Python 3 propaganda ("oh, just run the 2to3 utility and it >> does everything for you"). > > Propaganda? > > Are you referring to the official guidelines for migrating from Python 2 > to Python 3? The official guide at > doesn't support > that assertion. > > The ?2to3? program is presented as a tool to assist. I don't know of > anything official saying ?it does everything for you?. Even when it was > first introduced it was only ever presented as a *start* to the porting > effort. > Not much of a tool if the 47 outstanding issues on the bug tracker are anything to go by. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From bc at freeuk.com Mon Mar 30 06:54:52 2015 From: bc at freeuk.com (BartC) Date: Mon, 30 Mar 2015 11:54:52 +0100 Subject: Sudoku solver In-Reply-To: References: <87r3sdnw5t.fsf@elektro.pacujo.net> <4e81bdb9-52db-46e6-b449-d4241cb2a3f2@googlegroups.com> <87twx8amww.fsf@elektro.pacujo.net> <82e7c5b9-2f0f-405b-859c-b74916c475e0@googlegroups.com> <55176c2c$0$13009$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1Y9Sw.1371396$ls6.37583@fx16.am4> On 29/03/2015 08:57, Christian Gollwitzer wrote: > Am 29.03.15 um 05:06 schrieb Steven D'Aprano: [OT: Competing with compiled C code] >> I'm not one of those people who think that C is by definition the fastest >> language conceivable. (People who believe this sometimes make an >> exception >> for hand-crafted assembly, which is ironic since these days the best C >> optimizing compilers can generate faster, tighter code than human >> assembly >> programmers.) > Defeating a C compiler is possible in (rare) cases, I wouldn't really > count the examples you've posted, since they don't actually compute > anything useful. However, for instance the Intel C compiler is able to > replace a loop like this: > > for (int i=0; i for (int j=0; j for (int k=0; k z[i][k]+=x[i][j]*y[j][k]; > } > } > } > > with a call to an optimized BLAS matrix multiplication in "some" > (=impractical) cases. I have an interpreter for my language which has an implementation in C, and one in my own static language. That latter can also optionally make use of a byte-code dispatcher written in assembly (which tries to deal with each byte-code if it can, if not it passes it on to high-level code). This combination of HLL+ASM can be up to double the speed of the C/gcc/O3 version (and which has to use gcc extensions), when executing benchmarks. On real programs, it can still be up to 40-50% faster (ie. the C version takes 40-50% longer to execute). (My own static language by itself is 30% slower than C/gcc/O3 at the minute, when used for the interpreter, but I'm working on it... For small, tight benchmarks though it is still totally outclassed by gcc.) > Just look at the contrived PyPy benchmarks, for a very tuned selected > sample you can be almost twice as fast as C - for a random algorithm > like the Sudoku solver, not specifically tuned, C is 30x faster. It > still boils down to the classic rules: static unboxed types and static > or preallocated memory makes your code fast. In many cases, though, > programming in Python can free programmer time, which can lead in turn > to better algorithms that outperform the wisdom of the C compiler. I'm quite impressed with PyPy. While its implementation seems (to me) fantastically complicated compared with the very simple concept of a byte-code interpreter, it seems to do the job. For simple integer benchmarks, it can be double the speed of my HLL+ASM interpreter running the same algorithm (but not in Python). However I believe that CPython could be a bit faster than it is, even with all the dynamic stuff that is what's supposed to keep it slow. (If Python wasn't so huge, and if I understood it a lot more than I do, I'd be tempted to have a go myself. For example, I could change the syntax of my interpreted language so that it looks like Python. Then I can take a simple benchmark in this 'Python', and run it with both CPython and my interpreter, and mine is likely to be faster. Yet, it still uses a byte-code dispatch loop, and it is still dynamically typed. So what extra stuff is going on in CPython?) -- Bartc From ahlusar.ahluwalia at gmail.com Mon Mar 30 12:45:44 2015 From: ahlusar.ahluwalia at gmail.com (Saran A) Date: Mon, 30 Mar 2015 09:45:44 -0700 (PDT) Subject: Strategy/ Advice for How to Best Attack this Problem? In-Reply-To: References: <87a8yvs34u.fsf@jester.gateway.pace.com> Message-ID: On Sunday, March 29, 2015 at 10:04:45 PM UTC-4, Chris Angelico wrote: > On Mon, Mar 30, 2015 at 12:08 PM, Paul Rubin wrote: > > Saran Ahluwalia writes: > >> cross-platform... > >> * Monitors a folder for files that are dropped throughout the day > > > > I don't see a cross-platform way to do that other than by waking up and > > scanning the folder every so often (once a minute, say). The Linux way > > is with inotify and there's a Python module for it (search terms: python > > inotify). There might be comparable but non-identical interfaces for > > other platforms. > > All too often, "cross-platform" means probing for one option, then > another, then another, and using whichever one you can. On Windows, > there's FindFirstChangeNotification and ReadDirectoryChanges, which > Tim Golden wrote about, and which I coded up into a teleporter for > getting files out of a VM automatically: > > http://timgolden.me.uk/python/win32_how_do_i/watch_directory_for_changes.html > https://github.com/Rosuav/shed/blob/master/senddir.py > > ChrisA @Dave, Chris, Paul and Dennis: Thank you for resources and the notes regarding what I should keep in mind. I have an initial commit: https://github.com/ahlusar1989/IntroToPython/blob/master/Project1WG_with_assumptions_and_comments.py I welcome your thoughts on this From denismfmcmahon at gmail.com Mon Mar 30 13:21:02 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Mon, 30 Mar 2015 17:21:02 +0000 (UTC) Subject: Python 3 lack of support for fcgi/wsgi. References: Message-ID: On Sun, 29 Mar 2015 11:57:54 -0700, John Nagle wrote: > The Python 2 module "fcgi" is gone in Python 3. Was this part of the python standard library, or was it a third party library? I can only find cgi documentation in the python 2 core documentation, not fcgi documentation. Documentation for cgi is also present in the python 3 core documentation: Perhaps the issue is that your python 2 web application was built using 3rd party implementations of cgi interfaces which have not kept up with the development of python 3. The only core module I can find in python that appears relevant is the cgi module, and that exists both in python 2 and python 3. > The Python 3 documentation at > > https://docs.python.org/3/howto/webservers.html That appears to be a copy of the Python 2 Howto. It should probably make that clearer! It contains the following caveat: "See also: While this HOWTO tries to give an overview of Python in the web, it cannot always be as up to date as desired. Web development in Python is rapidly moving forward, so the wiki page on Web Programming may be more in sync with recent development." -- Denis McMahon, denismfmcmahon at gmail.com From sohcahtoa82 at gmail.com Mon Mar 30 13:36:01 2015 From: sohcahtoa82 at gmail.com (sohcahtoa82 at gmail.com) Date: Mon, 30 Mar 2015 10:36:01 -0700 (PDT) Subject: Communicating with multiple clients using one TCP socket pyt In-Reply-To: References: Message-ID: <11a97c37-23ec-413c-818f-f0e45dbddf1f@googlegroups.com> On Monday, March 30, 2015 at 1:44:17 AM UTC-7, bobbdeep wrote: > I am using TCP sockets to communicate between my server and clients. The server code and socket code are as below: > > server: > > from socket import * > > HOST = 'xx.xx.xx.xx' > PORT = 1999 > serversocket = socket(AF_INET,SOCK_STREAM) > serversocket.bind((HOST,PORT)) > print 'bind success' > serversocket.listen(5) > print 'listening' > while True: > (clientsocket, address) = serversocket.accept() > print ("Got client request from",address) > #clientsocket.send('True') > data = clientsocket.recv(1024) > print data > clientsocket.send('True') > clientsocket.close() > > > client: > > import socket > import sys > > # Create a TCP/IP socket > sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > > # Connect the socket to the port on the server given by the caller > server_address = ('xx.xx.xx.xx', 1999) > print >>sys.stderr, 'connecting to %s port %s' % server_address > sock.connect(server_address) > > try: > > message = 'This is the message. It will be repeated.' > print >>sys.stderr, 'sending' > for x in range (0,1): > name=raw_input ('what is ur name') > print type(name) > sock.send(name) > print sock.recv(1024) > > finally: > sock.close() > > > I am able to communicate with the server from client and able to send and receive data. But the problem I am facing is that I am not able to send and receive data continuously from the server. I have to restart my client code on my laptop to send and receive data again from the server. The way the above client code is working is that when I give a keyboard input, then the socket sends data to server and server responds back. But in the client code, in the for loop if I do two iterations, for the second iteration the data I enter from keyboard is not reaching server. I need to restart my client code to send data again. How do I fix this ? > > Also, when once client is connected to the server, the other cannot connect to the server. Any ideas on how to do this ? You have a bug here: for x in range(0, 1): range(0, 1) returns simply [0]. It is only going to loop once. If you want it to loop twice, just use range(2). Also, your server is immediately closing the connection after the first packet of data. data = clientsocket.recv(1024) print data clientsocket.send('True') clientsocket.close() Your server receives the first send from the client, prints it, sends back a 'True', then closes the connection. From rgaddi at technologyhighland.invalid Mon Mar 30 14:11:21 2015 From: rgaddi at technologyhighland.invalid (Rob Gaddi) Date: Mon, 30 Mar 2015 18:11:21 +0000 (UTC) Subject: Setuptools Confusion Message-ID: I'm having two issues trying to make setuptools do what I want to package up an application. Well, actually I'm having many issues, but I'll start with the two that are foremost right now. First, I've got documentation in RestructuredText format that I want to cook down to HTML to include in with the application. I've got a make_docs.py that I can run to do that. I want to make sure that make_docs is run prior to building the sdist package so that the docs in the package are always up to date. I have no idea how to do that. Secondly, I'm using QSettings to manage my application data, and would like to create an .INI file (complete with comments and whatnot) in the correct system-dependent location. Once again, I've got a function already written that does this. I tried the only thing I could find on StackOverflow, which was to overwrite the install method with: from setuptools.command.install import install as _install # Post-install hook class post_install(_install): def run(self): _install.run(self) from V120B.configuration import writeini writeini() setup( ... # Use the post-install hook to provide the default .INI file. cmdclass={ 'install' : post_install }, ) But I don't see the file getting created. Also, does this mean I'd also have to hook develop separately? I feel like both my questions come down to the same root; how do I hook setuptools to do additional tasks at appropriate times? Is it really as complicated as all this, or is there something trivial and stupid that I'm just missing? -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From denismfmcmahon at gmail.com Mon Mar 30 14:15:39 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Mon, 30 Mar 2015 18:15:39 +0000 (UTC) Subject: Python 3 lack of support for fcgi/wsgi. References: <55185E5D.5080604@animats.com> <87ego7s3e4.fsf@jester.gateway.pace.com> <871tk7s00m.fsf@jester.gateway.pace.com> <87wq1zqjtl.fsf@jester.gateway.pace.com> <1004e48b-138c-443b-8028-4b17a02ab70f@googlegroups.com> <87sicnqf0m.fsf@jester.gateway.pace.com> Message-ID: On Mon, 30 Mar 2015 15:47:23 +1100, Chris Angelico wrote: > On Mon, Mar 30, 2015 at 3:35 PM, Paul Rubin > wrote: >> 2b. John, thank you for describing your experience and making the >> community's picture of the current overall state of Python 3 more >> accurate. It was apparently a bit too rosy before, and we should avoid >> fostering unrealistic expectations in the future. > Not without some evidence of where this "a bit too rosy" picture came > from. So far, we've had rebuttals of vaguenesses, which pretty much > amount to FUD. I went and looked earlier - the HOWTO on the Python 3 documentation site appears to be almost a straight copy of the HOWTO from the Python 2 documentation. As such, it should either be updated to ensure that any external libraries and modules are Python 3 compatible, have a suitable caveat inserted, or be removed. -- Denis McMahon, denismfmcmahon at gmail.com From davea at davea.name Mon Mar 30 14:35:27 2015 From: davea at davea.name (Dave Angel) Date: Mon, 30 Mar 2015 14:35:27 -0400 Subject: Strategy/ Advice for How to Best Attack this Problem? In-Reply-To: References: <87a8yvs34u.fsf@jester.gateway.pace.com> Message-ID: <5519976F.8090904@davea.name> On 03/30/2015 12:45 PM, Saran A wrote: > On Sunday, March 29, 2015 at 10:04:45 PM UTC-4, Chris Angelico wrote: >> On Mon, Mar 30, 2015 at 12:08 PM, Paul Rubin wrote: >>> Saran Ahluwalia writes: >>>> cross-platform... >>>> * Monitors a folder for files that are dropped throughout the day >>> >>> I don't see a cross-platform way to do that other than by waking up and >>> scanning the folder every so often (once a minute, say). The Linux way >>> is with inotify and there's a Python module for it (search terms: python >>> inotify). There might be comparable but non-identical interfaces for >>> other platforms. >> >> All too often, "cross-platform" means probing for one option, then >> another, then another, and using whichever one you can. On Windows, >> there's FindFirstChangeNotification and ReadDirectoryChanges, which >> Tim Golden wrote about, and which I coded up into a teleporter for >> getting files out of a VM automatically: >> >> http://timgolden.me.uk/python/win32_how_do_i/watch_directory_for_changes.html >> https://github.com/Rosuav/shed/blob/master/senddir.py >> >> ChrisA > > @Dave, Chris, Paul and Dennis: Thank you for resources and the notes regarding what I should keep in mind. I have an initial commit: https://github.com/ahlusar1989/IntroToPython/blob/master/Project1WG_with_assumptions_and_comments.py > > I welcome your thoughts on this > It's missing a number of your requirements. But it's a start. If it were my file, I'd have a TODO comment at the bottom stating known changes that are needed. In it, I'd mention: 1) your present code is assuming all filenames come directly from the commandline. No searching of a directory. 2) your present code does not move any files to success or failure directories 3) your present code doesn't calculate or write to a text file any statistics. 4) your present code runs once through the names, and terminates. It doesn't "monitor" anything. 5) your present code doesn't check for zero-length files I'd also wonder why you bother checking whether the os.path.getsize(file) function returns the same value as the os.SEEK_END and ftell() code does. Is it that you don't trust the library? Or that you have to run on Windows, where the line-ending logic can change the apparent file size? I notice you're not specifying a file mode on the open. So in Python 3, your sizes are going to be specified in unicode characters after decoding. Is that what the spec says? It's probably safer to explicitly specify the mode (and the file encoding if you're in text). I see you call strip() before comparing the length. Could there ever be leading or trailing whitespace that's significant? Is that the actual specification of line size? -- DaveA From david at drmaciver.com Mon Mar 30 14:44:51 2015 From: david at drmaciver.com (David MacIver) Date: Mon, 30 Mar 2015 20:44:51 +0200 Subject: Hypothesis 1.0: A production quality property-based testing library for Python Message-ID: Hypothesis is a Python library for turning unit tests into generative tests, covering a far wider range of cases than you can manually. Rather than just testing for the things you already know about, Hypothesis goes out and actively hunts for bugs in your code. It usually finds them, and when it does it gives you simple and easy to read examples to demonstrate. Hypothesis is based on Quickcheck ( https://wiki.haskell.org/Introduction_to_QuickCheck2) but is designed to have a naturally Pythonic API and integrate well with Python testing libraries. It's easy to use, extremely solid, and probably more devious than you are at finding edge cases. The 1.0 release of Hypothesis has a stable and well documented public API. It's more than ready for you to use and it's easy to get started. Full documentation is available at http://hypothesis.readthedocs.org/en/latest/, or if you prefer you can skip straight to the quick start guide: http://hypothesis.readthedocs.org/en/latest/quickstart.html -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Mon Mar 30 15:03:01 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 31 Mar 2015 06:03:01 +1100 Subject: Setuptools Confusion References: Message-ID: <85twx22tqy.fsf@benfinney.id.au> Rob Gaddi writes: > I'm having two issues trying to make setuptools do what I want to package > up an application. Those questions are on-topic here. It's worth noting, though, that you may get better discussion of this by asking in the Distutils forum . > I feel like both my questions come down to the same root; how do I hook > setuptools to do additional tasks at appropriate times? In short, you need to extend the ?distutils.command? classes and specify your custom classes as commands. The Distutils documentation describes this . Note, though, that this is an advanced topic and not to be undertaken lightly; it isn't very well understood. > Is it really as complicated as all this, or is there something trivial > and stupid that I'm just missing? It's more complicated than you thought :-( The Python Packaging Authority has greatly improved the situation in recent years, with the Python Packaging User Guide among other works. The bad news is that, though better than ten years ago, Python package distribution is still surprisingly baroque and difficult to navigate. -- \ ?I never forget a face, but in your case I'll be glad to make | `\ an exception.? ?Groucho Marx | _o__) | Ben Finney From turiddociccuddu at yahoo.com Mon Mar 30 15:12:05 2015 From: turiddociccuddu at yahoo.com (ME MO CHE OTTO) Date: Mon, 30 Mar 2015 12:12:05 -0700 (PDT) Subject: -- redacted -- In-Reply-To: <7d471aa5-b6ed-4800-9855-37319ba126ee@googlegroups.com> References: <7d471aa5-b6ed-4800-9855-37319ba126ee@googlegroups.com> Message-ID: <697d9024-c8b6-41db-8aae-048aa9c1eb19@googlegroups.com> -- redacted -- From nagle at animats.com Mon Mar 30 16:07:49 2015 From: nagle at animats.com (John Nagle) Date: Mon, 30 Mar 2015 13:07:49 -0700 Subject: Python 3 lack of support for fcgi/wsgi. In-Reply-To: References: <55185E5D.5080604@animats.com> <87ego7s3e4.fsf@jester.gateway.pace.com> Message-ID: On 3/29/2015 7:11 PM, John Nagle wrote: > Meanwhile, I've found two more variants on "flup" > > https://pypi.python.org/pypi/flipflop > https://pypi.python.org/pypi/flup6 > > All of these are descended from the original "flup" code base. > > PyPi also has > > fcgi-python (Python 2.6, Windows only.) > fcgiapp (circa 2005) > superfcgi (circa 2009) > > Those can probably be ignored. > > One of the "flup" variants may do the job, but since there > are so many, and no single version has won out, testing is > necessary. "flipflop" looks promising, simply because the > author took all the code out that you don't need on a server. "flipflop" works well with Apache. It does log "WARNING: SCRIPT_NAME does not match REQUEST_URI" for any URL renamed using mod_rename with Apache, but other than that, it seems to do the job. The warning message was copied over from "flup", and there's an issue for it for one of the "flup" variants. So I referenced that issue for "flipflop": https://github.com/Kozea/flipflop/issues That's part of the problem of having all those forks - now each bug has to be fixed in each fork. After all this, the production system is now running entirely on Python 3. John Nagle From tjreedy at udel.edu Mon Mar 30 16:37:34 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 Mar 2015 16:37:34 -0400 Subject: Hypothesis 1.0: A production quality property-based testing library for Python In-Reply-To: References: Message-ID: On 3/30/2015 2:44 PM, David MacIver wrote: > Hypothesis is a Python library for turningunit tests into generative > tests, covering a far wider range of cases thanyou can manually. Rather > than just testing for thethings you already know about, Hypothesis goes > out and actively hunts forbugs in your code.It usually finds them, and > when it does it gives you simple and easy to read examples to demonstrate. Iteresting. Some years ago, Vickor Stinner wrote a fuzzing module (fusil?). I believe he found some bugs in the stdlib with it. https://www.python.org/dev/peps/pep-0484/ proposes the addition of a 'typing' module for defining types beyond the builtins and ABCs, such as List(int), Union(tuple, list). If and when it is accepted and added (maybe 3.5, maybe later), you should consider having Hypothesis accept the notations that it can work with. > Full documentation is available at > http://hypothesis.readthedocs.org/en/latest/, or if you prefer you can > skip straight to the quick start guide: > http://hypothesis.readthedocs.org/en/latest/quickstart.html -- Terry Jan Reedy From david at drmaciver.com Mon Mar 30 16:46:47 2015 From: david at drmaciver.com (David MacIver) Date: Mon, 30 Mar 2015 22:46:47 +0200 Subject: Hypothesis 1.0: A production quality property-based testing library for Python In-Reply-To: References: Message-ID: On 30 March 2015 at 22:37, Terry Reedy wrote: > On 3/30/2015 2:44 PM, David MacIver wrote: > >> Hypothesis is a Python library for turningunit tests into generative >> tests, covering a far wider range of cases thanyou can manually. Rather >> than just testing for thethings you already know about, Hypothesis goes >> out and actively hunts forbugs in your code.It usually finds them, and >> when it does it gives you simple and easy to read examples to demonstrate. >> > > Iteresting. Some years ago, Vickor Stinner wrote a fuzzing module > (fusil?). I believe he found some bugs in the stdlib with it. > Cool. I'd somehow missed fusil, thanks. It looks interesting and I'll have a dig through it for ideas :-) Hypothesis and fusil are aimed at somewhat different levels. Hypothesis is closer to being for unit testing (I mean you can use it for integration testing and other things just as easily, but that's not strictly its strength) whileas fusil looks better for testing whole programs. > > https://www.python.org/dev/peps/pep-0484/ > proposes the addition of a 'typing' module for defining types beyond the > builtins and ABCs, such as List(int), Union(tuple, list). If and when it > is accepted and added (maybe 3.5, maybe later), you should consider having > Hypothesis accept the notations that it can work with. Yes, definitely. Having something like that as standard would be great for Hypothesis and I intend to support it once it becomes available. (It will force me to finally figure out how to do staged APIs, with some versions of the API only supported on some versions of python, but I need to do that anyway. This might involve just shipping a compatibility layer for previous versions of Python in with Hypothesis) > > > Full documentation is available at >> http://hypothesis.readthedocs.org/en/latest/, or if you prefer you can >> skip straight to the quick start guide: >> http://hypothesis.readthedocs.org/en/latest/quickstart.html >> > > > -- > Terry Jan Reedy > > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From karthik.sharma at gmail.com Mon Mar 30 17:12:39 2015 From: karthik.sharma at gmail.com (karthik.sharma at gmail.com) Date: Mon, 30 Mar 2015 14:12:39 -0700 (PDT) Subject: Python JSON processing - extra data error Message-ID: I have the following python program to read a set of JSON files do some processing on it and dump them back to the same folder. However When I run the below program and then try to see the output of the JSON file using `cat file.json | python -m json.tool` I get the following error `extra data: line 1 column 307 - line 1 column 852 (char 306 - 851)` What is wrong with my program? #Process 'new' events to extract more info from 'Messages' rootDir = '/home/s_parts' for dirName, subdirList, fileList in os.walk(rootDir): print('Found directory: %s' % dirName) for fname in fileList: fname='s_parts/'+fname with open(fname, 'r+') as f: json_data = json.load(f) et = json_data['Et'] ms = json_data['Ms'] if (event == 'a.b.c.d') or (event == 'e.f.g.h'): url = re.sub('.+roxy=([^& ]*).*', r'\1', ms) nt = re.findall(r"NT:\s*([^,)]*)",ms)[0] bt = re.findall(r"BT:\s*([^,)]*)",ms)[0] xt = re.findall(r"XT:\s*([^,)]*)",ms)[0] appde = ms.split('Appde:')[1].strip().split('
    ')[0] version = ms.split('version:')[1].strip().split('
    ')[0] json_data["url"] = url json_data["BT"] = bt json_data["XT"] = xt json_data["NT"] = nt json_data["Appde"] = appde json_data["version"] = version else: json_data["url"] = "null" json_data["BT"] = "null" json_data["XT"] = "null" json_data["NT"] = "null" json_data["Appde"] = "null" json_data["version"] = "null" json.dump(json_data,f) If I do a `file` command on the output file I get `events_parts/data_95: ASCII text, with very long lines, with no line terminators` From ian.g.kelly at gmail.com Mon Mar 30 17:13:47 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 30 Mar 2015 15:13:47 -0600 Subject: Communicating with multiple clients using one TCP socket pyt In-Reply-To: References: Message-ID: On Mon, Mar 30, 2015 at 2:43 AM, bobbdeep wrote: > Also, when once client is connected to the server, the other cannot connect to the server. Any ideas on how to do this ? While one client is connected, the server can't accept new connections because it's tied up in a blocking call to recv, waiting for data. In order to accept additional simultaneous connections while handling the incoming data as it becomes ready, you'll need to multiplex your I/O events using the select module -- see https://docs.python.org/2/library/select.html#select.select Also, if you don't already have a book on network programming, I suggest getting one. From kai.peters at gmail.com Mon Mar 30 17:22:05 2015 From: kai.peters at gmail.com (kai.peters at gmail.com) Date: Mon, 30 Mar 2015 14:22:05 -0700 (PDT) Subject: Image rotation issue Message-ID: Last week some readers have kindly supplied ideas and code for a question I had asked around a form of image data compression required for specialized display hardware. I was able to solve my issues for all but one: The black & white only device (1024 (X) x 1280 (Y)) expects the compressed data based on portrait mode, i.e. 8 pixels combined into one bytes for 1280 rows of 128 bytes. This was working well until the desire came up to be able to tilt the display and use it in landscape mode - now I needed to rotate the text, as Pillow does not seem to support drawing at angles. No big deal - or so I thought after discovering rotate: from PIL import Image, ImageFont, ImageDraw white = 1 black = 0 img = Image.new('1', (1280, 1024), white) # start in landscape mode since we need to calc. based on that draw = ImageDraw.Draw(img) fontname = 'FreeSansBold.ttf' # in real life, x and y are calculated to center or align text both vertically and horizontally x = 10 y = 500 dfont = ImageFont.truetype(fontname, 96) draw.text((x, y), 'Hallo world', black, font = dfont) draw = ImageDraw.Draw(img) rotimg = img.rotate(270) # rotation is counterclockwise # i can almost make it work by resizing rotimg here, but the aspect ratio is then screwed #rotimg = rotimg.resize((1024, 1280)) rotimg.show() imagedata = list(rotimg.getdata()) But grabbing data from the rotimg does not work as it does not seem to return an image with swapped dimensions... What am I missing? From karthik.sharma at gmail.com Mon Mar 30 17:27:14 2015 From: karthik.sharma at gmail.com (Karthik Sharma) Date: Mon, 30 Mar 2015 14:27:14 -0700 (PDT) Subject: Error in processing JSON files in Python Message-ID: <63a251f6-01ff-4662-ab9c-588e3ffcd73a@googlegroups.com> I have the following python program to read a set of JSON files do some processing on it and dump them back to the same folder. However When I run the below program and then try to see the output of the JSON file using `cat file.json | python -m json.tool` I get the following error `extra data: line 1 column 307 - line 1 column 852 (char 306 - 851)` What is wrong with my program? #Process 'new' events to extract more info from 'Messages' rootDir = '/home/s_parts' for dirName, subdirList, fileList in os.walk(rootDir): print('Found directory: %s' % dirName) for fname in fileList: fname='s_parts/'+fname with open(fname, 'r+') as f: json_data = json.load(f) et = json_data['Et'] ms = json_data['Ms'] if (event == 'a.b.c.d') or (event == 'e.f.g.h'): url = re.sub('.+roxy=([^& ]*).*', r'\1', ms) nt = re.findall(r"NT:\s*([^,)]*)",ms)[0] bt = re.findall(r"BT:\s*([^,)]*)",ms)[0] xt = re.findall(r"XT:\s*([^,)]*)",ms)[0] appde = ms.split('Appde:')[1].strip().split('
    ')[0] version = ms.split('version:')[1].strip().split('
    ')[0] json_data["url"] = url json_data["BT"] = bt json_data["XT"] = xt json_data["NT"] = nt json_data["Appde"] = appde json_data["version"] = version else: json_data["url"] = "null" json_data["BT"] = "null" json_data["XT"] = "null" json_data["NT"] = "null" json_data["Appde"] = "null" json_data["version"] = "null" json.dump(json_data,f) If I do a `file` command on the output file I get `s_parts/data_95: ASCII text, with very long lines, with no line terminators` From ian.g.kelly at gmail.com Mon Mar 30 17:32:18 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 30 Mar 2015 15:32:18 -0600 Subject: Image rotation issue In-Reply-To: References: Message-ID: On Mon, Mar 30, 2015 at 3:22 PM, wrote: > rotimg = img.rotate(270) # rotation is counterclockwise > > # i can almost make it work by resizing rotimg here, but the aspect ratio is then screwed > #rotimg = rotimg.resize((1024, 1280)) > > rotimg.show() > imagedata = list(rotimg.getdata()) > > But grabbing data from the rotimg does not work as it does not seem to return an image with swapped dimensions... > > What am I missing? Have you tried passing the expand flag to rotate? http://pillow.readthedocs.org/en/latest/reference/Image.html#PIL.Image.Image.rotate I'm not sure if that will result in an image sized (1280, 1024) or (1280, 1280). If the latter, you should be able to fix it using Image.crop. From tjreedy at udel.edu Mon Mar 30 19:02:07 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 Mar 2015 19:02:07 -0400 Subject: Python 3 lack of support for fcgi/wsgi. In-Reply-To: References: <55185E5D.5080604@animats.com> <87ego7s3e4.fsf@jester.gateway.pace.com> Message-ID: On 3/30/2015 4:07 PM, John Nagle wrote: > After all this, the production system is now running entirely > on Python 3. I am really glad to read this. Aside from a bit of hyperbole, I appreciate the report of successes and difficulties. I also understand better that 'Python 3' means something different (more) to a user-developer than to CPython core developers, and that the boundary between stdlib modules and 3-rd party modules is much less important to you than to us. -- Terry Jan Reedy From python at mrabarnett.plus.com Mon Mar 30 19:18:06 2015 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 31 Mar 2015 00:18:06 +0100 Subject: Error in processing JSON files in Python In-Reply-To: <63a251f6-01ff-4662-ab9c-588e3ffcd73a@googlegroups.com> References: <63a251f6-01ff-4662-ab9c-588e3ffcd73a@googlegroups.com> Message-ID: <5519D9AE.6000106@mrabarnett.plus.com> On 2015-03-30 22:27, Karthik Sharma wrote: > I have the following python program to read a set of JSON files do some processing on it and dump them back to the same folder. However When I run the below program and then try to see the output of the JSON file using > > `cat file.json | python -m json.tool` > > I get the following error > > `extra data: line 1 column 307 - line 1 column 852 (char 306 - 851)` > > What is wrong with my program? > > #Process 'new' events to extract more info from 'Messages' > rootDir = '/home/s_parts' > for dirName, subdirList, fileList in os.walk(rootDir): > print('Found directory: %s' % dirName) > for fname in fileList: > fname='s_parts/'+fname > with open(fname, 'r+') as f: > json_data = json.load(f) > et = json_data['Et'] > ms = json_data['Ms'] > if (event == 'a.b.c.d') or (event == 'e.f.g.h'): > url = re.sub('.+roxy=([^& ]*).*', r'\1', ms) > nt = re.findall(r"NT:\s*([^,)]*)",ms)[0] > bt = re.findall(r"BT:\s*([^,)]*)",ms)[0] > xt = re.findall(r"XT:\s*([^,)]*)",ms)[0] > appde = ms.split('Appde:')[1].strip().split('
    ')[0] > version = ms.split('version:')[1].strip().split('
    ')[0] > json_data["url"] = url > json_data["BT"] = bt > json_data["XT"] = xt > json_data["NT"] = nt > json_data["Appde"] = appde > json_data["version"] = version > else: > json_data["url"] = "null" > json_data["BT"] = "null" > json_data["XT"] = "null" > json_data["NT"] = "null" > json_data["Appde"] = "null" > json_data["version"] = "null" > json.dump(json_data,f) > > If I do a `file` command on the output file I get > `s_parts/data_95: ASCII text, with very long lines, with no line terminators` > open(fname, 'r+') opens the file for update, json.load(f) reads from the file, and then json.dump(json_data,f) writes back to the file, _appending_ to it, so the file now contains the old data followed by the new data. Another point: "null" is a string and will be written as such. If you actually want a null in the JSON data, then that should be None. From tjreedy at udel.edu Mon Mar 30 19:28:16 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 Mar 2015 19:28:16 -0400 Subject: Python 3 success story Message-ID: Last summer, a college student, who prefers Python to Java and Racket (her other CS course languages), wanted to do a year-long AI research project using PyBrain (for the ai part), numpy (required for PyBrain), and pygame (for animated displays). We both preferred 3.x. That was not an issue for pygame and numpy as compiled 3.4 Windows binaries were easily available. PyBrain, however, was '2.7 only'. So I downloaded it, read the doc for 2to3, and ran it to do the conversion. Running the PyBrain test suite did not work because it uses fragile doctests. Looking at the non-test code, I could see that it mostly used things that did not change in 3.x and a few things that should have been converted correctly. This all took maybe an hour, certainly less than 2. So I suggested going ahead and testing PyBrain by using it. This appears to have worked out well. I believe the only 2-3 issue she ran into was a '/' that needed to become '//', that either 2to3 or I missed in the initial conversion. She had more problems with exception messages that she could not understand. If anything, those have been improved in 3.x (and such improvements continue). -- Terry Jan Reedy From ben+python at benfinney.id.au Mon Mar 30 19:30:32 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 31 Mar 2015 10:30:32 +1100 Subject: Python 3 lack of support for fcgi/wsgi. References: <55185E5D.5080604@animats.com> <87ego7s3e4.fsf@jester.gateway.pace.com> Message-ID: <85lhie2hd3.fsf@benfinney.id.au> John Nagle writes: > That's part of the problem of having all those forks - now > each bug has to be fixed in each fork. Agreed, there is too much focus on developing everything in isolation, too little focus on getting different libraries working together. > After all this, the production system is now running entirely > on Python 3. Hey, that's great! Congratulations on making it through to the actively-developed world of Python 3 :-) -- \ ?When in doubt tell the truth. It will confound your enemies | `\ and astound your friends.? ?Mark Twain, _Following the Equator_ | _o__) | Ben Finney From rosuav at gmail.com Mon Mar 30 19:47:53 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 31 Mar 2015 10:47:53 +1100 Subject: Image rotation issue In-Reply-To: References: Message-ID: On Tue, Mar 31, 2015 at 8:22 AM, wrote: > rotimg = img.rotate(270) # rotation is counterclockwise Unless the 90 and 270 cases are documented as being handled specially, I'd look for a dedicated function for doing those changes. A quick perusal of the docs showed up this: http://pillow.readthedocs.org/en/latest/reference/Image.html#PIL.Image.Image.transpose Is that any better, or is that doing the exact same thing as rotate()? By the way: > The black & white only device (1024 (X) x 1280 (Y)) expects the compressed data based on portrait mode, i.e. 8 pixels combined into one bytes for 1280 rows of 128 bytes. > This sounds to me like the fax standard. I wonder, can you make use of a TIFF library to do some of your work for you? ChrisA From marfig at gmail.com Mon Mar 30 20:24:50 2015 From: marfig at gmail.com (Mario Figueiredo) Date: Tue, 31 Mar 2015 01:24:50 +0100 Subject: Python 3 success story References: Message-ID: <2spjhad7815j59la4c9a3s6f3tu8j7lkdt@4ax.com> On Mon, 30 Mar 2015 19:28:16 -0400, Terry Reedy wrote: > >So I suggested going ahead and testing PyBrain by using it. This >appears to have worked out well. I believe the only 2-3 issue she ran >into was a '/' that needed to become '//', that either 2to3 or I missed >in the initial conversion. She had more problems with exception messages >that she could not understand. If anything, those have been improved in >3.x (and such improvements continue). This is good news, Terry. Have you considered requesting a fork from the authors? And if you don't get the required attention, just fork it yourself? Even if you don't plan to maintain it, it would be nice to have it available for someone else to do it. A quick look at the GitHub pages reveals the project has pretty much stalled. Although it could be it achieved a good enough stable status, this is a machine learning project and those tend to always require constant work. From tjreedy at udel.edu Mon Mar 30 20:46:52 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 Mar 2015 20:46:52 -0400 Subject: Hypothesis 1.0: A production quality property-based testing library for Python In-Reply-To: References: Message-ID: On 3/30/2015 4:46 PM, David MacIver wrote: > On 30 March 2015 at 22:37, Terry Reedy > wrote: > https://www.python.org/dev/__peps/pep-0484/ > > proposes the addition of a 'typing' module for defining types beyond > the builtins and ABCs, such as List(int), Union(tuple, list). If > and when it is accepted and added (maybe 3.5, maybe later), you > should consider having Hypothesis accept the notations that it can > work with. > > Yes, definitely. Having something like that as standard would be great > for Hypothesis and I intend to support it once it becomes available. I just posted "PEP 484: Generating test inputs from type hints" to python-ideas list. > (It will force me to finally figure out how to do staged APIs, with some > versions of the API only supported on some versions of python, but I > need to do that anyway. This might involve just shipping a compatibility > layer for previous versions of Python in with Hypothesis) I believe Guido intends that typing.py should be available on PyPI for use with current versions. > Full documentation is available at > http://hypothesis.readthedocs.__org/en/latest/ > you can > skip straight to the quick start guide: > http://hypothesis.readthedocs.__org/en/latest/quickstart.html -- Terry Jan Reedy From no.email at nospam.invalid Mon Mar 30 20:51:55 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 30 Mar 2015 17:51:55 -0700 Subject: Hypothesis 1.0: A production quality property-based testing library for Python References: Message-ID: <87k2xyq990.fsf@jester.gateway.pace.com> David MacIver writes: > Hypothesis is based on Quickcheck > (https://wiki.haskell.org/Introduction_to_QuickCheck2) This is great. Have you looked at the Erlang version of Quickcheck? It may have aspects more directly applicable to Python, since Erlang is dynamically typed like Python is. From high5storage at gmail.com Tue Mar 31 00:04:10 2015 From: high5storage at gmail.com (high5storage at gmail.com) Date: Mon, 30 Mar 2015 21:04:10 -0700 (PDT) Subject: Image rotation issue In-Reply-To: References: Message-ID: <71574a15-7686-4c41-891c-631f2a32987b@googlegroups.com> On Monday, 30 March 2015 16:48:08 UTC-7, Chris Angelico wrote: > On Tue, Mar 31, 2015 at 8:22 AM, wrote: > > rotimg = img.rotate(270) # rotation is counterclockwise > > Unless the 90 and 270 cases are documented as being handled specially, > I'd look for a dedicated function for doing those changes. A quick > perusal of the docs showed up this: > > http://pillow.readthedocs.org/en/latest/reference/Image.html#PIL.Image.Image.transpose > > Is that any better, or is that doing the exact same thing as rotate()? > > By the way: > > > The black & white only device (1024 (X) x 1280 (Y)) expects the compressed data based on portrait mode, i.e. 8 pixels combined into one bytes for 1280 rows of 128 bytes. > > > > This sounds to me like the fax standard. I wonder, can you make use of > a TIFF library to do some of your work for you? > > ChrisA According to the docs rotate & transform can both be used and should do the same in my case - but they are not. rotimg = img.transpose(Image.ROTATE_270) print img.getbbox() print rotimg.getbbox() gives (0, 0, 1280, 1024) (0, 0, 1024, 1280) while rotimg = img.rotate(270, 0, 1) print img.getbbox() print rotimg.getbbox() gives (0, 0, 1280, 1024) (1, 1, 1025, 1281) Neither one produces good output when the compression is applied. Don't think it's related to fax standards - it's proprietary (E-Ink Tile) From rosuav at gmail.com Tue Mar 31 00:09:21 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 31 Mar 2015 15:09:21 +1100 Subject: Image rotation issue In-Reply-To: <71574a15-7686-4c41-891c-631f2a32987b@googlegroups.com> References: <71574a15-7686-4c41-891c-631f2a32987b@googlegroups.com> Message-ID: On Tue, Mar 31, 2015 at 3:04 PM, wrote: > Neither one produces good output when the compression is applied. Oh well, was worth a try. > Don't think it's related to fax standards - it's proprietary (E-Ink Tile) Doesn't need to be specifically _related_, but it's looking similar. If you could do 90% of your work by pretending that this is a fax you're sending, you could possibly do the other 10% by snagging a byte stream from somewhere. But maybe not worth hunting down. Just a thought. ChrisA From victorhooi at gmail.com Tue Mar 31 00:47:45 2015 From: victorhooi at gmail.com (Victor Hooi) Date: Mon, 30 Mar 2015 21:47:45 -0700 (PDT) Subject: Using csv DictWriter - add a extra field Message-ID: Hi, I have a dict named "connections", with items like the following: In [18]: connections Out[18]: {'3424234': {'end_timestamp': datetime.datetime(2015, 3, 25, 5, 31, 30, 406000, tzinfo=datetime.timezone(datetime.timedelta(-1, 61200))), 'ip_address': '10.168.8.36:52440', 'open_timestamp': datetime.datetime(2015, 3, 25, 5, 31, 0, 383000, tzinfo=datetime.timezone(datetime.timedelta(-1, 61200))), 'time_open': datetime.timedelta(0, 30, 23000)}} In this case, the key is a connection id (e.g. "3424234"), and the value is a another dict, which contains things like 'end_timestamp', 'ip_address" etc. I'm writing the output of "connections" to a CSV file using DictWriter: fieldnames = ['connection_id', 'ip_address', 'open_timestamp', 'end_timestamp', 'time_open'] with open('output.csv', 'w') as csvfile: writer = DictWriter(csvfile, fieldnames) writer.writeheader() for connection, values in sorted(connections.items()): if 'time_open' in values: writer.writerow(values, {'connection_id': connection}) else: pass # DO SOME STUFF The only problem is, I'd also like output the connection_id field as part of each CSV record. However, connection_id in this case is the key for the parent dict. Is there a clean way to add a extra field to DictWriter writerows, or it is the contents of the dict and that's it? Cheers, Victor From dieter at handshake.de Tue Mar 31 02:05:17 2015 From: dieter at handshake.de (dieter) Date: Tue, 31 Mar 2015 08:05:17 +0200 Subject: Python JSON processing - extra data error References: Message-ID: <87sicl3dnm.fsf@handshake.de> karthik.sharma at gmail.com writes: > I have the following python program to read a set of JSON files do some processing on it and dump them back to the same folder. However When I run the below program and then try to see the output of the JSON file using > > `cat file.json | python -m json.tool` > > I get the following error > > `extra data: line 1 column 307 - line 1 column 852 (char 306 - 851)` You might have got a traceback which would tell you where precisely the problem was detected. Looking the the code there (Python is "Open Source"; thus, you can look at code) will tell you what apparently went wrong. "extra data" suggests to me that your JSON input may be invalid. "1 2", for example could cause such a problem, because it contains two integers (not a single one) without a containing container. From tjreedy at udel.edu Tue Mar 31 02:06:30 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 31 Mar 2015 02:06:30 -0400 Subject: Python 3 success story In-Reply-To: <2spjhad7815j59la4c9a3s6f3tu8j7lkdt@4ax.com> References: <2spjhad7815j59la4c9a3s6f3tu8j7lkdt@4ax.com> Message-ID: On 3/30/2015 8:24 PM, Mario Figueiredo wrote: > On Mon, 30 Mar 2015 19:28:16 -0400, Terry Reedy > wrote: >> So I suggested going ahead and testing PyBrain by using it. This >> appears to have worked out well. I believe the only 2-3 issue she ran >> into was a '/' that needed to become '//', that either 2to3 or I missed >> in the initial conversion. > > This is good news, Terry. Have you considered requesting a fork from > the authors? I considered and rejected the idea at the time because a) I was more than busy supervising a GSOC project and b) to work on it seriously, I would want to ditch doctest (which was not meant for serious unit testing) and convert to using unittest for both 2.7 and 3.x. > And if you don't get the required attention, just fork it > yourself? Even if you don't plan to maintain it, it would be nice to > have it available for someone else to do it. Now that the port has been used for some months, I a) can see that making it available might be helpful to others, and b) would feel more comfortable doing so on an as is, use at your own risk, basis (and possibly even accept and apply patches). > A quick look at the GitHub pages reveals the project has pretty much > stalled. Although it could be it achieved a good enough stable status, > this is a machine learning project and those tend to always require > constant work. Not knowing git and github adds a barrier, but thanks for the suggestion. -- Terry Jan Reedy From wxjmfauth at gmail.com Tue Mar 31 02:31:18 2015 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Mon, 30 Mar 2015 23:31:18 -0700 (PDT) Subject: Installing 3.5.0a3 on Windows!? In-Reply-To: References: Message-ID: <9b7dd601-e301-4af5-b947-8de5d5fba485@googlegroups.com> Le mardi 31 mars 2015 08:18:31 UTC+2, wxjm... at gmail.com a ?crit?: Addendum If I'm installing 3.5.0a3 on Windows, does it become automatically the "default" Python version? Without any possible control? *** Install for all users *** From david at drmaciver.com Tue Mar 31 02:41:13 2015 From: david at drmaciver.com (David MacIver) Date: Tue, 31 Mar 2015 08:41:13 +0200 Subject: Hypothesis 1.0: A production quality property-based testing library for Python In-Reply-To: <87k2xyq990.fsf@jester.gateway.pace.com> References: <87k2xyq990.fsf@jester.gateway.pace.com> Message-ID: On 31 March 2015 at 02:51, Paul Rubin wrote: > David MacIver writes: > > Hypothesis is based on Quickcheck > > (https://wiki.haskell.org/Introduction_to_QuickCheck2) > > This is great. Have you looked at the Erlang version of Quickcheck? It > may have aspects more directly applicable to Python, since Erlang is > dynamically typed like Python is. > I actually haven't looked at it much. I've read some of the associated papers, but due to a mix of my not really knowing erlang well and it being proprietary it's not as useful for idea mining as I'd like it to be. I have some friends who are more extensive users of it who I've talked to a bit about it for feature comparisons though. -------------- next part -------------- An HTML attachment was scrubbed... URL: From david at drmaciver.com Tue Mar 31 02:44:24 2015 From: david at drmaciver.com (David MacIver) Date: Tue, 31 Mar 2015 08:44:24 +0200 Subject: Hypothesis 1.0: A production quality property-based testing library for Python In-Reply-To: References: Message-ID: On 31 March 2015 at 02:46, Terry Reedy wrote: > On 3/30/2015 4:46 PM, David MacIver wrote: > >> On 30 March 2015 at 22:37, Terry Reedy > > wrote: >> > > https://www.python.org/dev/__peps/pep-0484/ >> >> proposes the addition of a 'typing' module for defining types beyond >> the builtins and ABCs, such as List(int), Union(tuple, list). If >> and when it is accepted and added (maybe 3.5, maybe later), you >> should consider having Hypothesis accept the notations that it can >> work with. >> >> Yes, definitely. Having something like that as standard would be great >> for Hypothesis and I intend to support it once it becomes available. >> > > I just posted "PEP 484: Generating test inputs from type hints" to > python-ideas list. Thanks. I'll pop over there and join in the discussion. > > > (It will force me to finally figure out how to do staged APIs, with some >> versions of the API only supported on some versions of python, but I >> need to do that anyway. This might involve just shipping a compatibility >> layer for previous versions of Python in with Hypothesis) >> > > I believe Guido intends that typing.py should be available on PyPI for use > with current versions. > > Ah, that would be useful. Does that include Python 2.7? The examples suggest yes. (I really hate having to ask that. I don't want to support Python 2.7 at all, but...) > Full documentation is available at >> http://hypothesis.readthedocs.__org/en/latest/ >> you can >> skip straight to the quick start guide: >> http://hypothesis.readthedocs.__org/en/latest/quickstart.html >> > > -- > Terry Jan Reedy > > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Tue Mar 31 03:23:53 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 31 Mar 2015 01:23:53 -0600 Subject: A simple single line, triple-quoted comment is giving syntax error. Why? In-Reply-To: <3894022.plrvF2nHWu@PointedEars.de> References: <3533816.ZYnZ2OzjCs@PointedEars.de> <3971951.908YQu3oQO@PointedEars.de> <1504323.jUKfeKbQsP@PointedEars.de> <2362875.FIK8ImHTJA@PointedEars.de> <1823599.Pr2V0MPR6q@PointedEars.de> <9781856.5cutuNVPEq@PointedEars.de> <3894022.plrvF2nHWu@PointedEars.de> Message-ID: On Sun, Mar 29, 2015 at 4:41 AM, Thomas 'PointedEars' Lahn wrote: > Ian Kelly wrote: > >> [?] Thomas 'PointedEars' Lahn [?] wrote: >>> Ian Kelly wrote: >> Why should the burden of proof be on me in the first place? > > Because *you* made the claim that ?STRING+? could be part of an AST in this > way. Okay, I didn't understand before that this was the part that you were objecting to. I had written "There is only one expr node, and it contains both STRING tokens", to which you replied "Prove it." I did not intend to imply anything at all by the inclusion of STRING+ in the tree. That pseudo-tree was hastily sketched out, and as both you and Gregory have pointed out, STRING+ is not a symbol of the grammar and should not have been included as a node. None of this has any bearing on what I was trying to demonstrate with that tree. >> Within a grammar, the question of "is an X a Y" is nonsensical in >> isolation. It can only be answered in relation to a parse tree. >> Consider the simple grammar: >> >> S -> A | B >> A -> x >> B -> x >> >> Is x an A? It depends. > > No, by the definition 2 below, that we all accepted implicitly up to this > point, x is *definitely* an A. What gives you the impression that I ever accepted it? >> If the tree that generates the x produces it from an A node, then yes. >> Otherwise, no. > > Fallacy. > > First, two definitions, so that we are clear what we are talking about: > > (1) Let a *production chain* be the repeated application of the production > rules of a formal grammar such that > > C ? D ? x > > is a production chain if there are production rules > > C ? D > D ? x. > > [Note the difference between ??? and ???.] Sure. > (2) Let the statement ?x is an A? be true if x can be produced in a > production chain starting with or including the non-terminal A > left-hand side ? > > x ? A ? ?A (? ? A ? ? ? x). Sorry, but this definition just seems entirely arbitrary to me. Mathematically, it looks nonsensical; A is a symbol, not a set. This question of whether "x is an A" is informal and not a topic of formal language theory so far as I'm aware. Can you cite some source for it? > Now, according to these definitions, in the offered grammar x is *both* an A > and a B. Because what matters is _not_ the practical result of production > chains (the actual parse tree), but the certainty of the theoretical > possibility of it. This strikes me as being a lot like arguing, "some kites are toys, and some kites are birds; therefore, all kites are both toys and birds." >> So when I write that the "foo" in "foo" "bar" is not an expression, I >> am only speaking in relation to the parse tree that generates "foo" >> "bar". > > But it has been indicated by others that the parse tree that you presented > is wrong, based on a misconception about the syntax of the formal grammar, > and you have not yet substantiated your claim that it is correct. As noted above, the inaccuracy that Gregory pointed out has no bearing on my argument. You're really going to make me spell it out, aren't you? Fine, here you go. single_input -> simple_stmt -> expr_stmt -> testlist_star_expr -> test -> or_test -> and_test -> not_test -> comparison -> expr -> xor_expr -> and_expr -> shift_expr -> arith_expr -> term -> factor -> power -> atom -> STRING STRING Note: the derivation contains exactly one expr node, which indirectly produces both STRINGs. Neither STRING in this derivation is individually produced from the expr. >> I don't know what you mean by a "backdoor". > > Appending a statement that is contradictory to what was stated just before, > or at least ambiguous, so that the possibility arises for one to say ?I did > not mean that? when that/a contradiction to the former statement is pointed > out later. The purpose was not to make the possibility arise to say that. The purpose was to point out the discontinuity *immediately* so that it would be already addressed and not *need* to be pointed out later (although we can see how well that turned out). I have to say that I find it highly surprising that you find this construction objectionable. Would you still consider it "contradictory" if I had phrased it equivalently as a logical "or" rather than using the word "except"? >> The purpose of that parenthetical was to explicitly acknowledge that the >> single STRING could be viewed as an expression when taken out of context, > > Yes, your fallacy is mainly based on ignoring the context. Context is > important; you cannot just ignore it and still make correct arguments. Funny, I thought that was my line. This whole argument came about because you seem to be stubbornly insistent on ignoring the context that I set for my statement, calling it "contradictory" instead. >> and to disclaim that I was excluding that case from the preceding >> statement. I still stand by that statement; The "foo" in "foo" "bar" is >> not an expression in the same sense that the "42" is not an expression in >> "hucr,.@#%c|42ptqc$". > > False analogy. The ?42? in there cannot be produced by ?expr? *in that > context* (it can only be produced by ?STRING?). I apologize for the confusion. The quotation marks there were only intended to separate the nonsense construction from my own text, not as string delimiters. I realize that in the first part of the analogy I did use them as string delimiters, so I was inconsistent. The analogy to be drawn is that a parse tree of ?"foo" "bar"? that contains an expr node for each STRING is an invalid parse, just as a parse tree of ?hucr,.@#%c|42ptqc$? that isolates ?42? as a single expr (or any other parse tree in this particular case) is invalid. >>> Actually, you were arguing against my statement that string literals are >>> expressions (that a string literal is an expression). You claimed, >>> rather explicitly, that they were not. See above. >> >> I have no idea what point you're trying to convey here. > > Is the ?See above? not enough a reference? I get the connection between what you wrote here and what you wrote above. I don't get the connection between what I wrote (that has now been trimmed away) and what you wrote in response to it. My parenthetical about parsing STRINGs in isolation was not in itself an argument against what you wrote. It was in fact agreeing, within a limited context. From __peter__ at web.de Tue Mar 31 04:22:46 2015 From: __peter__ at web.de (Peter Otten) Date: Tue, 31 Mar 2015 10:22:46 +0200 Subject: Using csv DictWriter - add a extra field References: Message-ID: Victor Hooi wrote: > Hi, > > I have a dict named "connections", with items like the following: > > In [18]: connections > Out[18]: > {'3424234': {'end_timestamp': datetime.datetime(2015, 3, 25, 5, 31, 30, > {406000, tzinfo=datetime.timezone(datetime.timedelta(-1, 61200))), > 'ip_address': '10.168.8.36:52440', > 'open_timestamp': datetime.datetime(2015, 3, 25, 5, 31, 0, 383000, > tzinfo=datetime.timezone(datetime.timedelta(-1, 61200))), 'time_open': > datetime.timedelta(0, 30, 23000)}} > > In this case, the key is a connection id (e.g. "3424234"), and the value > is a another dict, which contains things like 'end_timestamp', > 'ip_address" etc. > > I'm writing the output of "connections" to a CSV file using DictWriter: > > fieldnames = ['connection_id', 'ip_address', 'open_timestamp', > 'end_timestamp', 'time_open'] with open('output.csv', 'w') as csvfile: > writer = DictWriter(csvfile, fieldnames) > writer.writeheader() > for connection, values in sorted(connections.items()): > if 'time_open' in values: > writer.writerow(values, {'connection_id': connection}) > else: > pass > # DO SOME STUFF > > The only problem is, I'd also like output the connection_id field as part > of each CSV record. > > However, connection_id in this case is the key for the parent dict. > > Is there a clean way to add a extra field to DictWriter writerows, or it > is the contents of the dict and that's it? The latter. The obvious solution is to add the extra field to the dict: values['connection_id'] = connection writer.writerow(values) Or you use a collections.ChainMap (Python 3 only I think, but should work as well here) writer.writerow( collections.ChainMap(values, {"connection_id": connection})) From victorhooi at gmail.com Tue Mar 31 04:41:04 2015 From: victorhooi at gmail.com (Victor Hooi) Date: Tue, 31 Mar 2015 01:41:04 -0700 (PDT) Subject: Using csv DictWriter - add a extra field In-Reply-To: References: Message-ID: <62ae3aca-dcc4-45be-ba2f-c575bb08b7b3@googlegroups.com> Hi, Aha, yeah, I can add the connection_id as another field in the inner dict - the only drawback is that the data is duplicated twice. However, I suppose even if it's not elegant, it does work. However, that ChainMap does look interesting =). And yes, I am actually using Python 3.x (mainly because of http://bugs.python.org/issue6641). So if I understand correctly, I can just use ChainMap to join any arbitrary number of dicts together - it seems like the right solution here. Are there any drawbacks to using ChainMap here? (Aside from needing Python 3.x). Cheers, Victor From __peter__ at web.de Tue Mar 31 05:03:36 2015 From: __peter__ at web.de (Peter Otten) Date: Tue, 31 Mar 2015 11:03:36 +0200 Subject: Using csv DictWriter - add a extra field References: <62ae3aca-dcc4-45be-ba2f-c575bb08b7b3@googlegroups.com> Message-ID: Victor Hooi wrote: > Aha, yeah, I can add the connection_id as another field in the inner dict > - the only drawback is that the data is duplicated twice. However, I > suppose even if it's not elegant, it does work. The elegance lies in its simplicity, so it's still my personal favourite. > However, that ChainMap does look interesting =). And yes, I am actually > using Python 3.x (mainly because of http://bugs.python.org/issue6641). > > So if I understand correctly, I can just use ChainMap to join any > arbitrary number of dicts together - it seems like the right solution > here. > > Are there any drawbacks to using ChainMap here? (Aside from needing Python > 3.x). As it introduces another level of indirection it costs a little time, but compared to the actual I/O that should be negligible. So no, if there is a drawback I don't see it. From ahlusar.ahluwalia at gmail.com Tue Mar 31 07:00:46 2015 From: ahlusar.ahluwalia at gmail.com (Saran A) Date: Tue, 31 Mar 2015 04:00:46 -0700 (PDT) Subject: Strategy/ Advice for How to Best Attack this Problem? In-Reply-To: References: <87a8yvs34u.fsf@jester.gateway.pace.com> Message-ID: <0623f75c-bf93-4a0f-9d87-86986185cdc3@googlegroups.com> On Monday, March 30, 2015 at 2:36:02 PM UTC-4, Dave Angel wrote: > On 03/30/2015 12:45 PM, Saran A wrote: > > On Sunday, March 29, 2015 at 10:04:45 PM UTC-4, Chris Angelico wrote: > >> On Mon, Mar 30, 2015 at 12:08 PM, Paul Rubin wrote: > >>> Saran Ahluwalia writes: > >>>> cross-platform... > >>>> * Monitors a folder for files that are dropped throughout the day > >>> > >>> I don't see a cross-platform way to do that other than by waking up and > >>> scanning the folder every so often (once a minute, say). The Linux way > >>> is with inotify and there's a Python module for it (search terms: python > >>> inotify). There might be comparable but non-identical interfaces for > >>> other platforms. > >> > >> All too often, "cross-platform" means probing for one option, then > >> another, then another, and using whichever one you can. On Windows, > >> there's FindFirstChangeNotification and ReadDirectoryChanges, which > >> Tim Golden wrote about, and which I coded up into a teleporter for > >> getting files out of a VM automatically: > >> > >> http://timgolden.me.uk/python/win32_how_do_i/watch_directory_for_changes.html > >> https://github.com/Rosuav/shed/blob/master/senddir.py > >> > >> ChrisA > > > > @Dave, Chris, Paul and Dennis: Thank you for resources and the notes regarding what I should keep in mind. I have an initial commit: https://github.com/ahlusar1989/IntroToPython/blob/master/Project1WG_with_assumptions_and_comments.py > > > > I welcome your thoughts on this > > > > It's missing a number of your requirements. But it's a start. > > If it were my file, I'd have a TODO comment at the bottom stating known > changes that are needed. In it, I'd mention: > > 1) your present code is assuming all filenames come directly from the > commandline. No searching of a directory. > > 2) your present code does not move any files to success or failure > directories > > 3) your present code doesn't calculate or write to a text file any > statistics. > > 4) your present code runs once through the names, and terminates. It > doesn't "monitor" anything. > > 5) your present code doesn't check for zero-length files > > I'd also wonder why you bother checking whether the > os.path.getsize(file) function returns the same value as the os.SEEK_END > and ftell() code does. Is it that you don't trust the library? Or that > you have to run on Windows, where the line-ending logic can change the > apparent file size? > > I notice you're not specifying a file mode on the open. So in Python 3, > your sizes are going to be specified in unicode characters after > decoding. Is that what the spec says? It's probably safer to > explicitly specify the mode (and the file encoding if you're in text). > > I see you call strip() before comparing the length. Could there ever be > leading or trailing whitespace that's significant? Is that the actual > specification of line size? > > -- > DaveA @ Dave A On Monday, March 30, 2015 at 2:36:02 PM UTC-4, Dave Angel wrote: > On 03/30/2015 12:45 PM, Saran A wrote: > > On Sunday, March 29, 2015 at 10:04:45 PM UTC-4, Chris Angelico wrote: > >> On Mon, Mar 30, 2015 at 12:08 PM, Paul Rubin wrote: > >>> Saran Ahluwalia writes: > >>>> cross-platform... > >>>> * Monitors a folder for files that are dropped throughout the day > >>> > >>> I don't see a cross-platform way to do that other than by waking up and > >>> scanning the folder every so often (once a minute, say). The Linux way > >>> is with inotify and there's a Python module for it (search terms: python > >>> inotify). There might be comparable but non-identical interfaces for > >>> other platforms. > >> > >> All too often, "cross-platform" means probing for one option, then > >> another, then another, and using whichever one you can. On Windows, > >> there's FindFirstChangeNotification and ReadDirectoryChanges, which > >> Tim Golden wrote about, and which I coded up into a teleporter for > >> getting files out of a VM automatically: > >> > >> http://timgolden.me.uk/python/win32_how_do_i/watch_directory_for_changes.html > >> https://github.com/Rosuav/shed/blob/master/senddir.py > >> > >> ChrisA > > > > @Dave, Chris, Paul and Dennis: Thank you for resources and the notes regarding what I should keep in mind. I have an initial commit: https://github.com/ahlusar1989/IntroToPython/blob/master/Project1WG_with_assumptions_and_comments.py > > > > I welcome your thoughts on this > > > > It's missing a number of your requirements. But it's a start. > > If it were my file, I'd have a TODO comment at the bottom stating known > changes that are needed. In it, I'd mention: > > 1) your present code is assuming all filenames come directly from the > commandline. No searching of a directory. > > 2) your present code does not move any files to success or failure > directories > > 3) your present code doesn't calculate or write to a text file any > statistics. > > 4) your present code runs once through the names, and terminates. It > doesn't "monitor" anything. > > 5) your present code doesn't check for zero-length files > > I'd also wonder why you bother checking whether the > os.path.getsize(file) function returns the same value as the os.SEEK_END > and ftell() code does. Is it that you don't trust the library? Or that > you have to run on Windows, where the line-ending logic can change the > apparent file size? > > I notice you're not specifying a file mode on the open. So in Python 3, > your sizes are going to be specified in unicode characters after > decoding. Is that what the spec says? It's probably safer to > explicitly specify the mode (and the file encoding if you're in text). > > I see you call strip() before comparing the length. Could there ever be > leading or trailing whitespace that's significant? Is that the actual > specification of line size? > > -- > DaveA @DaveA: This is a homework assignment. As someone is not familiar (I have only been programming for 8 months) with best practice for writing to files, appending to folders and searching a directory. Is it possible that you could provide me with some snippets or guidance on where to place your suggestions (for your TO DOs 2,3,4,5)? I ask this because I have been searching fruitlessly through for some time and there are so many permutations that I am bamboozled by which is considered best practice. Moreover, as to the other comments, those are too specific. The scope of the assignment is very limited, but I am learning what I need to look out or ask questions regarding specs - in the future. From cloverobert at gmail.com Tue Mar 31 07:23:08 2015 From: cloverobert at gmail.com (Robert Clove) Date: Tue, 31 Mar 2015 16:53:08 +0530 Subject: Project, how to debug Message-ID: Hi All, I am facing a problem. I have been given a project written in python and asked to debug it. I have not been given the flow they said understand and debug. Can someone suggest me how to debug it in Wings IDE. Project have approx 10 files. Regards -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Tue Mar 31 07:38:17 2015 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 31 Mar 2015 13:38:17 +0200 (CEST) Subject: A simple single line, triple-quoted comment is giving syntax error. Why? In-Reply-To: Message-ID: <2111451009.4983144.1427801897410.JavaMail.root@sequans.com> ----- Original Message ----- > From: "Terry Reedy" > To: python-list at python.org > Sent: Wednesday, 18 March, 2015 10:47:40 PM > Subject: Re: A simple single line, triple-quoted comment is giving syntax error. Why? > > On 3/18/2015 3:53 PM, Thomas 'PointedEars' Lahn wrote: > > > I must strongly object and recommend against getting accustomed to > > the > > suggested use of multi-line string literals. > > I agree. I remember loosing a lot of time finding a bug that can be summarized like this (immagine a much larger list where the temptation of commenting a block is high): a = [ '1', '''shorten the list to speedup tests '2', '3', ''' '4', ] print a >>> ['1', "shorten the list to speedup tests\n\t\t'2',\n\t\t'3',\n4"] JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From __peter__ at web.de Tue Mar 31 07:49:32 2015 From: __peter__ at web.de (Peter Otten) Date: Tue, 31 Mar 2015 13:49:32 +0200 Subject: Project, how to debug References: Message-ID: Robert Clove wrote: > Hi All, > > I am facing a problem. > I have been given a project written in python and asked to debug it. > I have not been given the flow they said understand and debug. > > Can someone suggest me how to debug it in Wings IDE. Are those specific bugs that you are supposed to fix or are you to both find and fix bugs? > Project have approx 10 files. Generally speaking speaking this is not so much a matter of tools; if there is any documentation you can trust reading that is usually the best start; reading the code is important, too. Then you can consider your next steps depending on the "messiness" of the code base and the degree of coverage with unit tests. From rosuav at gmail.com Tue Mar 31 07:53:07 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 31 Mar 2015 22:53:07 +1100 Subject: Project, how to debug In-Reply-To: References: Message-ID: On Tue, Mar 31, 2015 at 10:23 PM, Robert Clove wrote: > > I am facing a problem. > I have been given a project written in python and asked to debug it. > I have not been given the flow they said understand and debug. > > Can someone suggest me how to debug it in Wings IDE. > Project have approx 10 files. Hi, sounds like this is a homework assignment. I don't know the IDE, so I'll just give some basic debugging advice. Most of this isn't even specific to Python - it's simply how you go about figuring out where a problem is in a piece of code. The first step is *always* to find out what the code ought to be doing. Should it be firing up a server of some sort? Running, performing some task, and terminating? Producing output on the console (stdout/stderr)? Bringing up a graphical window? If you don't already know, you might be able to find out from hints in the code itself - comments at the top, function names, string literals, that kind of thing. Otherwise, ask someone. You can't assess whether the code's doing the right thing or not without knowing what "the right thing" means. (Parenthesis: Some people think that a program crash is "the wrong thing" and the program not crashing is "the right thing". This is often enough true that it's very tempting, but if you believe your job is to stop the program crashing, then all you have to do is remove code until the failing part is gone. The result might not achieve anything, but hey! It's not crashing, right? You need to start by knowing what actual goal to not-remove. Also, sometimes it's absolutely right for a program to throw an exception; a test script for PEP 479 is simply probing to see which of two exceptions it gets, and "success" is defined by getting a RuntimeError. End of parenthesis.) Once you know what the code ought to do, check to see whether you trust the code enough to run it. In your case, you can probably trust the code-provider to not have anything openly malicious in the code, but otherwise, you'll need to look through the code, or run it in some specialized environment like a virtual machine, or something like that, to protect yourself. Remember, you're running code that someone else gave you, and it's buggy. If the program's purpose is "delete unnecessary files from your hard disk", then you want to be VERY careful with it - one small bug, and it might wipe out a whole lot of actively-used files. Just ask any sysadmin about the time he typed "rm * .pyc" or equivalent. So, you know what the program should do, and you either trust the code, or have taken measures to protect yourself. Great! Now comes the simple part: Run the program, see if it's doing what it should, and if not, change something. Repeat until success. 'Course, I never said it was easy. Just simple. :) Chances are you don't have enough information to know WHY it isn't doing what it should, though, and that's where most of what people talk of "debugging techniques" comes in. Your IDE might let you single-step through the code, place breakpoints, and all sorts of other fancy things; if so, use as many of those features as you're comfortable with, and ignore the rest. Your basic debugging technique will usually come down to one thing: Find out what the program's doing at . And the simplest and most basic form of that is what I call IIDPIO debugging: If In Doubt, Print It Out. Just add print() calls to key parts of the code, reporting on the contents of variables, or just announcing that control flow reached a certain point. It's amazing how easy a debugging job can become when you just get a little more info out of it. Give that a try, and see how you go. If symptoms persist, see your teacher. ChrisA From cloverobert at gmail.com Tue Mar 31 08:05:15 2015 From: cloverobert at gmail.com (Robert Clove) Date: Tue, 31 Mar 2015 17:35:15 +0530 Subject: Project, how to debug In-Reply-To: References: Message-ID: On Tue, Mar 31, 2015 at 5:19 PM, Peter Otten <__peter__ at web.de> wrote: > Robert Clove wrote: > > > Hi All, > > > > I am facing a problem. > > I have been given a project written in python and asked to debug it. > > I have not been given the flow they said understand and debug. > > > > Can someone suggest me how to debug it in Wings IDE. > > Are those specific bugs that you are supposed to fix or are you to both > find > and fix bugs? > > > Project have approx 10 files. > > Generally speaking speaking this is not so much a matter of tools; if there > is any documentation you can trust reading that is usually the best start; > reading the code is important, too. > > Then you can consider your next steps depending on the "messiness" of the > code base and the degree of coverage with unit tests. > > > -- > https://mail.python.org/mailman/listinfo/python-list > There is no documentation provided i have to read the code understand the flow first. -------------- next part -------------- An HTML attachment was scrubbed... URL: From albert at spenarnc.xs4all.nl Tue Mar 31 08:57:35 2015 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 31 Mar 2015 12:57:35 GMT Subject: generator/coroutine terminology References: <5503cf5f$0$12985$c3e8da3$5496439d@news.astraweb.com> <83d579c1-ab61-4a3d-a834-e65d28eace8a@googlegroups.com> Message-ID: <551a99bf$0$2987$e4fe514c@dreader35.news.xs4all.nl> In article <83d579c1-ab61-4a3d-a834-e65d28eace8a at googlegroups.com>, Rustom Mody wrote: >On Saturday, March 14, 2015 at 8:59:22 PM UTC+5:30, Rustom Mody wrote: >> On Saturday, March 14, 2015 at 11:34:27 AM UTC+5:30, Steven D'Aprano wrote: >> > >> > A generator (function) may be a function which returns an iterator,... >> >> I find "generator-function" misleading in the same way that "pineapple" >> misleadingly suggests "apple that grows on pines" >> >> A builtin function is a function in the builtin (or builtins -- can >never remember) module >> A pure function is function that does not assign or mutate non-locals >> A Steven-function is a function that presumably Steven wrote >> >> However a "generator function" is a weird sort of function (at best). >> Not regarding it as a function is IMO more reasonable. > >Another analogy somewhat closer home than pineapples. >In Pascal there are procedures and functions. >Even in the venerable Fortran there are subroutine-subprogram and >(sub)function-subprogram. The Algol 68 designers considered it a defect in the design. They created a situation like in Python, where a "def"-thingy need not return a value. > >C took the stupid approach of just throwing out one of these. >A decade of troubles was enough to convince people that it was needed and the >mysterious 'void-returning' function was introduced to simulate procedures The mistake this was intended to fix, was the rule that by default a function returns int in C. Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From cloverobert at gmail.com Tue Mar 31 09:02:58 2015 From: cloverobert at gmail.com (Robert Clove) Date: Tue, 31 Mar 2015 18:32:58 +0530 Subject: Python regex exercise Message-ID: Hi All, Do anyone have good links to python regex or other python problems for beginners but with solution. Please mail me. Regards -------------- next part -------------- An HTML attachment was scrubbed... URL: From albert at spenarnc.xs4all.nl Tue Mar 31 09:18:54 2015 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 31 Mar 2015 13:18:54 GMT Subject: generator/coroutine terminology References: <87y4mznmj8.fsf@elektro.pacujo.net> <55062bda$0$12998$c3e8da3$5496439d@news.astraweb.com> Message-ID: <551a9ebe$0$2987$e4fe514c@dreader35.news.xs4all.nl> In article <55062bda$0$12998$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: >Marko Rauhamaa wrote: > >> Chris Angelico : >> >>> On Sun, Mar 15, 2015 at 9:15 AM, Marko Rauhamaa wrote: >>>> Is it necessary/useful for a Python application programmer to be >>>> conscious of the different types of iterator? What mistaken usage >>>> could arise if the application just treated all iterators as, well, >>>> iterators? >>> >>> If you treat them all as iterators, then you're safe, because that's >>> the lowest common denominator. But there are a number of other >>> iterators that have more features, including files, generators, etc. >> >> What features do generator iterators provide on top of generic >> iterators? > >The biggest difference is syntactic. Here's an iterator which returns a >never-ending sequence of squared numbers 1, 4, 9, 16, ... > >class Squares: > def __init__(self): > self.i = 0 > def __next__(self): > self.i += 1 > return self.i**2 > def __iter__(self): > return self You should give an example of usage. As a newby I'm not up to figuring out the specification from source for something built of the mysterious __ internal thingies. (I did experiment with Squares interactively. But I didn't get further than creating a Squares object.) > > >Here's the same thing written as a generator: > >def squares(): > i = 1 > while True: > yield i**2 > i += 1 > > >Four lines, versus eight. The iterator version has a lot of boilerplate >(although some of it, the two-line __iter__ method, could be eliminated if >there was a standard Iterator builtin to inherit from). > >Here's a more complicated example: > >class Randoms: > def __init__(self): > self.finished = False > def __next__(self): > x = random.random() > if x > 0.5: > self.finished = True > if self.finished: > raise StopIteration > else: > return x > def __iter__(self): > return self > > >def randoms(): > x = random.random() > while x < 0.5: > yield x > x = random.random() > > >Generators, as a rule, are significantly easier to write, understand, and >debug. There's nothing they can do that can't be done with an iterator >class, but the fiddly, unexciting bits related to halting and resuming and >saving state are all handled for you, allowing you to concentrate on the >behaviour you want, not the boilerplate. This is illuminating. Thanks. > >-- >Steven Groetjes Albert > -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From davea at davea.name Tue Mar 31 09:19:06 2015 From: davea at davea.name (Dave Angel) Date: Tue, 31 Mar 2015 09:19:06 -0400 Subject: Strategy/ Advice for How to Best Attack this Problem? In-Reply-To: <0623f75c-bf93-4a0f-9d87-86986185cdc3@googlegroups.com> References: <87a8yvs34u.fsf@jester.gateway.pace.com> <0623f75c-bf93-4a0f-9d87-86986185cdc3@googlegroups.com> Message-ID: <551A9ECA.1000009@davea.name> On 03/31/2015 07:00 AM, Saran A wrote: > @DaveA: This is a homework assignment. .... Is it possible that you could provide me with some snippets or guidance on where to place your suggestions (for your TO DOs 2,3,4,5)? > > On Monday, March 30, 2015 at 2:36:02 PM UTC-4, Dave Angel wrote: >> >> It's missing a number of your requirements. But it's a start. >> >> If it were my file, I'd have a TODO comment at the bottom stating known >> changes that are needed. In it, I'd mention: >> >> 1) your present code is assuming all filenames come directly from the >> commandline. No searching of a directory. >> >> 2) your present code does not move any files to success or failure >> directories >> In function validate_files() Just after the line print('success with %s on %d reco... you could move the file, using shutil. Likewise after the failure print. >> 3) your present code doesn't calculate or write to a text file any >> statistics. You successfully print to sys.stderr. So you could print to some other file in the exact same way. >> >> 4) your present code runs once through the names, and terminates. It >> doesn't "monitor" anything. Make a new function, perhaps called main(), with a loop that calls validate_files(), with a sleep after each pass. Of course, unless you fix TODO#1, that'll keep looking for the same files. No harm in that if that's the spec, since you moved the earlier versions of the files. But if you want to "monitor" the directory, let the directory name be the argument to main, and let main do a dirlist each time through the loop, and pass the corresponding list to validate_files. >> >> 5) your present code doesn't check for zero-length files >> In validate_and_process_data(), instead of checking filesize against ftell, check it against zero. >> I'd also wonder why you bother checking whether the >> os.path.getsize(file) function returns the same value as the os.SEEK_END >> and ftell() code does. Is it that you don't trust the library? Or that >> you have to run on Windows, where the line-ending logic can change the >> apparent file size? >> >> I notice you're not specifying a file mode on the open. So in Python 3, >> your sizes are going to be specified in unicode characters after >> decoding. Is that what the spec says? It's probably safer to >> explicitly specify the mode (and the file encoding if you're in text). >> >> I see you call strip() before comparing the length. Could there ever be >> leading or trailing whitespace that's significant? Is that the actual >> specification of line size? >> >> -- >> DaveA > > > I ask this because I have been searching fruitlessly through for some time and there are so many permutations that I am bamboozled by which is considered best practice. > > Moreover, as to the other comments, those are too specific. The scope of the assignment is very limited, but I am learning what I need to look out or ask questions regarding specs - in the future. > -- DaveA From subhabrata.banerji at gmail.com Tue Mar 31 09:20:01 2015 From: subhabrata.banerji at gmail.com (subhabrata.banerji at gmail.com) Date: Tue, 31 Mar 2015 06:20:01 -0700 (PDT) Subject: How to handle file in Whoosh? Message-ID: <23b11937-781e-473b-ba6e-9b5d68b8ebbd@googlegroups.com> I am trying to build a search engine, I started with Whoosh. The tutorial and web based materials are fine. Web has sizable question and answers. The initial experiments seem going fine. But I want to handle files located in various parts of my machine. I found "from whoosh.filedb.filestore import FileStorage", but I am looking for a simple example to start with. I tried something as below, it may be giving some result but is it going okay? If any one may please see and correct if required? >>> txt_file1=open("/python27/whooshtext1.txt","r").read() >>> txt_file2=open("/python27/whooshtext3.txt","r").read() >>> writer.add_document(title=u"First document", path= unicode("indexdir"+os.sep+"a"),content=u"txt_file1") >>> writer.add_document(title=u"Second document", path= unicode("indexdir"+os.sep+"b"),content=u"txt_file2") >>> writer.commit() >>> with ix.searcher() as searcher: query = QueryParser("content", ix.schema).parse("flood") results = searcher.search(query) print results for result in results: print result >>> From davea at davea.name Tue Mar 31 09:38:16 2015 From: davea at davea.name (Dave Angel) Date: Tue, 31 Mar 2015 09:38:16 -0400 Subject: generator/coroutine terminology In-Reply-To: <551a9ebe$0$2987$e4fe514c@dreader35.news.xs4all.nl> References: <87y4mznmj8.fsf@elektro.pacujo.net> <55062bda$0$12998$c3e8da3$5496439d@news.astraweb.com> <551a9ebe$0$2987$e4fe514c@dreader35.news.xs4all.nl> Message-ID: <551AA348.9070209@davea.name> On 03/31/2015 09:18 AM, Albert van der Horst wrote: > In article <55062bda$0$12998$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: >> >> The biggest difference is syntactic. Here's an iterator which returns a >> never-ending sequence of squared numbers 1, 4, 9, 16, ... >> >> class Squares: >> def __init__(self): >> self.i = 0 >> def __next__(self): >> self.i += 1 >> return self.i**2 >> def __iter__(self): >> return self > > You should give an example of usage. As a newby I'm not up to > figuring out the specification from source for > something built of the mysterious __ internal > thingies. > (I did experiment with Squares interactively. But I didn't get > further than creating a Squares object.) > He did say it was an iterator. So for a first try, write a for loop: class Squares: def __init__(self): self.i = 0 def __next__(self): self.i += 1 return self.i**2 def __iter__(self): return self for i in Squares(): print(i) if i > 50: break print("done") > >> >> >> Here's the same thing written as a generator: >> >> def squares(): >> i = 1 >> while True: >> yield i**2 >> i += 1 >> >> >> Four lines, versus eight. The iterator version has a lot of boilerplate >> (although some of it, the two-line __iter__ method, could be eliminated if >> there was a standard Iterator builtin to inherit from). >> -- DaveA From __peter__ at web.de Tue Mar 31 09:52:27 2015 From: __peter__ at web.de (Peter Otten) Date: Tue, 31 Mar 2015 15:52:27 +0200 Subject: How to handle file in Whoosh? References: <23b11937-781e-473b-ba6e-9b5d68b8ebbd@googlegroups.com> Message-ID: subhabrata.banerji at gmail.com wrote: > I am trying to build a search engine, I started with Whoosh. The tutorial and web based materials are fine. Web has sizable question and answers. The initial experiments seem going fine. But I want to handle files located in various parts of my machine. I found "from whoosh.filedb.filestore import FileStorage", but I am looking for a simple example to start with. I tried something as below, it may be giving some result but is it going okay? If any one may please see and correct if required? > > >>> txt_file1=open("/python27/whooshtext1.txt","r").read() > >>> txt_file2=open("/python27/whooshtext3.txt","r").read() > >>> writer.add_document(title=u"First document", path= unicode("indexdir"+os.sep+"a"),content=u"txt_file1") I'm not a whoosh user myself, but if I were to guess: The content argument should contain the contents of the file, not the variable name, e. g.: import io ... ENCODING = "ascii" # replace with actual encoding of the file txt_file1 = io.open("/python27/whooshtext1.txt", encoding=ENCODING).read() ... writer.add_document( title=u"First document", path=os.path.join(u"indexdir", u"a"), content=txt_file1) > >>> writer.add_document(title=u"Second document", path= unicode("indexdir"+os.sep+"b"),content=u"txt_file2") > >>> writer.commit() > >>> with ix.searcher() as searcher: > query = QueryParser("content", ix.schema).parse("flood") > results = searcher.search(query) > print results > for result in results: > print result > > > u"flood" is indeed not in the string u"txt_file2" nor the string u"txt_file1", so that's the expected number of matches. From airween at gmail.com Tue Mar 31 10:50:12 2015 From: airween at gmail.com (Ervin =?utf-8?Q?Heged=C3=BCs?=) Date: Tue, 31 Mar 2015 16:50:12 +0200 Subject: Lockfile hanling Message-ID: <20150331145012.GA4460@arxnet.hu> Hello, there is an app, written in Python, which stores few bytes of datas in a single file. The application uses threads. Every thread can modify the file, but only one at a time. I'm using a lock file to prevent the multiple access. Here is the lock method: while True: try: fl = os.open(self.lockfile, os.O_CREAT | os.O_EXCL | os.O_RDWR) except OSError, e: if e.errno != errno.EEXIST: raise time.sleep(0.2) continue except: syslog.syslog(syslog.LOG_DEBUG, "Sync error: " + str(sys.exc_info()[1])) else: break This works as well for me - about 3-4 weeks. After some weeks, I got this error: OSError: [Errno 24] Too many open files: '/var/spool/myapp/queue.lock' Today the app had been restarted, about 3-4 hours ago. Now I see under the proc/PID/fd: lrwx------ 1 root root 64 m?rc 31 16.45 5 -> /var/spool/myapp/queue.lock (deleted) there are about 50 deleted FD's. After few weeks the process reaches the number if max fd's. How can I prevent or avoid this issue? What's the correct way to handle the lockfile in Python? Thanks, Ervin From skip.montanaro at gmail.com Tue Mar 31 10:55:57 2015 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Tue, 31 Mar 2015 09:55:57 -0500 Subject: Lockfile hanling In-Reply-To: <20150331145012.GA4460@arxnet.hu> References: <20150331145012.GA4460@arxnet.hu> Message-ID: On Tue, Mar 31, 2015 at 9:50 AM, Ervin Heged?s wrote: > After few weeks the process > reaches the number if max fd's. > > How can I prevent or avoid this issue? What's the correct way to > handle the lockfile in Python? Ervin, You need to close the files you open. I don't see that happening in your code snippet. You might consider the pylockfile module, available from PyPI: https://pypi.python.org/pypi/lockfile (I'm the original author, though others have taken it over.) Skip From albert at spenarnc.xs4all.nl Tue Mar 31 11:03:21 2015 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 31 Mar 2015 15:03:21 GMT Subject: generator/coroutine terminology References: <55062bda$0$12998$c3e8da3$5496439d@news.astraweb.com> <551a9ebe$0$2987$e4fe514c@dreader35.news.xs4all.nl> Message-ID: <551ab739$0$3042$e4fe514c@dreader35.news.xs4all.nl> In article , Dave Angel wrote: >On 03/31/2015 09:18 AM, Albert van der Horst wrote: >> In article <55062bda$0$12998$c3e8da3$5496439d at news.astraweb.com>, >> Steven D'Aprano wrote: > >>> >>> The biggest difference is syntactic. Here's an iterator which returns a >>> never-ending sequence of squared numbers 1, 4, 9, 16, ... >>> >>> class Squares: >>> def __init__(self): >>> self.i = 0 >>> def __next__(self): >>> self.i += 1 >>> return self.i**2 >>> def __iter__(self): >>> return self >> >> You should give an example of usage. As a newby I'm not up to >> figuring out the specification from source for >> something built of the mysterious __ internal >> thingies. >> (I did experiment with Squares interactively. But I didn't get >> further than creating a Squares object.) >> > >He did say it was an iterator. So for a first try, write a for loop: > >class Squares: > def __init__(self): > self.i = 0 > def __next__(self): > self.i += 1 > return self.i**2 > def __iter__(self): > return self > >for i in Squares(): > print(i) > if i > 50: > break > This is what I get: / -------------------------- albert at cherry:/tmp$ more aap.py class Squares: def __init__(self): self.i = 0 def __next__(self): self.i += 1 return self.i**2 def __iter__(self): return self albert at cherry:/tmp$ python Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from aap import * >>> for i in Squares(): ... print i ... if i>50: break ... Traceback (most recent call last): File "", line 1, in TypeError: instance has no next() method >>> / -------------------------- Probably not what is intended. Last minute note: renaming __next__() into next() did the job. >-- >DaveA Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From airween at gmail.com Tue Mar 31 11:06:56 2015 From: airween at gmail.com (Ervin =?utf-8?Q?Heged=C3=BCs?=) Date: Tue, 31 Mar 2015 17:06:56 +0200 Subject: Lockfile hanling In-Reply-To: References: <20150331145012.GA4460@arxnet.hu> Message-ID: <20150331150656.GA4740@arxnet.hu> Hi Skip, thanks for the reply, On Tue, Mar 31, 2015 at 09:55:57AM -0500, Skip Montanaro wrote: > On Tue, Mar 31, 2015 at 9:50 AM, Ervin Heged?s wrote: > > After few weeks the process > > reaches the number if max fd's. > > > > How can I prevent or avoid this issue? What's the correct way to > > handle the lockfile in Python? > > Ervin, > > You need to close the files you open. I don't see that happening in > your code snippet. sorry - at the end of the function there is a close() method to a file, after the thread passes the modifications: try: os.remove(self.lockfile) except: syslog.syslog(syslog.LOG_DEBUG, "Sync error: " + str(sys.exc_info()[1])) And I think, the "(deleted)" info near the filename in proc/PID/fd means the lockfile had been deleted. > You might consider the pylockfile module, available > from PyPI: > > https://pypi.python.org/pypi/lockfile > > (I'm the original author, though others have taken it over.) sounds good, thanks - what's the minimal version of Python? I've only 2.5 on that server... Regards, a. From skip.montanaro at gmail.com Tue Mar 31 11:19:27 2015 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Tue, 31 Mar 2015 10:19:27 -0500 Subject: Lockfile hanling In-Reply-To: <20150331150656.GA4740@arxnet.hu> References: <20150331145012.GA4460@arxnet.hu> <20150331150656.GA4740@arxnet.hu> Message-ID: > sorry - at the end of the function there is a close() method to a > file, after the thread passes the modifications: > > try: > os.remove(self.lockfile) > except: > syslog.syslog(syslog.LOG_DEBUG, "Sync error: " + str(sys.exc_info()[1])) Hmmm... Still not seeing os.close(fl)... > And I think, the "(deleted)" info near the filename in proc/PID/fd > means the lockfile had been deleted. os.remove() will remove the lockfile name from the directory. It doesn't automatically close the file. >> You might consider the pylockfile module... > sounds good, thanks - what's the minimal version of Python? I've > only 2.5 on that server... When I was still maintaining it, it worked with 2.5, and I distributed a patch you could apply to get it to work with 2.4. I'm not sure if the current maintainers have changed that. You'd have to look. If worse comes to worst, I believe 0.9.1 (the last version I released) should still work with 2.5. Skip From lynto28 at gmail.com Tue Mar 31 11:20:52 2015 From: lynto28 at gmail.com (Didymus) Date: Tue, 31 Mar 2015 08:20:52 -0700 (PDT) Subject: Logging Custom Levels? Message-ID: Hi, I've create a Python file called "log.py" and placed in the custom levels: # Performance Debug... logging.addLevelName(PDEBUG_NUM, "PDEBUG") def pdebug(self, message, *args, **kws): """ Performance Debug Message Level """ self.log(PDEBUG_NUM, message, *args, **kws) logging.Logger.pdebug = pdebug This works except that the %(module) and %(lineno) does not print properly, it instead prints out as the "log.py" and the line that this is on. I think I figured out a way to get the module and line from the calling custom level: import inspect frame = inspect.currentframe() filename = os.path.splitext(os.path.basename(frame.f_back.f_code.co_filename))[0] linenumber = frame.f_back.f_lineno My question is how do I pass this into the "self.log" call properly? I've tried a few different things without any luck. Any ideas how I can pass this into the custom logging level and get it to work? Thanks in Advance for any help! Tom From rosuav at gmail.com Tue Mar 31 11:36:50 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 1 Apr 2015 02:36:50 +1100 Subject: generator/coroutine terminology In-Reply-To: <551ab739$0$3042$e4fe514c@dreader35.news.xs4all.nl> References: <55062bda$0$12998$c3e8da3$5496439d@news.astraweb.com> <551a9ebe$0$2987$e4fe514c@dreader35.news.xs4all.nl> <551ab739$0$3042$e4fe514c@dreader35.news.xs4all.nl> Message-ID: On Wed, Apr 1, 2015 at 2:03 AM, Albert van der Horst wrote: > class Squares: > def __init__(self): > self.i = 0 > def __next__(self): > self.i += 1 > return self.i**2 > def __iter__(self): > return self > > albert at cherry:/tmp$ python > Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48) > [GCC 4.4.5] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> from aap import * >>>> for i in Squares(): > ... print i > ... if i>50: break > ... > Traceback (most recent call last): > File "", line 1, in > TypeError: instance has no next() method >>>> > > / -------------------------- > > Probably not what is intended. > > Last minute note: > renaming __next__() into next() did the job. That class was written for Python 3, not Python 2. In Py2, you need to rename __next__ to next, as you noted, and you probably also want to explicitly subclass object. Or just run it under Python 3. :) ChrisA From mmr15 at case.edu Tue Mar 31 11:50:06 2015 From: mmr15 at case.edu (Matthew Ruffalo) Date: Tue, 31 Mar 2015 11:50:06 -0400 Subject: Lockfile hanling In-Reply-To: <20150331145012.GA4460@arxnet.hu> References: <20150331145012.GA4460@arxnet.hu> Message-ID: <551AC22E.40209@case.edu> On 2015-03-31 10:50, Ervin Heged?s wrote: > there is an app, written in Python, which stores few bytes of > datas in a single file. The application uses threads. Every > thread can modify the file, but only one at a time. I'm using a > lock file to prevent the multiple access. > > ... > > How can I prevent or avoid this issue? What's the correct way to > handle the lockfile in Python? Hi Ervin- If only one instance of the app is running at a given time, and you only need to ensure mutual exclusion between its threads, you should probably not use a lock *file* for this. I would strongly recommend that you use a threading.Lock as per https://docs.python.org/2.5/lib/module-threading.html instead of a lock file. This will also allow you to avoid a 0.2-second polling loop; a call to threading.Lock.acquire() will block until it is released by another thread. MMR... From airween at gmail.com Tue Mar 31 11:56:26 2015 From: airween at gmail.com (Ervin =?utf-8?Q?Heged=C3=BCs?=) Date: Tue, 31 Mar 2015 17:56:26 +0200 Subject: Lockfile hanling In-Reply-To: References: <20150331145012.GA4460@arxnet.hu> <20150331150656.GA4740@arxnet.hu> Message-ID: <20150331155626.GA5536@arxnet.hu> Hi Skip, On Tue, Mar 31, 2015 at 10:19:27AM -0500, Skip Montanaro wrote: > > sorry - at the end of the function there is a close() method to a > > file, after the thread passes the modifications: > > > > try: > > os.remove(self.lockfile) > > except: > > syslog.syslog(syslog.LOG_DEBUG, "Sync error: " + str(sys.exc_info()[1])) > > Hmmm... Still not seeing os.close(fl)... > > > And I think, the "(deleted)" info near the filename in proc/PID/fd > > means the lockfile had been deleted. > > os.remove() will remove the lockfile name from the directory. It > doesn't automatically close the file. ah, well, many-many-many thanks - that was what I misses... > >> You might consider the pylockfile module... > > > sounds good, thanks - what's the minimal version of Python? I've > > only 2.5 on that server... > > When I was still maintaining it, it worked with 2.5, and I distributed > a patch you could apply to get it to work with 2.4. I'm not sure if > the current maintainers have changed that. You'd have to look. If > worse comes to worst, I believe 0.9.1 (the last version I released) > should still work with 2.5. thanks for the info - now it works as very well. a. From airween at gmail.com Tue Mar 31 11:58:09 2015 From: airween at gmail.com (Ervin =?utf-8?Q?Heged=C3=BCs?=) Date: Tue, 31 Mar 2015 17:58:09 +0200 Subject: Lockfile hanling In-Reply-To: <551AC22E.40209@case.edu> References: <20150331145012.GA4460@arxnet.hu> <551AC22E.40209@case.edu> Message-ID: <20150331155809.GB5536@arxnet.hu> Hi Matthew, On Tue, Mar 31, 2015 at 11:50:06AM -0400, Matthew Ruffalo wrote: > On 2015-03-31 10:50, Ervin Heged?s wrote: > > there is an app, written in Python, which stores few bytes of > > datas in a single file. The application uses threads. Every > > thread can modify the file, but only one at a time. I'm using a > > lock file to prevent the multiple access. > > > > ... > > > > How can I prevent or avoid this issue? What's the correct way to > > handle the lockfile in Python? > > Hi Ervin- > > If only one instance of the app is running at a given time, and you only > need to ensure mutual exclusion between its threads, you should probably > not use a lock *file* for this. I would strongly recommend that you use > a threading.Lock as per > https://docs.python.org/2.5/lib/module-threading.html instead of a lock > file. This will also allow you to avoid a 0.2-second polling loop; a > call to threading.Lock.acquire() will block until it is released by > another thread. > > MMR... thanks, I hope in the next version I can try this :) a. From jkellymdmph at yahoo.com Tue Mar 31 13:09:00 2015 From: jkellymdmph at yahoo.com (John Kelly) Date: Tue, 31 Mar 2015 17:09:00 +0000 (UTC) Subject: Quick question, if you please Message-ID: <1321280748.2187367.1427821740602.JavaMail.yahoo@mail.yahoo.com> Pythonites, I received Python with another install and my update software keeps signaling I need to install a newer version, and once I do, the older version is still there, so I keep getting told I need to update. Should I be able to uninstall the old version each time? Thanks for your kind attention,John Kelly -------------- next part -------------- An HTML attachment was scrubbed... URL: From rowen at uw.edu Tue Mar 31 13:29:27 2015 From: rowen at uw.edu (Russell Owen) Date: Tue, 31 Mar 2015 10:29:27 -0700 Subject: Quick question, if you please In-Reply-To: <1321280748.2187367.1427821740602.JavaMail.yahoo@mail.yahoo.com> References: <1321280748.2187367.1427821740602.JavaMail.yahoo@mail.yahoo.com> Message-ID: On 3/31/15 10:09 AM, John Kelly wrote: > Pythonites, > > I received Python with another install and my update software keeps > signaling I need to install a newer version, and once I do, the older > version is still there, so I keep getting told I need to update. Should > I be able to uninstall the old version each time? > > Thanks for your kind attention, > John Kelly I would need more information to help. What operating system are you on? How and where are you installing Python (and what do you mean by "received Python with another install"?). -- Russell From jeanmichel at sequans.com Tue Mar 31 13:37:13 2015 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 31 Mar 2015 19:37:13 +0200 (CEST) Subject: Logging Custom Levels? In-Reply-To: Message-ID: <1571503270.5030514.1427823433679.JavaMail.root@sequans.com> ----- Original Message ----- > From: "Didymus" > To: python-list at python.org > Sent: Tuesday, 31 March, 2015 5:20:52 PM > Subject: Logging Custom Levels? > > Hi, > > I've create a Python file called "log.py" and placed in the custom > levels: > > # Performance Debug... > logging.addLevelName(PDEBUG_NUM, "PDEBUG") > > def pdebug(self, message, *args, **kws): > """ Performance Debug Message Level """ > self.log(PDEBUG_NUM, message, *args, **kws) > > logging.Logger.pdebug = pdebug > > > This works except that the %(module) and %(lineno) does not print > properly, it instead prints out as the "log.py" and the line that > this is on. I think I figured out a way to get the module and line > from the calling custom level: > > import inspect > frame = inspect.currentframe() > filename = > os.path.splitext(os.path.basename(frame.f_back.f_code.co_filename))[0] > linenumber = frame.f_back.f_lineno > > > My question is how do I pass this into the "self.log" call properly? > I've tried a few different things without any luck. Any ideas how I > can pass this into the custom logging level and get it to work? > > Thanks in Advance for any help! > Tom A solution is pretty simple, do not use an intermediate log function pdebug. import logging PDEBUG_NUM=20 logging.addLevelName(PDEBUG_NUM, "PDEBUG") logger = logging.getLogger('foo') logging.basicConfig(level=logging.DEBUG, format='%(message)s %(lineno)d') logger.log(PDEBUG_NUM, 'This will work :') If you *really* want to go for the hackish way, forget about the inspect module, the following pdebug function should do the trick: def pdebug(self, message, *args, **kws): if self.isEnabledFor(PDEBUG_NUM): self._log(PDEBUG_NUM, message, args, **kws) Cheers, JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From auriocus at gmx.de Tue Mar 31 14:58:04 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Tue, 31 Mar 2015 20:58:04 +0200 Subject: Lockfile hanling In-Reply-To: References: Message-ID: Am 31.03.15 um 16:50 schrieb Ervin Heged?s: > there is an app, written in Python, which stores few bytes of > datas in a single file. The application uses threads. Every > thread can modify the file, but only one at a time. I'm using a > lock file to prevent the multiple access. > > Here is the lock method: > >[...] > This works as well for me - about 3-4 weeks. After some weeks, I > got this error: > > OSError: [Errno 24] Too many open files: '/var/spool/myapp/queue.lock' > Can you try if fcntl.flock() does what you want? Should be better than inventing your own locking mechanism. Christian From ian.g.kelly at gmail.com Tue Mar 31 15:17:10 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 31 Mar 2015 13:17:10 -0600 Subject: Lockfile hanling In-Reply-To: References: Message-ID: On Tue, Mar 31, 2015 at 12:58 PM, Christian Gollwitzer wrote: > Am 31.03.15 um 16:50 schrieb Ervin Heged?s: >> >> there is an app, written in Python, which stores few bytes of >> datas in a single file. The application uses threads. Every >> thread can modify the file, but only one at a time. I'm using a >> lock file to prevent the multiple access. >> >> Here is the lock method: >> >> [...] >> This works as well for me - about 3-4 weeks. After some weeks, I >> got this error: >> >> OSError: [Errno 24] Too many open files: '/var/spool/myapp/queue.lock' >> > > Can you try if fcntl.flock() does what you want? Should be better than > inventing your own locking mechanism. flock locks are per-process; they won't help for synchronizing access between competing threads in the same process. From denismfmcmahon at gmail.com Tue Mar 31 15:58:03 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Tue, 31 Mar 2015 19:58:03 +0000 (UTC) Subject: Error in processing JSON files in Python References: <63a251f6-01ff-4662-ab9c-588e3ffcd73a@googlegroups.com> Message-ID: On Mon, 30 Mar 2015 14:27:14 -0700, Karthik Sharma wrote: > I have the following python program to read a set of JSON files do some > processing on it and dump them back to the same folder. However When I > run the below program and then try to see the output of the JSON file > using > > `cat file.json | python -m json.tool` > > I get the following error > > `extra data: line 1 column 307 - line 1 column 852 (char 306 - 851)` > > What is wrong with my program? > > #Process 'new' events to extract more info from 'Messages' > rootDir = '/home/s_parts' > for dirName, subdirList, fileList in os.walk(rootDir): > print('Found directory: %s' % dirName) > for fname in fileList: > fname='s_parts/'+fname with open(fname, 'r+') as f: > json_data = json.load(f) > # do stuff to the data > json.dump(json_data,f) You're writing back to the same file as you loaded the data from having opened the file in append mode. This probably leads to a file containing two json objects, the original one and the one which you have processed. That's a bad json file. Note the caution in the python documentation: "Note - Unlike pickle and marshal, JSON is not a framed protocol, so trying to serialize multiple objects with repeated calls to dump() using the same fp will result in an invalid JSON file." Writing back to the same file as you read with json.load is the same thing. If you want to use the same file, you need to close it after the json.load(), and then open it again in write mode before the json.dump(). Write is "w", *NOT* "w+". -- Denis McMahon, denismfmcmahon at gmail.com From auriocus at gmx.de Tue Mar 31 15:59:43 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Tue, 31 Mar 2015 21:59:43 +0200 Subject: Lockfile hanling In-Reply-To: References: Message-ID: Am 31.03.15 um 21:17 schrieb Ian Kelly: > On Tue, Mar 31, 2015 at 12:58 PM, Christian Gollwitzer wrote: >> Am 31.03.15 um 16:50 schrieb Ervin Heged?s: >>> >>> there is an app, written in Python, which stores few bytes of >>> datas in a single file. The application uses threads. Every >>> thread can modify the file, but only one at a time. I'm using a >>> lock file to prevent the multiple access. >>> >>> Here is the lock method: >>> >>> [...] >>> This works as well for me - about 3-4 weeks. After some weeks, I >>> got this error: >>> >>> OSError: [Errno 24] Too many open files: '/var/spool/myapp/queue.lock' >>> >> >> Can you try if fcntl.flock() does what you want? Should be better than >> inventing your own locking mechanism. > > flock locks are per-process; they won't help for synchronizing access > between competing threads in the same process. > Ok. But if it is really all in one process, then a classical mutex would do, wouldn't it? I'm not experienced with threading in Python, but it seems from the documentation, that threading.Lock() works like a mutex. Christian From ian.g.kelly at gmail.com Tue Mar 31 16:12:46 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 31 Mar 2015 14:12:46 -0600 Subject: Lockfile hanling In-Reply-To: References: Message-ID: On Tue, Mar 31, 2015 at 1:59 PM, Christian Gollwitzer wrote: > Am 31.03.15 um 21:17 schrieb Ian Kelly: >> flock locks are per-process; they won't help for synchronizing access >> between competing threads in the same process. >> > > Ok. But if it is really all in one process, then a classical mutex would do, > wouldn't it? I'm not experienced with threading in Python, but it seems from > the documentation, that threading.Lock() works like a mutex. As long as there's not *also* some other external process that needs to access the file occasionally. :-) From amfarrell at mit.edu Tue Mar 31 16:38:16 2015 From: amfarrell at mit.edu (Andrew Farrell) Date: Tue, 31 Mar 2015 15:38:16 -0500 Subject: Project, how to debug In-Reply-To: References: Message-ID: points of general advice: - As noted by Chris, you first need to figure out what the code is *supposed* to do. - Have a notebook and pencil next to you as you are working through this so that you can make notes and draw out the structure of things. - Write down the general structure of the code on your notebook so you always keep yourself oriented. If you find yourself lost, don't just keep reading code; stop and write out what you do understand and try to turn your sense of confusion into concrete questions. - Use The Silver Searcher . If you find yourself thinking "I wish I could just see all the places where the variable 'herring' is used", then `ag -C 5 herring` is going to be your friend. - Use pdb , the python debugger that comes in the standard library. If you find yourself wanting to jump into a section of the code and print out variables and look at stack frames, sticking `import pdb;pdb.set_trace()` in there is going to be your friend. - Actually try using ipdb , which has a slightly better user interface than pdb. But don't worry if you can't install it. pdb is fine. - Much like you shouldn't just blindly read through code, don't just blindly step through code. If you lose sight of where you are, step back and re-orient yourself. - Find a colleague, friend, or rubber duck. Explain to them what you think the code is doing. This will force you to think about things more clearly. - Try writing unit tests for the code with with py.test . It will help you verify "okay, this piece right here is working correctly" and thereby mean that you don't have to check that piece again. - Use assert statements to check that things are as they should be. - Try sticking `assert False` into the middle of a function. If the function raises an error other than AssertionError, then the problem is before the assert statement. - In your spare time, read 9 Indespensible Rules for Debugging Software and Hardware Problems . It is both useful and enjoyable. On Tue, Mar 31, 2015 at 7:05 AM, Robert Clove wrote: > > > On Tue, Mar 31, 2015 at 5:19 PM, Peter Otten <__peter__ at web.de> wrote: > >> Robert Clove wrote: >> >> > Hi All, >> > >> > I am facing a problem. >> > I have been given a project written in python and asked to debug it. >> > I have not been given the flow they said understand and debug. >> > >> > Can someone suggest me how to debug it in Wings IDE. >> >> Are those specific bugs that you are supposed to fix or are you to both >> find >> and fix bugs? >> >> > Project have approx 10 files. >> >> Generally speaking speaking this is not so much a matter of tools; if >> there >> is any documentation you can trust reading that is usually the best start; >> reading the code is important, too. >> >> Then you can consider your next steps depending on the "messiness" of the >> code base and the degree of coverage with unit tests. >> >> >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > > There is no documentation provided i have to read the code understand the > flow first. > > > -- > https://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gordon at panix.com Tue Mar 31 18:00:31 2015 From: gordon at panix.com (John Gordon) Date: Tue, 31 Mar 2015 22:00:31 +0000 (UTC) Subject: Quick question, if you please References: Message-ID: In John Kelly writes: > I received Python with another install and my update software keeps > signaling I need to install a newer version, and once I do, the older > version is still there, so I keep getting told I need to update. Should > I be able to uninstall the old version each time? Yes, assuming you have no other software that depends on the older Python version. -- John Gordon Imagine what it must be like for a real medical doctor to gordon at panix.com watch 'House', or a real serial killer to watch 'Dexter'. From sohcahtoa82 at gmail.com Tue Mar 31 19:10:32 2015 From: sohcahtoa82 at gmail.com (sohcahtoa82 at gmail.com) Date: Tue, 31 Mar 2015 16:10:32 -0700 (PDT) Subject: A simple single line, triple-quoted comment is giving syntax error. Why? In-Reply-To: References: <3533816.ZYnZ2OzjCs@PointedEars.de> <3971951.908YQu3oQO@PointedEars.de> <1504323.jUKfeKbQsP@PointedEars.de> <2362875.FIK8ImHTJA@PointedEars.de> <1823599.Pr2V0MPR6q@PointedEars.de> <9781856.5cutuNVPEq@PointedEars.de> <3894022.plrvF2nHWu@PointedEars.de> Message-ID: <890fd8c0-a07d-409a-bb71-685c4877d8e2@googlegroups.com> On Tuesday, March 31, 2015 at 12:24:53 AM UTC-7, Ian wrote: > On Sun, Mar 29, 2015 at 4:41 AM, Thomas 'PointedEars' Lahn > wrote: > > Ian Kelly wrote: > > > >> [?] Thomas 'PointedEars' Lahn [?] wrote: > >>> Ian Kelly wrote: > >> Why should the burden of proof be on me in the first place? > > > > Because *you* made the claim that ?STRING+? could be part of an AST in this > > way. > > Okay, I didn't understand before that this was the part that you were > objecting to. I had written "There is only one expr node, and it > contains both STRING tokens", to which you replied "Prove it." I did > not intend to imply anything at all by the inclusion of STRING+ in the > tree. That pseudo-tree was hastily sketched out, and as both you and > Gregory have pointed out, STRING+ is not a symbol of the grammar and > should not have been included as a node. None of this has any bearing > on what I was trying to demonstrate with that tree. > > >> Within a grammar, the question of "is an X a Y" is nonsensical in > >> isolation. It can only be answered in relation to a parse tree. > >> Consider the simple grammar: > >> > >> S -> A | B > >> A -> x > >> B -> x > >> > >> Is x an A? It depends. > > > > No, by the definition 2 below, that we all accepted implicitly up to this > > point, x is *definitely* an A. > > What gives you the impression that I ever accepted it? > > >> If the tree that generates the x produces it from an A node, then yes. > >> Otherwise, no. > > > > Fallacy. > > > > First, two definitions, so that we are clear what we are talking about: > > > > (1) Let a *production chain* be the repeated application of the production > > rules of a formal grammar such that > > > > C ? D ? x > > > > is a production chain if there are production rules > > > > C ? D > > D ? x. > > > > [Note the difference between ??? and ???.] > > Sure. > > > (2) Let the statement ?x is an A? be true if x can be produced in a > > production chain starting with or including the non-terminal A > > left-hand side ? > > > > x ? A ? ?A (? ? A ? ? ? x). > > Sorry, but this definition just seems entirely arbitrary to me. > Mathematically, it looks nonsensical; A is a symbol, not a set. This > question of whether "x is an A" is informal and not a topic of formal > language theory so far as I'm aware. Can you cite some source for it? > > > Now, according to these definitions, in the offered grammar x is *both* an A > > and a B. Because what matters is _not_ the practical result of production > > chains (the actual parse tree), but the certainty of the theoretical > > possibility of it. > > This strikes me as being a lot like arguing, "some kites are toys, and > some kites are birds; therefore, all kites are both toys and birds." > > >> So when I write that the "foo" in "foo" "bar" is not an expression, I > >> am only speaking in relation to the parse tree that generates "foo" > >> "bar". > > > > But it has been indicated by others that the parse tree that you presented > > is wrong, based on a misconception about the syntax of the formal grammar, > > and you have not yet substantiated your claim that it is correct. > > As noted above, the inaccuracy that Gregory pointed out has no bearing > on my argument. > > You're really going to make me spell it out, aren't you? Fine, here you go. > > single_input -> simple_stmt -> expr_stmt -> testlist_star_expr -> test > -> or_test -> and_test -> not_test -> comparison -> expr -> xor_expr > -> and_expr -> shift_expr -> arith_expr -> term -> factor -> power -> > atom -> STRING STRING > > Note: the derivation contains exactly one expr node, which indirectly > produces both STRINGs. Neither STRING in this derivation is > individually produced from the expr. > > >> I don't know what you mean by a "backdoor". > > > > Appending a statement that is contradictory to what was stated just before, > > or at least ambiguous, so that the possibility arises for one to say ?I did > > not mean that? when that/a contradiction to the former statement is pointed > > out later. > > The purpose was not to make the possibility arise to say that. The > purpose was to point out the discontinuity *immediately* so that it > would be already addressed and not *need* to be pointed out later > (although we can see how well that turned out). > > I have to say that I find it highly surprising that you find this > construction objectionable. Would you still consider it > "contradictory" if I had phrased it equivalently as a logical "or" > rather than using the word "except"? > > >> The purpose of that parenthetical was to explicitly acknowledge that the > >> single STRING could be viewed as an expression when taken out of context, > > > > Yes, your fallacy is mainly based on ignoring the context. Context is > > important; you cannot just ignore it and still make correct arguments. > > Funny, I thought that was my line. This whole argument came about > because you seem to be stubbornly insistent on ignoring the context > that I set for my statement, calling it "contradictory" instead. > > >> and to disclaim that I was excluding that case from the preceding > >> statement. I still stand by that statement; The "foo" in "foo" "bar" is > >> not an expression in the same sense that the "42" is not an expression in > >> "hucr,.@#%c|42ptqc$". > > > > False analogy. The ?42? in there cannot be produced by ?expr? *in that > > context* (it can only be produced by ?STRING?). > > I apologize for the confusion. The quotation marks there were only > intended to separate the nonsense construction from my own text, not > as string delimiters. I realize that in the first part of the analogy > I did use them as string delimiters, so I was inconsistent. > > The analogy to be drawn is that a parse tree of ?"foo" "bar"? that > contains an expr node for each STRING is an invalid parse, just as a > parse tree of ?hucr,.@#%c|42ptqc$? that isolates ?42? as a single expr > (or any other parse tree in this particular case) is invalid. > > >>> Actually, you were arguing against my statement that string literals are > >>> expressions (that a string literal is an expression). You claimed, > >>> rather explicitly, that they were not. See above. > >> > >> I have no idea what point you're trying to convey here. > > > > Is the ?See above? not enough a reference? > > I get the connection between what you wrote here and what you wrote > above. I don't get the connection between what I wrote (that has now > been trimmed away) and what you wrote in response to it. My > parenthetical about parsing STRINGs in isolation was not in itself an > argument against what you wrote. It was in fact agreeing, within a > limited context. Holy hell, dude, you've been arguing about this for nearly two weeks now. Let it go. From rosuav at gmail.com Tue Mar 31 19:36:41 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 1 Apr 2015 10:36:41 +1100 Subject: A simple single line, triple-quoted comment is giving syntax error. Why? In-Reply-To: <890fd8c0-a07d-409a-bb71-685c4877d8e2@googlegroups.com> References: <3533816.ZYnZ2OzjCs@PointedEars.de> <3971951.908YQu3oQO@PointedEars.de> <1504323.jUKfeKbQsP@PointedEars.de> <2362875.FIK8ImHTJA@PointedEars.de> <1823599.Pr2V0MPR6q@PointedEars.de> <9781856.5cutuNVPEq@PointedEars.de> <3894022.plrvF2nHWu@PointedEars.de> <890fd8c0-a07d-409a-bb71-685c4877d8e2@googlegroups.com> Message-ID: On Wed, Apr 1, 2015 at 10:10 AM, wrote: > Holy hell, dude, you've been arguing about this for nearly two weeks now. > > Let it go. Not sure you understand the nature of language debates. They can't hold it back any more! ChrisA From ian.g.kelly at gmail.com Tue Mar 31 19:43:27 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 31 Mar 2015 17:43:27 -0600 Subject: A simple single line, triple-quoted comment is giving syntax error. Why? In-Reply-To: <890fd8c0-a07d-409a-bb71-685c4877d8e2@googlegroups.com> References: <3533816.ZYnZ2OzjCs@PointedEars.de> <3971951.908YQu3oQO@PointedEars.de> <1504323.jUKfeKbQsP@PointedEars.de> <2362875.FIK8ImHTJA@PointedEars.de> <1823599.Pr2V0MPR6q@PointedEars.de> <9781856.5cutuNVPEq@PointedEars.de> <3894022.plrvF2nHWu@PointedEars.de> <890fd8c0-a07d-409a-bb71-685c4877d8e2@googlegroups.com> Message-ID: On Mar 31, 2015 5:16 PM, wrote: > Holy hell, dude, you've been arguing about this for nearly two weeks now. > > Let it go. That's rather an exaggeration. I've made seven posts to this thread up until now, the first of which was six days ago, not two weeks. I don't think that's excessive. I suggested dropping it a couple of posts back, but Thomas seemed interested in continuing to seek clarity, which I have no objection to. -------------- next part -------------- An HTML attachment was scrubbed... URL: From wuwei23 at gmail.com Tue Mar 31 21:14:26 2015 From: wuwei23 at gmail.com (alex23) Date: Wed, 01 Apr 2015 11:14:26 +1000 Subject: Automation of Windows app? In-Reply-To: References: Message-ID: On 23/03/2015 1:43 PM, Michael Torrie wrote: > As near as I can tell the standard go-to utility for this is a program > called AutoIt. https://www.autoitscript.com/site/autoit/ > > Nothing to do with Python, and its scripting language is maybe not that > appealing to many, but it does the job, and does it pretty well. Actually, it's not *entirely* unrelated, as there's a Python wrapper for it: https://pypi.python.org/pypi/PyAutoIt/0.3 It's 2.7 only, though, so if 3.x is required, it's also possible to create your own wrapper using win32com: http://stackoverflow.com/questions/151846/get-other-running-processes-window-sizes-in-python/155587#155587 From me at anonymous.invalid Tue Mar 31 23:27:01 2015 From: me at anonymous.invalid (catperson) Date: Tue, 31 Mar 2015 20:27:01 -0700 Subject: New to Programming - XML Processing Message-ID: I am new to programming, though not new to computers. I'm looking to teach myself Python 3 and am working my way through a tutorial. At the point I'm at in the tutorial I am tasked with parsing out an XML file created with a Garmin Forerunner and am just having a terrible time getting my head around the concepts. What I'm looking for is some suggested reading that might give me some of the theory of operation behind ElementTree and then how to parse out specific elements. Most of what I have been able to find in examples that I can understand use very simplistic XML files and this Garmin file is many levels of sub-elements and some of those elements have attributes assigned, like . I'm hoping with enough reading I can experiment and work my way through the problem and end up with a hopefully clear understanding of the ElementTree module and Dictionairies. Thanks for any suggestions in advance. Jim. From rustompmody at gmail.com Tue Mar 31 23:53:42 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 31 Mar 2015 20:53:42 -0700 (PDT) Subject: OT Intuitionism+Platonism+Mysticism => CS (was Deep comparison of dicts...) In-Reply-To: <87zj76j241.fsf@elektro.pacujo.net> References: <817c8567-1dbb-436c-8a1f-86446e30d12d@googlegroups.com> <4712399a-7c27-4a32-a085-47ebbafe3ffa@googlegroups.com> <87a8z7pxo3.fsf@elektro.pacujo.net> <5c6fbed3-215e-4e1f-959e-f8c2f6751c11@googlegroups.com> <87zj76j241.fsf@elektro.pacujo.net> Message-ID: <3d2bad64-418c-42e9-83b1-220fc7fd96a3@googlegroups.com> On Saturday, March 21, 2015 at 11:58:43 AM UTC+5:30, Marko Rauhamaa wrote: > Rustom Mody : > > > However I am talking some historical facts, viz: Because some nuts did > > the 20th century equivalent of: "Break each others' heads about how > > many angels can dance on the head of a pin" therefore much of the > > world around us exists as it does (for better or worse) including my > > (and I guess your) degree and job. > > The deep philosophical questions around the year 1900 in both > mathematics and physics were left embarrassingly open. The way out was > to stop caring. Ive collected some of the above points and some from earlier threads here: http://blog.languager.org/2015/03/cs-history-0.html Anyone un-mentioned there that wants to figure -- or conversely :-) -- just give me the say-so.