From steve+comp.lang.python at pearwood.info Fri Aug 1 00:04:18 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Aug 2014 04:04:18 GMT Subject: Dict when defining not returning multi value key error References: Message-ID: <53db11c1$0$29986$c3e8da3$5496439d@news.astraweb.com> On Thu, 31 Jul 2014 20:12:12 -0700, Dan Stromberg wrote: > I removed some quotes, and noticed that 1 and 1.0 hash the same. That's > a bit unexpected, but I suppose it's not completely unreasonable. You should expect that two equal objects should hash to the same value in different versions of Python, or even from one run of Python to the next. But within a single session, then far from being "not completely unreasonable", having equal items hash to the same value is the only reasonable thing to do. It is part of the dict API that if x == y, then dict[x] == dict[y], and that cannot happen unless x and y hash to the same thing. In general, it's not entirely possible to enforce that, especially given how flexible custom __eq__ methods can be, so Python doesn't even try. But with *numbers* (or at least those which are part of the numeric tower), Python does insist that each distinct value should hash to the same result no matter what type that value happens to be: py> n = 23 py> hash(n) == hash(long(n)) == hash(float(n)) == hash(complex(n)) True py> from fractions import Fraction py> from decimal import Decimal py> hash(n) == hash(Fraction(n)) == hash(Decimal(n)) True With the possible exception of Decimal, which is not fully integrated with the numeric tower, all numbers in the standard library will obey the condition that if x == y, hash(x) == hash(y), regardless of type. -- Steven From ben+python at benfinney.id.au Fri Aug 1 00:17:41 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 01 Aug 2014 14:17:41 +1000 Subject: Dict when defining not returning multi value key error References: <53db11c1$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: <85ppgkdesa.fsf@benfinney.id.au> Steven D'Aprano writes: > On Thu, 31 Jul 2014 20:12:12 -0700, Dan Stromberg wrote: > > > I removed some quotes, and noticed that 1 and 1.0 hash the same. > > That's a bit unexpected, but I suppose it's not completely > > unreasonable. I would expect it, for the reasons Steven explains. Why is it unexpected? > You should expect that two equal objects should hash to the same value > in different versions of Python, or even from one run of Python to the > next. I suspect there's a ?not? missing there. To be explicit: You should not expect any particular comparisons to hold true for hash values between different Python versions, or even from one run to the next. Only those promises made or logically implied in the API should be expected. Implementation details should be expected to break assumptions ? in other words, don't depend on any particular behaviour of an implementation detail. If you expect the hash valuesto be the same, you're making a mistake; if you expect the hash values to be different, you're making a mistake. The correct attitude, with regard to implementation details, is to expect uncertainty and not assume anything :-) -- \ ?Natural catastrophes are rare, but they come often enough. We | `\ need not force the hand of nature.? ?Carl Sagan, _Cosmos_, 1980 | _o__) | Ben Finney From frank at chagford.com Fri Aug 1 02:22:30 2014 From: frank at chagford.com (Frank Millman) Date: Fri, 1 Aug 2014 08:22:30 +0200 Subject: Second edition - Porting to Python 3 Message-ID: Hi all Here is the blurb - Porting to Python 3 doesn't have to be daunting. This book guides you through the process of porting your Python 2 code to Python 3, from choosing a porting strategy to solving your distribution issues. Using plenty of code examples it takes you cross the hurdles and shows you the new Python features. Here is the link - http://python3porting.com/ Frank Millman From wolfgang.maier at biologie.uni-freiburg.de Fri Aug 1 02:52:33 2014 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Fri, 01 Aug 2014 08:52:33 +0200 Subject: converting ISO8601 date and time string representations to datetime In-Reply-To: References: Message-ID: <53DB3931.8070406@biologie.uni-freiburg.de> On 08/01/2014 01:30 AM, Roy Smith wrote: > In article , > Albert-Jan Roskam wrote: > >>> In article , >>> Wolfgang Maier wrote: >>> >>>> Hi, >>>> I'm trying to convert ISO8601-compliant strings representing dates or >>>> dates and times into datetime.datetime objects. >>> >>> https://pypi.python.org/pypi/iso8601 >> >> Yikes, what a regex. It must have been painstaking to get that right. >> https://bitbucket.org/micktwomey/pyiso8601/src/2bd28b5d6cd2481674a8b0c54a8bba6 >> 4ab775f81/iso8601/iso8601.py?at=default > > It is a thing of beauty. > No wonder I found it hard to write something that seemed bulletproof ! From wolfgang.maier at biologie.uni-freiburg.de Fri Aug 1 02:52:33 2014 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Fri, 01 Aug 2014 08:52:33 +0200 Subject: converting ISO8601 date and time string representations to datetime In-Reply-To: References: Message-ID: <53DB3931.8070406@biologie.uni-freiburg.de> On 08/01/2014 01:30 AM, Roy Smith wrote: > In article , > Albert-Jan Roskam wrote: > >>> In article , >>> Wolfgang Maier wrote: >>> >>>> Hi, >>>> I'm trying to convert ISO8601-compliant strings representing dates or >>>> dates and times into datetime.datetime objects. >>> >>> https://pypi.python.org/pypi/iso8601 >> >> Yikes, what a regex. It must have been painstaking to get that right. >> https://bitbucket.org/micktwomey/pyiso8601/src/2bd28b5d6cd2481674a8b0c54a8bba6 >> 4ab775f81/iso8601/iso8601.py?at=default > > It is a thing of beauty. > No wonder I found it hard to write something that seemed bulletproof ! From feliphil at gmx.net Fri Aug 1 07:10:35 2014 From: feliphil at gmx.net (Wolfgang Keller) Date: Fri, 1 Aug 2014 13:10:35 +0200 Subject: Python and IDEs [was Re: Python 3 is killing Python] References: <87zjga4j4v.fsf@elektro.pacujo.net> <53c57bae$0$9505$c3e8da3$5496439d@news.astraweb.com> <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> > Windows and OS X users, sadly, miss out on the power of an integrated > package manager. Thankfully, all actually user-friendly operating systems (MacOS, TOS, RiscOS, probably AmigaOS, MacOS X) spare(d) their users the bottomless cesspit of "package management" and/or "installers". Because on such operating systems, each and every application is an entirely self-contained package that doesn't need any "packages" or "installers" to use it. Sincerely, Wolfgang From rosuav at gmail.com Fri Aug 1 07:22:33 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 1 Aug 2014 21:22:33 +1000 Subject: Python and IDEs [was Re: Python 3 is killing Python] In-Reply-To: <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> References: <87zjga4j4v.fsf@elektro.pacujo.net> <53c57bae$0$9505$c3e8da3$5496439d@news.astraweb.com> <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> Message-ID: On Fri, Aug 1, 2014 at 9:10 PM, Wolfgang Keller wrote: > Thankfully, all actually user-friendly operating systems (MacOS, > TOS, RiscOS, probably AmigaOS, MacOS X) spare(d) their users the > bottomless cesspit of "package management" and/or "installers". > > Because on such operating systems, each and every application is an > entirely self-contained package that doesn't need any "packages" or > "installers" to use it. You mean everyone has to reinvent the proverbial wheel AND worry about dependency collisions? Yeah, that's a heavenly thought. ChrisA From rustompmody at gmail.com Fri Aug 1 08:03:28 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 1 Aug 2014 05:03:28 -0700 (PDT) Subject: What is best way to learn Python for advanced developer? In-Reply-To: References: Message-ID: On 07/30/2014 02:20 PM, guirec corbel wrote: > Hello, > I am a Ruby developer and I want to program in Python. I know how to > do simple things like create classes, methods, variables and all the > basics. I want to know more. I want to know what is the Python > philosophy, how to test, how to create maintenable software, etc. > I'm looking for online courses and any ressources I can have on the > subject. > Can you help me? Yes its true that most books and web material concentrate on toy material. I guess thats inevitable. I remember one of the CS greats - I think it was Peter Naur - saying that programming pedagogy is too much focused on language and too little on literature. Two books that try to buck this trend a bit come to mind [Ive not checked out either] 1. Expert Python Programming by Tarek Ziade 2. Hacker's guide by Danjou https://julien.danjou.info/books/the-hacker-guide-to-python From marko at pacujo.net Fri Aug 1 08:19:52 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 01 Aug 2014 15:19:52 +0300 Subject: Python and IDEs References: <87zjga4j4v.fsf@elektro.pacujo.net> <53c57bae$0$9505$c3e8da3$5496439d@news.astraweb.com> <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> Message-ID: <87oaw4z9jr.fsf@elektro.pacujo.net> Chris Angelico : > On Fri, Aug 1, 2014 at 9:10 PM, Wolfgang Keller wrote: >> Because on such operating systems, each and every application is an >> entirely self-contained package that doesn't need any "packages" or >> "installers" to use it. > > You mean everyone has to reinvent the proverbial wheel AND worry about > dependency collisions? Yeah, that's a heavenly thought. I'm guessing he's referring to the modern fad of application sandboxing. Each application is installed with everything it needs on top of the basic OS. If you have ten Python apps, you'll have ten Python installations. Also the applications have no way to communicate outside their respective sandboxes. They can't access each others' files, for example. Personally, I tend to stick to this package management strategy: install whatever is available with yum and write the rest yourself. Marko From rosuav at gmail.com Fri Aug 1 08:30:31 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 1 Aug 2014 22:30:31 +1000 Subject: Python and IDEs In-Reply-To: <87oaw4z9jr.fsf@elektro.pacujo.net> References: <87zjga4j4v.fsf@elektro.pacujo.net> <53c57bae$0$9505$c3e8da3$5496439d@news.astraweb.com> <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> <87oaw4z9jr.fsf@elektro.pacujo.net> Message-ID: On Fri, Aug 1, 2014 at 10:19 PM, Marko Rauhamaa wrote: > I'm guessing he's referring to the modern fad of application sandboxing. > Each application is installed with everything it needs on top of the > basic OS. > > If you have ten Python apps, you'll have ten Python installations. Also > the applications have no way to communicate outside their respective > sandboxes. They can't access each others' files, for example. > > Personally, I tend to stick to this package management strategy: install > whatever is available with yum and write the rest yourself. Only if by "write" you also include compiling someone else's program from source. I follow that strategy (except that I use apt rather than yum), and there's a fair bit that I build from source but don't write. Granted, that's partly because Debian Stable doesn't include a sufficiently recent Python, for instance, but still, there's a lot to be said for getting libraries (including dev versions) from the repo and building some applications yourself. ChrisA From wxjmfauth at gmail.com Fri Aug 1 08:35:12 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Fri, 1 Aug 2014 05:35:12 -0700 (PDT) Subject: What is best way to learn Python for advanced developer? In-Reply-To: References: Message-ID: <4d2cfd18-f172-4d4c-9d70-19d25c9cbea8@googlegroups.com> Le vendredi 1 ao?t 2014 14:03:28 UTC+2, Rustom Mody a ?crit?: > > > Yes its true that most books and web material concentrate on toy > > material. I guess thats inevitable. I remember one of the CS greats > > - I think it was Peter Naur - saying that programming pedagogy is too > > much focused on language and too little on literature. > > > >From what I reading here and there, it's more than clearer to me some Python devs never spend some time in lirerature covering Unicode or the coding of characters. And there are blindly and naively preferring toying and experimenting with an editor. jmf From zdoor at xs4all.nl Fri Aug 1 08:45:12 2014 From: zdoor at xs4all.nl (Alex van der Spek) Date: 01 Aug 2014 12:45:12 GMT Subject: dict to boolean expression, how to? Message-ID: <53db8bd8$0$2976$e4fe514c@news2.news.xs4all.nl> With a dict like so: cond = {'a': 1, 'b': 1, 'c': 1, 'A': 0, 'B', 0, 'C':0} how would you make a boolean expression like this: bool = (('a' == 1) & ('A' == 0) | ('b' == 1) & ('B' == 0) | ('c' == 1) & ('C' == 0)) The fact that lowercase and uppercase keys are stringed together with & is intentional albeit the actual condition is a bit more tricky. I've tried several approaches using eval() on a string built from the dict but landed with just spelling it out literally. Any pointers welcome. Alex From rosuav at gmail.com Fri Aug 1 09:04:03 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 1 Aug 2014 23:04:03 +1000 Subject: dict to boolean expression, how to? In-Reply-To: <53db8bd8$0$2976$e4fe514c@news2.news.xs4all.nl> References: <53db8bd8$0$2976$e4fe514c@news2.news.xs4all.nl> Message-ID: On Fri, Aug 1, 2014 at 10:45 PM, Alex van der Spek wrote: > how would you make a boolean expression like this: > > bool = (('a' == 1) & ('A' == 0) | > ('b' == 1) & ('B' == 0) | > ('c' == 1) & ('C' == 0)) Not sure what the use of this is, because 'a' will never be equal to 1. Are you trying to magically fetch names from your environment? Because that's usually a bad idea. ChrisA From steve+comp.lang.python at pearwood.info Fri Aug 1 09:10:00 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 01 Aug 2014 23:10:00 +1000 Subject: Python and IDEs References: <87zjga4j4v.fsf@elektro.pacujo.net> <53c57bae$0$9505$c3e8da3$5496439d@news.astraweb.com> <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> <87oaw4z9jr.fsf@elektro.pacujo.net> Message-ID: <53db91a8$0$30002$c3e8da3$5496439d@news.astraweb.com> Marko Rauhamaa wrote: > Chris Angelico : > >> On Fri, Aug 1, 2014 at 9:10 PM, Wolfgang Keller wrote: >>> Because on such operating systems, each and every application is an >>> entirely self-contained package that doesn't need any "packages" or >>> "installers" to use it. >> >> You mean everyone has to reinvent the proverbial wheel AND worry about >> dependency collisions? Yeah, that's a heavenly thought. > > I'm guessing he's referring to the modern fad of application sandboxing. > Each application is installed with everything it needs on top of the > basic OS. > > If you have ten Python apps, you'll have ten Python installations. A horrible thought. Hard drives are cheap, but not that cheap that one can trivially afford to turn every 1K Python script into a 25,000K install (based on the size of the Windows binary-only installer). On my system, the obvious application directories (I may have missed some) total 460MB: [steve at ando ~]$ du -hc /bin/ /sbin/ /usr/bin/ /usr/local/bin/ 7.9M /bin/ 38M /sbin/ 76K /usr/bin/mergetools 380M /usr/bin/ 35M /usr/local/bin/ 460M total If those apps were an average of 10,000 times larger, that makes 4.6TB, significantly larger than an entry level 1TB hard drive. It also makes rescue DVDs and boot USB sticks impractical, to say nothing of the expense of downloading upgrades. I can download (say) an entire Linux Mint system in an hour or three, which is significantly better than the two years it would take to download if everything was 10,000 times bigger. But even more problematic... if there's a security vulnerability in Python, would you rather wait for the vulnerability to patched once in a central Python binary, or individually in each and every single Python script that comes with a bundled Python binary? > Also > the applications have no way to communicate outside their respective > sandboxes. They can't access each others' files, for example. If two applications can both write to the file system, they can communicate. If they have sufficient file system privileges, they can even reach into each other's bundle and modify anything they want. > Personally, I tend to stick to this package management strategy: install > whatever is available with yum and write the rest yourself. +0.8 on that. Sometimes I install software outside of the package management system, but I always feel a tad dirty when I do so :-) -- Steven From roy at panix.com Fri Aug 1 09:24:48 2014 From: roy at panix.com (Roy Smith) Date: Fri, 01 Aug 2014 09:24:48 -0400 Subject: dict to boolean expression, how to? References: <53db8bd8$0$2976$e4fe514c@news2.news.xs4all.nl> Message-ID: In article <53db8bd8$0$2976$e4fe514c at news2.news.xs4all.nl>, Alex van der Spek wrote: > With a dict like so: > > cond = {'a': 1, 'b': 1, 'c': 1, > 'A': 0, 'B', 0, 'C':0} > > how would you make a boolean expression like this: > > bool = (('a' == 1) & ('A' == 0) | > ('b' == 1) & ('B' == 0) | > ('c' == 1) & ('C' == 0)) > > The fact that lowercase and uppercase keys are stringed together with & is > intentional albeit the actual condition is a bit more tricky. > > I've tried several approaches using eval() on a string built from the dict > but landed with just spelling it out literally. I would certainly avoid eval(), especially if there's any chance (including ways you can't possibly imagine right now) of external data getting included. Google for "little bobby tables". Maybe something like (coding on the fly, not tested): terms = [] for key in 'abc': term = cond[key] and not cond[key.upper()] terms.append(term) bool_value = any(terms) From steve+comp.lang.python at pearwood.info Fri Aug 1 09:28:06 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Aug 2014 13:28:06 GMT Subject: dict to boolean expression, how to? References: <53db8bd8$0$2976$e4fe514c@news2.news.xs4all.nl> Message-ID: <53db95e6$0$29986$c3e8da3$5496439d@news.astraweb.com> On Fri, 01 Aug 2014 12:45:12 +0000, Alex van der Spek wrote: > With a dict like so: > > cond = {'a': 1, 'b': 1, 'c': 1, > 'A': 0, 'B', 0, 'C':0} > > how would you make a boolean expression like this: > > bool = (('a' == 1) & ('A' == 0) | > ('b' == 1) & ('B' == 0) | > ('c' == 1) & ('C' == 0)) That's False. It's always False, because 'a' does not equal 1, etc. Also, you're using bitwise operators & and | rather than boolean operators. Finally, you are shadowing the built-in bool() type, which is probably a bad idea. In the first case, I think you mean cond['a'] == 1 rather than just 'a'==1; in the second case, the bool operators are called "and" and "or"; and in the third case, there are many equally good names for a generic boolean flag, like "flag". Putting those together, I think you probably mean something like this: flag = ( (cond['a'] == 1 and cond['A'] == 0) or (cond['b'] == 1 and cond['B'] == 0) or (cond['c'] == 1 and cond['C'] == 0) ) which can be simplified to: flag = any( cond[c] == 1 and cond[c.upper()] for c in ['a', 'b', 'c'] ) If you *really* mean bitwise-and, you can change the "and"s to & and "or"s to | but honesty that's pointless and inefficient because all your conditions are bools, not arbitrary integers. > The fact that lowercase and uppercase keys are stringed together with & > is intentional albeit the actual condition is a bit more tricky. > > I've tried several approaches using eval() on a string built from the > dict but landed with just spelling it out literally. Ayyyeee!!!! Don't use eval(). Really. Any time you think you need to use eval(), smash your hand with a hammer until the urge goes away. *wink* But seriously: if you need to ask "why not use eval?", you're not ready to use eval safely. But in a nutshell: - using eval is a large performance hit (about 10 times slower); - eval is dangerous and can introduce code injection vulnerabilities. eval is almost never the right solution to any problem, and in the very few exceptions, it needs careful handling by an expert to ensure you're not introducing serious security bugs. -- Steven From rosuav at gmail.com Fri Aug 1 09:30:03 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 1 Aug 2014 23:30:03 +1000 Subject: Python and IDEs In-Reply-To: <53db91a8$0$30002$c3e8da3$5496439d@news.astraweb.com> References: <87zjga4j4v.fsf@elektro.pacujo.net> <53c57bae$0$9505$c3e8da3$5496439d@news.astraweb.com> <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> <87oaw4z9jr.fsf@elektro.pacujo.net> <53db91a8$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Aug 1, 2014 at 11:10 PM, Steven D'Aprano wrote: > Marko Rauhamaa wrote: > >> I'm guessing he's referring to the modern fad of application sandboxing. >> Each application is installed with everything it needs on top of the >> basic OS. >> >> If you have ten Python apps, you'll have ten Python installations. > > A horrible thought. Hard drives are cheap, but not that cheap that one can > trivially afford to turn every 1K Python script into a 25,000K install > (based on the size of the Windows binary-only installer). On my system, the > obvious application directories (I may have missed some) total 460MB: > > [steve at ando ~]$ du -hc /bin/ /sbin/ /usr/bin/ /usr/local/bin/ > 7.9M /bin/ > 38M /sbin/ > 76K /usr/bin/mergetools > 380M /usr/bin/ > 35M /usr/local/bin/ > 460M total > > If those apps were an average of 10,000 times larger, that makes 4.6TB, > significantly larger than an entry level 1TB hard drive. It also makes > rescue DVDs and boot USB sticks impractical, to say nothing of the expense > of downloading upgrades. I can download (say) an entire Linux Mint system > in an hour or three, which is significantly better than the two years it > would take to download if everything was 10,000 times bigger. There is a solution. If all those binaries are marked as read-only, you could have a file system that stores things based on their hashes, effectively hardlinking (automatically) all the duplicates. Of course, that only works if they really are duplicates. If one ships Python 2.7.3 and another ships 2.7.4, there'll be a lot of almost-duplicated files that technically identical. > But even more problematic... if there's a security vulnerability in Python, > would you rather wait for the vulnerability to patched once in a central > Python binary, or individually in each and every single Python script that > comes with a bundled Python binary? This is exactly the problem that sandboxing "fixes", though. As soon as you upgrade the central Python binary, you risk breaking that application that depended on the exact version that it shipped with. Encouraging laziness and sloppy versioning, IMO. >> Also >> the applications have no way to communicate outside their respective >> sandboxes. They can't access each others' files, for example. > > If two applications can both write to the file system, they can communicate. > If they have sufficient file system privileges, they can even reach into > each other's bundle and modify anything they want. If you chroot to the sandbox, they shouldn't be able to. (Not to say there's no such thing as chroot leakage, of course, but they shouldn't.) >> Personally, I tend to stick to this package management strategy: install >> whatever is available with yum and write the rest yourself. > > +0.8 on that. Sometimes I install software outside of the package management > system, but I always feel a tad dirty when I do so :-) I don't. There's plenty that I've done that way - but only ever applications, or libraries that completely don't exist in the repos. I've never installed a newer version of a library than I can get from repo. ChrisA From steve+comp.lang.python at pearwood.info Fri Aug 1 09:31:40 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Aug 2014 13:31:40 GMT Subject: Dict when defining not returning multi value key error References: <53db11c1$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53db96bc$0$29986$c3e8da3$5496439d@news.astraweb.com> On Fri, 01 Aug 2014 14:17:41 +1000, Ben Finney wrote: > Steven D'Aprano writes: > >> On Thu, 31 Jul 2014 20:12:12 -0700, Dan Stromberg wrote: >> >> > I removed some quotes, and noticed that 1 and 1.0 hash the same. >> > That's a bit unexpected, but I suppose it's not completely >> > unreasonable. > > I would expect it, for the reasons Steven explains. Why is it > unexpected? > >> You should expect that two equal objects should hash to the same value >> in different versions of Python, or even from one run of Python to the >> next. > > I suspect there's a ?not? missing there. Thanks for spotting that. Correct, I meant that you should *not* expect hashing to return any specific value. [...] > If you expect the hash valuesto be the same, you're making a mistake; if > you expect the hash values to be different, you're making a mistake. Yes. Although Python promises (at least for classes in the standard library) that x == y should imply that hash(x) == hash(y), it says nothing about the other way: x == y implies that hash(x) == hash(y) but hash(x) == hash(y) does NOT imply that x == y. py> hash(2**128) == hash(1) True > The correct attitude, with regard to implementation details, is to > expect uncertainty and not assume anything :-) Yes, this! -- Steven From roy at panix.com Fri Aug 1 09:32:36 2014 From: roy at panix.com (Roy Smith) Date: Fri, 01 Aug 2014 09:32:36 -0400 Subject: dict to boolean expression, how to? References: <53db8bd8$0$2976$e4fe514c@news2.news.xs4all.nl> <53db95e6$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <53db95e6$0$29986$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > eval is almost never the right solution to any problem, and in the very > few exceptions, it needs careful handling by an expert to ensure you're > not introducing serious security bugs. Corollary to that rule: All the people who are smart enough to actually understand how to use eval() safety, are also smart enough to know not to use it. From robert.kern at gmail.com Fri Aug 1 09:39:09 2014 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 01 Aug 2014 14:39:09 +0100 Subject: Getting a list of all modules In-Reply-To: <53da1d5a$0$29974$c3e8da3$5496439d@news.astraweb.com> References: <53d8a20e$0$29977$c3e8da3$5496439d@news.astraweb.com> <53da1d5a$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2014-07-31 11:41, Steven D'Aprano wrote: > On Wed, 30 Jul 2014 21:22:18 +0800, Leo Jay wrote: > >> On Wed, Jul 30, 2014 at 3:43 PM, Steven D'Aprano >> wrote: >>> I'm looking for a programmatic way to get a list of all Python modules >>> and packages. Not just those already imported, but all those which >>> *could* be imported. >>> >>> >> If you don't actually import it, how can you know it could be imported? >> Not all .so files are valid python modules. Not all .py files could be >> imported by all python interpreters. > > You're right, of course, but I'm not concerned by whether or not the > module is error-free and can be imported successfully. > > I'm working on tab completion for module names. I have some alpha-quality > code working, so if I hit TAB after typing "import ma" I get this: > > > py> import ma > macpath macurl2path mailbox mailcap mangle > markupbase math > > For what it's worth, importing "mangle" fails with a SyntaxError. But > that's okay, I don't expect tab completion to only show *valid* > modules :-) > > Over the next few days I'll make an official announcement, but if anyone > wants a sneak-peek, check out: > > http://code.google.com/p/tabhistory/source/browse/tabhistory.py > > > where I have indenting, code completion, filename completion, and module > completion all working to some degree or another. Take a look at what has already been implemented in IPython: https://github.com/ipython/ipython/blob/master/IPython/core/completerlib.py#L208 -- 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 rosuav at gmail.com Fri Aug 1 09:57:57 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 1 Aug 2014 23:57:57 +1000 Subject: Dict when defining not returning multi value key error In-Reply-To: <53db96bc$0$29986$c3e8da3$5496439d@news.astraweb.com> References: <53db11c1$0$29986$c3e8da3$5496439d@news.astraweb.com> <53db96bc$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Aug 1, 2014 at 11:31 PM, Steven D'Aprano wrote: > Yes. Although Python promises (at least for classes in the standard > library) that x == y should imply that hash(x) == hash(y), it says > nothing about the other way: > > x == y implies that hash(x) == hash(y) This is the entire point of the hashing system. If equal values can hash differently, why bother calculating the hashes? Or if you prefer, the point of hashing is the logical converse of the above: hash(x) != hash(y) implies that x != y. If the hashes are different, you can skip the equality check, ergo you can build a data type that claims to search for the key that == the looked-up key, but actually does a much faster hash check first, and skips everything with a different hash. > but hash(x) == hash(y) does NOT imply that x == y. > Hello, pigeonhole principle :) If this were false - that is, if equal hashes DID imply equal objects - it would be necessary to completely encode an object's state in its hash, and hashes would be impossibly large. This would, in fact, destroy their value completely. ChrisA From nicholas.cole at gmail.com Fri Aug 1 10:28:56 2014 From: nicholas.cole at gmail.com (Nicholas Cole) Date: Fri, 1 Aug 2014 15:28:56 +0100 Subject: Python and IDEs [was Re: Python 3 is killing Python] In-Reply-To: References: <87zjga4j4v.fsf@elektro.pacujo.net> <53c57bae$0$9505$c3e8da3$5496439d@news.astraweb.com> <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> Message-ID: On Fri, Aug 1, 2014 at 12:22 PM, Chris Angelico wrote: > On Fri, Aug 1, 2014 at 9:10 PM, Wolfgang Keller wrote: >> Thankfully, all actually user-friendly operating systems (MacOS, >> TOS, RiscOS, probably AmigaOS, MacOS X) spare(d) their users the >> bottomless cesspit of "package management" and/or "installers". >> >> Because on such operating systems, each and every application is an >> entirely self-contained package that doesn't need any "packages" or >> "installers" to use it. > > You mean everyone has to reinvent the proverbial wheel AND worry about > dependency collisions? Yeah, that's a heavenly thought. Actually, that's not right. RiscOS had and OS X has (I'm sure the others do as well) a concept that is similar to a shared library. But the joy of an application bundle is that installing an application does not scatter its own files all over the file-system, putting configuration files here, binary resources there, library files somewhere else, executable files somewhere else again. The result on one of these other systems is that uninstalling an application is a simple matter of deleting the relevant bundle, which contains all of the resources necessary for that application. All that remains are whatever files exist within user directories. I've worked with both. Quite honestly, I really wish that other operating systems had gone down this route. MS didn't possibly to make it harder to steal software, and Unix...well, *nix has the concept of the "distribution" that will manage all of this for you. We all know the problems that this causes. N. From ned at nedbatchelder.com Fri Aug 1 10:29:10 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 01 Aug 2014 10:29:10 -0400 Subject: dict to boolean expression, how to? In-Reply-To: <53db8bd8$0$2976$e4fe514c@news2.news.xs4all.nl> References: <53db8bd8$0$2976$e4fe514c@news2.news.xs4all.nl> Message-ID: On 8/1/14 8:45 AM, Alex van der Spek wrote: > With a dict like so: > > cond = {'a': 1, 'b': 1, 'c': 1, > 'A': 0, 'B', 0, 'C':0} > > how would you make a boolean expression like this: > > bool = (('a' == 1) & ('A' == 0) | > ('b' == 1) & ('B' == 0) | > ('c' == 1) & ('C' == 0)) > > The fact that lowercase and uppercase keys are stringed together with & is > intentional albeit the actual condition is a bit more tricky. > > I've tried several approaches using eval() on a string built from the dict > but landed with just spelling it out literally. > > > Any pointers welcome. > Alex > Are you looking for this? bool = ( (cond['a'] == 1 and cond['A'] == 0) or (cond['b'] == 1 and cond['B'] == 0) or (cond['c'] == 1 and cond['C'] == 0) ) If so, what's wrong with that expression exactly? I'm not sure how eval could enter into it, so I feel like I'm missing something. -- Ned Batchelder, http://nedbatchelder.com From zdoor at xs4all.nl Fri Aug 1 10:26:38 2014 From: zdoor at xs4all.nl (Alex van der Spek) Date: 01 Aug 2014 14:26:38 GMT Subject: dict to boolean expression, how to? References: <53db8bd8$0$2976$e4fe514c@news2.news.xs4all.nl> Message-ID: <53dba39e$0$2976$e4fe514c@news2.news.xs4all.nl> On Fri, 01 Aug 2014 12:45:12 +0000, Alex van der Spek wrote: > With a dict like so: > > cond = {'a': 1, 'b': 1, 'c': 1, > 'A': 0, 'B', 0, 'C':0} > > how would you make a boolean expression like this: > > bool = (('a' == 1) & ('A' == 0) | > ('b' == 1) & ('B' == 0) | > ('c' == 1) & ('C' == 0)) > > The fact that lowercase and uppercase keys are stringed together with & > is intentional albeit the actual condition is a bit more tricky. > > I've tried several approaches using eval() on a string built from the > dict but landed with just spelling it out literally. > > > Any pointers welcome. > Alex I am sorry, the problem is ill posed. 'a', 'A' and so forth are my failed attempt to shorthand. In reality the dict's keys are column names in a pandas dataframe df. The boolean expression would therefore look like: bool = ((df['a'] == 1) & (df['A'] == 0) | (df['b'] == 1) & (df['B'] == 0) | (df['c'] == 1) & (df['C'] == 0)) I do know eval() lends itself to code injection but can't say I am fully aware of its dangers. It seemed like a handy tool to me. This newsgroup scares me, it appears to be for professional computer scientists only, the theoretical part is sometimes too much for this practical physicist with an old background in FORTRAN. Is there a better place to ask questions of this nature? Alex van der Spek From ian.g.kelly at gmail.com Fri Aug 1 10:30:21 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 1 Aug 2014 08:30:21 -0600 Subject: Dict when defining not returning multi value key error In-Reply-To: References: Message-ID: On Thu, Jul 31, 2014 at 9:28 PM, Terry Reedy wrote: > On 7/31/2014 5:15 PM, Ian Kelly wrote: >> >> On Thu, Jul 31, 2014 at 5:24 AM, Dilu Sasidharan >> wrote: >>> >>> Hi, >>> >>> I am wondering why the dictionary in python not returning multi value key >>> error when i define something like >>> >>> p = {'k':"value0",'k':"value1"} >>> >>> key is string immutable and sometimes shares same id. >>> >>> also if the key is immutable and have different ids. >>> >>> like >>> >>> p = {'1':"value0",'1.0':"value1"} >> >> >> In this latter case note that '1' and '1.0' are not equal, so this >> will simply result in two separate entries in the dict anyway. > > > Dilu presumably meant > >>>> p = {1:"value0", 1.0:"value1"} >>>> p > {1: 'value1'} Maybe, but it was explicitly stated that the keys were strings. From rosuav at gmail.com Fri Aug 1 10:39:01 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Aug 2014 00:39:01 +1000 Subject: Python and IDEs [was Re: Python 3 is killing Python] In-Reply-To: References: <87zjga4j4v.fsf@elektro.pacujo.net> <53c57bae$0$9505$c3e8da3$5496439d@news.astraweb.com> <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> Message-ID: On Sat, Aug 2, 2014 at 12:28 AM, Nicholas Cole wrote: > Actually, that's not right. RiscOS had and OS X has (I'm sure the > others do as well) a concept that is similar to a shared library. But > the joy of an application bundle is that installing an application > does not scatter its own files all over the file-system, putting > configuration files here, binary resources there, library files > somewhere else, executable files somewhere else again. Shared libraries are a code execution model. The question is, how do you locate them? Let's suppose I write a program that requires the Nettle cryptography library. I can't depend on you already having that on your system; you might, but I can't depend on it. What do I do? Do I include it in my application bundle, or do I have some small record that says "and by the way, I need libnettle"? Including it in the application bundle means there'll be duplicates everywhere, possibly of slightly different versions. Not including it means there needs to be some kind of system for resolving dependencies, which is exactly what apt-get, yum, pacman, and so on are for. The installer has basically three choices. 1) Install libnettle inside the application directory 2) Install libnettle to some system library directory 3) Don't install libnettle, and demand that someone else (perhaps the user, or the system package manager) install it. Option 1 results in duplications. (Unless one application is allowed to access a library in another application's directory, which is a HORRIBLE mess.) Option 2 is exactly what you're complaining about, scattering files all over the FS. And option 3 is what package managers are for. What are you advocating? ChrisA From steve+comp.lang.python at pearwood.info Fri Aug 1 11:02:06 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Aug 2014 15:02:06 GMT Subject: dict to boolean expression, how to? References: <53db8bd8$0$2976$e4fe514c@news2.news.xs4all.nl> <53db95e6$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53dbabee$0$29986$c3e8da3$5496439d@news.astraweb.com> On Fri, 01 Aug 2014 09:32:36 -0400, Roy Smith wrote: > In article <53db95e6$0$29986$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: > >> eval is almost never the right solution to any problem, and in the very >> few exceptions, it needs careful handling by an expert to ensure you're >> not introducing serious security bugs. > > Corollary to that rule: All the people who are smart enough to actually > understand how to use eval() safety, are also smart enough to know not > to use it. ... smart enough to know WHEN to use it (which is *rarely*). That's in production code, of course. There's nothing wrong with using eval in the interactive interpreter for quick and dirty exploration. But even then, I find that it's usually easier to write a line or two of Python code to process something than to try using eval. There are uses for eval (or exec), even if production code. See collections.namedtuple, doctest, and timeit, for example. In the first place, namedtuple takes extra care to sanitise the data being used. In the case of doctest and timeit, the whole point of them is to run trusted code. If you can't trust your own code that you're timing, what can you trust? -- Steven From marco.nawijn at colosso.nl Fri Aug 1 11:07:20 2014 From: marco.nawijn at colosso.nl (marco.nawijn at colosso.nl) Date: Fri, 1 Aug 2014 08:07:20 -0700 (PDT) Subject: dict to boolean expression, how to? In-Reply-To: <53dba39e$0$2976$e4fe514c@news2.news.xs4all.nl> References: <53db8bd8$0$2976$e4fe514c@news2.news.xs4all.nl> <53dba39e$0$2976$e4fe514c@news2.news.xs4all.nl> Message-ID: <21a7ebb6-25d7-4cba-a867-e82d995c1968@googlegroups.com> Hi, Are you aware of the Python operator module? It provides function equivalents of all (most?) python operator. So instead of a==b, you can state operator.eq(a,b). As a result, you can loop over the key/value pairs in the dict and built your logic with the operator.eq, operator.and_, and operator.or_ (notice the trailing underscore to avoid clashing with normal "and" and "or" statements. Marco From marko at pacujo.net Fri Aug 1 11:13:57 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 01 Aug 2014 18:13:57 +0300 Subject: Python and IDEs References: <87zjga4j4v.fsf@elektro.pacujo.net> <53c57bae$0$9505$c3e8da3$5496439d@news.astraweb.com> <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> <87oaw4z9jr.fsf@elektro.pacujo.net> <53db91a8$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87zjfonsy2.fsf@elektro.pacujo.net> Steven D'Aprano : > Marko Rauhamaa wrote: >> If you have ten Python apps, you'll have ten Python installations. > > A horrible thought. Hard drives are cheap, but not that cheap Well, iPhones aren't *that* expensive... >> Also the applications have no way to communicate outside their >> respective sandboxes. They can't access each others' files, for >> example. > > If two applications can both write to the file system, They can't. They are sandboxed. My WP8 phone has Python3 installed. Absolutely useless since it can't get out of its sandbox (except for Microsoft's cloud drive, I think). Marko From steve+comp.lang.python at pearwood.info Fri Aug 1 11:24:49 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Aug 2014 15:24:49 GMT Subject: dict to boolean expression, how to? References: <53db8bd8$0$2976$e4fe514c@news2.news.xs4all.nl> <53dba39e$0$2976$e4fe514c@news2.news.xs4all.nl> Message-ID: <53dbb140$0$29986$c3e8da3$5496439d@news.astraweb.com> On Fri, 01 Aug 2014 14:26:38 +0000, Alex van der Spek wrote: [...] > bool = ((df['a'] == 1) & (df['A'] == 0) | > (df['b'] == 1) & (df['B'] == 0) | > (df['c'] == 1) & (df['C'] == 0)) > > I do know eval() lends itself to code injection but can't say I am fully > aware of its dangers. It seemed like a handy tool to me. And in expert hands, it can be. But I can't see how you're using eval in this case. Since you're not having any success, perhaps it's not as handy as you imagine? Did you try the suggestion to use any( ... )? Did it work? > This newsgroup scares me, it appears to be for professional computer > scientists only, Not even close! Some of us aren't even professional programmers! > the theoretical part is sometimes too much for this > practical physicist with an old background in FORTRAN. Oh, I sympathise. I know it can be hard to avoid feeling overwhelmed when you are dropped far outside of your comfort zone in a topic you know nothing about. But you're a physicist, and therefore you've already proven you have the logical skills to reason about quite complex and mathematical topics. If you're lost now, I wager it's because you're unfamiliar with the territory, not because it's beyond you. So please, don't be shy about asking people to explain in simpler terms. Sometimes we forget that things which are second nature to us are not familiar to somebody new to the language. Or we don't want to patronise them by assuming that every person asking a question needs their hand- held and every little detail spelled out in painfully small steps. It's quite hard to find the right balance, especially when we don't know your level of knowledge. So please, ask concrete questions, the more specific the better. Don't be afraid to ask what unfamiliar terms means. > Is there a better place to ask questions of this nature? I don't know of anyone here who is an expert in pandas, so if you ask questions which are specific to pandas, we may run into the limits of our knowledge. If you can find a dedicated pandas mailing list or other forum, they may help too, but I don't know if they will be more or less willing to explain the basics about Python. -- Steven From marko at pacujo.net Fri Aug 1 11:39:30 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 01 Aug 2014 18:39:30 +0300 Subject: Dict when defining not returning multi value key error References: <53db11c1$0$29986$c3e8da3$5496439d@news.astraweb.com> <53db96bc$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87vbqcnrrh.fsf@elektro.pacujo.net> Chris Angelico : >> but hash(x) == hash(y) does NOT imply that x == y. > > Hello, pigeonhole principle :) If this were false - that is, if equal > hashes DID imply equal objects - it would be necessary to completely > encode an object's state in its hash, and hashes would be impossibly > large. This would, in fact, destroy their value completely. Well, modern computing assumes precisely: hash(x) == hash(y) => x == y That principle is at play with strong authentication (HTTPS et al), version control (git et al), A handful of bits uniquely identify an object regardless of its size. Marko From steve+comp.lang.python at pearwood.info Fri Aug 1 11:41:41 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Aug 2014 15:41:41 GMT Subject: Getting a list of all modules References: <53d8a20e$0$29977$c3e8da3$5496439d@news.astraweb.com> <53da1d5a$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53dbb534$0$29986$c3e8da3$5496439d@news.astraweb.com> On Fri, 01 Aug 2014 14:39:09 +0100, Robert Kern wrote: > Take a look at what has already been implemented in IPython: > > https://github.com/ipython/ipython/blob/master/IPython/core/ completerlib.py#L208 Awesome! Thank you! -- Steven From __peter__ at web.de Fri Aug 1 11:44:27 2014 From: __peter__ at web.de (Peter Otten) Date: Fri, 01 Aug 2014 17:44:27 +0200 Subject: dict to boolean expression, how to? References: <53db8bd8$0$2976$e4fe514c@news2.news.xs4all.nl> <53dba39e$0$2976$e4fe514c@news2.news.xs4all.nl> Message-ID: Alex van der Spek wrote: > I do know eval() lends itself to code injection but can't say I am > fully aware of its dangers. It seemed like a handy tool to me. In a lab if you don't need to protect your script against attacks from outside eval() (and exec()) is fine. If the data fed to eval() is completely under your control (think collections.namedtuple) eval() is also fine. Adding a public web interface on such a lab application means trouble. > This newsgroup scares me, If you dare say that you are not scared enough ;) > it appears to be for professional computer > scientists only, the theoretical part is sometimes too much for this > practical physicist with an old background in FORTRAN. That sounds like you are experienced enough to say "There may be problems with this code, but I choose not to care about them this time -- at my own risk" > Is there a better place to ask questions of this nature? There is the tutor mailing list which is mostly geared at absolute beginners, does more hand-holding, and the threads are more likely to stay on topic. You might take a look, but with your background you are probably better off here. > I am sorry, the problem is ill posed. > > 'a', 'A' and so forth are my failed attempt to shorthand. > > In reality the dict's keys are column names in a pandas dataframe df. > > The boolean expression would therefore look like: > > bool = ((df['a'] == 1) & (df['A'] == 0) | > (df['b'] == 1) & (df['B'] == 0) | > (df['c'] == 1) & (df['C'] == 0)) This is how it might look without eval(): #untested result = functools.reduce(operator.or_, ((v == 1) & (df[k.upper()] == 0) for k, v in df.items() if k.islower())) And here is an eval-based solution: # untested expr = "|".join( "((df[{}] == 1) | (df[{}] == 0))".format(c, c.upper()) for c in df is c.islower()) result = eval(expr) -------------- next part -------------- A non-text attachment was scrubbed... Name: konsole.desktop Type: application/x-desktop Size: 4773 bytes Desc: not available URL: From breamoreboy at yahoo.co.uk Fri Aug 1 11:50:51 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 01 Aug 2014 16:50:51 +0100 Subject: dict to boolean expression, how to? In-Reply-To: <53db95e6$0$29986$c3e8da3$5496439d@news.astraweb.com> References: <53db8bd8$0$2976$e4fe514c@news2.news.xs4all.nl> <53db95e6$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 01/08/2014 14:28, Steven D'Aprano wrote: > On Fri, 01 Aug 2014 12:45:12 +0000, Alex van der Spek wrote: > >> With a dict like so: >> >> cond = {'a': 1, 'b': 1, 'c': 1, >> 'A': 0, 'B', 0, 'C':0} >> >> how would you make a boolean expression like this: >> >> bool = (('a' == 1) & ('A' == 0) | >> ('b' == 1) & ('B' == 0) | >> ('c' == 1) & ('C' == 0)) > > That's False. It's always False, because 'a' does not equal 1, etc. Also, > you're using bitwise operators & and | rather than boolean operators. > Finally, you are shadowing the built-in bool() type, which is probably a > bad idea. > > In the first case, I think you mean cond['a'] == 1 rather than just > 'a'==1; in the second case, the bool operators are called "and" and "or"; > and in the third case, there are many equally good names for a generic > boolean flag, like "flag". > > Putting those together, I think you probably mean something like this: > > flag = ( > (cond['a'] == 1 and cond['A'] == 0) or > (cond['b'] == 1 and cond['B'] == 0) or > (cond['c'] == 1 and cond['C'] == 0) > ) > > which can be simplified to: > > flag = any( cond[c] == 1 and cond[c.upper()] for c in ['a', 'b', 'c'] ) > Shouldn't that be cond[c.upper()] == 0 ? -- 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 Aug 1 12:03:02 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 01 Aug 2014 17:03:02 +0100 Subject: dict to boolean expression, how to? In-Reply-To: <53dbb140$0$29986$c3e8da3$5496439d@news.astraweb.com> References: <53db8bd8$0$2976$e4fe514c@news2.news.xs4all.nl> <53dba39e$0$2976$e4fe514c@news2.news.xs4all.nl> <53dbb140$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 01/08/2014 16:24, Steven D'Aprano wrote: > I don't know of anyone here who is an expert in pandas, so if you ask > questions which are specific to pandas, we may run into the limits of our > knowledge. If you can find a dedicated pandas mailing list or other > forum, they may help too, but I don't know if they will be more or less > willing to explain the basics about Python. > https://mail.python.org/mailman/listinfo/pandas-dev or gmane.comp.python.pydata As it's so handy see here http://news.gmane.org/index.php?prefix=gmane.comp.python for the all python lists on gmane. -- 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 Aug 1 12:12:59 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 01 Aug 2014 17:12:59 +0100 Subject: dict to boolean expression, how to? In-Reply-To: <53dba39e$0$2976$e4fe514c@news2.news.xs4all.nl> References: <53db8bd8$0$2976$e4fe514c@news2.news.xs4all.nl> <53dba39e$0$2976$e4fe514c@news2.news.xs4all.nl> Message-ID: On 01/08/2014 15:26, Alex van der Spek wrote: > On Fri, 01 Aug 2014 12:45:12 +0000, Alex van der Spek wrote: > >> With a dict like so: >> >> cond = {'a': 1, 'b': 1, 'c': 1, >> 'A': 0, 'B', 0, 'C':0} >> >> how would you make a boolean expression like this: >> >> bool = (('a' == 1) & ('A' == 0) | >> ('b' == 1) & ('B' == 0) | >> ('c' == 1) & ('C' == 0)) >> >> The fact that lowercase and uppercase keys are stringed together with & >> is intentional albeit the actual condition is a bit more tricky. >> >> I've tried several approaches using eval() on a string built from the >> dict but landed with just spelling it out literally. >> >> >> Any pointers welcome. >> Alex > > I am sorry, the problem is ill posed. > > 'a', 'A' and so forth are my failed attempt to shorthand. > > In reality the dict's keys are column names in a pandas dataframe df. > > The boolean expression would therefore look like: > > bool = ((df['a'] == 1) & (df['A'] == 0) | > (df['b'] == 1) & (df['B'] == 0) | > (df['c'] == 1) & (df['C'] == 0)) See this http://stackoverflow.com/questions/19482970/python-get-list-from-pandas-dataframe-column-headers to get the column names. Combine this with Steven D'Aprano's earlier answer using any() and I suspect you're there. > > I do know eval() lends itself to code injection but can't say I am > fully aware of its dangers. It seemed like a handy tool to me. It strikes me as being like looking down the gun barrel to see if there's a bullet loaded whilst holding the trigger. Best avoided but there's always the "consenting adults" approach here :) > > This newsgroup scares me, it appears to be for professional computer > scientists only, the theoretical part is sometimes too much for this > practical physicist with an old background in FORTRAN. If you're smart enough to state that your first question was ill posed, you're smart enough to ask questions when you don't understand. > > Is there a better place to ask questions of this nature? No :) > > Alex van der Spek > -- 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 Aug 1 12:35:03 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Aug 2014 16:35:03 GMT Subject: dict to boolean expression, how to? References: <53db8bd8$0$2976$e4fe514c@news2.news.xs4all.nl> <53db95e6$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53dbc1b6$0$29986$c3e8da3$5496439d@news.astraweb.com> On Fri, 01 Aug 2014 16:50:51 +0100, Mark Lawrence wrote: >> which can be simplified to: >> >> flag = any( cond[c] == 1 and cond[c.upper()] for c in ['a', 'b', 'c'] ) >> >> > Shouldn't that be cond[c.upper()] == 0 ? Yes it should be, thank you! -- Steven From ppearson at nowhere.invalid Fri Aug 1 13:00:15 2014 From: ppearson at nowhere.invalid (Peter Pearson) Date: 1 Aug 2014 17:00:15 GMT Subject: dict to boolean expression, how to? References: <53db8bd8$0$2976$e4fe514c@news2.news.xs4all.nl> <53dba39e$0$2976$e4fe514c@news2.news.xs4all.nl> Message-ID: On 01 Aug 2014 14:26:38 GMT, Alex van der Spek wrote: [snip] > This newsgroup scares me, it appears to be for professional computer > scientists only, the theoretical part is sometimes too much for this > practical physicist with an old background in FORTRAN. > > Is there a better place to ask questions of this nature? Relax. This newsgroup cheerfully deals with noobs much more noobish than you. It's an amazingly polite and helpful place, and many of the regulars are top experts on Python. Hang around, you'll like it. -- To email me, substitute nowhere->spamcop, invalid->net. From maillist at schwertberger.de Fri Aug 1 13:16:43 2014 From: maillist at schwertberger.de (Dietmar Schwertberger) Date: Fri, 01 Aug 2014 19:16:43 +0200 Subject: Python and IDEs [was Re: Python 3 is killing Python] In-Reply-To: <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> References: <87zjga4j4v.fsf@elektro.pacujo.net> <53c57bae$0$9505$c3e8da3$5496439d@news.astraweb.com> <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> Message-ID: <53DBCB7B.80704@schwertberger.de> Am 01.08.2014 13:10, schrieb Wolfgang Keller: > Because on such operating systems, each and every application is an > entirely self-contained package that doesn't need any "packages" or > "installers" to use it. For people who have never used such a system it's probably difficult to see the advantages. Besides the easy installation, backup and replication of software the RISC OS way also had the advantage that you were able to organize your applications in folders just like other folders and files. There was no need for separate File and Program managers. MS never got this right. Instead, they tried to fix things later with the start menu and finally the box to type the software name to start it ... One effect was that under DOS/Windows people usually saved their documents in folders per application whereas under RISC OS they were usually grouped by content/project. When it came to usability, RISC OS had many advantages over the other systems, e.g. - real drag'n'drop for loading *and* saving of files/selections - drag'n'drop also for transfer between applications - a standard vector graphics format that all applications supported (and for which an application was provided by default with the OS) - good font display (still better than e.g. MS Windows today) - three mouse buttons for select/menu/adjust - no menu bars - the icon bar for running applications, drives, shares and other resources - consistent, orthogonal & logical user interfaces instead of assistants and wizards for each and every task - complete programmers reference manual Regards, Dietmar From bv4bv4bv4 at gmail.com Fri Aug 1 13:24:12 2014 From: bv4bv4bv4 at gmail.com (bv4bv4bv4 at gmail.com) Date: Fri, 1 Aug 2014 10:24:12 -0700 (PDT) Subject: Women's Rights in Islam Message-ID: <984ded8c-c31d-4cb2-92a8-403ea0035671@googlegroups.com> Women's Rights in Islam "And for women are rights over men, similar to those of men over women."Qur'an 2:228Women in Islam are thought to be subjugated, degraded, oppressed - but are they really? Are millions of Muslims simply that oppressive or are these misconceptions fabricated by a biased media? Over fourteen hundred years ago, Islam gave women rights that women in the West have only recently began to enjoy. In the 1930's, Annie Besant observed, "It is only in the last twenty years that Christian England has recognised the right of woman to property, while Islam has allowed this right from all times. It is a slander to say that Islam preaches that women have no souls." (The Life and Teachings of Mohammed, 1932). Men and women all descended from a single person - the Prophet Adam (peace be upon him). Islam does not accept for either of them anything but justice and kind treatment. Equal Reward & Equal Accountability Men and women worship Allah in the same way, meaning they worship the same God (Allah), perform the same acts of worship, follow the same scripture, and hold the same beliefs. Allah (the Arabic word for the One true God of all creation), judges all human beings fairly and equitably. Allah emphasises the just treatment and reward due to both men and women in many verses of the Qur'an: "Allah has promised to the believers, men and women, gardens under which rivers flow, to dwell therein, and beautiful mansions in gardens of everlasting bliss."Qur'an 9:72 "Never will I allow the loss of the work of any worker amongst you, male or female; you are of one another."Qur'an 3:195 These verses show that reward is dependent upon one's actions and not one's gender. Gender does not play any part in how a person is rewarded and judged. If we compare Islam to other religions, we see that it offers justice between the sexes. For example, Islam dismisses the idea that Eve is more to blame than Adam for eating from the forbidden tree. According to Islam, Adam and Eve both sinned, they both repented and God forgave them both. Equal Right to Knowledge Both men and women are equally encouraged to seek knowledge. The Prophet (peace be upon him) said, "Education is compulsory for every Muslim." Also, great female Muslim Scholars existed at and around the time of the Prophet (peace be upon him). Some were from his family and others were his companions or their daughters. Prominent amongst them was Aisha, the wife of the Prophet (peace be upon him) through whom a quarter of the Islamic law has been transmitted. Other females were great scholars of jurisprudence and had famous male scholars as their students. Equal Right to Choose a Spouse Islam has honoured women by giving them the right to choose a spouse and keep their original family name once married. Additionally, many have the impression that parents force their daughters into marriage. This is a cultural practice, and has no basis in Islam. In fact, it is prohibited. At the time of Prophet Muhammad (peace be upon him), a woman came to him and said, "My father has married me to my cousin to raise his social standing and I was forced into it." The Prophet sent for the girl's father and then in his presence gave the girl the option of remaining married or nullifying the marriage. She responded, "O Messenger of Allah, I have accepted what my father did, but I wanted to show other women (that they could not be forced into a marriage)." Equal yet Different While men and women have equal rights as a general principle, the specific rights and responsibilities granted to them are not identical. Men and women have complementary rights and responsibilities. Aside from external and internal anatomical differences, scientists know there are many other subtle differences in the way the brains of men and women process language, information and emotion, just to mention a few. A socio-biology expert, Edward O. Wilson of Harvard University, said that females tend to be higher than males in verbal skills, empathy and social skills, among other things, while men tend to be higher in independence, dominance, spatial and mathematical skills, rank-related aggression, and other characteristics. It would be foolish to treat both genders the same and to ignore their differences. Islam teaches that men and women have complementary, yet different, roles because it is best suited to their nature. God says: "And the male is not like the female."Qur'an 3:36 "Does not the One who created, know? And He is the Most Kind, the All Aware."Qur'an 67:14 The Family Unit God created men and women to be different, with unique roles, skills and responsibilities. These differences are not viewed as evidences of superiority or inferiority, but of specialisation. In Islam, the family is of central importance. The man is responsible for the financial well being of the family while the woman contributes to the family's physical, educational and emotional well being. This encourages cooperation rather than competition. By fulfilling their mutual responsibilities, strong families are created and hence strong societies. Also, emotionally, neither men nor women live a happy life without one another. Allah describes this beautifully by saying: "They are clothing for you and you are clothing for them."Qur'an 2:187 Clothing provides comfort, warmth and security as well as making one look good - this is how the relationship between the husband and wife is defined in Islam. Love & Mercy in Spousal Relations The Prophet (peace be upon him) also encouraged men to treat their spouses in the best way, "The best of you are those who are best (in treatment) to their wives." "And among His signs is that He created or you wives amongst yourselves that you may dwell in tranquillity with them; and He has put love and mercy between your (hearts). Surely in this are Signs for people who reflect."Qur'an 30:21 Aisha (the Prophet's wife) was once asked how the Prophet's conduct was in his home. She said,"He was like one of you at home, yet he was most lenient and most generous ... He was ready to give a helping hand to his wives in the ordinary work of the house, [he] sewed his own clothes and mended his own shoes." In general, he helped in whatever work his wives did. Lofty Positions of Mothers & Daughters A mother has the greatest influence on a child especially in the earlier years through her affection, care and love. Undoubtedly, the success of a society is due to mothers. Therefore, it is only right for Islam to honour and raise their status. Allah says in the Qur'an: "And we have enjoined on man to be dutiful and kind to his Parents, His mother bears him with hardship and she brings him forth with hardship."Qur'an 46:15 The Prophet (peace be upon him) was once asked, "O Messenger of Allah, who among people is most deserving of my good treatment?" He said, "Your mother." The man asked twice more, "Then who?" and was given the same response. Only until the fourth time did the Prophet respond, "Then your father." Reward is not only given to the good and kind treatment towards mothers. In fact, Islam has designated a special reward for raising daughters that is not granted for raising sons. The Prophet Muhammad (peace be upon him) said, "Whoever Allah has given two daughters and is kind towards them, they will be a reason for him entering Paradise." Conclusion Before Islam, women were considered shameful, female children were buried alive, prostitution was rampant, divorce was only in the hands of the husband, inheritance was only for the strong, and oppression was widespread. Islam came and abolished these practices. Even now, in "developed countries", women are not granted respect, dignity and honour, let alone equal pay for equal work. Islam, however, regards women as precious and valuable, not to be disrespected or disgraced. The mistreatment of women in some Middle-Eastern countries or Muslim families is due to cultural factors that some Muslims wrongly follow, not because of Islam. Why would many women around the world willingly enter Islam if it is an oppressive religion? We end with the words of our Lord and your Lord, the Creator and Sustainer of all men and women: "Surely the men who submit and the women who submit, and the believing men and the believing women, and the obedient men and the obedient women, and the truthful men and the truthful women, and the patient men and the patient women, and the humble men and the humble women... Allah has prepared for them forgiveness and a great reward."Qur'an 33:35 http://islamicpamphlets.com/womens-rights-in-islam/ Thank you From torriem at gmail.com Fri Aug 1 16:22:20 2014 From: torriem at gmail.com (Michael Torrie) Date: Fri, 01 Aug 2014 14:22:20 -0600 Subject: Python and IDEs [was Re: Python 3 is killing Python] In-Reply-To: References: <53c57bae$0$9505$c3e8da3$5496439d@news.astraweb.com> <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> Message-ID: <53DBF6FC.6020004@gmail.com> On 08/01/2014 08:39 AM, Chris Angelico wrote: > The installer has basically three choices. > 1) Install libnettle inside the application directory > 2) Install libnettle to some system library directory > 3) Don't install libnettle, and demand that someone else (perhaps the > user, or the system package manager) install it. > > Option 1 results in duplications. (Unless one application is allowed > to access a library in another application's directory, which is a > HORRIBLE mess.) Option 2 is exactly what you're complaining about, > scattering files all over the FS. And option 3 is what package > managers are for. What are you advocating? Option 1 also is a huge security hole. A prime example of this was the so-called heartbleed bug. In such a model, each app that distributes openssl in the app bundle has to be updated or it is at risk. This turns out to be a huge vulnerability. From w.g.sneddon at gmail.com Fri Aug 1 16:35:44 2014 From: w.g.sneddon at gmail.com (bSneddon) Date: Fri, 1 Aug 2014 13:35:44 -0700 (PDT) Subject: Creating a 2s compliment hex string for negitive numbers Message-ID: <17160115-a77f-436a-837c-cd2039a7c53f@googlegroups.com> I need to calculate an error correction code for an old protocol. I calculate the integer 4617 and want to code the 2s compliment in ASCII hex EDF7. When issue the following. >>> hex(-4617) '-0x1209' Does anyone know a clean way to get to the desired results? My ECC will always be 16 bit (4 nibble) hex number. Bill From python at mrabarnett.plus.com Fri Aug 1 16:47:20 2014 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 01 Aug 2014 21:47:20 +0100 Subject: Creating a 2s compliment hex string for negitive numbers In-Reply-To: <17160115-a77f-436a-837c-cd2039a7c53f@googlegroups.com> References: <17160115-a77f-436a-837c-cd2039a7c53f@googlegroups.com> Message-ID: <53DBFCD8.3030208@mrabarnett.plus.com> On 2014-08-01 21:35, bSneddon wrote: > I need to calculate an error correction code for an old protocol. > > I calculate the integer 4617 and want to code the 2s compliment in ASCII > hex EDF7. When issue the following. >>>> hex(-4617) > '-0x1209' > > Does anyone know a clean way to get to the desired results? My ECC will always > be 16 bit (4 nibble) hex number. > Use a bitwise AND: >>> hex(-4617 & 0xFFFF) '0xedf7' From python at mrabarnett.plus.com Fri Aug 1 17:09:12 2014 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 01 Aug 2014 22:09:12 +0100 Subject: Python and IDEs [was Re: Python 3 is killing Python] In-Reply-To: <53DBCB7B.80704@schwertberger.de> References: <87zjga4j4v.fsf@elektro.pacujo.net> <53c57bae$0$9505$c3e8da3$5496439d@news.astraweb.com> <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> <53DBCB7B.80704@schwertberger.de> Message-ID: <53DC01F8.3080505@mrabarnett.plus.com> On 2014-08-01 18:16, Dietmar Schwertberger wrote: > Am 01.08.2014 13:10, schrieb Wolfgang Keller: >> Because on such operating systems, each and every application is an >> entirely self-contained package that doesn't need any "packages" or >> "installers" to use it. > For people who have never used such a system it's probably difficult to see > the advantages. > > Besides the easy installation, backup and replication of software the > RISC OS > way also had the advantage that you were able to organize your > applications in folders just like other folders and files. > There was no need for separate File and Program managers. > MS never got this right. Instead, they tried to fix things later with the > start menu and finally the box to type the software name to start it ... > > One effect was that under DOS/Windows people usually saved their > documents in folders per application whereas under RISC OS they > were usually grouped by content/project. > > > When it came to usability, RISC OS had many advantages over the > other systems, e.g. > - real drag'n'drop for loading *and* saving of files/selections > - drag'n'drop also for transfer between applications > - a standard vector graphics format that all applications supported > (and for which an application was provided by default with the OS) > - good font display (still better than e.g. MS Windows today) > - three mouse buttons for select/menu/adjust > - no menu bars > - the icon bar for running applications, drives, shares and other > resources > - consistent, orthogonal & logical user interfaces instead of assistants > and wizards for each and every task > - complete programmers reference manual > I'd heard people say how user-friendly Apple Macs were, but when I got to use one I was somewhat disappointed. When opening files, it used old-fashioned dialog boxes like RISC OS's precursor from several years earlier. In RISC OS, if I had a directory window open, I could save to it with a simple drag-and-drop, but in MacOS, even if I had a directory window open, I had to navigate to the directory in the Save dialog. (OK, not quite true, because of a 3rd-party extension called "Click There It Is".) And don't mention the menu bar across the top, separated from the window to which it belonged. Or the way that clicking on any window of an application or the Finder brought not only it but also all of the its siblings to the front. On RISC OS, windows came to the front only when *I* wanted them to. From w.g.sneddon at gmail.com Fri Aug 1 17:25:40 2014 From: w.g.sneddon at gmail.com (bSneddon) Date: Fri, 1 Aug 2014 14:25:40 -0700 (PDT) Subject: Creating a 2s compliment hex string for negitive numbers In-Reply-To: References: <17160115-a77f-436a-837c-cd2039a7c53f@googlegroups.com> Message-ID: On Friday, August 1, 2014 4:47:20 PM UTC-4, MRAB wrote: > On 2014-08-01 21:35, bSneddon wrote: > > > I need to calculate an error correction code for an old protocol. > > > > > > I calculate the integer 4617 and want to code the 2s compliment in ASCII > > > hex EDF7. When issue the following. > > >>>> hex(-4617) > > > '-0x1209' > > > > > > Does anyone know a clean way to get to the desired results? My ECC will always > > > be 16 bit (4 nibble) hex number. > > > > > Use a bitwise AND: > > > > >>> hex(-4617 & 0xFFFF) > > '0xedf7' Thanks From tjreedy at udel.edu Fri Aug 1 17:42:10 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 01 Aug 2014 17:42:10 -0400 Subject: Dict when defining not returning multi value key error In-Reply-To: <87vbqcnrrh.fsf@elektro.pacujo.net> References: <53db11c1$0$29986$c3e8da3$5496439d@news.astraweb.com> <53db96bc$0$29986$c3e8da3$5496439d@news.astraweb.com> <87vbqcnrrh.fsf@elektro.pacujo.net> Message-ID: On 8/1/2014 11:39 AM, Marko Rauhamaa wrote: > Chris Angelico : > >>> but hash(x) == hash(y) does NOT imply that x == y. >> >> Hello, pigeonhole principle :) If this were false - that is, if equal >> hashes DID imply equal objects - it would be necessary to completely >> encode an object's state in its hash, and hashes would be impossibly >> large. This would, in fact, destroy their value completely. > > Well, modern computing assumes precisely: > > hash(x) == hash(y) => x == y Assuming that a false statement is true does not make it true, and can and has gotten 'computing' into trouble. > That principle is at play with strong authentication (HTTPS et al), > version control (git et al), The principle for these applications is stronghash(x) == stronghash(y) => x == y with probability 1 (or indistinguishable from 1). For mercurial, with no treat model, a 160 bit hash is used. Internet applications need more bits and carefully vetted algorithms to hopefully make the actual principle true. -- Terry Jan Reedy From tjreedy at udel.edu Fri Aug 1 18:16:54 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 01 Aug 2014 18:16:54 -0400 Subject: dict to boolean expression, how to? In-Reply-To: <53dbabee$0$29986$c3e8da3$5496439d@news.astraweb.com> References: <53db8bd8$0$2976$e4fe514c@news2.news.xs4all.nl> <53db95e6$0$29986$c3e8da3$5496439d@news.astraweb.com> <53dbabee$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 8/1/2014 11:02 AM, Steven D'Aprano wrote: > On Fri, 01 Aug 2014 09:32:36 -0400, Roy Smith wrote: > >> In article <53db95e6$0$29986$c3e8da3$5496439d at news.astraweb.com>, >> Steven D'Aprano wrote: >> >>> eval is almost never the right solution to any problem, and in the very >>> few exceptions, it needs careful handling by an expert to ensure you're >>> not introducing serious security bugs. >> >> Corollary to that rule: All the people who are smart enough to actually >> understand how to use eval() safety, are also smart enough to know not >> to use it. Eval is a specialized version of exec. Everything you do on a computer is evaluating and executing code. Here is a highly simplified version of a Python interpreter: user_program = get_user_python_code() __main__ = make_global_namespace() exec(user_program, __main__, __main__) CPython codes an expansion of the above in C. Idle uses an expansion of the above to do the same thing. The threat model is executing code from someone who does not have physical access to a machine to just run code and who should not be trusted. > ... smart enough to know WHEN to use it (which is *rarely*). > > That's in production code, of course. There's nothing wrong with using > eval in the interactive interpreter for quick and dirty exploration. But > even then, I find that it's usually easier to write a line or two of > Python code to process something than to try using eval. > > There are uses for eval (or exec), even if production code. See > collections.namedtuple, doctest, and timeit, for example. In the first > place, namedtuple takes extra care to sanitise the data being used. In > the case of doctest and timeit, the whole point of them is to run trusted > code. If you can't trust your own code that you're timing, what can you > trust? Exactly. If someone can start Python or Idle on a machine, they can start Windows Explorer and Command Prompt. Idle exec's user code because emulating the interactive interpreter is part of its purpose. It sometimes evals expression within user code in response to user requests. -- Terry Jan Reedy From greg.ewing at canterbury.ac.nz Fri Aug 1 19:14:20 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 02 Aug 2014 11:14:20 +1200 Subject: Python and IDEs [was Re: Python 3 is killing Python] In-Reply-To: References: <53c57bae$0$9505$c3e8da3$5496439d@news.astraweb.com> <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> Message-ID: Chris Angelico wrote: > The installer has basically three choices. > 1) Install libnettle inside the application directory > 2) Install libnettle to some system library directory > 3) Don't install libnettle, and demand that someone else (perhaps the > user, or the system package manager) install it. > > Option 2 is exactly what you're complaining about, > scattering files all over the FS. Not really. On MacOSX, if you installed a shared library called libnettle, *all* the files relating to it would be kept in one directory called Nettle.framework (either in /Library/Frameworks or ~/Library/Frameworks depending on whether it's system-wide or for a single user). MacOSX doesn't currently have an automatic dependency manager, but if it did, things would still be a lot neater and tidier than they are in Linux or Windows, where what is conceptually a single object (a package) gets split up and its parts scattered around several obscure locations. -- Greg From rosuav at gmail.com Fri Aug 1 19:48:16 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Aug 2014 09:48:16 +1000 Subject: Python and IDEs [was Re: Python 3 is killing Python] In-Reply-To: <53DBF6FC.6020004@gmail.com> References: <53c57bae$0$9505$c3e8da3$5496439d@news.astraweb.com> <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> <53DBF6FC.6020004@gmail.com> Message-ID: On Sat, Aug 2, 2014 at 6:22 AM, Michael Torrie wrote: > On 08/01/2014 08:39 AM, Chris Angelico wrote: >> The installer has basically three choices. >> 1) Install libnettle inside the application directory >> 2) Install libnettle to some system library directory >> 3) Don't install libnettle, and demand that someone else (perhaps the >> user, or the system package manager) install it. >> >> Option 1 results in duplications. (Unless one application is allowed >> to access a library in another application's directory, which is a >> HORRIBLE mess.) Option 2 is exactly what you're complaining about, >> scattering files all over the FS. And option 3 is what package >> managers are for. What are you advocating? > > Option 1 also is a huge security hole. A prime example of this was the > so-called heartbleed bug. In such a model, each app that distributes > openssl in the app bundle has to be updated or it is at risk. This > turns out to be a huge vulnerability. More generally, that's exactly what Steven said about needing every package to update before you can confidently say it's updated. But that's also the greatest feature of the first option: you can't break this application by upgrading that library, because only upgrading the application (which hopefully will have been tested by the author) will upgrade the library it uses. ChrisA From rosuav at gmail.com Fri Aug 1 19:50:13 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Aug 2014 09:50:13 +1000 Subject: Python and IDEs [was Re: Python 3 is killing Python] In-Reply-To: References: <53c57bae$0$9505$c3e8da3$5496439d@news.astraweb.com> <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> Message-ID: On Sat, Aug 2, 2014 at 9:14 AM, Gregory Ewing wrote: > Chris Angelico wrote: >> >> The installer has basically three choices. >> 1) Install libnettle inside the application directory >> 2) Install libnettle to some system library directory >> 3) Don't install libnettle, and demand that someone else (perhaps the >> user, or the system package manager) install it. >> >> Option 2 is exactly what you're complaining about, >> scattering files all over the FS. > > > Not really. On MacOSX, if you installed a shared library > called libnettle, *all* the files relating to it > would be kept in one directory called Nettle.framework > (either in /Library/Frameworks or ~/Library/Frameworks > depending on whether it's system-wide or for a single user). > > MacOSX doesn't currently have an automatic dependency > manager, but if it did, things would still be a lot neater > and tidier than they are in Linux or Windows, where what > is conceptually a single object (a package) gets split up > and its parts scattered around several obscure locations. That's fine if I explicitly install libnettle - that's the third option. What happens if I install Foo's Cool Chat App, and FCCA uses libnettle to encrypt conversations? Is FCCA allowed to install libnettle into /Library/Frameworks? If so, its files will be split between there and its own app directory. ChrisA From rosuav at gmail.com Fri Aug 1 19:57:02 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Aug 2014 09:57:02 +1000 Subject: Dict when defining not returning multi value key error In-Reply-To: References: <53db11c1$0$29986$c3e8da3$5496439d@news.astraweb.com> <53db96bc$0$29986$c3e8da3$5496439d@news.astraweb.com> <87vbqcnrrh.fsf@elektro.pacujo.net> Message-ID: On Sat, Aug 2, 2014 at 7:42 AM, Terry Reedy wrote: > For mercurial, with no treat model, a 160 bit hash is used. Internet > applications need more bits and carefully vetted algorithms to hopefully > make the actual principle true. Ditto git, which also has no threat model. I don't know of any situation in HTTPS that has this, but the classic concept of hashed passwords (quite independent of HTTPS) basically says "if I take an arbitrary/random salt and combine it with your password, and hash that, then the probability of a hash collision involving the same salt and a different password approaches 0". And any time "approaches 0" is provably false (or doesn't approach 0 closely enough), you have weak passwords, which is why it's a really bad idea to use MD5 passwording. Ergo MD5 is not (any more, at least) a "carefully vetted algorithm". (That said, though, I will happily use md5sum across a huge pile of files to find duplicates. It's a lot quicker than sha*sum, and I don't have reason to expect malicious hash collisions on my own hard drive. Plus, I can always just check some other way.) ChrisA From greg.ewing at canterbury.ac.nz Fri Aug 1 20:00:57 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 02 Aug 2014 12:00:57 +1200 Subject: Python and IDEs [was Re: Python 3 is killing Python] In-Reply-To: References: <87zjga4j4v.fsf@elektro.pacujo.net> <53c57bae$0$9505$c3e8da3$5496439d@news.astraweb.com> <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> <53DBCB7B.80704@schwertberger.de> Message-ID: MRAB wrote: > I'd heard people say how user-friendly Apple Macs were, but when I got > to use one I was somewhat disappointed. Well, they were compared to MS-DOS and the like, which was all that was within reach of the general public when the first Mac appeared. RISCOS came along somewhat later. > in MacOS, even if I had a directory window open, I had to navigate to the > directory in the Save dialog. Yes, that was annoying. It wasn't a problem to begin with, because the original Mac was strictly single-tasking -- you couldn't *have* a directory window and an application open at the same time. And all your files were on floppies in a flat file system -- folders only existed in the Finder's imagination -- so the only real choice to be made when saving a file was "which disk do I put it on". When multitasking, hard disks and hierarchical file systems came along, there was an opportunity for a rethink, but it never really happened. Things are somewhat better in MacOSX, where you can drag a folder from a Finder window onto a file dialog to take you there, but there is still more of a distinction between Finder windows and save dialogs than there needs to be. > And don't mention the menu bar across the top, separated from the > window to which it belonged. That seems to be a matter of taste. There are some advantages to the menu-bar-at-top model. It's an easier target to hit, because you can just flick the mouse up to the top. It only takes up space once, instead of once per window. It makes it possible for an app to be running without having any windows, and still be able to interact with it. > Or the way that clicking on any window of an application or the Finder > brought not only it but also all of the its siblings to the front. MacOSX has fixed that one, thankfully. Only the window you click comes to the front, now. -- Greg From rosuav at gmail.com Fri Aug 1 20:20:55 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Aug 2014 10:20:55 +1000 Subject: Python and IDEs [was Re: Python 3 is killing Python] In-Reply-To: References: <87zjga4j4v.fsf@elektro.pacujo.net> <53c57bae$0$9505$c3e8da3$5496439d@news.astraweb.com> <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> <53DBCB7B.80704@schwertberger.de> Message-ID: On Sat, Aug 2, 2014 at 10:00 AM, Gregory Ewing wrote: > MRAB wrote: >> in MacOS, even if I had a directory window open, I had to navigate to the >> directory in the Save dialog. > > Yes, that was annoying. It wasn't a problem to begin with, > because the original Mac was strictly single-tasking -- > you couldn't *have* a directory window and an application > open at the same time. And all your files were on floppies > in a flat file system -- folders only existed in the > Finder's imagination -- so the only real choice to be > made when saving a file was "which disk do I put it on". Okay, so it was like DOS 1.0... > When multitasking, hard disks and hierarchical file > systems came along, there was an opportunity for a > rethink, but it never really happened. ... and it didn't get improved when it grew directories like DOS 2.0 did. It's like how the default DOS prompt is actually $N$G when $P$G is a lot more useful, except that changing the default prompt is pretty easy and applies globally (not to mention that you might well want to enhance the prompt beyond just $P$G). >> And don't mention the menu bar across the top, separated from the >> window to which it belonged. > > That seems to be a matter of taste. There are some > advantages to the menu-bar-at-top model. It's an easier > target to hit, because you can just flick the mouse up > to the top. It only takes up space once, instead of > once per window. It makes it possible for an app to > be running without having any windows, and still be > able to interact with it. Downside: It separates (graphically and logically) a window from its menu bar. The "easier target for the mouse" argument is valuable ONLY when you use the mouse to access the menu bar. If you use the keyboard (and take advantage of mnemonic letters), it's much more useful to have the menu bar attached to its window. In the rare case of an app that runs without any windows, incidentally, how do you tell the system that you want that app's menu bar instead of (say) Finder, which comes up when you click on the desktop? ChrisA From steve+comp.lang.python at pearwood.info Fri Aug 1 21:47:38 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 02 Aug 2014 11:47:38 +1000 Subject: Dict when defining not returning multi value key error References: <53db11c1$0$29986$c3e8da3$5496439d@news.astraweb.com> <53db96bc$0$29986$c3e8da3$5496439d@news.astraweb.com> <87vbqcnrrh.fsf@elektro.pacujo.net> Message-ID: <53dc433b$0$29979$c3e8da3$5496439d@news.astraweb.com> Marko Rauhamaa wrote: > Chris Angelico : > >>> but hash(x) == hash(y) does NOT imply that x == y. >> >> Hello, pigeonhole principle :) If this were false - that is, if equal >> hashes DID imply equal objects - it would be necessary to completely >> encode an object's state in its hash, and hashes would be impossibly >> large. This would, in fact, destroy their value completely. > > Well, modern computing assumes precisely: > > hash(x) == hash(y) => x == y I really don't think that the behaviour of Python's built-in hash() function is of fundamental concern to all of modern computing. Python's hash() function is of fundamental concern to Python dicts, and that's all. > That principle is at play with strong authentication (HTTPS et al), > version control (git et al), git is not even written in Python. HTTPS is a protocol, so it could be written in Python, but typically isn't. Neither of them use Python's hash(), because the people writing these applications aren't insane. Collisions in Python's hash() are trivially easy to find, and the existence of such collisions is well-known. Perhaps you're talking about cryptographically strong hash functions, of which there are a few? If so, a brief note that you were changing the subject would be appreciated :-) The pigeonhole principle applies to crypto hash functions too, and there is active research into creating newer and stronger hash functions as the older ones are broken. For instance, md4, md5, md2 and sha-0 hash functions have all be broken, and shouldn't be used for anything where security is of concern. > A handful of bits uniquely identify an object regardless of its size. No. The principle being applied is not that a handful of bits *uniquely* identifies an object, since that is clearly and obviously untrue: consider objects of size 1K, there are 2**1024 possible such objects. I don't know what "a handful" of bits is, but let's say 128 bits, so there are 2**128 possible hashes. It doesn't take much mathematics to see that you cannot *uniquely* hash 2**1024 objects into only 2**128 checksums without quite a few collisions. The actual principle being applied is that, with a cryptographically strong hash function, a handful of bits can *practically* identify an object regardless of its size. Let's take that 128 bit checksum again: that means that there are 340282366920938463463374607431768211456 possible checksums. If the input files are unpredictably hashed over that entire range, on average you would have to generate half that number of hashes before stumbling across a collision purely by chance. Half of 2**128 is still a rather big number: if you generated a million hashes a second, on average it would take you considerably more than a billion years to accidentally hit a collision. For practical purposes, that's good enough. But note that there are numerous provisos there, including: - It relies on the hash function generating a large enough handful of bits. An 8 bit checksum only has 2**8 = 256 unique values, so you would find a collision pretty quickly. - It relies on the mapping of original object to checksum being randomly distributed. If they are not randomly distributed, then there will be sets of objects which collide more often than expected. For instance, suppose that every object containing a 0 byte hashed to the same value. Then, on average, you would not have to wait very long before finding your first collision. - It relies on the checksum being unpredictable, to prevent substitution attacks: you're expecting object x with checksum a, but somebody substitutes object y with checksum a instead. Python's hash() function is not cryptographically strong and makes no claim to be. -- Steven From rosuav at gmail.com Fri Aug 1 22:13:27 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Aug 2014 12:13:27 +1000 Subject: Dict when defining not returning multi value key error In-Reply-To: <53dc433b$0$29979$c3e8da3$5496439d@news.astraweb.com> References: <53db11c1$0$29986$c3e8da3$5496439d@news.astraweb.com> <53db96bc$0$29986$c3e8da3$5496439d@news.astraweb.com> <87vbqcnrrh.fsf@elektro.pacujo.net> <53dc433b$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Aug 2, 2014 at 11:47 AM, Steven D'Aprano wrote: > - It relies on the checksum being unpredictable, to prevent substitution > attacks: you're expecting object x with checksum a, but somebody > substitutes object y with checksum a instead. Note that this requirement is only an issue when there are actual attacks involved. In many cases, hashing is used to detect either errors in transfer (eg truncated files) or meaningfully different files (eg MP3s of different songs). A collision between those won't be the result of someone deliberately crafting a file with the right checksum; it'll happen only by chance, so md5sum can be safely used there. But if you're trying to use this to prove that a file was downloaded correctly, you do need to worry about that. If I say that you can download the binary of my program from , and that the MD5 checksum is 123456...DEF, then someone could do a DNS hack (cache poisoning, proxy interference, whatever) to capture your attempted download, and send you instead to his own server, where he has a carefully crafted binary that does everything mine does, plus it tells him all your passwords - and it has arbitrary junk buried in it to make sure the MD5 sum matches. So an MD5 checksum is broken for anything from the internet, but is quite usable for certain specific cases. There is one aspect of the unpredictability that's important even in the simple cases, though, and that's the avalanche effect. If anything changes in the file, the whole hash should completely and arbitrarily change. That means you don't need to stare at the whole hash, trying to see if that 8 became a 0; any change to the file will probably make the first few digits visibly different, so it's easily obvious that the hash has changed. ChrisA From 4kir4.1i at gmail.com Fri Aug 1 22:17:52 2014 From: 4kir4.1i at gmail.com (Akira Li) Date: Sat, 02 Aug 2014 06:17:52 +0400 Subject: Bug with help (was Re: Getting a list of all modules) References: <53d8a20e$0$29977$c3e8da3$5496439d@news.astraweb.com> <87oaw5xsrd.fsf@gmail.com> Message-ID: <877g2r7hyn.fsf@gmail.com> Mark Lawrence writes: > On 31/07/2014 19:55, Akira Li wrote: >> Steven D'Aprano writes: >> >>> I'm looking for a programmatic way to get a list of all Python modules >>> and packages. Not just those already imported, but all those which >>> *could* be imported. >> ... >>> Is this problem already solved? Can anyone make any suggestions? >> >> Look at how `help('modules')` is implemented. Though it crashes on my >> system. >> > > Have you reported this at bugs.python.org or is there already an issue > for the problem that you see? It is this issue for python2.7: https://bugs.launchpad.net/ubuntu/+source/python2.7/+bug/896836 python3 doesn't crash with currently installed packages. -- Akira From 4kir4.1i at gmail.com Fri Aug 1 22:53:44 2014 From: 4kir4.1i at gmail.com (Akira Li) Date: Sat, 02 Aug 2014 06:53:44 +0400 Subject: converting ISO8601 date and time string representations to datetime References: <53DB3931.8070406@biologie.uni-freiburg.de> Message-ID: <8738df7gav.fsf@gmail.com> Wolfgang Maier writes: > On 08/01/2014 01:30 AM, Roy Smith wrote: >> In article , >> Albert-Jan Roskam wrote: >> >>>> In article , >>>> Wolfgang Maier wrote: >>>> >>>>> Hi, >>>>> I'm trying to convert ISO8601-compliant strings representing dates or >>>>> dates and times into datetime.datetime objects. >>>> >>>> https://pypi.python.org/pypi/iso8601 >>> >>> Yikes, what a regex. It must have been painstaking to get that right. >>> https://bitbucket.org/micktwomey/pyiso8601/src/2bd28b5d6cd2481674a8b0c54a8bba6 >>> 4ab775f81/iso8601/iso8601.py?at=default >> >> It is a thing of beauty. >> > > No wonder I found it hard to write something that seemed bulletproof ! It seems it supports only some custom subset of ISO 8601. There is rfc 3339 [1] that describes a profile of the ISO 8601 standard. rfc 3339 combines human readability with the simplicity of machine parsing. [1] http://tools.ietf.org/html/rfc3339 -- Akira From steve+comp.lang.python at pearwood.info Fri Aug 1 22:59:20 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 Aug 2014 02:59:20 GMT Subject: eval [was Re: dict to boolean expression, how to?] References: <53db8bd8$0$2976$e4fe514c@news2.news.xs4all.nl> <53dba39e$0$2976$e4fe514c@news2.news.xs4all.nl> Message-ID: <53dc5407$0$29986$c3e8da3$5496439d@news.astraweb.com> On Fri, 01 Aug 2014 17:44:27 +0200, Peter Otten wrote: > Alex van der Spek wrote: > > >> I do know eval() lends itself to code injection but can't say I am >> fully aware of its dangers. It seemed like a handy tool to me. > > In a lab if you don't need to protect your script against attacks from > outside eval() (and exec()) is fine. If the data fed to eval() is > completely under your control (think collections.namedtuple) eval() is > also fine. I'm not entirely happy with describing eval as "fine", even when you're not concerned with security. There are at least two problems with eval that should make it a tool of last resort: * its less direct, typically more convoluted, which makes it hard to read, harder to write, and harder to reason about; * it's slower than running code directly (in my experience, about ten times slower). If you have the choice between running code directly, or running eval() or exec() that runs the same code, you should nearly always prefer to run the code directly. y = x + 1 # Yes. y = eval("x + 1") # No. y = eval("eval('x + 1')") # Good grief what are you thinking??? Now obviously nobody sensible is going to use eval in production code for such simple expressions as "x+1", but the same principle applies even for more complex examples. If you can write the code once, as source code, it's usually better than generating the source code at runtime and running it with eval or exec. Consider the namedtuple implementation in the standard library. There's a lot of criticism of it, some of it justified. It uses exec extensively, which means the code is dominated by a giant string template. This defeats your editor's syntax colouring, makes refactoring harder, and makes how the namedtuple works rather less understandable. It seems to me that it's only generating the __new__ method which genuinely needs to use exec, the rest of the namedtuple could and should use just an ordinary class object (although I concede that some of this is just a matter of personal taste). Raymond Hettinger's original, using exec for the entire inner class: http://code.activestate.com/recipes/500261-named-tuples/ My refactoring, with the bare minimum use of exec necessary: https://code.activestate.com/recipes/578918-yet-another-namedtuple/ [...] >> bool = ((df['a'] == 1) & (df['A'] == 0) | >> (df['b'] == 1) & (df['B'] == 0) | >> (df['c'] == 1) & (df['C'] == 0)) > > This is how it might look without eval(): > > #untested > result = functools.reduce(operator.or_, ((v == 1) & (df[k.upper()] == 0) > for k, v in df.items() if k.islower())) For those who agree with Guido that reduce makes code unreadable: result = True for key in df: if key.islower(): result = result or (df[key] == 1 and df[key.upper()] == 0) Or if you insist on a single expression: result = any(df[k] == 1 and df[k.upper()] == 0 for k in df if k.islower()) > And here is an eval-based solution: > > # untested > expr = "|".join( > "((df[{}] == 1) | (df[{}] == 0))".format(c, c.upper()) for c in df > is c.islower()) > result = eval(expr) I really don't believe that there is any benefit to that in readability, power, flexibility, or performance. Also, you're using bitwise operators instead of shortcut bool operators. Any reason why? -- Steven From v+python at g.nevcal.com Sat Aug 2 02:18:47 2014 From: v+python at g.nevcal.com (Glenn Linderman) Date: Fri, 01 Aug 2014 23:18:47 -0700 Subject: Python 3 is killing Python In-Reply-To: References: <57ajo9poljjre4c4ig0n0ss8kph8k78lp0@4ax.com> <5389cb53$0$29978$c3e8da3$5496439d@news.astraweb.com> <99b7b2a2-7521-42d7-a5a0-1a35d4d5b922@googlegroups.com> <53C4A454.9010600@gmail.com> <87zjga4j4v.fsf@elektro.pacujo.net> <53c57bae$0$9505$c3e8da3$5496439d@news.astraweb.com> <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> Message-ID: <53DC82C7.5040300@g.nevcal.com> On 7/16/2014 7:27 AM, Frank Millman wrote: > I just tried an experiment in my own project. Ned Batchelder, in his > Pragmatic Unicode presentation, http://nedbatchelder.com/text/unipain.html, > suggests that you always have some unicode characters in your data, just to > ensure that they are handled correctly. He has a tongue-in-cheek example > which spells the word PYTHON using various exotic unicode characters. I used > this to populate a field in my database, to see if it would display in my > browser-based client. > > The hardest part was getting it in. There are 6 characters, but utf-8 > requires 16 bytes to store it - > > b'\xe2\x84\x99\xc6\xb4\xe2\x98\x82\xe2\x84\x8c\xc3\xb8\xe1\xbc\xa4'.decode('utf-8') > > However, that was it. Without any changes to my program, it read it from the > database and displayed it on the screen. IE8 could only display 2 out of the > 6 characters correctly, and Chrome could display 5 out of 6, but that is a > separate issue. Python3 handled it perfectly. wrapping the above in a print(), on Windows, I get: Traceback (most recent call last): File "D:\my\py\python-utf8.py", line 1, in print(b'\xe2\x84\x99\xc6\xb4\xe2\x98\x82\xe2\x84\x8c\xc3\xb8\xe1\xbc\xa4'.decode('utf-8')) File "C:\Python33\lib\encodings\cp437.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_map)[0] UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-5: character maps to So Python3 doesn't handle it perfectly on Windows. And I saw someone blame the Windows console for that... but the Windows console can properly display all those characters if the proper APIs are used. The bug is 7 years old: http://bugs.python.org/issue1602 and hasn't been fixed, although the technology for fixing it is available, and various workarounds (with limitations) have been available for 5 years, and patches have been available for 3 years that work pretty good. However, just a few days ago, 26 July 2014, Drekin had an insight that may possibly lead to a patch that will work well enough to be integrated into some future version of Python... I hope he follows up on it. This is a serious limitation, and it is, and always has been, a bug in Python 3 Unicode handling on Windows. -------------- next part -------------- An HTML attachment was scrubbed... URL: From marko at pacujo.net Sat Aug 2 02:41:44 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 02 Aug 2014 09:41:44 +0300 Subject: Dict when defining not returning multi value key error References: <53db11c1$0$29986$c3e8da3$5496439d@news.astraweb.com> <53db96bc$0$29986$c3e8da3$5496439d@news.astraweb.com> <87vbqcnrrh.fsf@elektro.pacujo.net> Message-ID: <87zjfnmlzr.fsf@elektro.pacujo.net> Chris Angelico : > On Sat, Aug 2, 2014 at 7:42 AM, Terry Reedy wrote: >> For mercurial, with no treat model, a 160 bit hash is used. Internet >> applications need more bits and carefully vetted algorithms to >> hopefully make the actual principle true. > > Ditto git, which also has no threat model. I don't know why you way hg and git have no threat models. A great deal of damage could be inflicted if you could sneak malicious edits into version control systems without altering the hash. Important systems absolutely rely on the fact that the hashes can be used for identification. They are not just checksums. They are not double-checked with bit-to-bit comparisons of the actual data. Marko From list at qtrac.plus.com Sat Aug 2 02:45:14 2014 From: list at qtrac.plus.com (Mark Summerfield) Date: Fri, 1 Aug 2014 23:45:14 -0700 (PDT) Subject: 3 Suggestions to Make Python Easier For Children Message-ID: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> Last week I spent a couple of days teaching two children (10 and 13 -- too big an age gap!) how to do some turtle graphics with Python. Neither had programmed Python before -- one is a Minecraft ace and the other had done Scratch. Suggestion #1: Make IDLE start in the user's home directory. Suggestion #2: Make all the turtle examples begin "from turtle import *" so no leading turtle. is needed in the examples. Suggestion #3: Make object(key=value, ...) legal and equiv of types.SimpleNamespace(key=value, ...). Explanation & Rationale (long): They both had Windows laptops and so we began by installing Python. They didn't know if they had 32- or 64-bit computers but it didn't matter, the installs just worked. One child had no problem but the other ended up on the Download page which lists all the possible Windows downloads; so we had to go back and start again. We discovered that IDLE's working directory is C:\Python34 -- surely this is the wrong working directory for 99% of normal users and for 100% of beginners? Naturally they saved all their .py files there until I realised. And then when I got them to create a new directory for their own files ("Python" and "pie_thon") and dragged them across they also managed to move python.exe and pythonw.exe. Couldn't IDLE start in the home directory? The turtle package is quite nice and there is a very short but dramatic colored star example at the start of the docs. There really ought to be a little gallery of similar examples, including circle, polygon, and star (yes I know circle and polygon are built in but it is nice for children to see a simple implementation), and of course a few more -- but not any that compose shapes (e.g., face and house), since one would want them to learn how to compose themselves. Making them type turtle.this and turtle.that would be torture, so we began every file with from turtle import * I wish the doc examples did the same. (For randint we did from random import randint since only the one function was needed.) I stuck to pure procedural programming since OO would have been too much cognitive load to add given the time. I did make sure that once they'd created something (e.g., a face), they then put it inside a function. However, when it came to making a game ("hit the hippo") we needed to maintain some state that several functions could access. (I had to gloss over that we were doing higher order programming! -- e.g. onscreenclick(goto) etc.) What I wanted to write was this: state = object(moving=True, score=0) # Illegal! ... state.moving = False # etc. But was forced to do this: state = {'moving': True, 'score': 0} ... state['moving'] = False # so they get confused between {} and [] There is an alternative: from types import SimpleNamespace state = SimpleNamespace(moving=True, score=0) ... state.moving = False # etc. But I felt that explaining what a namespace was would be too much -- remember they're having problems remembering to put () at the end of function calls etc. It would be nicer if object() acted as it does now but object(key=value,...) behaved like types.SimpleNamespace. From marko at pacujo.net Sat Aug 2 03:06:02 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 02 Aug 2014 10:06:02 +0300 Subject: Dict when defining not returning multi value key error References: <53db11c1$0$29986$c3e8da3$5496439d@news.astraweb.com> <53db96bc$0$29986$c3e8da3$5496439d@news.astraweb.com> <87vbqcnrrh.fsf@elektro.pacujo.net> <87zjfnmlzr.fsf@elektro.pacujo.net> Message-ID: <87vbqbmkv9.fsf@elektro.pacujo.net> Marko Rauhamaa : > Important systems absolutely rely on the fact that the hashes can be > used for identification. They are not just checksums. They are not > double-checked with bit-to-bit comparisons of the actual data. And in fact, you can use the principle in Python: class Thingy: def __init__(self, ...): ... self.stronghash = self.compute_strong_hash() self.hash = struct.unpack("Q", self.stronghash[:8])[0] def __hash__(self): return self.hash def __eq__(self, other): try: return self.stronghash == other.stronghash except AttributeError: return False Marko From marko at pacujo.net Sat Aug 2 03:14:08 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 02 Aug 2014 10:14:08 +0300 Subject: 3 Suggestions to Make Python Easier For Children References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> Message-ID: <87r40zmkhr.fsf@elektro.pacujo.net> Mark Summerfield : > Suggestion #1: Make IDLE start in the user's home directory. > > Suggestion #2: Make all the turtle examples begin "from turtle import > *" so no leading turtle. is needed in the examples. > > Suggestion #3: Make object(key=value, ...) legal and equiv of > types.SimpleNamespace(key=value, ...). Great suggestions for adults as well. Expanding #3: >>> o = object() >>> o.x = 3 Traceback (most recent call last): File "", line 1, in AttributeError: 'object' object has no attribute 'x' Why? Marko From olaf at aepfle.de Sat Aug 2 03:10:44 2014 From: olaf at aepfle.de (Olaf Hering) Date: Sat, 2 Aug 2014 09:10:44 +0200 Subject: Python and IDEs [was Re: Python 3 is killing Python] In-Reply-To: References: <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> Message-ID: <20140802071044.GA6011@aepfle.de> On Sat, Aug 02, Gregory Ewing wrote: > MacOSX doesn't currently have an automatic dependency > manager, but if it did, things would still be a lot neater > and tidier than they are in Linux or Windows, where what > is conceptually a single object (a package) gets split up > and its parts scattered around several obscure locations. How does "a package" differ? Its "a package" here and there. Just use the correct tools to inspect "a package", like 'rpm -qliv $package' to see what "a package" is all about. Olaf From list at qtrac.plus.com Sat Aug 2 03:38:08 2014 From: list at qtrac.plus.com (Mark Summerfield) Date: Sat, 2 Aug 2014 00:38:08 -0700 (PDT) Subject: 3 Suggestions to Make Python Easier For Children In-Reply-To: <87r40zmkhr.fsf@elektro.pacujo.net> References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> Message-ID: On Saturday, 2 August 2014 08:14:08 UTC+1, Marko Rauhamaa wrote: > Mark Summerfield: > > > Suggestion #1: Make IDLE start in the user's home directory. > > > Suggestion #2: Make all the turtle examples begin "from turtle import > > *" so no leading turtle. is needed in the examples. > > > > Suggestion #3: Make object(key=value, ...) legal and equiv of > > types.SimpleNamespace(key=value, ...). > > Great suggestions for adults as well. > > Expanding #3: > > >>> o = object() > >>> o.x = 3 > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'object' object has no attribute 'x' > > Why? > > Marko object() returns a minimal featureless object with no dictionary (no __dict__ attribute). This makes sense for efficiency since not all objects need a dictionary. What I'm suggesting is that _in addition_ to the existing behavior, a new behavior is introduced whereby object() called with keyword arguments creates a types.SimpleNamespace object (i.e., a basic object that has a dictionary initialized by the keyword arguments). Mark. From __peter__ at web.de Sat Aug 2 03:43:54 2014 From: __peter__ at web.de (Peter Otten) Date: Sat, 02 Aug 2014 09:43:54 +0200 Subject: eval [was Re: dict to boolean expression, how to?] References: <53db8bd8$0$2976$e4fe514c@news2.news.xs4all.nl> <53dba39e$0$2976$e4fe514c@news2.news.xs4all.nl> <53dc5407$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Fri, 01 Aug 2014 17:44:27 +0200, Peter Otten wrote: > [...] >>> bool = ((df['a'] == 1) & (df['A'] == 0) | >>> (df['b'] == 1) & (df['B'] == 0) | >>> (df['c'] == 1) & (df['C'] == 0)) >> >> This is how it might look without eval(): >> >> #untested >> result = functools.reduce(operator.or_, ((v == 1) & (df[k.upper()] == 0) >> for k, v in df.items() if k.islower())) > > For those who agree with Guido that reduce makes code unreadable: > > result = True > for key in df: > if key.islower(): > result = result or (df[key] == 1 and df[key.upper()] == 0) I cheated a bit and gave the solution that the OP was unlikely to come up with ;) > Or if you insist on a single expression: > > result = any(df[k] == 1 and df[k.upper()] == 0 for k in df if k.islower()) > > >> And here is an eval-based solution: >> >> # untested >> expr = "|".join( >> "((df[{}] == 1) | (df[{}] == 0))".format(c, c.upper()) for c in df >> is c.islower()) >> result = eval(expr) > > I really don't believe that there is any benefit to that in readability, > power, flexibility, or performance. You can put in a print(expr) to verify that it's identical to the original spelt out expression. > Also, you're using bitwise operators > instead of shortcut bool operators. Any reason why? Since he started the thread Alex has moved the goal posts a bit and added that he is using a pandas DataFrame. That works much like a numpy array. So: >>> df a A b B c C 0 1 4 100 1000 7 14 1 2 1 200 2000 21 28 2 1 0 300 3000 35 42 >>> df["a"] == 1 0 True 1 False 2 True Name: a, dtype: bool >>> (df["a"] == 1) and (df["A"] == 0) Traceback (most recent call last): File "", line 1, in ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() >>> (df["a"] == 1) & (df["A"] == 0) 0 False 1 False 2 True dtype: bool From breamoreboy at yahoo.co.uk Sat Aug 2 03:46:04 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 02 Aug 2014 08:46:04 +0100 Subject: 3 Suggestions to Make Python Easier For Children In-Reply-To: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> Message-ID: On 02/08/2014 07:45, Mark Summerfield wrote: > Last week I spent a couple of days teaching two children (10 and 13 -- too big an age gap!) how to do some turtle graphics with Python. Neither had programmed Python before -- one is a Minecraft ace and the other had done Scratch. > > Suggestion #1: Make IDLE start in the user's home directory. Entirely agree. Please raise an enhancement request on the bug tracker if there isn't already one. > > Suggestion #2: Make all the turtle examples begin "from turtle import *" so no leading turtle. is needed in the examples. I'm not so sure about this, but raise an enhancement request and see what happens. Worst case it gets rejected, best case it gets accepted, implemented and patch applied. > > Suggestion #3: Make object(key=value, ...) legal and equiv of types.SimpleNamespace(key=value, ...). Haven't the faintest idea and too lazy to find out :) I suggest follow advice from #2. > > Explanation & Rationale (long): > > They both had Windows laptops and so we began by installing Python. They didn't know if they had 32- or 64-bit computers but it didn't matter, the installs just worked. One child had no problem but the other ended up on the Download page which lists all the possible Windows downloads; so we had to go back and start again. > > We discovered that IDLE's working directory is C:\Python34 -- surely this is the wrong working directory for 99% of normal users and for 100% of beginners? Naturally they saved all their .py files there until I realised. And then when I got them to create a new directory for their own files ("Python" and "pie_thon") and dragged them across they also managed to move python.exe and pythonw.exe. > > Couldn't IDLE start in the home directory? > > The turtle package is quite nice and there is a very short but dramatic colored star example at the start of the docs. There really ought to be a little gallery of similar examples, including circle, polygon, and star (yes I know circle and polygon are built in but it is nice for children to see a simple implementation), and of course a few more -- but not any that compose shapes (e.g., face and house), since one would want them to learn how to compose themselves. > > Making them type turtle.this and turtle.that would be torture, so we began every file with > > from turtle import * > > I wish the doc examples did the same. (For randint we did from random import randint since only the one function was needed.) > > I stuck to pure procedural programming since OO would have been too much cognitive load to add given the time. I did make sure that once they'd created something (e.g., a face), they then put it inside a function. > > However, when it came to making a game ("hit the hippo") we needed to maintain some state that several functions could access. (I had to gloss over that we were doing higher order programming! -- e.g. onscreenclick(goto) etc.) What I wanted to write was this: > > state = object(moving=True, score=0) # Illegal! > ... > state.moving = False # etc. > > But was forced to do this: > > state = {'moving': True, 'score': 0} > ... > state['moving'] = False # so they get confused between {} and [] > > There is an alternative: > > from types import SimpleNamespace > > state = SimpleNamespace(moving=True, score=0) > ... > state.moving = False # etc. > > But I felt that explaining what a namespace was would be too much -- remember they're having problems remembering to put () at the end of function calls etc. > It would be nicer if object() acted as it does now but object(key=value,...) behaved like types.SimpleNamespace. > Finally I believe there's a very strong chance that of of this will be taken on board. I've noticed activity on the bugtracker recently regarding turtle, GSOC student maybe? -- 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 Aug 2 03:59:30 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 02 Aug 2014 08:59:30 +0100 Subject: eval [was Re: dict to boolean expression, how to?] In-Reply-To: <53dc5407$0$29986$c3e8da3$5496439d@news.astraweb.com> References: <53db8bd8$0$2976$e4fe514c@news2.news.xs4all.nl> <53dba39e$0$2976$e4fe514c@news2.news.xs4all.nl> <53dc5407$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 02/08/2014 03:59, Steven D'Aprano wrote: > > My refactoring, with the bare minimum use of exec necessary: > > https://code.activestate.com/recipes/578918-yet-another-namedtuple/ > FTR I get the feed of new recipes from gwene.com.activestate.code.feeds.recipes.langs.python from news.gmane.org. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From list at qtrac.plus.com Sat Aug 2 04:03:02 2014 From: list at qtrac.plus.com (Mark Summerfield) Date: Sat, 2 Aug 2014 01:03:02 -0700 (PDT) Subject: 3 Suggestions to Make Python Easier For Children In-Reply-To: References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> Message-ID: <97480d7d-a078-45a8-a4a9-2652b68d7c80@googlegroups.com> On Saturday, 2 August 2014 08:46:04 UTC+1, Mark Lawrence wrote: > On 02/08/2014 07:45, Mark Summerfield wrote: > [snip] > > > Suggestion #1: Make IDLE start in the user's home directory. > > Entirely agree. Please raise an enhancement request on the bug tracker > if there isn't already one. Done: http://bugs.python.org/issue22121 > > Suggestion #2: Make all the turtle examples begin "from turtle import *" so no leading turtle. is needed in the examples. > > I'm not so sure about this, but raise an enhancement request and see > what happens. Worst case it gets rejected, best case it gets accepted, > implemented and patch applied. Done: http://bugs.python.org/issue22122 > > Suggestion #3: Make object(key=value, ...) legal and equiv of types.SimpleNamespace(key=value, ...). > > Haven't the faintest idea and too lazy to find out :) I suggest follow > advice from #2. Done: http://bugs.python.org/issue22123 Mark. From marko at pacujo.net Sat Aug 2 04:03:37 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 02 Aug 2014 11:03:37 +0300 Subject: 3 Suggestions to Make Python Easier For Children References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> Message-ID: <87mwbnmi7a.fsf@elektro.pacujo.net> Mark Summerfield : > object() returns a minimal featureless object with no dictionary (no > __dict__ attribute). This makes sense for efficiency since not all > objects need a dictionary. __setattr__ could create __dict__ belatedly. Marko From HeinzSchmitz at gmx.net Sat Aug 2 04:33:38 2014 From: HeinzSchmitz at gmx.net (Heinz Schmitz) Date: Sat, 02 Aug 2014 10:33:38 +0200 Subject: Bug with help (was Re: Getting a list of all modules) References: <53d8a20e$0$29977$c3e8da3$5496439d@news.astraweb.com> <87oaw5xsrd.fsf@gmail.com> Message-ID: Akira Li wrote: >>> Look at how `help('modules')` is implemented. Though it crashes on my >>> system. >> Have you reported this at bugs.python.org or is there already an issue >> for the problem that you see? >It is this issue for python2.7: >https://bugs.launchpad.net/ubuntu/+source/python2.7/+bug/896836 > >python3 doesn't crash with currently installed packages. Python 2.7 on Windows XP Sp2 doesn't crash with this. So it seems to be a python<->OS-problem. Regards, H. From rosuav at gmail.com Sat Aug 2 06:58:44 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Aug 2014 20:58:44 +1000 Subject: Dict when defining not returning multi value key error In-Reply-To: <87zjfnmlzr.fsf@elektro.pacujo.net> References: <53db11c1$0$29986$c3e8da3$5496439d@news.astraweb.com> <53db96bc$0$29986$c3e8da3$5496439d@news.astraweb.com> <87vbqcnrrh.fsf@elektro.pacujo.net> <87zjfnmlzr.fsf@elektro.pacujo.net> Message-ID: On Sat, Aug 2, 2014 at 4:41 PM, Marko Rauhamaa wrote: > I don't know why you way hg and git have no threat models. A great deal > of damage could be inflicted if you could sneak malicious edits into > version control systems without altering the hash. You would have to somehow push that change into someone else's repository. I'm not sure how you'd go about doing that without actually having a commit, which will be kinda visible. ChrisA From greg.ewing at canterbury.ac.nz Sat Aug 2 07:33:11 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 02 Aug 2014 23:33:11 +1200 Subject: Python and IDEs [was Re: Python 3 is killing Python] In-Reply-To: References: <87zjga4j4v.fsf@elektro.pacujo.net> <53c57bae$0$9505$c3e8da3$5496439d@news.astraweb.com> <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> <53DBCB7B.80704@schwertberger.de> Message-ID: Chris Angelico wrote: > The "easier target for the mouse" argument is valuable ONLY > when you use the mouse to access the menu bar. If you use the keyboard > (and take advantage of mnemonic letters), it's much more useful to > have the menu bar attached to its window. Seems to me that if you use the keyboard for everything, it doesn't matter where the menu bar is. Unless you're talking about the way you can use the keyboard to make menus drop down in Windows... but that's not the way Mac menu shortcuts work. The menu doesn't visually drop down when you invoke a Mac menu command with the keyboard. > In the rare case of an app > that runs without any windows, incidentally, how do you tell the > system that you want that app's menu bar instead of (say) Finder, > which comes up when you click on the desktop? In classic MacOS, there was a menu of running applications in the top right corner. In MacOSX, you click on the app's icon in the dock. Also, while completely windowless applications might be rare, it's not rare for an app to have some commands that pertain to the app itself, and not to any particular window, e.g. "New". It's more logical for those to appear in a user interface element that's not tied to a window. -- Greg From greg.ewing at canterbury.ac.nz Sat Aug 2 07:38:59 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 02 Aug 2014 23:38:59 +1200 Subject: Python and IDEs [was Re: Python 3 is killing Python] In-Reply-To: References: <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> Message-ID: Olaf Hering wrote: > How does "a package" differ? Its "a package" here and there. > Just use the correct tools to inspect "a package", like > 'rpm -qliv $package' to see what "a package" is all about. Splitting the package up creates a problem, which you then need to invent a special tool to solve. Seems to me it's simpler not to create the problem in the first place. -- Greg From ned at nedbatchelder.com Sat Aug 2 07:43:49 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 02 Aug 2014 07:43:49 -0400 Subject: Dict when defining not returning multi value key error In-Reply-To: References: Message-ID: On 8/1/14 10:30 AM, Ian Kelly wrote: > On Thu, Jul 31, 2014 at 9:28 PM, Terry Reedy wrote: >> On 7/31/2014 5:15 PM, Ian Kelly wrote: >>> >>> On Thu, Jul 31, 2014 at 5:24 AM, Dilu Sasidharan >>> wrote: >>>> >>>> Hi, >>>> >>>> I am wondering why the dictionary in python not returning multi value key >>>> error when i define something like >>>> >>>> p = {'k':"value0",'k':"value1"} >>>> >>>> key is string immutable and sometimes shares same id. >>>> >>>> also if the key is immutable and have different ids. >>>> >>>> like >>>> >>>> p = {'1':"value0",'1.0':"value1"} >>> >>> >>> In this latter case note that '1' and '1.0' are not equal, so this >>> will simply result in two separate entries in the dict anyway. >> >> >> Dilu presumably meant >> >>>>> p = {1:"value0", 1.0:"value1"} >>>>> p >> {1: 'value1'} > > Maybe, but it was explicitly stated that the keys were strings. > You are right, my mistake. Apologies. -- Ned Batchelder, http://nedbatchelder.com From robert.kern at gmail.com Sat Aug 2 08:13:27 2014 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 02 Aug 2014 13:13:27 +0100 Subject: Bug with help (was Re: Getting a list of all modules) In-Reply-To: References: <53d8a20e$0$29977$c3e8da3$5496439d@news.astraweb.com> <87oaw5xsrd.fsf@gmail.com> Message-ID: On 2014-08-02 09:33, Heinz Schmitz wrote: > Akira Li wrote: > >>>> Look at how `help('modules')` is implemented. Though it crashes on my >>>> system. > >>> Have you reported this at bugs.python.org or is there already an issue >>> for the problem that you see? > >> It is this issue for python2.7: >> https://bugs.launchpad.net/ubuntu/+source/python2.7/+bug/896836 >> >> python3 doesn't crash with currently installed packages. > > Python 2.7 on Windows XP Sp2 doesn't crash with this. So it seems to > be a python<->OS-problem. Well, it's just that `help('modules')` imports every module in the calling process (at least in Python 2.7; I haven't checked Python 3). Some extension modules conflict with each other and cause a crash when both are imported together. It's possible that you just don't have such modules installed. While the proximate cause of the crash is in the 3rd party modules, Python could (and maybe Python 3 does) import each module in a separate subprocess and collect the information that way. -- 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 rosuav at gmail.com Sat Aug 2 09:01:03 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Aug 2014 23:01:03 +1000 Subject: Python and IDEs [was Re: Python 3 is killing Python] In-Reply-To: References: <87zjga4j4v.fsf@elektro.pacujo.net> <53c57bae$0$9505$c3e8da3$5496439d@news.astraweb.com> <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> <53DBCB7B.80704@schwertberger.de> Message-ID: On Sat, Aug 2, 2014 at 9:33 PM, Gregory Ewing wrote: > Chris Angelico wrote: >> >> The "easier target for the mouse" argument is valuable ONLY >> when you use the mouse to access the menu bar. If you use the keyboard >> (and take advantage of mnemonic letters), it's much more useful to >> have the menu bar attached to its window. > > > Seems to me that if you use the keyboard for everything, > it doesn't matter where the menu bar is. Unless you're > talking about the way you can use the keyboard to make > menus drop down in Windows... but that's not the way > Mac menu shortcuts work. The menu doesn't visually drop > down when you invoke a Mac menu command with the keyboard. There are two forms of shortcut key. One is a direct-action keystroke that immediately does the same thing that you can do using the menus (say, Ctrl-O is the same as File... Open). With those, the menu is completely unnecessary, except as a list of available keystrokes; it could just as easily be a help screen that says "Press Ctrl-O to open a file", so the menu's actual location is quite arbitrary. Downside: There's only so many keystrokes available, and not all of them have memorable meanings. It's usually best to keep this to the few most common functions (opening a file, yes, but not "reinterpret this file as ISO-8859-3", unless you make that configurable per user). But the other form, usually described as menu mnemonics, is where you press Alt-F to bring up the _File menu, and then O to activate _Open. (In OS/2, those would be ~File and ~Open; in GTK, the mnemonic is preceded by an underscore. Windows 3.1 used an ampersand, and I believe Win32 does the same thing. It's a little awkward when you have an invoicing screen and you put something like "P&O Shipping" as your customer name, and suddenly Alt-O takes you someplace different. The tilde has the advantage that it doesn't often come up accidentally; the underscore makes sense because the mnemonic is underlined; I have no idea why an ampersand should be used. But I digress.) When you work this way, you aren't grabbing the mouse, so the advantage of not needing to aim so carefully doesn't exist; but if the menu comes up right near where your eyes are already focused, you need to move _them_ less distance - and that means you can focus on the menu more quickly, plus it emphasizes that the visual change (opening the menu) occurred in your current program, not in something else. In Xfce, I can press Alt-F1 to open up the main Applications Menu. That's at the top of the screen (in fact, top left corner), so it gets the "throw the mouse" benefit; I think I use the mouse with that a lot more often than I use the mouse with a program's own menu, because there's more likely to be something unusual in there. If I install a new piece of software, I have to figure out where it's landed in the menu; but Gypsum's four menus aren't changing unexpectedly, so I'm happy using Alt-O, V to open up Advanced Options. >> In the rare case of an app >> that runs without any windows, incidentally, how do you tell the >> system that you want that app's menu bar instead of (say) Finder, >> which comes up when you click on the desktop? > > In classic MacOS, there was a menu of running applications > in the top right corner. In MacOSX, you click on the app's > icon in the dock. Okay. So you need to first click on something in the dock - that's the thing down the bottom of the screen, right? - and then go all the way up to the top of the screen to use its menu bar. I think I'd much rather have a popup menu - right-click the program's dock icon and get the menu right there where the mouse already is. Oh wait, that requires people to understand more than a single mouse button, so it's contrary to Mac philosophy :) > Also, while completely windowless applications might be > rare, it's not rare for an app to have some commands that > pertain to the app itself, and not to any particular > window, e.g. "New". It's more logical for those to appear > in a user interface element that's not tied to a window. Sure, but those elements are usually rare enough that they can be stuck on the window anyway. Audacity has a "New" that opens up a new window, and it's slightly surprising the first couple of times, but after that you get used to it. It's not a big enough issue to warrant a change of UI. It is an issue, yes, but I wouldn't warp anything around it any more than I'd warp my UI around the possibility of a user having no screen or keyboard and is using the mouse blind. Sure it happens (I've done it, and I know what I could code to make it easier!), but not often. ChrisA From python at mrabarnett.plus.com Sat Aug 2 09:55:17 2014 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 02 Aug 2014 14:55:17 +0100 Subject: Python and IDEs [was Re: Python 3 is killing Python] In-Reply-To: References: <87zjga4j4v.fsf@elektro.pacujo.net> <53c57bae$0$9505$c3e8da3$5496439d@news.astraweb.com> <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> <53DBCB7B.80704@schwertberger.de> Message-ID: <53DCEDC5.50601@mrabarnett.plus.com> On 2014-08-02 01:00, Gregory Ewing wrote: > MRAB wrote: [snip] >> And don't mention the menu bar across the top, separated from the >> window to which it belonged. > > That seems to be a matter of taste. There are some advantages to the > menu-bar-at-top model. It's an easier target to hit, because you can > just flick the mouse up to the top. It only takes up space once, > instead of once per window. It makes it possible for an app to be > running without having any windows, and still be able to interact > with it. > RISC OS didn't have a menu bar at the top of each window either; its menus were all pop-up. You didn't have to keep flicking the mouse at all! From roy at panix.com Sat Aug 2 10:27:03 2014 From: roy at panix.com (Roy Smith) Date: Sat, 02 Aug 2014 10:27:03 -0400 Subject: Python and IDEs [was Re: Python 3 is killing Python] References: <87zjga4j4v.fsf@elektro.pacujo.net> <53c57bae$0$9505$c3e8da3$5496439d@news.astraweb.com> <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> <53DBCB7B.80704@schwertberger.de> Message-ID: In article , Gregory Ewing wrote: > > And don't mention the menu bar across the top, separated from the > > window to which it belonged. > > That seems to be a matter of taste. There are some > advantages to the menu-bar-at-top model. It's an easier > target to hit, because you can just flick the mouse up > to the top. It only takes up space once, instead of > once per window. It makes it possible for an app to > be running without having any windows, and still be > able to interact with it. In the old days, we had really small screens (the original Mac had a 9 inch screen with 512 x 342 resolution). Most application windows filled most of the screen, so there really wasn't much difference between per-desktop and per-window menu bars. These days, I'm running multiple 24 inch monitors. The single menu bar paradigm starts to break down in an environment like that. I find I tend to put the few windows I'm actively using near the top of my primary screen (the one with the menu bar), and use the second screen to hold windows I'm not interacting with much. From nicholascannon1 at gmail.com Sat Aug 2 10:38:28 2014 From: nicholascannon1 at gmail.com (Nicholas Cannon) Date: Sat, 2 Aug 2014 07:38:28 -0700 (PDT) Subject: Tkinter grid autosize help Message-ID: <60f53f24-7ce7-48e5-9fed-7d9ac8841b7f@googlegroups.com> So i have a basic calculator program and i have a label that i want to go across the top to show the numbers and stuff like on a normal calculator. The only way i can make the buttons look neat and then when i keep pressing one the label gets larger and then half the buttons move out of the screen. I cant seem to fix this i have tried columnspan, columnconfigure and heaps of other stuff and non works it always expands. is there a way i can stop the grid from expanding? From python at mrabarnett.plus.com Sat Aug 2 11:33:51 2014 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 02 Aug 2014 16:33:51 +0100 Subject: Tkinter grid autosize help In-Reply-To: <60f53f24-7ce7-48e5-9fed-7d9ac8841b7f@googlegroups.com> References: <60f53f24-7ce7-48e5-9fed-7d9ac8841b7f@googlegroups.com> Message-ID: <53DD04DF.30401@mrabarnett.plus.com> On 2014-08-02 15:38, Nicholas Cannon wrote: > So i have a basic calculator program and i have a label that i want > to go across the top to show the numbers and stuff like on a normal > calculator. The only way i can make the buttons look neat and then > when i keep pressing one the label gets larger and then half the > buttons move out of the screen. I cant seem to fix this i have tried > columnspan, columnconfigure and heaps of other stuff and non works it > always expands. is there a way i can stop the grid from expanding? > You haven't provided any code, so it's not possible to say where you're going wrong! From steve+comp.lang.python at pearwood.info Sat Aug 2 11:43:18 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 03 Aug 2014 01:43:18 +1000 Subject: 3 Suggestions to Make Python Easier For Children References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> Message-ID: <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> Marko Rauhamaa wrote: > Expanding #3: > > >>> o = object() > >>> o.x = 3 > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'object' object has no attribute 'x' > > Why? There are two intended uses for object and its instances: - as the base class for all other classes; - instances can be used as featureless sentinel objects where only identity matters. If you need instances which carry state, then object is the wrong class. -- Steven From steve+comp.lang.python at pearwood.info Sat Aug 2 12:00:47 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 03 Aug 2014 02:00:47 +1000 Subject: 3 Suggestions to Make Python Easier For Children References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <87mwbnmi7a.fsf@elektro.pacujo.net> Message-ID: <53dd0b30$0$29968$c3e8da3$5496439d@news.astraweb.com> Marko Rauhamaa wrote: > Mark Summerfield : > >> object() returns a minimal featureless object with no dictionary (no >> __dict__ attribute). This makes sense for efficiency since not all >> objects need a dictionary. > > __setattr__ could create __dict__ belatedly. Are we designing Son Of PHP, or a sensible language? *wink* If object.__setattr__ did this, then we're left with two equally horrible choices: - only object works this way, not subclasses of object, which violates the Liskov substitution principle; - all instances, of every type, work this way, which causes chaos and destruction everywhere. Some of the consequences: * Classes with __slots__ will stop working as expected. * Immutable instances will no longer be immutable, since they can have mutable state. * The CPython interpreter shares immutable built-ins like ints across multiple processes. Either CPython would have to stop doing this (increasing memory requirements significantly), or one process could reach across to another and mutate its ints. Well, perhaps not *equally* horrible. Compared to the second alternative, violating the LSP seems relatively benign. There's also the implementation difficulty that instance.__dict__ is kept in a slot (obviously, since it cannot be stored in the per instance __dict__ !), which means that you cannot easily or practically expect to dynamically add/or delete it from instances. Now I'm sure with sufficient effort we could do so, but that's a lot of effort for negligible (or even negative) gain. -- Steven From breamoreboy at yahoo.co.uk Sat Aug 2 12:14:25 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 02 Aug 2014 17:14:25 +0100 Subject: Tkinter grid autosize help In-Reply-To: <60f53f24-7ce7-48e5-9fed-7d9ac8841b7f@googlegroups.com> References: <60f53f24-7ce7-48e5-9fed-7d9ac8841b7f@googlegroups.com> Message-ID: On 02/08/2014 15:38, Nicholas Cannon wrote: > So i have a basic calculator program and i have a label that i want to go across the top to show the numbers and stuff like on a normal calculator. The only way i can make the buttons look neat and then when i keep pressing one the label gets larger and then half the buttons move out of the screen. I cant seem to fix this i have tried columnspan, columnconfigure and heaps of other stuff and non works it always expands. is there a way i can stop the grid from expanding? > Please help us to help you by reading and actioning this http://sscce.org/, thanks. p.s. being British I must point out that I is spelt I and not i :) -- 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 Aug 2 13:07:48 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 02 Aug 2014 20:07:48 +0300 Subject: 3 Suggestions to Make Python Easier For Children References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <87mwbnmi7a.fsf@elektro.pacujo.net> <53dd0b30$0$29968$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87k36qzuor.fsf@elektro.pacujo.net> Steven D'Aprano : > Marko Rauhamaa wrote: >> __setattr__ could create __dict__ belatedly. > > Are we designing Son Of PHP, or a sensible language? *wink* > > If object.__setattr__ did this, then we're left with two equally > horrible choices: Not a huge issue. Only mildly annoying to have to create: class Object: pass in every application. And the newest Python releases let you replace that with: import types Object = types.SimpleNamespace Marko From breamoreboy at yahoo.co.uk Sat Aug 2 13:29:26 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 02 Aug 2014 18:29:26 +0100 Subject: 3 Suggestions to Make Python Easier For Children In-Reply-To: <87k36qzuor.fsf@elektro.pacujo.net> References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <87mwbnmi7a.fsf@elektro.pacujo.net> <53dd0b30$0$29968$c3e8da3$5496439d@news.astraweb.com> <87k36qzuor.fsf@elektro.pacujo.net> Message-ID: On 02/08/2014 18:07, Marko Rauhamaa wrote: > Steven D'Aprano : > >> Marko Rauhamaa wrote: >>> __setattr__ could create __dict__ belatedly. >> >> Are we designing Son Of PHP, or a sensible language? *wink* >> >> If object.__setattr__ did this, then we're left with two equally >> horrible choices: > > Not a huge issue. Only mildly annoying to have to create: > > class Object: pass > > in every application. > > And the newest Python releases let you replace that with: > > import types > Object = types.SimpleNamespace > > > Marko > With the latter being part of suggestion #3 in the original post. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From tjreedy at udel.edu Sat Aug 2 14:17:26 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 02 Aug 2014 14:17:26 -0400 Subject: Bug with help (was Re: Getting a list of all modules) In-Reply-To: References: <53d8a20e$0$29977$c3e8da3$5496439d@news.astraweb.com> <87oaw5xsrd.fsf@gmail.com> Message-ID: On 8/2/2014 8:13 AM, Robert Kern wrote: > On 2014-08-02 09:33, Heinz Schmitz wrote: >> Akira Li wrote: >> >>>>> Look at how `help('modules')` is implemented. Though it crashes on my >>>>> system. >> >>>> Have you reported this at bugs.python.org or is there already an issue >>>> for the problem that you see? >> >>> It is this issue for python2.7: >>> https://bugs.launchpad.net/ubuntu/+source/python2.7/+bug/896836 >>> >>> python3 doesn't crash with currently installed packages. >> >> Python 2.7 on Windows XP Sp2 doesn't crash with this. So it seems to >> be a python<->OS-problem. It is a local system problem. > Well, it's just that `help('modules')` imports every module in the > calling process (at least in Python 2.7; I haven't checked Python 3). > Some extension modules conflict with each other and cause a crash when > both are imported together. It's possible that you just don't have such > modules installed. While the proximate cause of the crash is in the 3rd > party modules, Python could (and maybe Python 3 does) import each module > in a separate subprocess and collect the information that way. That would slow down help('modules') much more. The suggestion in http://bugs.python.org/issue12902 "help("modules") executes module code" is that help() should instead parse the module to get the docstring. -- Terry Jan Reedy From marko at pacujo.net Sat Aug 2 14:33:46 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 02 Aug 2014 21:33:46 +0300 Subject: 3 Suggestions to Make Python Easier For Children References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <87mwbnmi7a.fsf@elektro.pacujo.net> <53dd0b30$0$29968$c3e8da3$5496439d@news.astraweb.com> <87k36qzuor.fsf@elektro.pacujo.net> Message-ID: <87a97mn3lh.fsf@elektro.pacujo.net> Mark Lawrence : > On 02/08/2014 18:07, Marko Rauhamaa wrote: >> And the newest Python releases let you replace that with: >> >> import types >> Object = types.SimpleNamespace > > With the latter being part of suggestion #3 in the original post. Not quite. Even though Sugg. #3 would allow me to do: object(x=3) this wouldn't work: object().x = 3 However, these would continue working: types.SimpleNamespace(x=3) types.SimpleNamespace().x = 3 Also, assuming Sugg. #3, would this work: object(x=3).y = 2 as this does: types.SimpleNamespace(x=3).y = 2 Marko From ben+python at benfinney.id.au Sat Aug 2 15:58:59 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 03 Aug 2014 05:58:59 +1000 Subject: Correct type for a simple =?utf-8?Q?=E2=80=9Cbag?= of =?utf-8?Q?a?= =?utf-8?Q?ttributes=E2=80=9D?= namespace object (was: 3 Suggestions to Make Python Easier For Children) References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: <857g2qd5oc.fsf_-_@benfinney.id.au> Steven D'Aprano writes: > If you need instances which carry state, then object is the wrong > class. Right. The ?types? module provides a SimpleNamespace class for the common ?bag of attributes? use case:: >>> import types >>> foo = types.SimpleNamespace() >>> foo.x = 3 >>> foo namespace(x=3) -- \ ?Nothing is more sacred than the facts.? ?Sam Harris, _The End | `\ of Faith_, 2004 | _o__) | Ben Finney From list at qtrac.plus.com Sat Aug 2 16:46:04 2014 From: list at qtrac.plus.com (Mark Summerfield) Date: Sat, 2 Aug 2014 13:46:04 -0700 (PDT) Subject: Correct type for a simple "bag of attributes" namespace object (was: 3 Suggestions to Make Python Easier For Children) In-Reply-To: References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: <70e5f2f1-661f-40f2-bb7a-76e569c4d092@googlegroups.com> On Saturday, 2 August 2014 20:58:59 UTC+1, Ben Finney wrote: > Steven D'Aprano writes: > > > If you need instances which carry state, then object is the wrong > > class. Fair enough. > Right. The 'types' module provides a SimpleNamespace class for the > common "bag of attributes" use case:: > > >>> import types > >>> foo = types.SimpleNamespace() > >>> foo.x = 3 > >>> foo > namespace(x=3) This is too much for children (& beginners). But perhaps what I should be asking for is for a new built-in that does what types.SimpleNamespace() does, so that without any import you can write, say, foo = namespace(a=1, b=2) # or bar = namespace() bar.a = 1 where under the hood namespace has the same behavior as types.SimpleNamespace(). Naturally, I understand that adding a new name is a big deal and may be too much to ask for beginners. From rosuav at gmail.com Sat Aug 2 17:05:39 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Aug 2014 07:05:39 +1000 Subject: Correct type for a simple "bag of attributes" namespace object (was: 3 Suggestions to Make Python Easier For Children) In-Reply-To: <70e5f2f1-661f-40f2-bb7a-76e569c4d092@googlegroups.com> References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> <70e5f2f1-661f-40f2-bb7a-76e569c4d092@googlegroups.com> Message-ID: On Sun, Aug 3, 2014 at 6:46 AM, Mark Summerfield wrote: > But perhaps what I should be asking for is for a new built-in that does what types.SimpleNamespace() does, so that without any import you can write, say, > > foo = namespace(a=1, b=2) > # or > bar = namespace() > bar.a = 1 > > where under the hood namespace has the same behavior as types.SimpleNamespace(). > > Naturally, I understand that adding a new name is a big deal and may be too much to ask for beginners. This is where you might want to consider putting some imports into site.py. That way, you can set up your own customized Python, without waiting for changes to be approved for core (which they probably won't - new builtins have a high requirement for necessity, not just "I don't want to have to type import"). ChrisA From jonnicoll11 at googlemail.com Sat Aug 2 17:13:30 2014 From: jonnicoll11 at googlemail.com (jonnicoll11 at googlemail.com) Date: Sat, 2 Aug 2014 14:13:30 -0700 (PDT) Subject: Getting a list of all modules In-Reply-To: <53dbb534$0$29986$c3e8da3$5496439d@news.astraweb.com> References: <53d8a20e$0$29977$c3e8da3$5496439d@news.astraweb.com> <53da1d5a$0$29974$c3e8da3$5496439d@news.astraweb.com> <53dbb534$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: <799e6cd8-9d6e-455d-9fe4-0d8797672cfc@googlegroups.com> On Friday, 1 August 2014 16:41:41 UTC+1, Steven D'Aprano wrote: > On Fri, 01 Aug 2014 14:39:09 +0100, Robert Kern wrote: > > > > > Take a look at what has already been implemented in IPython: > > > > > > https://github.com/ipython/ipython/blob/master/IPython/core/ > > completerlib.py#L208 > > > > > > Awesome! Thank you! > > > > > > -- > > Steven Also this, possibly: https://github.com/davidhalter/jedi Jon N From breamoreboy at yahoo.co.uk Sat Aug 2 17:16:17 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 02 Aug 2014 22:16:17 +0100 Subject: Correct type for a simple "bag of attributes" namespace object In-Reply-To: References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> <70e5f2f1-661f-40f2-bb7a-76e569c4d092@googlegroups.com> Message-ID: On 02/08/2014 22:05, Chris Angelico wrote: > On Sun, Aug 3, 2014 at 6:46 AM, Mark Summerfield wrote: >> But perhaps what I should be asking for is for a new built-in that does what types.SimpleNamespace() does, so that without any import you can write, say, >> >> foo = namespace(a=1, b=2) >> # or >> bar = namespace() >> bar.a = 1 >> >> where under the hood namespace has the same behavior as types.SimpleNamespace(). >> >> Naturally, I understand that adding a new name is a big deal and may be too much to ask for beginners. > > This is where you might want to consider putting some imports into > site.py. That way, you can set up your own customized Python, without > waiting for changes to be approved for core (which they probably won't > - new builtins have a high requirement for necessity, not just "I > don't want to have to type import"). > > ChrisA > I'd forgotten all about site.py so went to the 3.4.1 docs and found "Deprecated since version 3.4: Support for the ?site-python? directory will be removed in 3.5.". Plan B? :) -- 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 Aug 2 17:22:08 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 02 Aug 2014 22:22:08 +0100 Subject: Getting a list of all modules In-Reply-To: <799e6cd8-9d6e-455d-9fe4-0d8797672cfc@googlegroups.com> References: <53d8a20e$0$29977$c3e8da3$5496439d@news.astraweb.com> <53da1d5a$0$29974$c3e8da3$5496439d@news.astraweb.com> <53dbb534$0$29986$c3e8da3$5496439d@news.astraweb.com> <799e6cd8-9d6e-455d-9fe4-0d8797672cfc@googlegroups.com> Message-ID: On 02/08/2014 22:13, jonnicoll11 at googlemail.com wrote: > On Friday, 1 August 2014 16:41:41 UTC+1, Steven D'Aprano wrote: >> On Fri, 01 Aug 2014 14:39:09 +0100, Robert Kern wrote: >> >> >> >>> Take a look at what has already been implemented in IPython: >> >>> >> >>> https://github.com/ipython/ipython/blob/master/IPython/core/ >> >> completerlib.py#L208 >> >> >> >> >> >> Awesome! Thank you! >> >> >> >> >> >> -- >> >> Steven > > Also this, possibly: > > https://github.com/davidhalter/jedi > > Jon N > Would you please read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the double line spacing above, 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 Sat Aug 2 17:24:35 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Aug 2014 07:24:35 +1000 Subject: Correct type for a simple "bag of attributes" namespace object In-Reply-To: References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> <70e5f2f1-661f-40f2-bb7a-76e569c4d092@googlegroups.com> Message-ID: On Sun, Aug 3, 2014 at 7:16 AM, Mark Lawrence wrote: > I'd forgotten all about site.py so went to the 3.4.1 docs and found > "Deprecated since version 3.4: Support for the ?site-python? directory will > be removed in 3.5.". > > Plan B? :) Oh. Hrm. I've no idea... but I'm sure there'll be a way to say "execute this at the beginning of an interactive session". Dig in the docs. ChrisA From breamoreboy at yahoo.co.uk Sat Aug 2 17:23:12 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 02 Aug 2014 22:23:12 +0100 Subject: Correct type for a simple "bag of attributes" namespace object In-Reply-To: References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> <70e5f2f1-661f-40f2-bb7a-76e569c4d092@googlegroups.com> Message-ID: On 02/08/2014 22:16, Mark Lawrence wrote: > On 02/08/2014 22:05, Chris Angelico wrote: >> On Sun, Aug 3, 2014 at 6:46 AM, Mark Summerfield >> wrote: >>> But perhaps what I should be asking for is for a new built-in that >>> does what types.SimpleNamespace() does, so that without any import >>> you can write, say, >>> >>> foo = namespace(a=1, b=2) >>> # or >>> bar = namespace() >>> bar.a = 1 >>> >>> where under the hood namespace has the same behavior as >>> types.SimpleNamespace(). >>> >>> Naturally, I understand that adding a new name is a big deal and may >>> be too much to ask for beginners. >> >> This is where you might want to consider putting some imports into >> site.py. That way, you can set up your own customized Python, without >> waiting for changes to be approved for core (which they probably won't >> - new builtins have a high requirement for necessity, not just "I >> don't want to have to type import"). >> >> ChrisA >> > > I'd forgotten all about site.py so went to the 3.4.1 docs and found > "Deprecated since version 3.4: Support for the ?site-python? directory > will be removed in 3.5.". > > Plan B? :) > Plan B is revert to plan A, I didn't read things anything like thoroughly enough, sorry about the noise :( -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From Seymore4Head at Hotmail.invalid Sat Aug 2 18:13:50 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Sat, 02 Aug 2014 18:13:50 -0400 Subject: Python Programing for the Absoulte Beginner Message-ID: https://www.google.com/webhp?hl=en&tab=ww&gws_rd=ssl#hl=en&q=python+programing+for+the+absolute+beginner There is a book listed as a PDF. When I try the first example of print "Game Over" I get a syntax error. I have tried running the command line and the GUI. I get the feeling there is something else I need to run. http://imgur.com/RH3yczP From rosuav at gmail.com Sat Aug 2 18:30:15 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Aug 2014 08:30:15 +1000 Subject: Python Programing for the Absoulte Beginner In-Reply-To: References: Message-ID: On Sun, Aug 3, 2014 at 8:13 AM, Seymore4Head wrote: > https://www.google.com/webhp?hl=en&tab=ww&gws_rd=ssl#hl=en&q=python+programing+for+the+absolute+beginner > > There is a book listed as a PDF. > > When I try the first example of print "Game Over" I get a syntax > error. > > I have tried running the command line and the GUI. I get the feeling > there is something else I need to run. > > http://imgur.com/RH3yczP Try this instead: print("Game Over") You're looking at a Python 2 book, and you're running Python 3. I would recommend instead getting a Python 3 tutorial: https://docs.python.org/3/tutorial/ ChrisA From breamoreboy at yahoo.co.uk Sat Aug 2 18:31:35 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 02 Aug 2014 23:31:35 +0100 Subject: Python Programing for the Absoulte Beginner In-Reply-To: References: Message-ID: On 02/08/2014 23:13, Seymore4Head wrote: > https://www.google.com/webhp?hl=en&tab=ww&gws_rd=ssl#hl=en&q=python+programing+for+the+absolute+beginner > > There is a book listed as a PDF. > > When I try the first example of print "Game Over" I get a syntax > error. > > I have tried running the command line and the GUI. I get the feeling > there is something else I need to run. > > http://imgur.com/RH3yczP > If the book is for Python 2 and you have 3.3 it should be print("Game Over") -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From Seymore4Head at Hotmail.invalid Sat Aug 2 18:39:33 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Sat, 02 Aug 2014 18:39:33 -0400 Subject: Python Programing for the Absoulte Beginner References: Message-ID: On Sun, 3 Aug 2014 08:30:15 +1000, Chris Angelico wrote: >On Sun, Aug 3, 2014 at 8:13 AM, Seymore4Head > wrote: >> https://www.google.com/webhp?hl=en&tab=ww&gws_rd=ssl#hl=en&q=python+programing+for+the+absolute+beginner >> >> There is a book listed as a PDF. >> >> When I try the first example of print "Game Over" I get a syntax >> error. >> >> I have tried running the command line and the GUI. I get the feeling >> there is something else I need to run. >> >> http://imgur.com/RH3yczP > >Try this instead: > >print("Game Over") > >You're looking at a Python 2 book, and you're running Python 3. I >would recommend instead getting a Python 3 tutorial: > >https://docs.python.org/3/tutorial/ > >ChrisA Thanks. I was reading a little in this group and someone had recommended trying codecademy.com That seems to be a pretty good way to start so far. I will also try your link. From Seymore4Head at Hotmail.invalid Sat Aug 2 18:41:05 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Sat, 02 Aug 2014 18:41:05 -0400 Subject: Python Programing for the Absoulte Beginner References: Message-ID: On Sat, 02 Aug 2014 23:31:35 +0100, Mark Lawrence wrote: >On 02/08/2014 23:13, Seymore4Head wrote: >> https://www.google.com/webhp?hl=en&tab=ww&gws_rd=ssl#hl=en&q=python+programing+for+the+absolute+beginner >> >> There is a book listed as a PDF. >> >> When I try the first example of print "Game Over" I get a syntax >> error. >> >> I have tried running the command line and the GUI. I get the feeling >> there is something else I need to run. >> >> http://imgur.com/RH3yczP >> > >If the book is for Python 2 and you have 3.3 it should be print("Game Over") Thanks I am sure they had a good reason to add using 2 more characters for doing the same job. From nicholascannon1 at gmail.com Sat Aug 2 18:53:12 2014 From: nicholascannon1 at gmail.com (Nicholas Cannon) Date: Sat, 2 Aug 2014 15:53:12 -0700 (PDT) Subject: Tkinter grid autosize help In-Reply-To: <60f53f24-7ce7-48e5-9fed-7d9ac8841b7f@googlegroups.com> References: <60f53f24-7ce7-48e5-9fed-7d9ac8841b7f@googlegroups.com> Message-ID: On Saturday, August 2, 2014 10:38:28 PM UTC+8, Nicholas Cannon wrote: > So i have a basic calculator program and i have a label that i want to go across the top to show the numbers and stuff like on a normal calculator. The only way i can make the buttons look neat and then when i keep pressing one the label gets larger and then half the buttons move out of the screen. I cant seem to fix this i have tried columnspan, columnconfigure and heaps of other stuff and non works it always expands. is there a way i can stop the grid from expanding? ok here is the code: #window setup main = Tk() main.title('Calculator') main.geometry('300x350') main.resizable() app = Frame(main) app.grid() app.columnconfigure(0, weight=500) app.columnconfigure(1, weight=500) #number view label number = ' ' numberView = Label(app, text= number) numberView.grid(row=0, column=0, columnspan=100) #Num Pad Buttons below num1 = '1' button1 = Button(app, text='1', command= lambda: add(num1), width=5) button1.grid(row=1, column=0) num2 = '2' button1 = Button(app, text='2', command= lambda: add(num2), width=5) button1.grid(row=1, column=1) num3 = '3' button1 = Button(app, text='3', command= lambda: add(num3), width=5) button1.grid(row=1, column=2) num4 = '4' button1 = Button(app, text='4', command= lambda: add(num4), width=5) button1.grid(row=2, column=0) num5 = '5' button1 = Button(app, text='5', command= lambda: add(num5), width=5) button1.grid(row=2, column=1) num6 = '6' button1 = Button(app, text='6', command= lambda: add(num6), width=5) button1.grid(row=2, column=2) num7 = '7' button1 = Button(app, text='7', command= lambda: add(num7), width=5) button1.grid(row=3, column=0) num8 = '8' button1 = Button(app, text='8', command= lambda: add(num8), width=5) button1.grid(row=3, column=1) num9 = '9' button1 = Button(app, text='9', command= lambda: add(num9), width=5) button1.grid(row=3, column=2) num0 = '0' button1 = Button(app, text='0', command= lambda: add(num0), width=5) button1.grid(row=4, column=1) main.mainloop() From rosuav at gmail.com Sat Aug 2 18:55:31 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Aug 2014 08:55:31 +1000 Subject: Python Programing for the Absoulte Beginner In-Reply-To: References: Message-ID: On Sun, Aug 3, 2014 at 8:41 AM, Seymore4Head wrote: >>If the book is for Python 2 and you have 3.3 it should be print("Game Over") > > Thanks > > I am sure they had a good reason to add using 2 more characters for > doing the same job. One more, since you'll normally have a space after the word "print" anyway. :) Language keywords are inflexible. Sure, it's nice and simple to do straightforward output, but when you want to send that to stderr instead of stdout, or change the separator between args, or change what's at the end of what's printed (a newline, normally), or anything like that, there needs to be special magical syntax added. Plus, it's nearly impossible to do a simple replacement of print with something else; pretty much the only way is to play with the code as it's being compiled. With a function, all that is fixed; there are standard ways of providing extra information (keyword arguments), you can replace print with any other function just by shadowing it, and all this can be done with perfectly normal syntax. This is how to tee print to a file as well as stdout: log_file = open("print.log","w") orig_print = print def print(*args, **kw): if "file" not in kw: orig_print(*args, **kw, file=log_file) orig_print(*args, **kw) So easy! You can grab a reference to the original print functionality with ordinary assignment (functions can be passed around and referenced by names; statements can't), you can replace it just by creating something else of the same name, and all its magic just comes through as arguments. There has been a move, now and then, to allow parens-free function calls. If some such scheme were accepted, you could then use the Python 2 syntax, and it would call the function; additionally, you could use the shorthand for any other function, too - "sys.exit 1" for instance. So far, there hasn't been a proposal that's satisfied all the requirements and given a compelling argument for acceptance, but I don't think the Python devs are philosophically opposed to the concept. ChrisA From tjreedy at udel.edu Sat Aug 2 19:12:28 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 02 Aug 2014 19:12:28 -0400 Subject: 3 Suggestions to Make Python Easier For Children In-Reply-To: References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> Message-ID: On 8/2/2014 3:46 AM, Mark Lawrence wrote: > On 02/08/2014 07:45, Mark Summerfield wrote: >> Last week I spent a couple of days teaching two children (10 and 13 -- >> too big an age gap!) how to do some turtle graphics with Python. >> Neither had programmed Python before -- one is a Minecraft ace and the >> other had done Scratch. >> >> Suggestion #1: Make IDLE start in the user's home directory. > > Entirely agree. Please raise an enhancement request on the bug tracker > if there isn't already one. > >> >> Suggestion #2: Make all the turtle examples begin "from turtle import >> *" so no leading turtle. is needed in the examples. > > I'm not so sure about this, but raise an enhancement request and see > what happens. Worst case it gets rejected, best case it gets accepted, > implemented and patch applied. > >> >> Suggestion #3: Make object(key=value, ...) legal and equiv of >> types.SimpleNamespace(key=value, ...). > > Haven't the faintest idea and too lazy to find out :) I suggest follow > advice from #2. Mark L: I think that redirecting discussion to the tracker a hour after these ideas were posted, certainly for #2 and #3, which you were rightfully unsure about, was a bit premature. Enhancement ideas generally benefit from being cooked a bit longer on one or another discussion list. -- Terry Jan Reedy From demianbrecht at gmail.com Sat Aug 2 19:04:05 2014 From: demianbrecht at gmail.com (Demian Brecht) Date: Sat, 2 Aug 2014 16:04:05 -0700 Subject: From git to hg Message-ID: For gits looking to transition to hg (namely to work on cpython): http://demianbrecht.github.io/vcs/2014/07/31/from-git-to-hg/. My learnings beginning to work with mercurial while working on the stdlib. (This was sent out to core-mentorship already, just figured this is likely a larger audience with potentially more interested people making the same transition) -- Demian Brecht http://demianbrecht.github.com From jeanpierreda at gmail.com Sat Aug 2 19:18:07 2014 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sat, 2 Aug 2014 16:18:07 -0700 Subject: Correct type for a simple "bag of attributes" namespace object (was: 3 Suggestions to Make Python Easier For Children) In-Reply-To: References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> <70e5f2f1-661f-40f2-bb7a-76e569c4d092@googlegroups.com> Message-ID: On Sat, Aug 2, 2014 at 2:05 PM, Chris Angelico wrote: > On Sun, Aug 3, 2014 at 6:46 AM, Mark Summerfield wrote: >> Naturally, I understand that adding a new name is a big deal and may be too much to ask for beginners. > > This is where you might want to consider putting some imports into > site.py. That way, you can set up your own customized Python, without > waiting for changes to be approved for core (which they probably won't > - new builtins have a high requirement for necessity, not just "I > don't want to have to type import"). Teaching a beginner a new programming language, but pretending it's Python, doesn't sound like a fantastic idea. -- Devin From tjreedy at udel.edu Sat Aug 2 19:14:46 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 02 Aug 2014 19:14:46 -0400 Subject: 3 Suggestions to Make Python Easier For Children In-Reply-To: <97480d7d-a078-45a8-a4a9-2652b68d7c80@googlegroups.com> References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <97480d7d-a078-45a8-a4a9-2652b68d7c80@googlegroups.com> Message-ID: On 8/2/2014 4:03 AM, Mark Summerfield wrote: > On Saturday, 2 August 2014 08:46:04 UTC+1, Mark Lawrence wrote: >> On 02/08/2014 07:45, Mark Summerfield wrote: Summarizing my responses on the tracker... >>> Suggestion #1: Make IDLE start in the user's home directory. >> >> Entirely agree. Please raise an enhancement request on the bug tracker >> if there isn't already one. > > Done: http://bugs.python.org/issue22121 As modified to fit existing behavior, this is a good idea and something will probably happen eventually. >>> Suggestion #2: Make all the turtle examples begin "from turtle import *" so no leading turtle. is needed in the examples. >> >> I'm not so sure about this, but raise an enhancement request and see >> what happens. Worst case it gets rejected, best case it gets accepted, >> implemented and patch applied. > > Done: http://bugs.python.org/issue22122 I suggest that the existing doc should be clarified instead. >>> Suggestion #3: Make object(key=value, ...) legal and equiv of types.SimpleNamespace(key=value, ...). >> >> Haven't the faintest idea and too lazy to find out :) I suggest follow >> advice from #2. > > Done: http://bugs.python.org/issue22123 This idea would mask bugs and is not necessary for the goal of making types.SimpleNamespace more accessible. It should have had more discussion here or on python-ideas. -- Terry Jan Reedy From rosuav at gmail.com Sat Aug 2 19:27:18 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Aug 2014 09:27:18 +1000 Subject: Correct type for a simple "bag of attributes" namespace object (was: 3 Suggestions to Make Python Easier For Children) In-Reply-To: References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> <70e5f2f1-661f-40f2-bb7a-76e569c4d092@googlegroups.com> Message-ID: On Sun, Aug 3, 2014 at 9:18 AM, Devin Jeanpierre wrote: > On Sat, Aug 2, 2014 at 2:05 PM, Chris Angelico wrote: >> On Sun, Aug 3, 2014 at 6:46 AM, Mark Summerfield wrote: >>> Naturally, I understand that adding a new name is a big deal and may be too much to ask for beginners. >> >> This is where you might want to consider putting some imports into >> site.py. That way, you can set up your own customized Python, without >> waiting for changes to be approved for core (which they probably won't >> - new builtins have a high requirement for necessity, not just "I >> don't want to have to type import"). > > Teaching a beginner a new programming language, but pretending it's > Python, doesn't sound like a fantastic idea. It would still be Python, you just teach that certain lines just always go at the top of your scripts (like "from __future__ import print_function" if you're on Py2). ChrisA From rosuav at gmail.com Sat Aug 2 19:29:27 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Aug 2014 09:29:27 +1000 Subject: From git to hg In-Reply-To: References: Message-ID: On Sun, Aug 3, 2014 at 9:04 AM, Demian Brecht wrote: > For gits looking to transition to hg (namely to work on cpython): > http://demianbrecht.github.io/vcs/2014/07/31/from-git-to-hg/. > > My learnings beginning to work with mercurial while working on the stdlib. > > (This was sent out to core-mentorship already, just figured this is > likely a larger audience with potentially more interested people > making the same transition) The same transition, or the same the other direction, has been done plenty of times. Here's a reference that I keep handy (I'm fluent in git and a bit less so in hg - I don't do advanced hg work often): https://github.com/sympy/sympy/wiki/Git-hg-rosetta-stone ChrisA From greg.ewing at canterbury.ac.nz Sat Aug 2 20:01:05 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 03 Aug 2014 12:01:05 +1200 Subject: Python and IDEs [was Re: Python 3 is killing Python] In-Reply-To: References: <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> <53DBCB7B.80704@schwertberger.de> Message-ID: Chris Angelico wrote: > It's a little awkward when you have > an invoicing screen and you put something like "P&O Shipping" as your > customer name, and suddenly Alt-O takes you someplace different. An app that did that would be seriously broken, wouldn't it? The & should only be interpreted that way in menu items, etc., not in user data. > but if the menu comes up > right near where your eyes are already focused, you need to move > _them_ less distance But putting the menu bar at the top of the window doesn't guarantee that it will be near where your eyes are. If you have a window taking up most of the screen and you're editing something near the bottom, a menu bar at the top of the window is nearly as far away as one at the top of the screen. It would make more sense to pop the menu up near the text cursor. There's no law that says a menu summoned by keystroke has to appear in the same place as one summoned by mouse. In any case, when you use a shortcut sequence, do you really *look* at the menu that comes up, or do you just memorise the appropriate alt-sequence? If you use it frequently, I suspect the latter. If you don't use it very often, having to look away doesn't matter so much. > Okay. So you need to first click on something in the dock - that's the > thing down the bottom of the screen, right? - and then go all the way > up to the top of the screen to use its menu bar. Because of the "throw the mouse" effect, going *all* the way to the top takes a tiny fraction of a second and is almost effortless. Going any lesser distance takes *much* longer. > I think I'd much > rather have a popup menu - right-click the program's dock icon and get > the menu right there where the mouse already is. Dock icons do have a contextual menu, but it's just a menu of windows. Fitting all of the app's menus in there would require hierarchical menus, which are an abomination you don't want to get me started on. :-) > Oh wait, that > requires people to understand more than a single mouse button, so it's > contrary to Mac philosophy :) The Mac philosophy on that seems to be widely misunderstood. Having only one button on my mouse doesn't mean there's only one thing I can do with it. I can shift-click, option- click, command-click, and nowadays control-click, plus any combination of those. That's enough for anyone to keep in their head, I would have thought. There's also one concrete advantage to using modifiers instead of extra mouse buttons: you can provide feedback by changing the cursor when a modifier is held down. -- Greg From greg.ewing at canterbury.ac.nz Sat Aug 2 20:04:56 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 03 Aug 2014 12:04:56 +1200 Subject: Python and IDEs [was Re: Python 3 is killing Python] In-Reply-To: References: <87zjga4j4v.fsf@elektro.pacujo.net> <53c57bae$0$9505$c3e8da3$5496439d@news.astraweb.com> <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> <53DBCB7B.80704@schwertberger.de> Message-ID: MRAB wrote: > RISC OS didn't have a menu bar at the top of each window either; its > menus were all pop-up. You didn't have to keep flicking the mouse at > all! The main reason for having a menu bar is discoverability. The idea is that you can browse through the menus and get a feel for what commands are potentially available to you. That's not so easy to do when everything is hidden in contextual menus. -- Greg From greg.ewing at canterbury.ac.nz Sat Aug 2 20:20:13 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 03 Aug 2014 12:20:13 +1200 Subject: Python and IDEs [was Re: Python 3 is killing Python] In-Reply-To: References: <87zjga4j4v.fsf@elektro.pacujo.net> <53c57bae$0$9505$c3e8da3$5496439d@news.astraweb.com> <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> <53DBCB7B.80704@schwertberger.de> Message-ID: Roy Smith wrote: > These days, I'm running multiple 24 inch monitors. The single menu bar > paradigm starts to break down in an environment like that. Yes, that's an issue. However, even on a large screen, most of my windows are at least half a screen high, putting their tops a considerable distance from where I'm working. And the targeting effect means that a target at the top of the screen is still easier to hit than one half way up. Multiple screens are a problem. Probably what should happen is for the menu bar to move to the screen holding the currently active window, instead of being tied to one "primary" screen. -- Greg From ian.g.kelly at gmail.com Sat Aug 2 20:59:44 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 2 Aug 2014 18:59:44 -0600 Subject: Correct type for a simple "bag of attributes" namespace object (was: 3 Suggestions to Make Python Easier For Children) In-Reply-To: <70e5f2f1-661f-40f2-bb7a-76e569c4d092@googlegroups.com> References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> <70e5f2f1-661f-40f2-bb7a-76e569c4d092@googlegroups.com> Message-ID: On Sat, Aug 2, 2014 at 2:46 PM, Mark Summerfield wrote: > On Saturday, 2 August 2014 20:58:59 UTC+1, Ben Finney wrote: >> Steven D'Aprano writes: >> >> > If you need instances which carry state, then object is the wrong >> > class. > > Fair enough. > >> Right. The 'types' module provides a SimpleNamespace class for the >> common "bag of attributes" use case:: >> >> >>> import types >> >>> foo = types.SimpleNamespace() >> >>> foo.x = 3 >> >>> foo >> namespace(x=3) > > This is too much for children (& beginners). > > But perhaps what I should be asking for is for a new built-in that does what types.SimpleNamespace() does, so that without any import you can write, say, > > foo = namespace(a=1, b=2) > # or > bar = namespace() > bar.a = 1 > > where under the hood namespace has the same behavior as types.SimpleNamespace(). > > Naturally, I understand that adding a new name is a big deal and may be too much to ask for beginners. from types import SimpleNamespace as namespace Just have them put that at the top of each file, and tell them not to worry about what it does. From rosuav at gmail.com Sat Aug 2 21:12:39 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Aug 2014 11:12:39 +1000 Subject: Python and IDEs [was Re: Python 3 is killing Python] In-Reply-To: References: <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> <53DBCB7B.80704@schwertberger.de> Message-ID: On Sun, Aug 3, 2014 at 10:01 AM, Gregory Ewing wrote: > Chris Angelico wrote: >> >> It's a little awkward when you have >> an invoicing screen and you put something like "P&O Shipping" as your >> customer name, and suddenly Alt-O takes you someplace different. > > > An app that did that would be seriously broken, wouldn't it? > The & should only be interpreted that way in menu items, etc., > not in user data. Mnemonics can also be used on text labels, and then they apply to the adjacent field - for instance, you could have "_Name" followed by an entry field for the Name, and hitting Alt-N will take you to that field. The app I'm talking about used a label to show the customer's name, and we had exactly that issue (although more often with couples' names - for instance, if we had an order from John and Mary Smith, but didn't know their full names, we'd identify them as J&M Smith, and voila, Alt-M would take us to... whatever field came after the display of the name (which was the address). To be quite honest, that particular program was a lot more broken than that. But still, it did drive home the value of using ~ instead of & for that job. And of course, _ makes enough sense that we can accept its potential for collisions. (Plus it's usually possible to disable underscore interpretation. Or, more properly, you have to explicitly enable their interpretation; in GTK, I have to call set_use_underline(1) before it'll create a mnemonic.) >> but if the menu comes up >> right near where your eyes are already focused, you need to move >> _them_ less distance > > > But putting the menu bar at the top of the window doesn't > guarantee that it will be near where your eyes are. If > you have a window taking up most of the screen and you're > editing something near the bottom, a menu bar at the top > of the window is nearly as far away as one at the top of > the screen. Putting it at the top of the window cannot possibly make it further away than putting it at the top of the screen. It's potentially going to be a lot closer, but at its worst, it'll be just as bad (modulo the title bar's height). > It would make more sense to pop the menu up near the text > cursor. There's no law that says a menu summoned by > keystroke has to appear in the same place as one summoned > by mouse. Sure. And I know of plenty of applications where that's possible. The standard used to be Shift-F10 to bring up a context menu, identical to right-clicking the mouse except that the menu appears at the object you're working on rather than at the mouse's location. These days, you often get something like that on the Menu key (aka the other Windows key, on some keyboards); same result. But that's a context menu, not the pull-down menu; although it's common to have the same menu items on them. > In any case, when you use a shortcut sequence, do you > really *look* at the menu that comes up, or do you just > memorise the appropriate alt-sequence? If you use it > frequently, I suspect the latter. If you don't use it > very often, having to look away doesn't matter so much. If I'm using "Alt-F, O" as a command keystroke, then sure, it doesn't make any difference where the menu is. But often I'll pull down a menu, then look at it to figure out what I want to hit. Once my eye has found it, I'll press its underlined letter, so I still don't use the mouse; but I do need it to have a mnemonic, and I need the entire menu to be near my eye. >> Okay. So you need to first click on something in the dock - that's the >> thing down the bottom of the screen, right? - and then go all the way >> up to the top of the screen to use its menu bar. > > Because of the "throw the mouse" effect, going *all* the > way to the top takes a tiny fraction of a second and is > almost effortless. Going any lesser distance takes > *much* longer. Right, but it still takes time. Also, if your mouse is set fast enough to go all the way from the bottom to the top of the screen in less than 0.1s, then either your screen is fairly small (may have been true in the past, but is getting pretty rare now), or you seriously penalize any going-less-distance operations. In fact, it becomes self-perpetuating: if you set the mouse fast, it becomes really important to use the edges and avoid the middle, and if applications always use the edges and never the middle, it's really important to set your mouse faster. Conversely, slower mouse settings mean it's easier to be precise with interior movements, while reducing the advantage of the borders. But no matter how fast you set the mouse, it still takes a nonzero time to move it to a specific position. The absolute easiest place to reach is... where you already are. Put the menu there! That's what popup menus are for. >> I think I'd much >> rather have a popup menu - right-click the program's dock icon and get >> the menu right there where the mouse already is. > > Dock icons do have a contextual menu, but it's just a > menu of windows. Fitting all of the app's menus in there > would require hierarchical menus, which are an abomination > you don't want to get me started on. :-) I detest window stacking. Each window stands alone, even if some are from the same application. (Either that, or some of them are to be altogether hidden. But anything that gets shown should be shown at top level.) >> Oh wait, that >> requires people to understand more than a single mouse button, so it's >> contrary to Mac philosophy :) > > > The Mac philosophy on that seems to be widely misunderstood. > Having only one button on my mouse doesn't mean there's > only one thing I can do with it. I can shift-click, option- > click, command-click, and nowadays control-click, plus any > combination of those. That's enough for anyone to keep in > their head, I would have thought. I can do all those, AND I can do those with right-click. And bare right-click has the advantage that it can be done one-handed; that can be quite a difference when you have a son/daughter/brother/sister hanging off your left arm... > There's also one concrete advantage to using modifiers > instead of extra mouse buttons: you can provide feedback > by changing the cursor when a modifier is held down. Sure. But that shouldn't preclude the use of additional mouse buttons too. ChrisA From tjreedy at udel.edu Sat Aug 2 22:16:40 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 02 Aug 2014 22:16:40 -0400 Subject: Tkinter grid autosize help In-Reply-To: References: <60f53f24-7ce7-48e5-9fed-7d9ac8841b7f@googlegroups.com> Message-ID: On 8/2/2014 6:53 PM, Nicholas Cannon wrote: > On Saturday, August 2, 2014 10:38:28 PM UTC+8, Nicholas Cannon wrote: >> So i have a basic calculator program and i have a label that i want to go across >> the top to show the numbers and stuff like on a normal calculator. The buttons are labelled already with numbers. Whatever stuff you meant, is not diplayed. >> The only way i can make the buttons look neat and then when i keep >> pressing one the label gets larger and then half the buttons >> move out of the screen. Since nothing gets bigger, I have no idea what you mean. >> I cant seem to fix this i have tried columnspan, columnconfigure >> and heaps of other stuff and non works it always expands. >> is there a way i can stop the grid from expanding? If I shrink the window horizontally, the minimun size is 3 columns. If I shrink vertically, bottom buttons disappear. I am not sure why. > ok here is the code: Only some of it. from tkinter import * def add(*args): print(args) > #window setup > main = Tk() > main.title('Calculator') > main.geometry('300x350') > main.resizable() > > app = Frame(main) > app.grid() > app.columnconfigure(0, weight=500) > app.columnconfigure(1, weight=500) You left out column 2. > > #number view label > number = ' ' > numberView = Label(app, text= number) > numberView.grid(row=0, column=0, columnspan=100) What you need for a changing label is number = StringVar() number.set('') numberView = Label(app, textvariable=number) but see below > #Num Pad Buttons below > num1 = '1' > button1 = Button(app, text='1', command= lambda: add(num1), width=5) > button1.grid(row=1, column=0) You are using the braindead telephone keypad layout. Calculators and number keypads have the more sensible layout 7 8 9 4 5 6 1 2 3 0 > num2 = '2' > button1 = Button(app, text='2', command= lambda: add(num2), width=5) > button1.grid(row=1, column=1) > > num3 = '3' > button1 = Button(app, text='3', command= lambda: add(num3), width=5) > button1.grid(row=1, column=2) > > num4 = '4' > button1 = Button(app, text='4', command= lambda: add(num4), width=5) > button1.grid(row=2, column=0) > > num5 = '5' > button1 = Button(app, text='5', command= lambda: add(num5), width=5) > button1.grid(row=2, column=1) > > num6 = '6' > button1 = Button(app, text='6', command= lambda: add(num6), width=5) > button1.grid(row=2, column=2) > > num7 = '7' > button1 = Button(app, text='7', command= lambda: add(num7), width=5) > button1.grid(row=3, column=0) > > num8 = '8' > button1 = Button(app, text='8', command= lambda: add(num8), width=5) > button1.grid(row=3, column=1) > > num9 = '9' > button1 = Button(app, text='9', command= lambda: add(num9), width=5) > button1.grid(row=3, column=2) > > num0 = '0' > button1 = Button(app, text='0', command= lambda: add(num0), width=5) > button1.grid(row=4, column=1) ) > This sort of repetitious code is crying for a loop. For one thing, if you want to change the buttons, there should only be one Button call to modify. Since I am still learning to write tkinter myself, I wrote the following, which I suspect does what you wanted and a bit more. from tkinter import * main = Tk() main.title('Calculator') main.geometry('300x350') #main.resizable() # does nothing app = Frame(main) app.grid() total = IntVar() total.set(0) entry = StringVar() entry.set('') Label(app, text='Total').grid(row=0, column=0) Label(app, textvariable=total).grid(row=0, column=1, columnspan=3) Label(app, text='Entry').grid(row=1, column=0) Label(app, textvariable=entry).grid(row=1, column=1, columnspan=3) def append(digit): entry.set(entry.get() + digit) def add(): total.set(total.get() + int(entry.get())) entry.set('') def sub(): total.set(total.get() - int(entry.get())) entry.set('') header_rows = 2 for num, r, c in ( ('7', 0, 0), ('8', 0, 1), ('9', 0, 2), ('4', 1, 0), ('5', 1, 1), ('6', 1, 2), ('1', 2, 0), ('2', 2, 1), ('3', 2, 2), ('0', 3, 0), ('+', 3, 1), ('-', 3, 2),): cmd = {'+':add, '-':sub}.get(num, lambda num=num: append(num)) b = Button(app, text=num, command=cmd, width=5) b.grid(row=header_rows+r, column=c) main.mainloop() -- Terry Jan Reedy From rantingrickjohnson at gmail.com Sat Aug 2 22:24:27 2014 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 2 Aug 2014 19:24:27 -0700 (PDT) Subject: Tkinter grid autosize help In-Reply-To: References: <60f53f24-7ce7-48e5-9fed-7d9ac8841b7f@googlegroups.com> Message-ID: <81db112d-53d6-4279-96de-86e91b9cb27b@googlegroups.com> On Saturday, August 2, 2014 5:53:12 PM UTC-5, Nicholas Cannon wrote: > So i have a basic calculator program and i > have a label that i want to go across the top to show the > numbers and stuff like on a normal calculator. The only > way i can make the buttons look neat and then when i keep > pressing one the label gets larger and then half the > buttons move out of the screen. A Tkinter Label widget will "naturally" adjust its size to accommodate the text it contains. > I cant seem to fix this i have tried columnspan, > columnconfigure and heaps of other stuff and non works it > always expands. is there a way i can stop the grid from > expanding? The "grid is expanding" because the first row of the grid (which contains a label that is being updated by user input) is expanding, and as such, all subsequent rows will expand to match the first row. You should use an Entry instead of a Label because: 1. Entry will accommodate values that exceed their current size *WITHOUT* growing. 2. Label widgets do not allow direct input from the user. Sure, in some cases you want to prevent the user from editing text via the keyboard but *NOT* in this case! All calculator apps should allow the use a choice between mouse clicks or keyboard entry. *HOWEVER*, if you do decide to implement the "numberView" as an Entry widget, you will need to create a keypress filter to prevent illegal input! > ok here is the code: > #window setup > main = Tk() > main.title('Calculator') > main.geometry('300x350') > main.resizable() > app = Frame(main) > app.grid() > app.columnconfigure(0, weight=500) > app.columnconfigure(1, weight=500) > #number view label > number = ' ' > numberView = Label(app, text= number) > numberView.grid(row=0, column=0, columnspan=100) > #Num Pad Buttons below > num1 = '1' > button1 = Button(app, text='1', command= lambda: add(num1), width=5) > button1.grid(row=1, column=0) > num2 = '2' > button1 = Button(app, text='2', command= lambda: add(num2), width=5) > button1.grid(row=1, column=1) > num3 = '3' > button1 = Button(app, text='3', command= lambda: add(num3), width=5) > button1.grid(row=1, column=2) > num4 = '4' > button1 = Button(app, text='4', command= lambda: add(num4), width=5) > button1.grid(row=2, column=0) > num5 = '5' > button1 = Button(app, text='5', command= lambda: add(num5), width=5) > button1.grid(row=2, column=1) > num6 = '6' > button1 = Button(app, text='6', command= lambda: add(num6), width=5) > button1.grid(row=2, column=2) > num7 = '7' > button1 = Button(app, text='7', command= lambda: add(num7), width=5) > button1.grid(row=3, column=0) > num8 = '8' > button1 = Button(app, text='8', command= lambda: add(num8), width=5) > button1.grid(row=3, column=1) > num9 = '9' > button1 = Button(app, text='9', command= lambda: add(num9), width=5) > button1.grid(row=3, column=2) > num0 = '0' > button1 = Button(app, text='0', command= lambda: add(num0), width=5) > button1.grid(row=4, column=1) > main.mainloop() A few points about your code: 1. "add" is a horrendous name for a function that updates the numerical display, ESPECIALLY in an application that is used to add, subtract, blah-blah-blah! 2. You should use a loop to layout the "grid of buttons", which could be accomplished in just a mere couple lines of code. 3. Declaring the value of the lambda arguments seems superfluous to me. Finally, there is always more to an interface than we initially imagine. For instance, the width of the "numberView" should fill the containing window to allow the user "view flexibility", however, if the entry is allowed to be dynamic and the "number grid" is not dynamic, then the application is not going to feel very professional. Of course, at this time, just getting something working is most important. We can jazz it up later :) Here is a slightly modified version of your code that may help you get going in the correct direction. Note, i am *NOT* going to write this code for you, i will offer *slight* suggestions and comments where i believe improvements could be made, but you are required to do the heavy lifting. ############################################################ # START CODE ############################################################ import Tkinter as tk from Tkconstants import E, W, END def update_entry(arg): oldValue = entry.get() entry.delete(0, END) entry.insert(0, oldValue + arg) def onKeyPress_entry(event): key = event.keysym.lower() print 'The user pressed {0}'.format(key) # # The following conditional showcases how to prevent # illegal input but utilizing a return value of "break" if key == 'w': print 'The char "w" is not allowed!' return "break" app = tk.Tk() app.title('Calculator') app.geometry('300x350') entry = tk.Entry(app) entry.grid(row=0, column=0, sticky=E+W, columnspan=3) entry.bind("", onKeyPress_entry) if True: # OPTION_1: Create buttons with repetitive code: w = tk.Button(app, text='1', command=lambda: update_entry('1'), width=5) w.grid(row=1, column=0) w = tk.Button(app, text='2', command=lambda: update_entry('2'), width=5) w.grid(row=1, column=1) w = tk.Button(app, text='3', command=lambda: update_entry('3'), width=5) w.grid(row=1, column=2) w = tk.Button(app, text='4', command=lambda: update_entry('4'), width=5) w.grid(row=2, column=0) w = tk.Button(app, text='5', command=lambda: update_entry('5'), width=5) w.grid(row=2, column=1) w = tk.Button(app, text='6', command=lambda: update_entry('6'), width=5) w.grid(row=2, column=2) w = tk.Button(app, text='7', command=lambda: update_entry('7'), width=5) w.grid(row=3, column=0) w = tk.Button(app, text='8', command=lambda: update_entry('8'), width=5) w.grid(row=3, column=1) w = tk.Button(app, text='9', command=lambda: update_entry('9'), width=5) w.grid(row=3, column=2) else: # OPTION_2: Create Buttons by off-loading the work onto Python. number = 1 for r in range(1, 4): for c in range(3): print r, c, number # Can you figure out what to do here? number += 1 w = tk.Button(app, text='0', command=lambda: update_entry('0'), width=5) w.grid(row=4, column=1) if __name__ == '__main__': app.mainloop() ############################################################ # END CODE ############################################################ From nicholascannon1 at gmail.com Sat Aug 2 22:36:44 2014 From: nicholascannon1 at gmail.com (Nicholas Cannon) Date: Sat, 2 Aug 2014 19:36:44 -0700 (PDT) Subject: Tkinter grid autosize help In-Reply-To: <60f53f24-7ce7-48e5-9fed-7d9ac8841b7f@googlegroups.com> References: <60f53f24-7ce7-48e5-9fed-7d9ac8841b7f@googlegroups.com> Message-ID: <9e91ba17-9a6b-4677-a84c-65fbb057b0ae@googlegroups.com> On Saturday, August 2, 2014 10:38:28 PM UTC+8, Nicholas Cannon wrote: > So i have a basic calculator program and i have a label that i want to go across the top to show the numbers and stuff like on a normal calculator. The only way i can make the buttons look neat and then when i keep pressing one the label gets larger and then half the buttons move out of the screen. I cant seem to fix this i have tried columnspan, columnconfigure and heaps of other stuff and non works it always expands. is there a way i can stop the grid from expanding? Ok so I have just started out Tkinter and I feel I should study more of it because some of the code given is quite intimidating to me right now. Also I have only been coding python for 3 months right now. I think I need to learn how to write python better haha. I appreciate the help guys. From tjreedy at udel.edu Sat Aug 2 22:40:43 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 02 Aug 2014 22:40:43 -0400 Subject: Correct type for a simple "bag of attributes" namespace object In-Reply-To: References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> <70e5f2f1-661f-40f2-bb7a-76e569c4d092@googlegroups.com> Message-ID: On 8/2/2014 5:16 PM, Mark Lawrence wrote: > On 02/08/2014 22:05, Chris Angelico wrote: >> On Sun, Aug 3, 2014 at 6:46 AM, Mark Summerfield >> wrote: >>> But perhaps what I should be asking for is for a new built-in that >>> does what types.SimpleNamespace() does, so that without any import >>> you can write, say, >>> >>> foo = namespace(a=1, b=2) >>> # or >>> bar = namespace() >>> bar.a = 1 >>> >>> where under the hood namespace has the same behavior as >>> types.SimpleNamespace(). >>> >>> Naturally, I understand that adding a new name is a big deal and may >>> be too much to ask for beginners. >> >> This is where you might want to consider putting some imports into >> site.py. That way, you can set up your own customized Python, without >> waiting for changes to be approved for core (which they probably won't >> - new builtins have a high requirement for necessity, not just "I >> don't want to have to type import"). >> >> ChrisA >> > > I'd forgotten all about site.py so went to the 3.4.1 docs and found > "Deprecated since version 3.4: Support for the ?site-python? directory > will be removed in 3.5.". site-python is *nix only and differetn from site.py, which will not go away. I believe PYTHONSTARTUP is also cross platform. -- Terry Jan Reedy From tjreedy at udel.edu Sat Aug 2 22:43:53 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 02 Aug 2014 22:43:53 -0400 Subject: Correct type for a simple "bag of attributes" namespace object In-Reply-To: References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> <70e5f2f1-661f-40f2-bb7a-76e569c4d092@googlegroups.com> Message-ID: On 8/2/2014 8:59 PM, Ian Kelly wrote: > On Sat, Aug 2, 2014 at 2:46 PM, Mark Summerfield wrote: >> On Saturday, 2 August 2014 20:58:59 UTC+1, Ben Finney wrote: >>> Steven D'Aprano writes: >>> >>>> If you need instances which carry state, then object is the wrong >>>> class. >> >> Fair enough. >> >>> Right. The 'types' module provides a SimpleNamespace class for the >>> common "bag of attributes" use case:: >>> >>> >>> import types >>> >>> foo = types.SimpleNamespace() >>> >>> foo.x = 3 >>> >>> foo >>> namespace(x=3) >> >> This is too much for children (& beginners). >> >> But perhaps what I should be asking for is for a new built-in that does what types.SimpleNamespace() does, so that without any import you can write, say, >> >> foo = namespace(a=1, b=2) >> # or >> bar = namespace() >> bar.a = 1 >> >> where under the hood namespace has the same behavior as types.SimpleNamespace(). >> >> Naturally, I understand that adding a new name is a big deal and may be too much to ask for beginners. > > from types import SimpleNamespace as namespace > > Just have them put that at the top of each file, and tell them not to > worry about what it does. In fact, for the original usecase, put it in a 'template file' that also includes a turtle import. For one of my projects, I have @template with several lines of boilerplate that I use for new files. -- Terry Jan Reedy From tjreedy at udel.edu Sat Aug 2 23:22:29 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 02 Aug 2014 23:22:29 -0400 Subject: Tkinter grid autosize help In-Reply-To: References: <60f53f24-7ce7-48e5-9fed-7d9ac8841b7f@googlegroups.com> Message-ID: On 8/2/2014 10:16 PM, Terry Reedy wrote: > On 8/2/2014 6:53 PM, Nicholas Cannon wrote: >> The only way i can make the buttons look neat and then when i keep >> pressing one the label gets larger and then half the buttons >> move out of the screen With my code below, I tried entering a 20 digit number and the button boxes separate horizontally. This is not exactly what you describe, but it does mess up the initially neat display. >> is there a way i can stop the grid from expanding? One thing I might do, besides using an entry box, it to grid the buttons in a separate frame. I wrote the code below, with the header_rows variable, with that in mind. > This sort of repetitious code is crying for a loop. For one thing, if > you want to change the buttons, there should only be one Button call to > modify. Since I am still learning to write tkinter myself, I wrote the > following, which I suspect does what you wanted and a bit more. > > from tkinter import * > > main = Tk() > main.title('Calculator') > main.geometry('300x350') > #main.resizable() # does nothing > > app = Frame(main) > app.grid() > > total = IntVar() > total.set(0) > entry = StringVar() > entry.set('') > > Label(app, text='Total').grid(row=0, column=0) > Label(app, textvariable=total).grid(row=0, column=1, columnspan=3) > Label(app, text='Entry').grid(row=1, column=0) > Label(app, textvariable=entry).grid(row=1, column=1, columnspan=3) > > def append(digit): > entry.set(entry.get() + digit) > > def add(): > total.set(total.get() + int(entry.get())) > entry.set('') > def sub(): > total.set(total.get() - int(entry.get())) > entry.set('') > > header_rows = 2 > for num, r, c in ( > ('7', 0, 0), ('8', 0, 1), ('9', 0, 2), > ('4', 1, 0), ('5', 1, 1), ('6', 1, 2), > ('1', 2, 0), ('2', 2, 1), ('3', 2, 2), > ('0', 3, 0), ('+', 3, 1), ('-', 3, 2),): > cmd = {'+':add, '-':sub}.get(num, lambda num=num: append(num)) > b = Button(app, text=num, command=cmd, width=5) > b.grid(row=header_rows+r, column=c) > > main.mainloop() With regard to your next message: If you do not understand the function definitions above, including the lambda expression, and the loop, you should definitely look more at the tutorial. -- Terry Jan Reedy From hayesstw at telkomsa.net Sun Aug 3 01:11:46 2014 From: hayesstw at telkomsa.net (Steve Hayes) Date: Sun, 03 Aug 2014 07:11:46 +0200 Subject: Python Programing for the Absoulte Beginner References: Message-ID: On Sun, 3 Aug 2014 08:30:15 +1000, Chris Angelico wrote: >On Sun, Aug 3, 2014 at 8:13 AM, Seymore4Head > wrote: >> https://www.google.com/webhp?hl=en&tab=ww&gws_rd=ssl#hl=en&q=python+programing+for+the+absolute+beginner >> >> There is a book listed as a PDF. >> >> When I try the first example of print "Game Over" I get a syntax >> error. >> >> I have tried running the command line and the GUI. I get the feeling >> there is something else I need to run. >> >> http://imgur.com/RH3yczP > >Try this instead: > >print("Game Over") > >You're looking at a Python 2 book, and you're running Python 3. I >would recommend instead getting a Python 3 tutorial: Or do as I did, and install Python 2. -- 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 rosuav at gmail.com Sun Aug 3 01:12:02 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Aug 2014 15:12:02 +1000 Subject: Python Programing for the Absoulte Beginner In-Reply-To: References: Message-ID: On Sun, Aug 3, 2014 at 3:11 PM, Steve Hayes wrote: >>You're looking at a Python 2 book, and you're running Python 3. I >>would recommend instead getting a Python 3 tutorial: > > Or do as I did, and install Python 2. Better to install and learn Python 3. Much better. ChrisA From hayesstw at telkomsa.net Sun Aug 3 01:20:01 2014 From: hayesstw at telkomsa.net (Steve Hayes) Date: Sun, 03 Aug 2014 07:20:01 +0200 Subject: Python Programing for the Absoulte Beginner References: Message-ID: <0hhrt99lb6hhfh9q7mhra55d8base6eumg@4ax.com> On Sun, 3 Aug 2014 15:12:02 +1000, Chris Angelico wrote: >On Sun, Aug 3, 2014 at 3:11 PM, Steve Hayes wrote: >>>You're looking at a Python 2 book, and you're running Python 3. I >>>would recommend instead getting a Python 3 tutorial: >> >> Or do as I did, and install Python 2. > >Better to install and learn Python 3. Much better. I've got too big an investment in books on Python 2, and there are no books available on Python 3 (I don't regard downloadable PDFs or other onlines stuff as "books"). -- 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 memilanuk at gmail.com Sun Aug 3 01:31:12 2014 From: memilanuk at gmail.com (memilanuk) Date: Sat, 02 Aug 2014 22:31:12 -0700 Subject: Python Programing for the Absoulte Beginner In-Reply-To: <0hhrt99lb6hhfh9q7mhra55d8base6eumg@4ax.com> References: <0hhrt99lb6hhfh9q7mhra55d8base6eumg@4ax.com> Message-ID: On 08/02/2014 10:20 PM, Steve Hayes wrote: > there are no books available on Python 3 (I don't regard downloadable PDFs > or other onlines stuff as "books"). That's a very broad... and very *wrong* statement. -- Shiny! Let's be bad guys. Reach me @ memilanuk (at) gmail dot com From rosuav at gmail.com Sun Aug 3 01:43:48 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Aug 2014 15:43:48 +1000 Subject: Python Programing for the Absoulte Beginner In-Reply-To: <0hhrt99lb6hhfh9q7mhra55d8base6eumg@4ax.com> References: <0hhrt99lb6hhfh9q7mhra55d8base6eumg@4ax.com> Message-ID: On Sun, Aug 3, 2014 at 3:20 PM, Steve Hayes wrote: > On Sun, 3 Aug 2014 15:12:02 +1000, Chris Angelico wrote: > >>On Sun, Aug 3, 2014 at 3:11 PM, Steve Hayes wrote: >>>>You're looking at a Python 2 book, and you're running Python 3. I >>>>would recommend instead getting a Python 3 tutorial: >>> >>> Or do as I did, and install Python 2. >> >>Better to install and learn Python 3. Much better. > > I've got too big an investment in books on Python 2, and there are no books > available on Python 3 (I don't regard downloadable PDFs or other onlines stuff > as "books"). But there are plenty of courses for Python 3, and lots of people are happy to take online information when learning coding. (Personally, I can't be bothered with paper books at all. I get all my books online if I possibly can... or even get both, pay for the paper one to support the author, and then download it so I have something I can actually read and search.) Don't tie yourself to the Python branch that's not getting development (bugfixes, some IDLE enhancements, but no new features) unless you have a good reason to. For someone who's just starting out with Python, learn Python 3. Don't bother going into all the debates; if you have need of Python 2, you'll find out when the time comes; and when it does, you'll be better placed for having learned Python 3. ChrisA From steve+comp.lang.python at pearwood.info Sun Aug 3 04:09:19 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 03 Aug 2014 18:09:19 +1000 Subject: Python Programing for the Absoulte Beginner References: <0hhrt99lb6hhfh9q7mhra55d8base6eumg@4ax.com> Message-ID: <53ddee30$0$29976$c3e8da3$5496439d@news.astraweb.com> Steve Hayes wrote: > I've got too big an investment in books on Python 2, and there are no > books available on Python 3 (I don't regard downloadable PDFs or other > onlines stuff as "books"). I love Python 3, it's way better than Python 2, and there's less and less reason to stick to Python 2 now. You really should learn Python 3, you won't be sorry. But, if you choose not to, there's nothing to be ashamed of. Python 2.7 has got at least six years of life left in it, and when you're done with it, migrating to Python 3 isn't like learning a new language. It's more like the difference between American and British English. -- Steven From fomcl at yahoo.com Sun Aug 3 05:17:44 2014 From: fomcl at yahoo.com (Albert-Jan Roskam) Date: Sun, 3 Aug 2014 02:17:44 -0700 Subject: Correct type for a simple "bag of attributes" namespace object In-Reply-To: References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> <70e5f2f1-661f-40f2-bb7a-76e569c4d092@googlegroups.com> Message-ID: <1407057464.64980.YahooMailNeo@web163806.mail.gq1.yahoo.com> --- Original Message ----- > From: Terry Reedy > To: python-list at python.org > Cc: > Sent: Sunday, August 3, 2014 4:43 AM > Subject: Re: Correct type for a simple "bag of attributes" namespace object > > On 8/2/2014 8:59 PM, Ian Kelly wrote: >> On Sat, Aug 2, 2014 at 2:46 PM, Mark Summerfield > wrote: >>> On Saturday, 2 August 2014 20:58:59 UTC+1, Ben Finney? wrote: >>>> Steven D'Aprano writes: >>>> >>>>> If you need instances which carry state, then object is the > wrong >>>>> class. >>> >>> Fair enough. >>> >>>> Right. The 'types' module provides a SimpleNamespace class > for the >>>> common "bag of attributes" use case:: >>>> >>>> ? ? ? >>> import types >>>> ? ? ? >>> foo = types.SimpleNamespace() >>>> ? ? ? >>> foo.x = 3 >>>> ? ? ? >>> foo >>>> ? ? ? namespace(x=3) >>> >>> This is too much for children (& beginners). >>> >>> But perhaps what I should be asking for is for a new built-in that does > what types.SimpleNamespace() does, so that without any import you can write, > say, >>> >>> foo = namespace(a=1, b=2) >>> # or >>> bar = namespace() >>> bar.a = 1 I find the following obscure (to me at least) use of type() useful exactly for this "bag of attributes" use case: >>> employee = type("Employee", (object,), {}) >>> employee.name = "John Doe" >>> employee.position = "Python programmer" >>> employee.name, employee.position, employee ('John Doe', 'Python programmer', ) >>> details = dict(name="John Doe", position="Python programmer") >>> employee = type("Employee", (object,), details) >>> employee.name, employee.position, employee ('John Doe', 'Python programmer', ) regards, Albert-Jan From __peter__ at web.de Sun Aug 3 05:37:04 2014 From: __peter__ at web.de (Peter Otten) Date: Sun, 03 Aug 2014 11:37:04 +0200 Subject: Correct type for a simple "bag of attributes" namespace object References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> <70e5f2f1-661f-40f2-bb7a-76e569c4d092@googlegroups.com> <1407057464.64980.YahooMailNeo@web163806.mail.gq1.yahoo.com> Message-ID: Albert-Jan Roskam wrote: > I find the following obscure (to me at least) use of type() useful exactly > for this "bag of attributes" use case: >>>> employee = type("Employee", (object,), {}) >>>> employee.name = "John Doe" >>>> employee.position = "Python programmer" >>>> employee.name, employee.position, employee > ('John Doe', 'Python programmer', ) Are you sure you know what you are doing? The above is equivalent to >>> class employee: ... name = "John Doe" ... position = "Python programmer" ... >>> employee.name, employee.position, employee ('John Doe', 'Python programmer', ) >>> type(employee) Basically you are using classes as instances. While there is no fundamental difference between classes and instances in Python you'll surprise readers of your code and waste some space: >>> import sys >>> sys.getsizeof(employee) 976 >>> class Employee: pass ... >>> employee = Employee() >>> employee.name = "John Doe" >>> employee.position = "Python programmer" >>> sys.getsizeof(employee) 64 From shieldfire at gmail.com Sun Aug 3 06:02:12 2014 From: shieldfire at gmail.com (Martin S) Date: Sun, 3 Aug 2014 12:02:12 +0200 Subject: SQLAlchemy tutorial Message-ID: Hi, I've been looking at various tutorials on SQLAlchemy as I am planning to do fill a void among the Linux applications (unless someone has seen a diabetic result "analyser" thingy that's common for Android et al). But I need to get a database working. Problem is the Alchemy tutorials I've been looking at all produce various errors when following them (and pretty early on). Anyone got a suggestion for SQLAlchemy and Python 3.4 they can recommend? /Martin S -- Regards, Martin S From ben+python at benfinney.id.au Sun Aug 3 06:17:56 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 03 Aug 2014 20:17:56 +1000 Subject: SQLAlchemy tutorial References: Message-ID: <8538dddgh7.fsf@benfinney.id.au> Martin S writes: > Problem is the [SQLAlchemy] tutorials I've been looking at all produce > various errors when following them (and pretty early on). SQLAlchemy has been progressively adding support for Python 3, so it matters which version of SQLAlchemy you install. For best results, it seems SQLAlchemy version 0.9 or later supports Python 3 seamlessly. > Anyone got a suggestion for SQLAlchemy and Python 3.4 they can > recommend? The official documentation is the right place to start, once you can get compatible versions of SQLAlchemy and Python together. -- \ ?It seems intuitively obvious to me, which means that it might | `\ be wrong.? ?Chris Torek | _o__) | Ben Finney From fomcl at yahoo.com Sun Aug 3 06:51:12 2014 From: fomcl at yahoo.com (Albert-Jan Roskam) Date: Sun, 3 Aug 2014 03:51:12 -0700 Subject: Correct type for a simple "bag of attributes" namespace object In-Reply-To: References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> <70e5f2f1-661f-40f2-bb7a-76e569c4d092@googlegroups.com> <1407057464.64980.YahooMailNeo@web163806.mail.gq1.yahoo.com> Message-ID: <1407063072.46317.YahooMailNeo@web163803.mail.gq1.yahoo.com> ----- Original Message ----- > From: Peter Otten <__peter__ at web.de> > To: python-list at python.org > Cc: > Sent: Sunday, August 3, 2014 11:37 AM > Subject: Re: Correct type for a simple "bag of attributes" namespace object > > Albert-Jan Roskam wrote: > >> I find the following obscure (to me at least) use of type() useful exactly >> for this "bag of attributes" use case: >>>>> employee = type("Employee", (object,), {}) >>>>> employee.name = "John Doe" >>>>> employee.position = "Python programmer" >>>>> employee.name, employee.position, employee >> ('John Doe', 'Python programmer', '__main__.Employee'>) > > Are you sure you know what you are doing? The above is equivalent to > >>>> class employee: > ...? ? name = "John Doe" > ...? ? position = "Python programmer" > ... >>>> employee.name, employee.position, employee > ('John Doe', 'Python programmer', '__main__.employee'>) >>>> type(employee) > > > Basically you are using classes as instances. While there is no fundamental > difference between classes and instances in Python you'll surprise readers > of your code and waste some space: Yes, I know that it is equivalent, but I have always found it kind of ugly to use class() just to bundle a number of items. Like you are 'announcing OOP' (not sure how to put this into words), and then it's merely a simple bundle. Or maybe it's just me being silly, because it's even in the Python tutorial: https://docs.python.org/2/tutorial/classes.html#odds-and-ends ? >>>> import sys >>>> sys.getsizeof(employee) > 976 >>>> class Employee: pass > ... >>>> employee = Employee() >>>> employee.name = "John Doe" >>>> employee.position = "Python programmer" >>>> sys.getsizeof(employee) > 64 Wow, I was not aware of that at all. So they are not equivalent after all. From dufriz at gmail.com Sun Aug 3 07:05:01 2014 From: dufriz at gmail.com (dufriz at gmail.com) Date: Sun, 3 Aug 2014 04:05:01 -0700 (PDT) Subject: How to turn off Python's event log window in the background? Message-ID: <6361ee6c-49c0-4b4d-b044-4a29f035b71d@googlegroups.com> Hi, whenever I run the Leo editor (a Python application) from Windows (8.1), there is always an event log window in the background. I want to turn it off. It was suggested to me on another forum that I use pythonw.exe instead of python.exe to prevent the window from being displayed, but I don't know how to do this, because it is all automatic: I just click on the .py file, and the python interpreter is automatically loaded. Could someone please tell me how to disable the event log window? Thanks From fomcl at yahoo.com Sun Aug 3 07:14:12 2014 From: fomcl at yahoo.com (Albert-Jan Roskam) Date: Sun, 3 Aug 2014 04:14:12 -0700 Subject: Correct type for a simple "bag of attributes" namespace object In-Reply-To: <1407057464.64980.YahooMailNeo@web163806.mail.gq1.yahoo.com> References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> <70e5f2f1-661f-40f2-bb7a-76e569c4d092@googlegroups.com> <1407057464.64980.YahooMailNeo@web163806.mail.gq1.yahoo.com> Message-ID: <1407064452.80279.YahooMailNeo@web163804.mail.gq1.yahoo.com> ----- Original Message ----- > From: Albert-Jan Roskam > To: Terry Reedy ; "python-list at python.org" > Cc: > Sent: Sunday, August 3, 2014 11:17 AM > Subject: Re: Correct type for a simple "bag of attributes" namespace object >>>>> ? Right. The 'types' module provides a SimpleNamespace > class >> for the >>>>> ? common "bag of attributes" use case:: >>>>> >>>>> ? ? ? >>> import types >>>>> ? ? ? >>> foo = types.SimpleNamespace() >>>>> ? ? ? >>> foo.x = 3 >>>>> ? ? ? >>> foo >>>>> ? ? ? namespace(x=3) >>>> >>>> ? This is too much for children (& beginners). >>>> >>>> ? But perhaps what I should be asking for is for a new built-in that > does >> what types.SimpleNamespace() does, so that without any import you can > write, >> say, >>>> >>>> ? foo = namespace(a=1, b=2) >>>> ? # or >>>> ? bar = namespace() >>>> ? bar.a = 1 > > I find the following obscure (to me at least) use of type() useful exactly for > this "bag of attributes" use case: >>>> employee = type("Employee", (object,), {}) >>>> employee.name = "John Doe" >>>> employee.position = "Python programmer" >>>> employee.name, employee.position, employee > ('John Doe', 'Python programmer', '__main__.Employee'>) > >>>> details = dict(name="John Doe", position="Python > programmer") >>>> employee = type("Employee", (object,), details) >>>> employee.name, employee.position, employee > ('John Doe', 'Python programmer', '__main__.Employee'>) PS to my previous mail: class() can (should?) be used here to do the exact same thing but it feels a little like "Getting your car [OOP] just because you need an ashtray [bundled items]". :-) From __peter__ at web.de Sun Aug 3 07:23:42 2014 From: __peter__ at web.de (Peter Otten) Date: Sun, 03 Aug 2014 13:23:42 +0200 Subject: Correct type for a simple "bag of attributes" namespace object References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> <70e5f2f1-661f-40f2-bb7a-76e569c4d092@googlegroups.com> <1407057464.64980.YahooMailNeo@web163806.mail.gq1.yahoo.com> <1407063072.46317.YahooMailNeo@web163803.mail.gq1.yahoo.com> Message-ID: Albert-Jan Roskam wrote: > > > ----- Original Message ----- > >> From: Peter Otten <__peter__ at web.de> >> To: python-list at python.org >> Cc: >> Sent: Sunday, August 3, 2014 11:37 AM >> Subject: Re: Correct type for a simple "bag of attributes" namespace >> object >> >> Albert-Jan Roskam wrote: >> >>> I find the following obscure (to me at least) use of type() useful >>> exactly for this "bag of attributes" use case: >>>>>> employee = type("Employee", (object,), {}) >>>>>> employee.name = "John Doe" >>>>>> employee.position = "Python programmer" >>>>>> employee.name, employee.position, employee >>> ('John Doe', 'Python programmer', > '__main__.Employee'>) >> >> Are you sure you know what you are doing? The above is equivalent to >> >>>>> class employee: >> ... name = "John Doe" >> ... position = "Python programmer" >> ... >>>>> employee.name, employee.position, employee >> ('John Doe', 'Python programmer', > '__main__.employee'>) >>>>> type(employee) >> >> >> Basically you are using classes as instances. While there is no >> fundamental difference between classes and instances in Python you'll >> surprise readers of your code and waste some space: > > Yes, I know that it is equivalent, but I have always found it kind of ugly > to use class() just to bundle a number of items. But that's what you are doing, you just spell it differently. > Like you are 'announcing > OOP' (not sure how to put this into words), and then it's merely a simple > bundle. Or maybe it's just me being silly, because it's even in the Python > tutorial: https://docs.python.org/2/tutorial/classes.html#odds-and-ends > >>>>> import sys >>>>> sys.getsizeof(employee) >> 976 >>>>> class Employee: pass >> ... >>>>> employee = Employee() >>>>> employee.name = "John Doe" >>>>> employee.position = "Python programmer" >>>>> sys.getsizeof(employee) >> 64 > Wow, I was not aware of that at all. So they are not equivalent after all. I think you are misunderstanding what I was trying to say; so to be explicit: >>> class Employee: pass ... >>> sys.getsizeof(Employee) 976 i. e. you have a per-class and per-instance memory consumption. The latter is smaller, so with regards to memory consumption instantiating only pays off when there is more than one employee. From rosuav at gmail.com Sun Aug 3 07:34:54 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Aug 2014 21:34:54 +1000 Subject: How to turn off Python's event log window in the background? In-Reply-To: <6361ee6c-49c0-4b4d-b044-4a29f035b71d@googlegroups.com> References: <6361ee6c-49c0-4b4d-b044-4a29f035b71d@googlegroups.com> Message-ID: On Sun, Aug 3, 2014 at 9:05 PM, wrote: > It was suggested to me on another forum that I use pythonw.exe instead of python.exe to prevent the window from being displayed, but I don't know how to do this, because it is all automatic: I just click on the .py file, and the python interpreter is automatically loaded. > Assuming you have your installation set up in the normal way, renaming your .py file to .pyw will have it run with pythonw.exe instead of python.exe. That should do what you want. Have fun! ChrisA From breamoreboy at yahoo.co.uk Sun Aug 3 08:28:58 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 03 Aug 2014 13:28:58 +0100 Subject: Correct type for a simple =?UTF-8?B?4oCcYmFnIG9mIGF0dHJpYnV0?= =?UTF-8?B?ZXPigJ0gbmFtZXNwYWNlIG9iamVjdA==?= In-Reply-To: <857g2qd5oc.fsf_-_@benfinney.id.au> References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> <857g2qd5oc.fsf_-_@benfinney.id.au> Message-ID: On 02/08/2014 20:58, Ben Finney wrote: > Steven D'Aprano writes: > >> If you need instances which carry state, then object is the wrong >> class. > > Right. The ?types? module provides a SimpleNamespace class for the > common ?bag of attributes? use case:: > > >>> import types > >>> foo = types.SimpleNamespace() > >>> foo.x = 3 > >>> foo > namespace(x=3) > > > What Alex Martelli called a bunch? http://code.activestate.com/recipes/52308-the-simple-but-handy-collector-of-a-bunch-of-named/ -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From roy at panix.com Sun Aug 3 08:40:48 2014 From: roy at panix.com (Roy Smith) Date: Sun, 03 Aug 2014 08:40:48 -0400 Subject: Correct type for a simple “bag of attributes” namespace object References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> <857g2qd5oc.fsf_-_@benfinney.id.au> Message-ID: In article , Mark Lawrence wrote: > On 02/08/2014 20:58, Ben Finney wrote: > > Steven D'Aprano writes: > > > >> If you need instances which carry state, then object is the wrong > >> class. > > > > Right. The ???types??? module provides a SimpleNamespace class for the > > common ???bag of attributes??? use case:: > > > > >>> import types > > >>> foo = types.SimpleNamespace() > > >>> foo.x = 3 > > >>> foo > > namespace(x=3) > > > > > > > > What Alex Martelli called a bunch? > > http://code.activestate.com/recipes/52308-the-simple-but-handy-collector-of-a- > bunch-of-named/ Still overkill :-) I usually just do: class Data: pass my_obj = Data() That's all you really need. It's annoying that you can't just do: my_obj = object() which would be even simpler, because (for reasons I don't understand), you can't create new attributes on my_obj. From rosuav at gmail.com Sun Aug 3 08:56:37 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Aug 2014 22:56:37 +1000 Subject: =?UTF-8?Q?Re=3A_Correct_type_for_a_simple_=E2=80=9Cbag_of_attributes?= =?UTF-8?Q?=E2=80=9D_namespace_object?= In-Reply-To: References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> <857g2qd5oc.fsf_-_@benfinney.id.au> Message-ID: On Sun, Aug 3, 2014 at 10:40 PM, Roy Smith wrote: > I usually just do: > > class Data: > pass > my_obj = Data() > > That's all you really need. It's annoying that you can't just do: > > my_obj = object() > > which would be even simpler, because (for reasons I don't understand), > you can't create new attributes on my_obj. Python 3.4 on Windows (32-bit): >>> import sys >>> class Data: pass >>> sys.getsizeof(Data()) 32 >>> sys.getsizeof(object()) 8 Even before you add a single attribute, the object is four times the size it needs to be. When you need a sentinel (for a function's default argument, for instance), you don't need any attributes on it - all you need is some object whose identity can be tested. And the excess would be multiplied by a fairly large number of objects in the system (it's not just object() that doesn't take attributes). If you want a bag of attributes, get a bag of attributes, don't expect object() to be it :) The only reason I can think of for expecting a basic object to work this way is because of the parallel with ECMAScript; it's not a fundamental part of the type hierarchy. ChrisA From roy at panix.com Sun Aug 3 09:25:53 2014 From: roy at panix.com (Roy Smith) Date: Sun, 03 Aug 2014 09:25:53 -0400 Subject: Correct type for a simple “bag of attributes” namespace object References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> <857g2qd5oc.fsf_-_@benfinney.id.au> Message-ID: In article , Chris Angelico wrote: > On Sun, Aug 3, 2014 at 10:40 PM, Roy Smith wrote: > > I usually just do: > > > > class Data: > > pass > > my_obj = Data() > > > > That's all you really need. It's annoying that you can't just do: > > > > my_obj = object() > > > > which would be even simpler, because (for reasons I don't understand), > > you can't create new attributes on my_obj. > > [...] > The only reason I can think of for expecting a > basic object to work this way is because of the parallel with > ECMAScript; it's not a fundamental part of the type hierarchy. I don't know about that. I agree that your explanation about object size makes sense for why it wasn't built to work that way, but I don't think the expectation should be surprising. When I write: class Foo(Bar): # stuff I'm saying, "make Foos be just like Bars, except for this stuff". I can do: >>> class Foo(object): ... pass ... >>> f = Foo() >>> f.x = 1 in which case, I've said, "make Foos just like objects, except for, oh, never mind, there aren't any differences". But, in reality, the system bolted on the ability to have user-defined attributes without telling me. I don't think it's unreasonable to be surprised at that. From rosuav at gmail.com Sun Aug 3 09:35:18 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Aug 2014 23:35:18 +1000 Subject: =?UTF-8?Q?Re=3A_Correct_type_for_a_simple_=E2=80=9Cbag_of_attributes?= =?UTF-8?Q?=E2=80=9D_namespace_object?= In-Reply-To: References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> <857g2qd5oc.fsf_-_@benfinney.id.au> Message-ID: On Sun, Aug 3, 2014 at 11:25 PM, Roy Smith wrote: > in which case, I've said, "make Foos just like objects, except for, oh, > never mind, there aren't any differences". But, in reality, the system > bolted on the ability to have user-defined attributes without telling > me. I don't think it's unreasonable to be surprised at that. I agree that this is slightly surprising. However, imagine if it were the other way: class Foo(object): x = 1 def __init__(self): self.y = 2 These would throw errors, unless you explicitly disable __slots__ processing. When there's two ways to do things and both would be surprising, you pick the one that's going to be less of a surprise, or surprising less often, and accept it. That doesn't mean it's not a problem, but it's better than the alternative. ChrisA From breamoreboy at yahoo.co.uk Sun Aug 3 09:38:53 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 03 Aug 2014 14:38:53 +0100 Subject: Getting a list of all modules In-Reply-To: <53dbb534$0$29986$c3e8da3$5496439d@news.astraweb.com> References: <53d8a20e$0$29977$c3e8da3$5496439d@news.astraweb.com> <53da1d5a$0$29974$c3e8da3$5496439d@news.astraweb.com> <53dbb534$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 01/08/2014 16:41, Steven D'Aprano wrote: > On Fri, 01 Aug 2014 14:39:09 +0100, Robert Kern wrote: > >> Take a look at what has already been implemented in IPython: >> >> https://github.com/ipython/ipython/blob/master/IPython/core/ > completerlib.py#L208 > > Awesome! Thank you! > Is Lib/idlelib/AutoComplete.py of any use? I found it when looking at this http://bugs.python.org/issue18766 -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From khamenya at gmail.com Sun Aug 3 10:01:41 2014 From: khamenya at gmail.com (Valery Khamenya) Date: Sun, 3 Aug 2014 16:01:41 +0200 Subject: asyncio with map&reduce flavor and without flooding the event loop Message-ID: Hi all I am trying to use asyncio in real applications and it doesn't go that easy, a help of asyncio gurus is needed badly. Consider a task like crawling the web starting from some web-sites. Each site leads to generation of new downloading tasks in exponential(!) progression. However we don't want neither to flood the event loop nor to overload our network. We'd like to control the task flow. This is what I achieve well with modification of nice Maxime's solution proposed here: https://mail.python.org/pipermail/python-list/2014-July/675048.html Well, but I'd need as well a very natural thing, kind of map() & reduce() or functools.reduce() if we are on python3 already. That is, I'd need to call a "summarizing" function for all the downloading tasks completed on links from a page. This is where i fail :( I'd propose an oversimplified but still a nice test to model the use case: Let's use fibonacci function implementation in its ineffective form. That is, let the coro_sum() be our reduce() function and coro_fib be our map(). Something like this: @asyncio.coroutine def coro_sum(x): return sum(x) @asyncio.coroutine def coro_fib(x): if x < 2: return 1 res_coro = executor_pool.spawn_task_when_arg_list_of_coros_ready(coro=coro_sum, arg_coro_list=[coro_fib(x - 1), coro_fib(x - 2)]) return res_coro So that we could run the following tests. Test #1 on one worker: executor_pool = ExecutorPool(workers=1) executor_pool.as_completed( coro_fib(x) for x in range(20) ) Test #2 on two workers: executor_pool = ExecutorPool(workers=2) executor_pool.as_completed( coro_fib(x) for x in range(20) ) It would be very important that both each coro_fib() and coro_sum() invocations are done via a Task on some worker, not just spawned implicitly and unmanaged! It would be cool to find asyncio gurus interested in this very natural goal. Your help and ideas would be very much appreciated. best regards -- Valery -------------- next part -------------- An HTML attachment was scrubbed... URL: From 4kir4.1i at gmail.com Sun Aug 3 10:22:09 2014 From: 4kir4.1i at gmail.com (Akira Li) Date: Sun, 03 Aug 2014 18:22:09 +0400 Subject: Correct type for a simple "bag of attributes" namespace object References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> <70e5f2f1-661f-40f2-bb7a-76e569c4d092@googlegroups.com> <1407057464.64980.YahooMailNeo@web163806.mail.gq1.yahoo.com> Message-ID: <87bns1ejqm.fsf@gmail.com> Albert-Jan Roskam writes: > I find the following obscure (to me at least) use of type() useful > exactly for this "bag of attributes" use case: >>>> employee = type("Employee", (object,), {}) >>>> employee.name = "John Doe" >>>> employee.position = "Python programmer" You could write it as: class Employee: name = "Johh Doe" position = "Python programmer" It also makes it clear that `type()` returns a *class Employee*, not its instance (Employee()) and therefore name, position are class attributes. -- Akira From badouglas at gmail.com Sun Aug 3 10:29:23 2014 From: badouglas at gmail.com (bruce) Date: Sun, 3 Aug 2014 10:29:23 -0400 Subject: try/exception - error block Message-ID: Hi. I have a long running process, it generates calls to a separate py app. The py app appears to generate errors, as indicated in the /var/log/messages file for the abrtd daemon.. The errors are intermittent. So, to quickly capture all possible exceptions/errors, I decided to wrap the entire "main" block of the test py func in a try/exception block. This didn't work, as I'm not getting any output in the err file generated in the exception block. I'm posting the test code I'm using. Pointers/comments would be helpful/useful. //////////////////// the if that gets run is the fac1 logic which operates on the input packet/data.. elif (level=='collegeFaculty1'): #getClasses(url, college, termVal,termName,deptName,deptAbbrv) ret=getParseCollegeFacultyList1(url,content) //////////////////// Thanks. if __name__ == "__main__": # main app try: #college="asu" #url="https://webapp4.asu.edu/catalog" #termurl="https://webapp4.asu.edu/catalog/TooltipTerms.ext" #termVal=2141 # # get the input struct, parse it, determine the level # #cmd='cat /apps/parseapp2/asuclass1.dat' #print "cmd= "+cmd #proc=subprocess.Popen(cmd, shell=True,stdout=subprocess.PIPE) #content=proc.communicate()[0].strip() #print content #sys.exit() #s=getClasses(content) #print "arg1 =",sys.argv[0] if(len(sys.argv)<2): print "error\n" sys.exit() a=sys.argv[1] aaa=a # # data is coming from the parentApp.php # data has been rawurlencode(json_encode(t)) # -reverse/split the data.. # -do the fetch, # -save the fetched page/content if any # -create the returned struct # -echo/print/return the struct to the # calling parent/call # ##print urllib.unquote_plus(a).decode('utf8') #print "\n" #print simplejson.loads(urllib.unquote_plus(a)) z=simplejson.loads(urllib.unquote_plus(a)) ##z=simplejson.loads(urllib.unquote(a).decode('utf8')) #z=simplejson.loads(urllib2.unquote(a).decode('utf8')) #print "aa \n" print z #print "\n bb \n" # #-passed in # url=str(z['currentURL']) level=str(z['level']) cname=str(z['parseContentFileName']) # # need to check the contentFname # -should have been checked in the parentApp # -check it anyway, return err if required # -if valid, get/import the content into # the "content" var for the function/parsing # ##cmd='echo ${yolo_clientFetchOutputDir}/' cmd='echo ${yolo_clientParseInputDir}/' #print "cmd= "+cmd proc=subprocess.Popen(cmd, shell=True,stdout=subprocess.PIPE) cpath=proc.communicate()[0].strip() cname=cpath+cname #print "cn = "+cname+"\n" #sys.exit() cmd='test -e '+cname+' && echo 1' #print "cmd= "+cmd proc=subprocess.Popen(cmd, shell=True,stdout=subprocess.PIPE) c1=proc.communicate()[0].strip() if(not c1): #got an error - process it, return print "error in parse" # # we're here, no err.. got content # #fff= "sdsu2.dat" with open(cname,"r") as myfile: content=myfile.read() myfile.close() #-passed in #college="louisville" #url="http://htmlaccess.louisville.edu/classSchedule/" #termVal="4138" #print "term = "+str(termVal)+"\n" #print "url = "+url+"\n" #jtest() #sys.exit() #getTerm(url,college,termVal) ret={} # null it out to start if (level=='rState'): #ret=getTerm(content,termVal) ret=getParseStates(content) elif (level=='stateCollegeList'): #getDepts(url,college, termValue,termName) ret=getParseStateCollegeList(url,content) elif (level=='collegeFaculty1'): #getClasses(url, college, termVal,termName,deptName,deptAbbrv) ret=getParseCollegeFacultyList1(url,content) elif (level=='collegeFaculty2'): #getClasses(url, college, termVal,termName,deptName,deptAbbrv) ret=getParseCollegeFacultyList2(content) # # the idea of this section.. we have the resulting # fetched content/page... # a={} status=False if(ret['status']==True): s=ascii_strip(ret['data']) if(((s.find("-1) or (s.find("-1)) and ((s.find("-1) or (s.find("-1)) and level=='classSectionDay'): status=True #print "herh" #sys.exit() # # build the returned struct # # a['Status']=True a['recCount']=ret['count'] a['data']=ret['data'] a['nextLevel']='' a['timestamp']='' a['macAddress']='' elif(ret['status']==False): a['Status']=False a['recCount']=0 a['data']='' a['nextLevel']='' a['timestamp']='' a['macAddress']='' res=urllib.quote(simplejson.dumps(a)) ##print res name=subprocess.Popen('uuidgen -t', shell=True,stdout=subprocess.PIPE) name=name.communicate()[0].strip() name=name.replace("-","_") ## if status==True: name2=tmpParseDir+"/rr_"+name+".dat" ofile1=open(name2,"w+") ofile1.write(res) ofile1.close() print name2 if status==False: sname=tmpParseDir+"/serr_"+name+".dat" ofile1=open(sname,"w+") ofile1.write(aaa) ofile1.close() sys.exit() print "term = "+str(termVal)+"\n" print "url = "+url+"\n" getTerm(url,college,termVal) print "exit" sys.exit() except Exception, e: print e print "pycolFac1 - error!! \n"; name=subprocess.Popen('uuidgen -t', shell=True,stdout=subprocess.PIPE) name=name.communicate()[0].strip() name=name.replace("-","_") name2="/home/ihubuser/parseErrTest/pp_"+name+".dat" ofile1=open(name2,"w+") ofile1.write(e) ofile1.write(aaa) ofile1.close() sys.exit() From roy at panix.com Sun Aug 3 10:36:23 2014 From: roy at panix.com (Roy Smith) Date: Sun, 03 Aug 2014 10:36:23 -0400 Subject: Correct type for a simple “bag of attributes” namespace object References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> <857g2qd5oc.fsf_-_@benfinney.id.au> Message-ID: In article , Chris Angelico wrote: > On Sun, Aug 3, 2014 at 11:25 PM, Roy Smith wrote: > > in which case, I've said, "make Foos just like objects, except for, oh, > > never mind, there aren't any differences". But, in reality, the system > > bolted on the ability to have user-defined attributes without telling > > me. I don't think it's unreasonable to be surprised at that. > > I agree that this is slightly surprising. However, imagine if it were > the other way: > > class Foo(object): > x = 1 > def __init__(self): self.y = 2 > > These would throw errors, unless you explicitly disable __slots__ > processing. When there's two ways to do things and both would be > surprising, you pick the one that's going to be less of a surprise, or > surprising less often, and accept it. That doesn't mean it's not a > problem, but it's better than the alternative. > > ChrisA I'm not following you at all. What does "the other way" mean, and how would that cause the above to generate errors, and what does this have to do with __slots__? From roy at panix.com Sun Aug 3 10:39:19 2014 From: roy at panix.com (Roy Smith) Date: Sun, 03 Aug 2014 10:39:19 -0400 Subject: try/exception - error block References: Message-ID: In article , bruce wrote: > I'm posting the test code I'm using. Pointers/comments would be > helpful/useful. It would be really helpful if you could post a minimal code example which demonstrates the problem you're having. Leave out everything (including the commented-out code) which isn't necessary to demonstrate the behavior. From marko at pacujo.net Sun Aug 3 10:51:10 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 03 Aug 2014 17:51:10 +0300 Subject: Correct type for a simple "bag of attributes" namespace object References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> <70e5f2f1-661f-40f2-bb7a-76e569c4d092@googlegroups.com> <1407057464.64980.YahooMailNeo@web163806.mail.gq1.yahoo.com> <1407063072.46317.YahooMailNeo@web163803.mail.gq1.yahoo.com> Message-ID: <87wqaplj8h.fsf@elektro.pacujo.net> Peter Otten <__peter__ at web.de>: > i. e. you have a per-class and per-instance memory consumption. The > latter is smaller, so with regards to memory consumption instantiating > only pays off when there is more than one employee. I've reached a point where I think classes are a superfluous OO concept. You only need objects. Python is close to that reality. The "class" keyword really creates a function that creates objects, and the objects' class membership is ignored in ducktyping. Classes may or may not save RAM, but that is rather a low-brow point of view toward OO. Marko From breamoreboy at yahoo.co.uk Sun Aug 3 10:55:59 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 03 Aug 2014 15:55:59 +0100 Subject: try/exception - error block In-Reply-To: References: Message-ID: On 03/08/2014 15:39, Roy Smith wrote: > In article , > bruce wrote: > >> I'm posting the test code I'm using. Pointers/comments would be >> helpful/useful. > > It would be really helpful if you could post a minimal code example > which demonstrates the problem you're having. Leave out everything > (including the commented-out code) which isn't necessary to demonstrate > the behavior. > How to go about this is at "Short, Self Contained, Correct (Compilable), Example" at http://sscce.org/ -- 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 Aug 3 11:00:35 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 4 Aug 2014 01:00:35 +1000 Subject: =?UTF-8?Q?Re=3A_Correct_type_for_a_simple_=E2=80=9Cbag_of_attributes?= =?UTF-8?Q?=E2=80=9D_namespace_object?= In-Reply-To: References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> <857g2qd5oc.fsf_-_@benfinney.id.au> Message-ID: On Mon, Aug 4, 2014 at 12:36 AM, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> On Sun, Aug 3, 2014 at 11:25 PM, Roy Smith wrote: >> > in which case, I've said, "make Foos just like objects, except for, oh, >> > never mind, there aren't any differences". But, in reality, the system >> > bolted on the ability to have user-defined attributes without telling >> > me. I don't think it's unreasonable to be surprised at that. >> >> I agree that this is slightly surprising. However, imagine if it were >> the other way: >> >> class Foo(object): >> x = 1 >> def __init__(self): self.y = 2 >> >> These would throw errors, unless you explicitly disable __slots__ >> processing. When there's two ways to do things and both would be >> surprising, you pick the one that's going to be less of a surprise, or >> surprising less often, and accept it. That doesn't mean it's not a >> problem, but it's better than the alternative. >> >> ChrisA > > I'm not following you at all. What does "the other way" mean, and how > would that cause the above to generate errors, and what does this have > to do with __slots__? Fact #1: Some classes, like object, don't have a dictionary for arbitrary attributes. (I'll call this __slots__ mode, although it's not technically __slots__when it's a C-implemented class.) Fact #2: You can subclass such objects. There are two ways that this subclassing could be done. Either it maintains __slots__ mode, which means you can see every change (and going "class Foo(Bar): pass" will make an exact subclass of Bar with identical behaviour), or it drops __slots__ and adds a dictionary unless you explicitly reenable __slots__. >>> class Base(object): __slots__ = ('a', 'b', 'c') >>> class Deriv(Base): pass >>> Base().d = 1 Traceback (most recent call last): File "", line 1, in Base().d = 1 AttributeError: 'Base' object has no attribute 'd' >>> Deriv().d = 1 Python opted to go with the second behaviour: the subclass is not bound to the superclass's __slots__, but gets a dictionary unless it itself specifies __slots__ (in which case it gets all of them, parent's included): >>> class SlottedDeriv(Base): __slots__ = ('d', 'e', 'f') >>> SlottedDeriv().a = 1 >>> SlottedDeriv().d = 1 >>> SlottedDeriv().g = 1 Traceback (most recent call last): File "", line 1, in SlottedDeriv().g = 1 AttributeError: 'SlottedDeriv' object has no attribute 'g' The alternative would be for __slots__ to normally copy down, and to have to be explicitly removed - for "pass" to be actually equivalent to this: >>> class Deriv(Base): __slots__ = Base.__slots__ >>> Deriv().d = 1 Traceback (most recent call last): File "", line 1, in Deriv().d = 1 AttributeError: 'Deriv' object has no attribute 'd' and for some other syntax to do what "pass" currently does. That has the benefit of purity (it's easy to describe what happens, there's no magic going on), but at the expense of practicality (you'd have to explicitly de-slottify your classes before you can add functionality to them). And we know what the Zen of Python says about which of those takes priority. ChrisA From roy at panix.com Sun Aug 3 11:09:47 2014 From: roy at panix.com (Roy Smith) Date: Sun, 03 Aug 2014 11:09:47 -0400 Subject: Correct type for a simple "bag of attributes" namespace object References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> <70e5f2f1-661f-40f2-bb7a-76e569c4d092@googlegroups.com> <1407057464.64980.YahooMailNeo@web163806.mail.gq1.yahoo.com> <1407063072.46317.YahooMailNeo@web163803.mail.gq1.yahoo.com> <87wqaplj8h.fsf@elektro.pacujo.net> Message-ID: In article <87wqaplj8h.fsf at elektro.pacujo.net>, Marko Rauhamaa wrote: > I've reached a point where I think classes are a superfluous OO concept. > You only need objects. comp.lang.javascript is over that way --> From alexandrucalin29 at gmail.com Sun Aug 3 11:13:45 2014 From: alexandrucalin29 at gmail.com (Alexander Williams) Date: Sun, 3 Aug 2014 08:13:45 -0700 (PDT) Subject: M2Crypto - Extract detached PKCS7 signature from PKCS7 (signature&data) Message-ID: I want to break a PKCS7 signature that contains data + signature into separate: raw data & detached PKCS7 signature in python. I can get the data fro the signature because the verification routine returns it, but how can I get the detached signature ? def verify_pkcs7(data_bio, signature_bio, cacert_bio, format=X509.FORMAT_PEM): sm_obj = SMIME.SMIME() st = X509.X509_Store() st.add_cert(X509.load_cert_string(cacert_bio)) sm_obj.set_x509_store(st) if format == X509.FORMAT_PEM: p7 = SMIME.load_pkcs7_bio(signature_bio) else: p7 = SMIME.PKCS7(m2.pkcs7_read_bio_der(signature_bio._ptr()), 1) sk = p7.get0_signers(X509.X509_Stack()) sm_obj.set_x509_stack(sk) try: v = sm_obj.verify(p7, data_bio) if v: print "Client signature verified." with open('file.rar', 'wb') as ff: ff.write(v) except Exception as e: print str(e) print "*** INVALID CLIENT MESSAGE SIGNATURE ***" My wild guess is that it one of these functions.. I base my assumption on the fact that M2Crypto is a wrapper over OpenSSL. From marko at pacujo.net Sun Aug 3 11:52:36 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 03 Aug 2014 18:52:36 +0300 Subject: Correct type for a simple "bag of attributes" namespace object References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> <70e5f2f1-661f-40f2-bb7a-76e569c4d092@googlegroups.com> <1407057464.64980.YahooMailNeo@web163806.mail.gq1.yahoo.com> <1407063072.46317.YahooMailNeo@web163803.mail.gq1.yahoo.com> <87wqaplj8h.fsf@elektro.pacujo.net> Message-ID: <87egwxlge3.fsf@elektro.pacujo.net> Roy Smith : > Marko Rauhamaa wrote: > >> I've reached a point where I think classes are a superfluous OO >> concept. You only need objects. > > comp.lang.javascript is over that way --> Thanks for the insight. I'm currently more absorbed by comp.lang.scheme, though. Now, Python is ducktyped. It is (rightly) considered bad taste to consult the datatype (class) of an object. Compare these two definitions: class Point: def __init__(self, x, y): self.x = x self.y = y def x(self): return self.x def y(self): return self.y and: class Object: pass def Point(x, y): self = Object() self.__dict__ = dict(x=lambda: x, y=lambda: y) return self For all practical purposes, the two definitions are identical even though the latter doesn't specify any class. Inheritance needs to be addressed, but that can be taken care of without classes as well. Obviously, Python's syntax makes it convenient to deal with classes, and there's no practical downside to it. However, conceptually, classes are unnecessary baggage and at odds with ducktyping. Marko From breamoreboy at yahoo.co.uk Sun Aug 3 12:20:20 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 03 Aug 2014 17:20:20 +0100 Subject: try/exception - error block In-Reply-To: References: Message-ID: On 03/08/2014 15:29, bruce wrote: [snipped to bits] Please see this http://sscce.org/ as already requested on the main mailing list. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From roy at panix.com Sun Aug 3 12:27:02 2014 From: roy at panix.com (Roy Smith) Date: Sun, 03 Aug 2014 12:27:02 -0400 Subject: try/exception - error block References: Message-ID: In article , Mark Lawrence wrote: > How to go about this is at "Short, Self Contained, Correct (Compilable), > Example" at http://sscce.org/ It says there, "most readers will stop reading by 100 lines of code". I guess I have a short attention span relative to "most readers", because my tl;dnr threshold is a lot shorter than that. The other advantage to coming up with a minimal example is that often the exercise of cutting your problem down to a minimal example is enough to allow you to figure it out for yourself :-) From rosuav at gmail.com Sun Aug 3 12:42:05 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 4 Aug 2014 02:42:05 +1000 Subject: try/exception - error block In-Reply-To: References: Message-ID: On Mon, Aug 4, 2014 at 2:27 AM, Roy Smith wrote: > It says there, "most readers will stop reading by 100 lines of code". I > guess I have a short attention span relative to "most readers", because > my tl;dnr threshold is a lot shorter than that. "by" 100 lines includes everyone who stops at 10 lines, 40 lines, or 80 lines, too. What it means is that if you post >100 lines of code, you've lost most of your audience. ChrisA From tomcsanyi at slovanet.sk Sun Aug 3 13:24:13 2014 From: tomcsanyi at slovanet.sk (Peter Tomcsanyi) Date: Sun, 3 Aug 2014 19:24:13 +0200 Subject: Tcl/Tk alpha channel bug on OSX Mavericks is fixeded, but how/when can I use the fix? Message-ID: Hello to all, My OSX is 10.9 Mavericks. I use Python 3.4. with ActiveTcl 8.5.15.1. I was struggling with several approaches to using PNG files with alpha channel (partial transparency). Following my question in this newsgroup (see the thread "Python 3.4.1 installer on Mac links Python to old Tcl/Tk" and all the kind suggestions what to do), I have tried several things: - Used the package Img with Tk 8.5 - Used PIL to load the file and then converting it by ImageTk.PhotoImage. - Installed MacPorts' version of Python 3.4 with Tk 8.6 But none of the approaches were able to show corretly my partially transparent image - the image was loaded and shown but the alpha channel was reduced to binary transparency. I think that it is because of this problem in Mavericks: http://core.tcl.tk/tk/tktview?name=99b84e49ff The above link says that it has been solved in Tcl/Tk. But: what does it mean for me - a Python user? Can anyone say when a version containing the above bug fix will be available in a form of an installable package that I can use with Python on a Mac? How can I know that such a package is avaibale? Or can anyone point me to some instructions how could I compile Tcl/Tk for myslef and (more importanty) how to install the result of that compilation so that Python 3.4 recognizes that it should use that package (and not three other installations of Tcl/Tk in my computer)? Thanks, Peter From breamoreboy at yahoo.co.uk Sun Aug 3 13:38:04 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 03 Aug 2014 18:38:04 +0100 Subject: Correct type for a simple =?UTF-8?B?4oCcYmFnIG9mIGF0dHJpYnV0?= =?UTF-8?B?ZXPigJ0gbmFtZXNwYWNlIG9iamVjdA==?= In-Reply-To: <857g2qd5oc.fsf_-_@benfinney.id.au> References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> <857g2qd5oc.fsf_-_@benfinney.id.au> Message-ID: On 02/08/2014 20:58, Ben Finney wrote: > Steven D'Aprano writes: > >> If you need instances which carry state, then object is the wrong >> class. > > Right. The ?types? module provides a SimpleNamespace class for the > common ?bag of attributes? use case:: > > >>> import types > >>> foo = types.SimpleNamespace() > >>> foo.x = 3 > >>> foo > namespace(x=3) > > > A slight aside but from the link "SimpleNamespace may be useful as a replacement for class NS: pass." I'm not quite sure how that class definition is meant to read, other than guessing that NS stands for NameSpace, any ideas? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From roy at panix.com Sun Aug 3 13:44:14 2014 From: roy at panix.com (Roy Smith) Date: Sun, 03 Aug 2014 13:44:14 -0400 Subject: Correct type for a simple “bag of attributes” namespace object References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> <857g2qd5oc.fsf_-_@benfinney.id.au> Message-ID: In article , Mark Lawrence wrote: > On 02/08/2014 20:58, Ben Finney wrote: > > Steven D'Aprano writes: > > > >> If you need instances which carry state, then object is the wrong > >> class. > > > > Right. The ???types??? module provides a SimpleNamespace class for the > > common ???bag of attributes??? use case:: > > > > >>> import types > > >>> foo = types.SimpleNamespace() > > >>> foo.x = 3 > > >>> foo > > namespace(x=3) > > > > > > > > A slight aside but from the link "SimpleNamespace may be useful as a > replacement for class NS: pass." I'm not quite sure how that class > definition is meant to read, other than guessing that NS stands for > NameSpace, any ideas? Trivia: argparse.ArgumentParser().parse_args() returns a Namespace. From badouglas at gmail.com Sun Aug 3 13:52:13 2014 From: badouglas at gmail.com (bruce) Date: Sun, 3 Aug 2014 13:52:13 -0400 Subject: try/exception - error block In-Reply-To: References: Message-ID: chris.. my bad.. I wasnt intending to mail you personally. Or I wouldn't have inserted the "thanks guys"! > thanks guys... > > but in all that.. no one could tell me .. why i'm not getting any > errs/exceptions in the err file which gets created on the exception!!! > > but thanks for the information on posting test code! Don't email me privately - respond to the list :) Also, please don't top-post. ChrisA On Sun, Aug 3, 2014 at 10:29 AM, bruce wrote: > Hi. > > I have a long running process, it generates calls to a separate py > app. The py app appears to generate errors, as indicated in the > /var/log/messages file for the abrtd daemon.. The errors are > intermittent. > > So, to quickly capture all possible exceptions/errors, I decided to > wrap the entire "main" block of the test py func in a try/exception > block. > > This didn't work, as I'm not getting any output in the err file > generated in the exception block. > > I'm posting the test code I'm using. Pointers/comments would be helpful/useful. > > //////////////////// > the if that gets run is the fac1 logic which operates on the input > packet/data.. > elif (level=='collegeFaculty1'): > #getClasses(url, college, termVal,termName,deptName,deptAbbrv) > ret=getParseCollegeFacultyList1(url,content) > //////////////////// > > Thanks. > > if __name__ == "__main__": > # main app > > try: > #college="asu" > #url="https://webapp4.asu.edu/catalog" > #termurl="https://webapp4.asu.edu/catalog/TooltipTerms.ext" > > > #termVal=2141 > # > # get the input struct, parse it, determine the level > # > > #cmd='cat /apps/parseapp2/asuclass1.dat' > #print "cmd= "+cmd > #proc=subprocess.Popen(cmd, shell=True,stdout=subprocess.PIPE) > #content=proc.communicate()[0].strip() > #print content > #sys.exit() > > #s=getClasses(content) > > #print "arg1 =",sys.argv[0] > if(len(sys.argv)<2): > print "error\n" > sys.exit() > > a=sys.argv[1] > aaa=a > > # > # data is coming from the parentApp.php > # data has been rawurlencode(json_encode(t)) > # -reverse/split the data.. > # -do the fetch, > # -save the fetched page/content if any > # -create the returned struct > # -echo/print/return the struct to the > # calling parent/call > # > > ##print urllib.unquote_plus(a).decode('utf8') > #print "\n" > #print simplejson.loads(urllib.unquote_plus(a)) > z=simplejson.loads(urllib.unquote_plus(a)) > ##z=simplejson.loads(urllib.unquote(a).decode('utf8')) > #z=simplejson.loads(urllib2.unquote(a).decode('utf8')) > > #print "aa \n" > print z > #print "\n bb \n" > > # > #-passed in > # > url=str(z['currentURL']) > level=str(z['level']) > cname=str(z['parseContentFileName']) > > > # > # need to check the contentFname > # -should have been checked in the parentApp > # -check it anyway, return err if required > # -if valid, get/import the content into > # the "content" var for the function/parsing > # > > ##cmd='echo ${yolo_clientFetchOutputDir}/' > cmd='echo ${yolo_clientParseInputDir}/' > #print "cmd= "+cmd > proc=subprocess.Popen(cmd, shell=True,stdout=subprocess.PIPE) > cpath=proc.communicate()[0].strip() > > cname=cpath+cname > #print "cn = "+cname+"\n" > #sys.exit() > > > cmd='test -e '+cname+' && echo 1' > #print "cmd= "+cmd > proc=subprocess.Popen(cmd, shell=True,stdout=subprocess.PIPE) > c1=proc.communicate()[0].strip() > > if(not c1): > #got an error - process it, return > print "error in parse" > > # > # we're here, no err.. got content > # > > #fff= "sdsu2.dat" > with open(cname,"r") as myfile: > content=myfile.read() > myfile.close() > > > #-passed in > #college="louisville" > #url="http://htmlaccess.louisville.edu/classSchedule/" > #termVal="4138" > > > #print "term = "+str(termVal)+"\n" > #print "url = "+url+"\n" > > #jtest() > #sys.exit() > > #getTerm(url,college,termVal) > > > ret={} # null it out to start > if (level=='rState'): > #ret=getTerm(content,termVal) > ret=getParseStates(content) > > elif (level=='stateCollegeList'): > #getDepts(url,college, termValue,termName) > ret=getParseStateCollegeList(url,content) > > elif (level=='collegeFaculty1'): > #getClasses(url, college, termVal,termName,deptName,deptAbbrv) > ret=getParseCollegeFacultyList1(url,content) > > elif (level=='collegeFaculty2'): > #getClasses(url, college, termVal,termName,deptName,deptAbbrv) > ret=getParseCollegeFacultyList2(content) > > > > # > # the idea of this section.. we have the resulting > # fetched content/page... > # > > a={} > status=False > if(ret['status']==True): > > s=ascii_strip(ret['data']) > if(((s.find("-1) or (s.find("-1)) and > ((s.find("-1) or (s.find("-1)) and > level=='classSectionDay'): > > status=True > #print "herh" > #sys.exit() > > # > # build the returned struct > # > # > > a['Status']=True > a['recCount']=ret['count'] > a['data']=ret['data'] > a['nextLevel']='' > a['timestamp']='' > a['macAddress']='' > elif(ret['status']==False): > a['Status']=False > a['recCount']=0 > a['data']='' > a['nextLevel']='' > a['timestamp']='' > a['macAddress']='' > > res=urllib.quote(simplejson.dumps(a)) > ##print res > > name=subprocess.Popen('uuidgen -t', shell=True,stdout=subprocess.PIPE) > name=name.communicate()[0].strip() > name=name.replace("-","_") > > > ## if status==True: > name2=tmpParseDir+"/rr_"+name+".dat" > ofile1=open(name2,"w+") > ofile1.write(res) > ofile1.close() > print name2 > > if status==False: > sname=tmpParseDir+"/serr_"+name+".dat" > ofile1=open(sname,"w+") > ofile1.write(aaa) > ofile1.close() > > > sys.exit() > > > > > print "term = "+str(termVal)+"\n" > print "url = "+url+"\n" > > getTerm(url,college,termVal) > > > print "exit" > sys.exit() > > except Exception, e: > print e > print "pycolFac1 - error!! \n"; > name=subprocess.Popen('uuidgen -t', shell=True,stdout=subprocess.PIPE) > name=name.communicate()[0].strip() > name=name.replace("-","_") > name2="/home/ihubuser/parseErrTest/pp_"+name+".dat" > ofile1=open(name2,"w+") > ofile1.write(e) > ofile1.write(aaa) > ofile1.close() > > sys.exit() From rosuav at gmail.com Sun Aug 3 13:54:50 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 4 Aug 2014 03:54:50 +1000 Subject: try/exception - error block In-Reply-To: References: Message-ID: On Mon, Aug 4, 2014 at 3:52 AM, bruce wrote: > chris.. my bad.. I wasnt intending to mail you personally. > > Or I wouldn't have inserted the "thanks guys"! > > >> thanks guys... >> >> but in all that.. no one could tell me .. why i'm not getting any >> errs/exceptions in the err file which gets created on the exception!!! >> >> but thanks for the information on posting test code! > > Don't email me privately - respond to the list :) > > Also, please don't top-post. > > ChrisA I figured that was an accident :) Now if you could just master the interleaved posting style, that would be a great help. https://en.wikipedia.org/wiki/Posting_style#Interleaved_style ChrisA From maillist at schwertberger.de Sun Aug 3 03:46:20 2014 From: maillist at schwertberger.de (Dietmar Schwertberger) Date: Sun, 03 Aug 2014 09:46:20 +0200 Subject: Python and IDEs [was Re: Python 3 is killing Python] In-Reply-To: References: <53c57bae$0$9505$c3e8da3$5496439d@news.astraweb.com> <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> <53DBCB7B.80704@schwertberger.de> Message-ID: <53DDE8CC.6080104@schwertberger.de> Am 03.08.2014 02:04, schrieb Gregory Ewing: > MRAB wrote: >> RISC OS didn't have a menu bar at the top of each window either; its >> menus were all pop-up. You didn't have to keep flicking the mouse at >> all! > The main reason for having a menu bar is discoverability. The > idea is that you can browse through the menus and get a feel > for what commands are potentially available to you. That's not > so easy to do when everything is hidden in contextual menus. This was not a problem with the RISC OS menu concept. Only some menu items were depending on the mouse position. Actually the menu items were easier to discover as the non-applicable items were not hidden but greyed out. Regards, Dietmar From alan.gauld at btinternet.com Sun Aug 3 16:01:24 2014 From: alan.gauld at btinternet.com (Alan Gauld) Date: Sun, 03 Aug 2014 21:01:24 +0100 Subject: try/exception - error block In-Reply-To: References: Message-ID: On 03/08/14 18:52, bruce wrote: >> but in all that.. no one could tell me .. why i'm not getting any >> errs/exceptions in the err file which gets created on the exception!!! Does the file actually get created? Do you see the print statement output - are they what you expect? Did you try the things Steven suggested. >> except Exception, e: >> print e >> print "pycolFac1 - error!! \n"; >> name=subprocess.Popen('uuidgen -t', shell=True,stdout=subprocess.PIPE) >> name=name.communicate()[0].strip() >> name=name.replace("-","_") This is usually a bad idea. You are using name for the process and its output. Use more names... What about: uuid=subprocess.Popen('uuidgen -t',shell=True,stdout=subprocess.PIPE) output=uuid.communicate()[0].strip() name=output.replace("-","_") >> name2="/home/ihubuser/parseErrTest/pp_"+name+".dat" This would be a good place to insert a print print name2 >> ofile1=open(name2,"w+") Why are you using w+ mode? You are only writing. Keep life as simple as possible. >> ofile1.write(e) e is quite likely to be empty >> ofile1.write(aaa) Are you sure aaa exists at this point? Remember you are catching all errors so if an error happens prior to aaa being created this will fail. >> ofile1.close() You used the with form earlier, why not here too. It's considered better style... Some final comments. 1) You call sys.exit() several times inside the try block. sys.exit will not be caught by your except block, is that what you expect?. 2) The combination of confusing naming of variables, reuse of names and poor code layout and excessive commented code makes it very difficult to read your code. That makes it hard to figure out what might be going on. - Use sensible variable names not a,aaa,z, etc - use 3 or 4 level indentation not 2 - use a version control system (RCS,CVS, SVN,...) instead of commenting out big blocks - use consistent code style eg with f as ... or open(f)/close(f) but not both - use the os module (and friends) instead of subprocess if possible 3) Have you tried deleting all the files in the /home/ihubuser/parseErrTest/ folder and starting again, just to be sure that your current code is actually producing the empty files? 4) You use tmpParseDir in a couple of places but I don't see it being set anywhere? That's about the best I can offer based on the information available. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.flickr.com/photos/alangauldphotos From dihedral88888 at gmail.com Sun Aug 3 17:13:20 2014 From: dihedral88888 at gmail.com (CHIN Dihedral) Date: Sun, 3 Aug 2014 14:13:20 -0700 (PDT) Subject: try/exception - error block In-Reply-To: References: Message-ID: <1ec1046a-f363-4e2c-802d-0d455423ee3a@googlegroups.com> On Sunday, August 3, 2014 10:39:19 PM UTC+8, Roy Smith wrote: > In article , > > bruce wrote: > > > > > I'm posting the test code I'm using. Pointers/comments would be > > > helpful/useful. > > > > It would be really helpful if you could post a minimal code example > > which demonstrates the problem you're having. Leave out everything > > (including the commented-out code) which isn't necessary to demonstrate > > the behavior. Oh, I remember I was working with a professional programer who agreed with me that a subroutine or function longer than 80 lines in C/C++/PASCAL/Fortan, etc. must explain the reason in the commented preamble claearly for other programer to check the necessity of the unusual length. From badouglas at gmail.com Sun Aug 3 17:33:06 2014 From: badouglas at gmail.com (bruce) Date: Sun, 3 Aug 2014 17:33:06 -0400 Subject: try/exception - error block In-Reply-To: References: Message-ID: Hi Alan. Yep, the err file in the exception block gets created. and the weird thing is it matches the time of the abrtd information in the /var/log/messages log.. Just nothing in the file! On Sun, Aug 3, 2014 at 4:01 PM, Alan Gauld wrote: > On 03/08/14 18:52, bruce wrote: > >>> but in all that.. no one could tell me .. why i'm not getting any >>> errs/exceptions in the err file which gets created on the exception!!! > > > Does the file actually get created? > Do you see the print statement output - are they what you expect? > > Did you try the things Steven suggested. > > >>> except Exception, e: >>> print e >>> print "pycolFac1 - error!! \n"; >>> name=subprocess.Popen('uuidgen -t', >>> shell=True,stdout=subprocess.PIPE) >>> name=name.communicate()[0].strip() >>> name=name.replace("-","_") > > > This is usually a bad idea. You are using name for the process and its > output. Use more names... > What about: > > uuid=subprocess.Popen('uuidgen -t',shell=True,stdout=subprocess.PIPE) > output=uuid.communicate()[0].strip() > name=output.replace("-","_") > >>> name2="/home/ihubuser/parseErrTest/pp_"+name+".dat" > > > This would be a good place to insert a print > > print name2 > >>> ofile1=open(name2,"w+") > > > Why are you using w+ mode? You are only writing. > Keep life as simple as possible. > >>> ofile1.write(e) > > > e is quite likely to be empty > >>> ofile1.write(aaa) > > > Are you sure aaa exists at this point? Remember you are catching all errors > so if an error happens prior to aaa being created this will > fail. > >>> ofile1.close() > > > You used the with form earlier, why not here too. > It's considered better style... > > Some final comments. > 1) You call sys.exit() several times inside > the try block. sys.exit will not be caught by your except block, > is that what you expect?. > > 2) The combination of confusing naming of variables, > reuse of names and poor code layout and excessive commented > code makes it very difficult to read your code. > That makes it hard to figure out what might be going on. > - Use sensible variable names not a,aaa,z, etc > - use 3 or 4 level indentation not 2 > - use a version control system (RCS,CVS, SVN,...) instead > of commenting out big blocks > - use consistent code style > eg with f as ... or open(f)/close(f) but not both > - use the os module (and friends) instead of subprocess if possible > > 3) Have you tried deleting all the files in the > /home/ihubuser/parseErrTest/ folder and starting again, > just to be sure that your current code is actually > producing the empty files? > > 4) You use tmpParseDir in a couple of places but I don't > see it being set anywhere? > > > That's about the best I can offer based on the > information available. > > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > http://www.flickr.com/photos/alangauldphotos > > -- > https://mail.python.org/mailman/listinfo/python-list From robkotenko at gmail.com Sun Aug 3 17:34:04 2014 From: robkotenko at gmail.com (robkotenko at gmail.com) Date: Sun, 3 Aug 2014 14:34:04 -0700 (PDT) Subject: Why does not pprint work? In-Reply-To: <6e09bc9c-d510-4076-b20d-32df796ca59e@googlegroups.com> References: <6e09bc9c-d510-4076-b20d-32df796ca59e@googlegroups.com> Message-ID: <71cc5e7f-9933-4702-b2ac-b0fab6e0457e@googlegroups.com> With the way you have imported, you trying to use the module pprint instead of the function pprint.pprint. You need to use pprint.pprint or you need to import as: from pprint import pprint if you want to use the shorter form. On Tuesday, July 22, 2014 5:42:02 PM UTC-4, fl wrote: > Hi, > > > > I read web tutorial at: > > > > http://nedbatchelder.com/blog/201308/names_and_values_making_a_game_board.html > > > > I enter the example lines of that website: > > > > > > import pprint > > board = [ [0]*8 ] * 8 > > pprint(board) > > > > > > It echos error with Python 2.7: > > > > Traceback (most recent call last): > > File "C:\Python27\Lib\SITE-P~1\PYTHON~2\pywin\framework\scriptutils.py", > > line 323, in RunScript > > debugger.run(codeObject, __main__.__dict__, start_stepping=0) > > File "C:\Python27\Lib\SITE-P~1\PYTHON~2\pywin\debugger\__init__.py", > > line 60, in run > > _GetCurrentDebugger().run(cmd, globals,locals, start_stepping) > > File "C:\Python27\Lib\SITE-P~1\PYTHON~2\pywin\debugger\debugger.py", > > line 655, in run > > exec cmd in globals, locals > > File "C:\cygwin64\home\Jeff\Python_lesson\ppn.py", line 1, in > > import pprint > > TypeError: 'module' object is not callable > > > > It has similar error with Python 3.4.1. > > > > > > Why does pprint not work? > > > > > > Thanks, From kw at codebykevin.com Sun Aug 3 18:10:34 2014 From: kw at codebykevin.com (Kevin Walzer) Date: Sun, 03 Aug 2014 18:10:34 -0400 Subject: Tcl/Tk alpha channel bug on OSX Mavericks is fixeded, but how/when can I use the fix? In-Reply-To: References: Message-ID: On 8/3/14, 1:24 PM, Peter Tomcsanyi wrote: > > I think that it is because of this problem in Mavericks: > http://core.tcl.tk/tk/tktview?name=99b84e49ff > > The above link says that it has been solved in Tcl/Tk. > But: what does it mean for me - a Python user? > Can anyone say when a version containing the above bug fix will be > available in a form of an installable package that I can use with Python > on a Mac? > How can I know that such a package is avaibale? > Or can anyone point me to some instructions how could I compile Tcl/Tk > for myslef and (more importanty) how to install the result of that > compilation so that Python 3.4 recognizes that it should use that > package (and not three other installations of Tcl/Tk in my computer)? > New releases of Tcl/Tk 8.5 and 8.6 are due out soon; right now they are undergoing final testing as betas/release candidates. If you are using the standard Python installer from Python.org, then you can wait for ActiveTcl to be updated (not sure of their release schedule) or you can download the source tarballs for Tcl and Tk when they are released, untar them to a specific directory, cd to the directory, and run these commands: make -C $insert_tcl_dirname_here/macosx make -C $insert_tk_dirname_here/macosx and then sudo make -C $insert_tcl_dirname_here/macosx install sudo make -C $insert_tk_dirname_here/macosx install This will install the updated version of Tcl and Tk in /Library/Frameworks, and Python should pick them up. These instructions assume you have Apple's developer tools installed and are at least minimally comfortable using the command line. If you have installed Python via some other process, cf. MacPorts or Homebrew, you'll have to wait until they pick up the new versions of Tcl and Tk and follow their instructions for upgrading. Hope this helps, Kevin -- Kevin Walzer Code by Kevin/Mobile Code by Kevin http://www.codebykevin.com http://www.wtmobilesoftware.com From __peter__ at web.de Sun Aug 3 18:20:52 2014 From: __peter__ at web.de (Peter Otten) Date: Mon, 04 Aug 2014 00:20:52 +0200 Subject: try/exception - error block References: Message-ID: bruce wrote: > Hi. > > I have a long running process, it generates calls to a separate py > app. The py app appears to generate errors, as indicated in the > /var/log/messages file for the abrtd daemon.. The errors are > intermittent. > > So, to quickly capture all possible exceptions/errors, I decided to > wrap the entire "main" block of the test py func in a try/exception > block. > > This didn't work, as I'm not getting any output in the err file > generated in the exception block. > > I'm posting the test code I'm using. Pointers/comments would be > helpful/useful. > try: [...] > except Exception, e: > print e > print "pycolFac1 - error!! \n"; > name=subprocess.Popen('uuidgen -t', shell=True,stdout=subprocess.PIPE) > name=name.communicate()[0].strip() > name=name.replace("-","_") > name2="/home/ihubuser/parseErrTest/pp_"+name+".dat" > ofile1=open(name2,"w+") > ofile1.write(e) You can't write exceptions to the file, just strings. Try print >> ofile1, e or ofile1.write(str(e) + "\n") instead of the above line. > ofile1.write(aaa) > ofile1.close() > > sys.exit() From breamoreboy at yahoo.co.uk Sun Aug 3 18:49:53 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 03 Aug 2014 23:49:53 +0100 Subject: Why does not pprint work? In-Reply-To: <71cc5e7f-9933-4702-b2ac-b0fab6e0457e@googlegroups.com> References: <6e09bc9c-d510-4076-b20d-32df796ca59e@googlegroups.com> <71cc5e7f-9933-4702-b2ac-b0fab6e0457e@googlegroups.com> Message-ID: On 03/08/2014 22:34, robkotenko at gmail.com wrote: [snipped to bits] Please don't top post, further would you read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing double line spacing and single line paragraphs, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From look at signature.invalid Sun Aug 3 18:52:29 2014 From: look at signature.invalid (Wiktor) Date: Mon, 4 Aug 2014 00:52:29 +0200 Subject: cmd.exe on WIndows - problem with displaying some Unicode characters Message-ID: Hi, as OO programming exercise, I'm trying to port to Python one of my favorite game from early'90 (Atari 65XL/XE) - Kolony (here's video from original version on C64 https://www.youtube.com/watch?v=UFycYOp2cbE, and here's video from modern rewritten (for Atari emulators) version: Kolony 2106 https://www.youtube.com/watch?v=eX20Qqqm5eg - you get the idea? ;-)). OO Design is one thing, but I want to make it look as near as possible to the original (those windows-like menus in console window). I tried to use 'standard' Unicode characters (I can see that most of my Windows monospaced fonts have them) to draw frame around menu. Something like this: ???????????????? ? Construction ? ? Production ? ? Research ? ? Exploration ? ???????????????? ? Next turn ? ???????????????? (I like the look of double lines on right and at the bottom) But when I try to print those characters, I get an error: | Traceback (most recent call last): | File "E:\Moje dokumenty\python\kolony\menu.py", line 14, in | """ | File "C:\Python34\lib\encodings\cp852.py", line 19, in encode | return codecs.charmap_encode(input,self.errors,encoding_map)[0] | UnicodeEncodeError: 'charmap' codec can't encode character '\u2556' in position 1 | 6: character maps to Now I know what that means. Code page that my cmd.exe is using (852) doesn't have "?", "?", "?" and "?" symbols. Changing code page to Unicode (65001) doesn't really help, because all is messed up: ???????????????? ? Construction ? ? Production ? ? Research ? ? Exploration ? ???????????????? ? Next turn ? ???????????????? ??????????? ? Next turn ? ???????????????? ??????????????? ???????? ?? (I believe that's cmd.exe bug with Unicode support, not Python fault) Before I drop entirely this idea of using double lines on right and bottom edges, and make it look like this ???????????????? ? Construction ? ?--------------? ? Next turn ? ???????????????? I have to ask - is there a way to make that original concept work? I know, that CP437 has symbols "?", "?" and "?", but does not have polish letters - and I need to display them too. I also know, that cmd.exe can display those Unicode characters (by copy/paste them in command line or by listing filenames containing that characters), no matter what CP is set. How does it manage to do it? Can I exploit that writing my Python program? Wiktor -- Best regards, Wiktor Matuszewski 'py{}@wu{}em.pl'.format('wkm', 'ka') From tjreedy at udel.edu Sun Aug 3 18:55:13 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 03 Aug 2014 18:55:13 -0400 Subject: Correct type for a simple "bag of attributes" namespace object In-Reply-To: <87wqaplj8h.fsf@elektro.pacujo.net> References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> <70e5f2f1-661f-40f2-bb7a-76e569c4d092@googlegroups.com> <1407057464.64980.YahooMailNeo@web163806.mail.gq1.yahoo.com> <1407063072.46317.YahooMailNeo@web163803.mail.gq1.yahoo.com> <87wqaplj8h.fsf@elektro.pacujo.net> Message-ID: On 8/3/2014 10:51 AM, Marko Rauhamaa wrote: > Peter Otten <__peter__ at web.de>: > >> i. e. you have a per-class and per-instance memory consumption. The >> latter is smaller, so with regards to memory consumption instantiating >> only pays off when there is more than one employee. > > I've reached a point where I think classes are a superfluous OO concept. > You only need objects. > > Python is close to that reality. The "class" keyword really creates a > function that creates objects, and the objects' class membership is > ignored in ducktyping. The object class is used to implement duck typing. It is the delegation of operations to class instance methods that makes extensible duck typing possible. 'a + b' is equivalent to type(a).__add__(a, b) -- Terry Jan Reedy From rosuav at gmail.com Sun Aug 3 19:08:22 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 4 Aug 2014 09:08:22 +1000 Subject: cmd.exe on WIndows - problem with displaying some Unicode characters In-Reply-To: References: Message-ID: On Mon, Aug 4, 2014 at 8:52 AM, Wiktor wrote: > I have to ask - is there a way to make that original concept work? I know, > that CP437 has symbols "?", "?" and "?", but does not have polish letters - > and I need to display them too. Yeah, that's exactly the problem with codepages :) The best way to do it is to use the Unicode codepage, but cmd.exe just plain has issues. There are underlying Windows APIs for displaying text that have problems with astral characters (I think that's what it is), so ultimately, you're largely stuck. One option would be to render the whole thing graphically, abandoning cmd.exe altogether. That would be how a lot of telnet and SSH clients will do the work. Get a proper Unicode-supporting toolkit (Tkinter has issues with astral characters too, AIUI), and yes, you'll have to do a lot of work yourself. Or maybe, grab an actual telnet client, and write this as a socket server. I'd be delighted to help you with that option - I'm a MUDder and have spent innumerable dev hours on telnet clients! ChrisA From breamoreboy at yahoo.co.uk Sun Aug 3 19:20:53 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 04 Aug 2014 00:20:53 +0100 Subject: cmd.exe on WIndows - problem with displaying some Unicode characters In-Reply-To: References: Message-ID: On 03/08/2014 23:52, Wiktor wrote: > > Hi, > > as OO programming exercise, I'm trying to port to Python one of my favorite > game from early'90 (Atari 65XL/XE) - Kolony (here's video from original > version on C64 https://www.youtube.com/watch?v=UFycYOp2cbE, and here's > video from modern rewritten (for Atari emulators) version: Kolony 2106 > https://www.youtube.com/watch?v=eX20Qqqm5eg - you get the idea? ;-)). > > OO Design is one thing, but I want to make it look as near as possible to > the original (those windows-like menus in console window). I tried to use > 'standard' Unicode characters (I can see that most of my Windows monospaced > fonts have them) to draw frame around menu. Something like this: > > ???????????????? > ? Construction ? > ? Production ? > ? Research ? > ? Exploration ? > ???????????????? > ? Next turn ? > ???????????????? > > (I like the look of double lines on right and at the bottom) > But when I try to print those characters, I get an error: > > | Traceback (most recent call last): > | File "E:\Moje dokumenty\python\kolony\menu.py", line 14, in > | """ > | File "C:\Python34\lib\encodings\cp852.py", line 19, in encode > | return codecs.charmap_encode(input,self.errors,encoding_map)[0] > | UnicodeEncodeError: 'charmap' codec can't encode character '\u2556' in position 1 > | 6: character maps to > > Now I know what that means. Code page that my cmd.exe is using (852) > doesn't have "?", "?", "?" and "?" symbols. Changing code page to Unicode > (65001) doesn't really help, because all is messed up: > ???????????????? > ? Construction ? > ? Production ? > ? Research ? > ? Exploration ? > ???????????????? > ? Next turn ? > ???????????????? > ??????????? > ? Next turn ? > ???????????????? > ??????????????? > ???????? > ?? > (I believe that's cmd.exe bug with Unicode support, not Python fault) > > > Before I drop entirely this idea of using double lines on right and bottom > edges, and make it look like this > ???????????????? > ? Construction ? > ?--------------? > ? Next turn ? > ???????????????? > I have to ask - is there a way to make that original concept work? I know, > that CP437 has symbols "?", "?" and "?", but does not have polish letters - > and I need to display them too. > I also know, that cmd.exe can display those Unicode characters (by > copy/paste them in command line or by listing filenames containing that > characters), no matter what CP is set. How does it manage to do it? Can I > exploit that writing my Python program? > Wiktor > There are multiple known problems with cmd.exe and unicode. A solution might be to use powershell, but windows being windows who really knows? :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From aberg010 at my.hennepintech.edu Sun Aug 3 19:25:41 2014 From: aberg010 at my.hennepintech.edu (Andrew Berg) Date: Sun, 3 Aug 2014 18:25:41 -0500 Subject: cmd.exe on WIndows - problem with displaying some Unicode characters In-Reply-To: References: Message-ID: <53DEC4F5.8090805@my.hennepintech.edu> On 2014.08.03 18:08, Chris Angelico wrote: > The best way to do it is to use the Unicode codepage, but cmd.exe just > plain has issues. There are underlying Windows APIs for displaying > text that have problems with astral characters (I think that's what it > is), so ultimately, you're largely stuck. That is not quite true. The terminal has these issues, not the shell. Using cp65001 does make Unicode in a Windows terminal possible, but using a better terminal[1] makes it almost perfect (my experience has been that input can be difficult, but output works well). I personally have used an IRC bot written in Python with logging output containing Unicode characters that display just fine (both locally and over SSH). [1] I recommend ConEmu: https://code.google.com/p/conemu-maximus5/ From breamoreboy at yahoo.co.uk Sun Aug 3 19:29:42 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 04 Aug 2014 00:29:42 +0100 Subject: cmd.exe on WIndows - problem with displaying some Unicode characters In-Reply-To: <53DEC4F5.8090805@my.hennepintech.edu> References: <53DEC4F5.8090805@my.hennepintech.edu> Message-ID: On 04/08/2014 00:25, Andrew Berg wrote: > On 2014.08.03 18:08, Chris Angelico wrote: >> The best way to do it is to use the Unicode codepage, but cmd.exe just >> plain has issues. There are underlying Windows APIs for displaying >> text that have problems with astral characters (I think that's what it >> is), so ultimately, you're largely stuck. > That is not quite true. The terminal has these issues, not the shell. Using > cp65001 does make Unicode in a Windows terminal possible, but using a better > terminal[1] makes it almost perfect (my experience has been that input can be > difficult, but output works well). I personally have used an IRC bot written in > Python with logging output containing Unicode characters that display just fine > (both locally and over SSH). > > [1] I recommend ConEmu: https://code.google.com/p/conemu-maximus5/ > *facepalm* forgot all about ConEmu, but then I only use it on a daily basis :) -- 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 Aug 3 19:39:35 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 4 Aug 2014 09:39:35 +1000 Subject: cmd.exe on WIndows - problem with displaying some Unicode characters In-Reply-To: <53DEC4F5.8090805@my.hennepintech.edu> References: <53DEC4F5.8090805@my.hennepintech.edu> Message-ID: On Mon, Aug 4, 2014 at 9:25 AM, Andrew Berg wrote: > On 2014.08.03 18:08, Chris Angelico wrote: >> The best way to do it is to use the Unicode codepage, but cmd.exe just >> plain has issues. There are underlying Windows APIs for displaying >> text that have problems with astral characters (I think that's what it >> is), so ultimately, you're largely stuck. > That is not quite true. The terminal has these issues, not the shell. Using > cp65001 does make Unicode in a Windows terminal possible, but using a better > terminal[1] makes it almost perfect (my experience has been that input can be > difficult, but output works well). I personally have used an IRC bot written in > Python with logging output containing Unicode characters that display just fine > (both locally and over SSH). > > [1] I recommend ConEmu: https://code.google.com/p/conemu-maximus5/ Sorry, yeah, my terminology was sloppy. It's not technically cmd.exe, but the default console. I just played around with a CP-437 decode of everything 128-255, rendered in various different fonts, all using my MUD client on Windows. (For what it's worth, it renders using GTK2 and Pango. But I suspect this is more a font issue than a display engine one.) Most fonts had those little boxes-with-numbers for most of the line drawing characters, but Lucida Sans Unicode, Meiryo, and Tahoma all managed to display all the characters. However, I wasn't able to visually distinguish between the single-line and double-line characters, so you may want to play around with it a bit more. Your simplest solution may still be to abandon those double lines and just go with single. ChrisA From rosuav at gmail.com Sun Aug 3 20:14:03 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 4 Aug 2014 10:14:03 +1000 Subject: cmd.exe on WIndows - problem with displaying some Unicode characters In-Reply-To: References: <53DEC4F5.8090805@my.hennepintech.edu> Message-ID: On Mon, Aug 4, 2014 at 9:39 AM, Chris Angelico wrote: > I just played around with a CP-437 decode of everything 128-255, > rendered in various different fonts, all using my MUD client on > Windows. (For what it's worth, it renders using GTK2 and Pango. But I > suspect this is more a font issue than a display engine one.) Most > fonts had those little boxes-with-numbers for most of the line drawing > characters, but Lucida Sans Unicode, Meiryo, and Tahoma all managed to > display all the characters. However, I wasn't able to visually > distinguish between the single-line and double-line characters, so you > may want to play around with it a bit more. Hmm. Actually... I'd mucked up my CP-437 decode. For instance, I'd represented 0xC8 as U+251D BOX DRAWINGS VERTICAL LIGHT AND RIGHT HEAVY, where it's actually U+255A BOX DRAWINGS DOUBLE UP AND RIGHT. When I get the right characters, the default fonts on Windows work just fine. (There's still the issue that the supposedly "HEAVY" lines are coming out with the exact same thickness as the "LIGHT" lines, but that's unlikely to bother you as you don't need those characters.) So, conclusion: If you do the drawing yourself, all those characters are fine. Go ahead and use them! ChrisA From steve+comp.lang.python at pearwood.info Sun Aug 3 20:13:33 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 04 Aug 2014 10:13:33 +1000 Subject: Correct type for a simple "bag of attributes" namespace object References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> <70e5f2f1-661f-40f2-bb7a-76e569c4d092@googlegroups.com> <1407057464.64980.YahooMailNeo@web163806.mail.gq1.yahoo.com> <1407063072.46317.YahooMailNeo@web163803.mail.gq1.yahoo.com> <87wqaplj8h.fsf@elektro.pacujo.net> Message-ID: <53ded02e$0$29980$c3e8da3$5496439d@news.astraweb.com> Marko Rauhamaa wrote: > I've reached a point where I think classes are a superfluous OO concept. > You only need objects. I don't know whether "superfluous" is correct, but they certainly are *optional*. There are at least two types of object oriented programming: class-bases, and prototype-based. Java, Python, Ruby, etc. are all class-based. The only example of a prototype-based OOP language I know of is Javascript, and even that has recently gained the ability to define classes. I don't know enough about prototyped OOP to really give a definitive answer, but I believe that the popularity of class-based OOP is because there is a huge body of theory on types, which makes it easier for compiler designers to reason about classes than prototypes. For example, if Haskell introduces OOP (and it may already have, I don't know) I would expect it to be class-based. Also, the first OOP languages (Simula and, especially, Smalltalk) are class-based, and people tend to copy what's been done before and what they're familiar with. -- Steven From v+python at g.nevcal.com Sun Aug 3 20:17:59 2014 From: v+python at g.nevcal.com (Glenn Linderman) Date: Sun, 03 Aug 2014 17:17:59 -0700 Subject: cmd.exe on WIndows - problem with displaying some Unicode characters In-Reply-To: <53DEC4F5.8090805@my.hennepintech.edu> References: <53DEC4F5.8090805@my.hennepintech.edu> Message-ID: <53DED137.7080907@g.nevcal.com> On 8/3/2014 4:25 PM, Andrew Berg wrote: > On 2014.08.03 18:08, Chris Angelico wrote: >> The best way to do it is to use the Unicode codepage, but cmd.exe just >> plain has issues. There are underlying Windows APIs for displaying >> text that have problems with astral characters (I think that's what it >> is), so ultimately, you're largely stuck. > That is not quite true. The terminal has these issues, not the shell. Using > cp65001 does make Unicode in a Windows terminal possible, but using a better > terminal[1] makes it almost perfect (my experience has been that input can be > difficult, but output works well). I personally have used an IRC bot written in > Python with logging output containing Unicode characters that display just fine > (both locally and over SSH). > > [1] I recommend ConEmu: https://code.google.com/p/conemu-maximus5/ I will be reading more about conemu, thanks for the reference. http://bugs.python.org/issue1602 describes 7 years worth of discussion of the problems with the console/terminal used by default by cmd.exe and other Windows command line programs, versus Python. The recent insights in the last couple weeks have given me hope that Python might be able to be fixed to work properly with the default Windows console at long last... at least for non-astral characters (I'm not sure whether or not the Windows console supports non-BMP characters). For this OP problem, it is mostly a matter of finding a fixed-width font that supports the box drawing characters and the Polish characters that are desired. Lucida Console has a fair repertoire, and Consolas has a fair repertoire, in the fixed-width font arena. There may be others, documented on Polish language web sites that I wouldn't know about, and I don't know enough Polish to be sure those I mentioned suffice. And then, the workarounds mentioned in the above-referenced bug or on the GitHub or PyPi sites mentioned should provide any needed additional solutions... and hopefully something along this line finally integrated into Python so that it can finally be said that Python supports Unicode properly on Windows (or at least as properly as Windows allows... but it is pretty clear that Windows supports Unicode, even for the console, using different APIs that Python is presently using, and that mismatch between APIs is really the source of the problems with using Unicode in Python on Windows). Glenn -------------- next part -------------- An HTML attachment was scrubbed... URL: From ikorot01 at gmail.com Sun Aug 3 20:20:28 2014 From: ikorot01 at gmail.com (Igor Korot) Date: Sun, 3 Aug 2014 17:20:28 -0700 Subject: Python crashing when script is running against live system Message-ID: Hi, ALL, I'm working on the script that should starting from the given directory enumerate all directories and files underneath and calculates the hash value of such file. It works fine when I start it from some particular directory, but when I give the "C:\" it crashes python. The last thing the script processes is the file in cmdcons directory, which is AFAIU from the ComboFix run. I have Windows XP SP3 with python 2.7. Now, I'm confused. My questions are: 1. Am I able to catch such situation and see where the crash occur? 2. If not, what is the proper way to debug such situation? I am getting the window saying that python.exe has encountered a problem and needs to close. The last file processed was "c:\cmdcons\dpti20.sy_". What strange about it that when I run the script under debugger (I'm using winpdb), it is running further and crashing on some other file. Thank you for any help tracking down the issue. From rosuav at gmail.com Sun Aug 3 20:38:36 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 4 Aug 2014 10:38:36 +1000 Subject: Python crashing when script is running against live system In-Reply-To: References: Message-ID: On Mon, Aug 4, 2014 at 10:20 AM, Igor Korot wrote: > I'm working on the script that should starting from the given > directory enumerate all directories and files underneath and > calculates the hash value of such file. > It works fine when I start it from some particular directory, but when > I give the "C:\" it crashes python. > > The last thing the script processes is the file in cmdcons directory, > which is AFAIU from the ComboFix run. > I have Windows XP SP3 with python 2.7. > > Now, I'm confused. > My questions are: > > 1. Am I able to catch such situation and see where the crash occur? > 2. If not, what is the proper way to debug such situation? Great. A Heisenbug. These are so much fun... Okay. Here's how I'd try to track it down. 1) Sort the directory listings before you start iterating, to ensure that you're processing the files in a consistent order. Also, be sure you're flushing to disk every time you produce a line of output - you can probably do this by recording everything to stderr, which is generally unbuffered. 2) Do a dry run. Run the script exactly the same as it does when it crashes, but comment out the actual file reading and hash calculation. This will almost certainly succeed. 3) Using the output of step 2, make yourself an enumerated text file with all the files that the script would hash. 4) Do a half-dry run. Have the script alternate between doing the actual hashing, and just skipping it and pretending it did. 5) Do the other-half-dry run - as above but switch whether it hashes or skips the first one. Ideally, your output from step 2 should be something like this: 1: c:\config.sys 2: c:\msdos.sys 3: c:\hiberfile.sys 4: c:\cmdcons\dpti20.sy_ ... etc etc etc ... Your step 4 and 5 runs should then be doing (either way around) c:\config.sys and c:\hiberfile.sys, and c:\msdos.sys and c:\cmdcons\dpti20.sy_. That'll give you valuable information. I can imagine a few different crash scenarios from the half-and-half runs: * One of them might crash on the same file that the full run crashed on, which suggests that that file has an issue. * They might both crash, roughly twice as far into the list, which suggests that it's a memory leak or something that crashes after doing a certain amount of hashing. * They might crash at some completely different location, in which case you'd have to look for clues there. Another way to get some more info out of it would be to add a few seconds' sleep after each file. You should be able to count off the files by time, which will give additional hints. But try the other way first, as this will potentially take a looooooong time. There are a few possibilities to look out for - RAM fault, hard drive issue, stuff like that - which would be a REAL pain, but if it's not that kind of thing, it's probably a crash in the hashing code. That would at least be a Mandelbug. ChrisA From roy at panix.com Sun Aug 3 20:59:17 2014 From: roy at panix.com (Roy Smith) Date: Sun, 03 Aug 2014 20:59:17 -0400 Subject: Correct type for a simple "bag of attributes" namespace object References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> <70e5f2f1-661f-40f2-bb7a-76e569c4d092@googlegroups.com> <1407057464.64980.YahooMailNeo@web163806.mail.gq1.yahoo.com> <1407063072.46317.YahooMailNeo@web163803.mail.gq1.yahoo.com> <87wqaplj8h.fsf@elektro.pacujo.net> <53ded02e$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <53ded02e$0$29980$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > Marko Rauhamaa wrote: > > > I've reached a point where I think classes are a superfluous OO concept. > > You only need objects. > > I don't know whether "superfluous" is correct, but they certainly are > *optional*. There are at least two types of object oriented programming: > class-bases, and prototype-based. Java, Python, Ruby, etc. are all > class-based. The only example of a prototype-based OOP language I know of > is Javascript, and even that has recently gained the ability to define > classes. > > I don't know enough about prototyped OOP to really give a definitive answer, > but I believe that the popularity of class-based OOP is because there is a > huge body of theory on types, which makes it easier for compiler designers > to reason about classes than prototypes. For example, if Haskell introduces > OOP (and it may already have, I don't know) I would expect it to be > class-based. Also, the first OOP languages (Simula and, especially, > Smalltalk) are class-based, and people tend to copy what's been done before > and what they're familiar with. The first code I ever saw which had any OO concepts was the Unix kernel I/O drivers. The whole thing was written in C. It essentially implemented something we would recognize today as static class inheritance with polymorphic method dispatch. Each driver was required to implement a number of functions (read, write, open, etc), with specified signatures and contracts. Effectively, the all subclassed a (mythical) BaseIODriver. There was a big table where the rows were the different drivers (indexed by major device number), and the columns were the different methods. That was in the early 70s. From greg.ewing at canterbury.ac.nz Sun Aug 3 21:00:57 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 04 Aug 2014 13:00:57 +1200 Subject: Correct type for a simple "bag of attributes" namespace object In-Reply-To: <53ded02e$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> <70e5f2f1-661f-40f2-bb7a-76e569c4d092@googlegroups.com> <1407057464.64980.YahooMailNeo@web163806.mail.gq1.yahoo.com> <1407063072.46317.YahooMailNeo@web163803.mail.gq1.yahoo.com> <87wqaplj8h.fsf@elektro.pacujo.net> <53ded02e$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > I don't know enough about prototyped OOP to really give a definitive answer, > but I believe that the popularity of class-based OOP is because there is a > huge body of theory on types, I think it's more than that. I thought about prototype-based OO systems in some depth a while ago, and I came to the conclusion that the supposed simplification that comes from not having classes is an illusion. It *seems* simpler to have only one kind of object and allow any object to inherit from any other. But actually using it in such an undisciplined way would lead to chaos. In practice, you end up with two groups of objects, with one being used in a class-like way, and the other in an instance-like way. So you effectively have classes anyway, whether you call them that or not. -- Greg From Seymore4Head at Hotmail.invalid Sun Aug 3 21:06:58 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Sun, 03 Aug 2014 21:06:58 -0400 Subject: CodeSkulptor Message-ID: I am very new to Python. Right now I am using two tools. I am trying the tutorials at codecademy.com which is walking me through it pretty slow. The second thing I am doing is using codeskulptor to try out a few things I have learned at codecademy. I am getting a mismatch. The example I am working on is: (codecademy) from datetime import datetime now = datetime.now() current_year = now.year current_month = now.month current_day = now.day Putting that in codeskulptor gets Line 4: ImportError: No module named datetime The commands I am used to in codeskulptor is something like import random import math import simplegui import datetime < Changing this to import instead of from datetime import datetime still doesn't work. From steve+comp.lang.python at pearwood.info Sun Aug 3 21:19:29 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 04 Aug 2014 11:19:29 +1000 Subject: Correct type for a simple "bag of attributes" namespace object References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> <70e5f2f1-661f-40f2-bb7a-76e569c4d092@googlegroups.com> <1407057464.64980.YahooMailNeo@web163806.mail.gq1.yahoo.com> <1407063072.46317.YahooMailNeo@web163803.mail.gq1.yahoo.com> <87wqaplj8h.fsf@elektro.pacujo.net> Message-ID: <53dedfa2$0$29988$c3e8da3$5496439d@news.astraweb.com> Terry Reedy wrote: > The object class is used to implement duck typing. It is the delegation > of operations to class instance methods that makes extensible duck > typing possible. That cannot possibly be true, because Python had duck typing before it had object. object and new-style classes were introduced in Python 2.2, which means that there were a good half-dozen versions of Python, including the very popular 1.5, where people couldn't use object. (Also, I'm not sure what you mean by "class instance methods" -- methods can be class methods, or they can be instance methods, but not both at the same time.) > 'a + b' is equivalent to type(a).__add__(a, b) It's actually more complicated than that, because type(b).__radd__ also gets considered, but either way, I don't think that the *implementation* of + is relevant here. Duck-typing isn't really a mechanism, in the sense that static/dynamic or strong/weak typing are mechanisms: - static typing means that the compiler can tell at compile-time what type a variable will have, and prohibit code which may violate that constraint; - dynamic typing means that types are associated with values, not with variables; - strong typing means that the compiler will do nothing (or very little) to automatically convert values from one type to another; - weak typing means that the compiler will do a lot to automatically convert values from one type to another, including possibly some conversions which are considered by many to be unsafe or silly. Duck-typing is more of a programming philosophy than a mechanism, at least in Python: - you shouldn't care whether a value has a specific type or not, but whether it exposes the interface you care about. Some languages (like Java) try to formalise this, providing a mechanism by which you can implement a particular interface in a way known to the compiler: https://en.wikipedia.org/wiki/Interface_%28Java%29 Python's ABCs (abstract base classes, introduced in version 2.6) are similar. In both cases, they use the type system (in Java's case, at compile-time, in Python's case, at run-time) to check for an interface up-front, i.e. a form of "Look Before You Leap". In Python, duck-typing can also be more ad hoc and informal: if you want to know whether an object provides a certain interface, you typically just try it and see if it breaks, hoping that it will raise an exception sooner rather than later (i.e. "Easier to Ask for Forgiveness than Permission"). That's why I call it more of a philosophy than a mechanism. Duck-typing, of course, is not infallible. Suppose you're expecting an Artist, and call the artist.draw() method, but somebody gives you a Gunfighter instead. There's also the problem of what to do when an object provides only *part* of an interface: sometimes, by the time you have to ask forgiveness, you've already made irreversible changes to something (a file, a database, or launched the missiles). -- Steven From breamoreboy at yahoo.co.uk Sun Aug 3 21:21:40 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 04 Aug 2014 02:21:40 +0100 Subject: CodeSkulptor In-Reply-To: References: Message-ID: On 04/08/2014 02:06, Seymore4Head wrote: > I am very new to Python. > Right now I am using two tools. > I am trying the tutorials at codecademy.com which is walking me > through it pretty slow. > The second thing I am doing is using codeskulptor to try out a few > things I have learned at codecademy. > > I am getting a mismatch. > > The example I am working on is: > (codecademy) > from datetime import datetime > now = datetime.now() > > current_year = now.year > current_month = now.month > current_day = now.day > > Putting that in codeskulptor gets > > Line 4: ImportError: No module named datetime > > The commands I am used to in codeskulptor is something like > import random > import math > import simplegui > import datetime < Changing this to import instead of > from datetime import datetime > still doesn't work. > Please define "still doesn't work" as my crystal ball has broken down and been sent for repair. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From kw at codebykevin.com Sun Aug 3 21:21:26 2014 From: kw at codebykevin.com (Kevin Walzer) Date: Sun, 03 Aug 2014 21:21:26 -0400 Subject: Python 3 is killing Python In-Reply-To: References: <5389cb53$0$29978$c3e8da3$5496439d@news.astraweb.com> <99b7b2a2-7521-42d7-a5a0-1a35d4d5b922@googlegroups.com> <53C4A454.9010600@gmail.com> <87zjga4j4v.fsf@elektro.pacujo.net> <53c57bae$0$9505$c3e8da3$5496439d@news.astraweb.com> <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> Message-ID: RIck, On 7/17/14, 2:15 PM, Rick Johnson wrote: > Sadly, all of my calls to improve IDLE have been meet with > rebukes about me "whining". The "powers that be" would wise > to*UTILIZE* and*ENCOURAGE* my participation instead of > *IGNORING* valuable talent and*IMPEDING* the expansion of > this "private boys club". A bit late to this, I suppose... Where are your patches? Can you point me to anywhere at the Python bug tracker where they can be found? I'll highlight the two major patches I've submitted over the past few years: http://bugs.python.org/issue15853 http://bugs.python.org/issue6075 One fixed a pretty bad crash on the Mac, and the other optimized IDLE's Mac port to adjust to some API changes in Tk because of a switch in the native back end (Carbon to Cocoa). In both cases I posted an e-mail or two to the relevant mailing list (IDLE-dev and MacPython) to provide a head-up about the patch, answer questions, and so on--but that was it. No major "calls to improve IDLE," just some code that DID improve IDLE. The "powers that be" didn't commit the patches right away, and not without some modification and testing, but they eventually did commit them, and the outcome satisfied my intention in submitting the patches in the first place. Both of these patches addressed issues that made IDLE pretty much un-usable for me. Obviously a crash will do this, but also, when I switched my installation of Tk from the Carbon-backed one to the Cocoa-backed one, there were lots of little glitches because of subtle differences in how Cocoa did things. I suppose I simply could have filled the mailing lists with complaints that these things were Big Problems for me and Someone Should Do Something About Them, but there was no guarantee that someone would pick up the challenge. Fortunately, I had the knowledge, skills and time to submit patches that were sufficiently developed that the relevant Python maintainers could take them, apply them, modify slightly as required, test them, and then commit them. This did ensure that Something Would Be Done about my issue, because the Person Who Did Something About It was me. I know you are proficient in both Python and Tkinter, as I've noted from the helpful advice you give Tkinter newbies on the list from time to time, and so I'm sure you have the skill set to put together some patches that address specific points of pain for you. And despite the disagreement that others may register with you in these threads from time to time, I'm quite confident that useful patches will be gratefully accepted, even if not immediately. --Kevin -- Kevin Walzer Code by Kevin/Mobile Code by Kevin http://www.codebykevin.com http://www.wtmobilesoftware.com From steve+comp.lang.python at pearwood.info Sun Aug 3 21:29:06 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 04 Aug 2014 11:29:06 +1000 Subject: CodeSkulptor References: Message-ID: <53dee1e2$0$9505$c3e8da3$5496439d@news.astraweb.com> Seymore4Head wrote: [...] > The second thing I am doing is using codeskulptor to try out a few > things I have learned at codecademy. What's CodeSkulptor? > Putting that in codeskulptor gets > > Line 4: ImportError: No module named datetime Well that's a bug in CodeSkultor. datetime is a standard Python library, if CodeSkulptor doesn't provide it, that's a serious bug. -- Steven From rosuav at gmail.com Sun Aug 3 21:43:48 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 4 Aug 2014 11:43:48 +1000 Subject: CodeSkulptor In-Reply-To: <53dee1e2$0$9505$c3e8da3$5496439d@news.astraweb.com> References: <53dee1e2$0$9505$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Aug 4, 2014 at 11:29 AM, Steven D'Aprano wrote: >> Putting that in codeskulptor gets >> >> Line 4: ImportError: No module named datetime > > Well that's a bug in CodeSkultor. datetime is a standard Python library, if > CodeSkulptor doesn't provide it, that's a serious bug. I think it's not a bug, but a restriction; since it's letting you run code on their server, and since Python sandboxing is a hard problem, CodeSkulptor cuts down the available modules. From the docs: http://www.codeskulptor.org/docs.html#tabs-Python """ CodeSkulptor implements the following subset of the Python standard library. To use these operations, first import the relevant module with an import statement, such asimport math. """ Solution: Don't try to run Python code in your browser, but download and install an actual interpreter. ChrisA From steve+comp.lang.python at pearwood.info Sun Aug 3 21:41:46 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 04 Aug 2014 11:41:46 +1000 Subject: try/exception - error block References: Message-ID: <53dee4db$0$29987$c3e8da3$5496439d@news.astraweb.com> You also posted this question to the tutor at python.org mailing list, which is where I gave an answer. This is a much better place, so I'll re-post the most important parts of my answer here. If you read nothing else, scroll down to the end and read the last part of my comment. bruce wrote: > I have a long running process, it generates calls to a separate py > app. The py app appears to generate errors, as indicated in the > /var/log/messages file for the abrtd daemon.. The errors are > intermittent. Well, what do the errors say? [...] > if __name__ == "__main__": > # main app > > try: [deleting lots of commented out code] > if(len(sys.argv)<2): > print "error\n" > sys.exit() You really should raise an exception on errors, but if you insist on doing things this way, you should print to stderr, not stdout, and you should exit with a non-zero status: print >>sys.stdout, "descriptive error messages are better\n" sys.exit(101) > a=sys.argv[1] > aaa=a A minor stylistic thing: you can write this as: a = aaa = sys.argv[1] but of course you really ought to use descriptive variable names rather than cryptic "a" and "aaa" and "z" and other meaningless names. [deleting more fossil code] > z=simplejson.loads(urllib.unquote_plus(a)) > print z > url=str(z['currentURL']) > level=str(z['level']) > cname=str(z['parseContentFileName']) > cmd='echo ${yolo_clientParseInputDir}/' > proc=subprocess.Popen(cmd, shell=True,stdout=subprocess.PIPE) > cpath=proc.communicate()[0].strip() Hmmm. Are you trying to read the value of an environment variable using subprocess? If so, then try this instead: cpath = os.getenv('yolo_clientParseInputDir') If not, then sorry for the noise. Perhaps you could explain what your call to echo in the shell is meant to do? > cname=cpath+cname > cmd='test -e '+cname+' && echo 1' > proc=subprocess.Popen(cmd, shell=True,stdout=subprocess.PIPE) > c1=proc.communicate()[0].strip() And here I think you're trying to test whether a file exists? os.path.exists(cname) > if(not c1): > #got an error - process it, return > print "error in parse" Um, surely not? Surely the error is that the file doesn't exist, not that it is a parsing error? > with open(cname,"r") as myfile: > content=myfile.read() > myfile.close() If you use the "with open" form, there is no need to manually close the file, it will be automatically closed for you. with open(cname,"r") as myfile: content = myfile.read() is all you need (assuming you have permission to open the file, and that it still exists). [lots more fossils deleted] > ret={} # null it out to start > if (level=='rState'): > ret=getParseStates(content) > elif (level=='stateCollegeList'): > ret=getParseStateCollegeList(url,content) > elif (level=='collegeFaculty1'): > ret=getParseCollegeFacultyList1(url,content) > elif (level=='collegeFaculty2'): > ret=getParseCollegeFacultyList2(content) I'm not really sure if any of that code is relevant to the problem you're having. > a={} > status=False > if(ret['status']==True): > s=ascii_strip(ret['data']) > if(((s.find("-1) or (s.find("-1)) and > ((s.find("-1) or (s.find("-1)) and > level=='classSectionDay'): > status=True > a['Status']=True > a['recCount']=ret['count'] > a['data']=ret['data'] > a['nextLevel']='' > a['timestamp']='' > a['macAddress']='' > elif(ret['status']==False): > a['Status']=False > a['recCount']=0 > a['data']='' > a['nextLevel']='' > a['timestamp']='' > a['macAddress']='' > res=urllib.quote(simplejson.dumps(a)) Your code will be much, much, much more readable if you use a reasonable indent between levels. Four spaces rather than two, or a tab. I'm finding it quite difficult to keep track of the levels when they are so close together. > name=subprocess.Popen('uuidgen -t', shell=True,stdout=subprocess.PIPE) > name=name.communicate()[0].strip() > name=name.replace("-","_") > name2=tmpParseDir+"/rr_"+name+".dat" > ofile1=open(name2,"w+") > ofile1.write(res) > ofile1.close() > print name2 So does this file get written to? Does name2 get printed? > if status==False: > sname=tmpParseDir+"/serr_"+name+".dat" > ofile1=open(sname,"w+") > ofile1.write(aaa) > ofile1.close() How about this one? Does it get written to? > sys.exit() Since you exit here, the rest of the code in the block is never executed: > print "term = "+str(termVal)+"\n" > print "url = "+url+"\n" > getTerm(url,college,termVal) > print "exit" > sys.exit() That's all dead code. I hope it isn't important. > except Exception, e: > print e > print "pycolFac1 - error!! \n"; Does that get printed? > name=subprocess.Popen('uuidgen -t', shell=True,stdout=subprocess.PIPE) > name=name.communicate()[0].strip() > name=name.replace("-","_") > name2="/home/ihubuser/parseErrTest/pp_"+name+".dat" > ofile1=open(name2,"w+") > ofile1.write(e) > ofile1.write(aaa) > ofile1.close() > sys.exit() That's awfully ambitious code for an except clause that you're not even sure is working. Simplify, simplify, simplify. except Exception, e: with open("/tmp/myerror.txt", "w") as f: f.write("%r" % e) sys.exit(102) Now you should be able to see the error written to the file, which you should have write privileges to unless you're doing something very unusual. -- Steven From Seymore4Head at Hotmail.invalid Sun Aug 3 21:41:21 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Sun, 03 Aug 2014 21:41:21 -0400 Subject: CodeSkulptor References: <53dee1e2$0$9505$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1pott9lj8bidbfjv0rvc6i24kc5lm7jg91@4ax.com> On Mon, 04 Aug 2014 11:29:06 +1000, Steven D'Aprano wrote: >Seymore4Head wrote: > >[...] >> The second thing I am doing is using codeskulptor to try out a few >> things I have learned at codecademy. > >What's CodeSkulptor? > >> Putting that in codeskulptor gets >> >> Line 4: ImportError: No module named datetime > >Well that's a bug in CodeSkultor. datetime is a standard Python library, if >CodeSkulptor doesn't provide it, that's a serious bug. Is codeskulptor only free to users of coursra? I assumed that codeskulptor was free to everyone. Could you verify that datetime is not included in codeskulptor? http://www.codeskulptor.org/ I just tried 3 simple lines of code at codeskulptor import random import math import datetime Line 3: ImportError: No module named datetime I guess I should be using Python 3.3. Thanks From breamoreboy at yahoo.co.uk Sun Aug 3 21:56:34 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 04 Aug 2014 02:56:34 +0100 Subject: CodeSkulptor In-Reply-To: <1pott9lj8bidbfjv0rvc6i24kc5lm7jg91@4ax.com> References: <53dee1e2$0$9505$c3e8da3$5496439d@news.astraweb.com> <1pott9lj8bidbfjv0rvc6i24kc5lm7jg91@4ax.com> Message-ID: On 04/08/2014 02:41, Seymore4Head wrote: > On Mon, 04 Aug 2014 11:29:06 +1000, Steven D'Aprano > wrote: > >> Seymore4Head wrote: >> >> [...] >>> The second thing I am doing is using codeskulptor to try out a few >>> things I have learned at codecademy. >> >> What's CodeSkulptor? >> >>> Putting that in codeskulptor gets >>> >>> Line 4: ImportError: No module named datetime >> >> Well that's a bug in CodeSkultor. datetime is a standard Python library, if >> CodeSkulptor doesn't provide it, that's a serious bug. > > Is codeskulptor only free to users of coursra? I assumed that > codeskulptor was free to everyone. > > Could you verify that datetime is not included in codeskulptor? > http://www.codeskulptor.org/ > > I just tried 3 simple lines of code at codeskulptor > import random > import math > import datetime > > Line 3: ImportError: No module named datetime > > I guess I should be using Python 3.3. > > Thanks > That won't do you any good at all, the datetime module has been around for years. Try your favourite search engine for something like "free online python code tester", there's bound to be something to suit your needs. Alternatively what's stopping you running Python on your own machine? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From Seymore4Head at Hotmail.invalid Sun Aug 3 22:07:13 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Sun, 03 Aug 2014 22:07:13 -0400 Subject: CodeSkulptor References: <53dee1e2$0$9505$c3e8da3$5496439d@news.astraweb.com> <1pott9lj8bidbfjv0rvc6i24kc5lm7jg91@4ax.com> Message-ID: <8gqtt9heke2vrk4nl5rbb7lv2p141pm17g@4ax.com> On Mon, 04 Aug 2014 02:56:34 +0100, Mark Lawrence wrote: >On 04/08/2014 02:41, Seymore4Head wrote: >> On Mon, 04 Aug 2014 11:29:06 +1000, Steven D'Aprano >> wrote: >> >>> Seymore4Head wrote: >>> >>> [...] >>>> The second thing I am doing is using codeskulptor to try out a few >>>> things I have learned at codecademy. >>> >>> What's CodeSkulptor? >>> >>>> Putting that in codeskulptor gets >>>> >>>> Line 4: ImportError: No module named datetime >>> >>> Well that's a bug in CodeSkultor. datetime is a standard Python library, if >>> CodeSkulptor doesn't provide it, that's a serious bug. >> >> Is codeskulptor only free to users of coursra? I assumed that >> codeskulptor was free to everyone. >> >> Could you verify that datetime is not included in codeskulptor? >> http://www.codeskulptor.org/ >> >> I just tried 3 simple lines of code at codeskulptor >> import random >> import math >> import datetime >> >> Line 3: ImportError: No module named datetime >> >> I guess I should be using Python 3.3. >> >> Thanks >> > >That won't do you any good at all, the datetime module has been around >for years. Try your favourite search engine for something like "free >online python code tester", there's bound to be something to suit your >needs. Alternatively what's stopping you running Python on your own >machine? Well........it is just a small thing, but I am going to have to do it. I run Win7 and like to keep it lean so I also have an XP machine that I use for experimenting. I log into the XP machine remotely. I don't like to have to keep it running 24/7 like I use to. I guess I will have to get over that, won't I? Thanks From Seymore4Head at Hotmail.invalid Sun Aug 3 22:08:21 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Sun, 03 Aug 2014 22:08:21 -0400 Subject: CodeSkulptor References: <53dee1e2$0$9505$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, 4 Aug 2014 11:43:48 +1000, Chris Angelico wrote: >On Mon, Aug 4, 2014 at 11:29 AM, Steven D'Aprano > wrote: >>> Putting that in codeskulptor gets >>> >>> Line 4: ImportError: No module named datetime >> >> Well that's a bug in CodeSkultor. datetime is a standard Python library, if >> CodeSkulptor doesn't provide it, that's a serious bug. > >I think it's not a bug, but a restriction; since it's letting you run >code on their server, and since Python sandboxing is a hard problem, >CodeSkulptor cuts down the available modules. From the docs: > >http://www.codeskulptor.org/docs.html#tabs-Python >""" >CodeSkulptor implements the following subset of the Python standard >library. To use these operations, first import the relevant module >with an import statement, such asimport math. >""" > >Solution: Don't try to run Python code in your browser, but download >and install an actual interpreter. > >ChrisA I am just going to run 3.3 remotely. Thanks From davea at davea.name Sun Aug 3 22:17:43 2014 From: davea at davea.name (Dave Angel) Date: Sun, 3 Aug 2014 22:17:43 -0400 (EDT) Subject: Python crashing when script is running against live system References: Message-ID: Igor Korot Wrote in message: > Hi, ALL, > I'm working on the script that should starting from the given > directory enumerate all directories and files underneath and > calculates the hash value of such file. > It works fine when I start it from some particular directory, but when > I give the "C:\" it crashes python. How are you 'giving' that string? It's not a valid literal. How are you running this script? Are you starting it from a cmd prompt (dos box) or some other way? And is that 'other way' eating your error information? Do you get any messages at all? Nearly every problem that aborts a python program will also display some form of error messages to stderr. > > The last thing the script processes is the file in cmdcons directory, > which is AFAIU from the ComboFix run. > I have Windows XP SP3 with python 2.7. > I haven't needed to use Windows for a long time, but I seem to recall that directory is special to Windows, containing backup copies of certain critical files. So Windows may be protecting it from corruption. What file mode are you using to open those files? I would expect 'rb'. > Now, I'm confused. So are we, you include no source code, nor do you copy/paste the error tracebacks. > My questions are: > > 1. Am I able to catch such situation and see where the crash occur? > 2. If not, what is the proper way to debug such situation? > > I am getting the window saying that python.exe has encountered a > problem and needs to close. > > The last file processed was "c:\cmdcons\dpti20.sy_". > > What strange about it that when I run the script under debugger (I'm > using winpdb), it is running further and crashing on some other file. What's the path to that file? Is it in the same directory? Are you using stderr for your messages so you'll see them all even if the program crashes? Does the program run long enough that you can watch memory usage with task manager or equivalent? Can you run to completion if you skip the part where you open the file and calculate the checksums? How about if you skip that particular directory? Or if you sort the directories in forward or reverse order? If you do change the sorts, does it affect where the crash occurs? This program should be only about 25 lines, so please show it. -- DaveA From elearn2014 at gmail.com Sun Aug 3 22:33:04 2014 From: elearn2014 at gmail.com (elearn) Date: Mon, 04 Aug 2014 10:33:04 +0800 Subject: how to call back a method ? Message-ID: <53DEF0E0.4020909@gmail.com> I want to call back a function which is the method of a class . def callback(self.do,x): return(self.do(x)) That is what i want to write,when i input def callback(self.do,x): error message: File "", line 1 def callback(self.do,x): ^ SyntaxError: invalid syntax `do` is a method in my class ,how to write the code? From rosuav at gmail.com Sun Aug 3 22:42:12 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 4 Aug 2014 12:42:12 +1000 Subject: how to call back a method ? In-Reply-To: <53DEF0E0.4020909@gmail.com> References: <53DEF0E0.4020909@gmail.com> Message-ID: On Mon, Aug 4, 2014 at 12:33 PM, elearn wrote: > I want to call back a function which is the method of a class . > > def callback(self.do,x): > return(self.do(x)) > > That is what i want to write,when i input > > def callback(self.do,x): > > error message: > > > File "", line 1 > def callback(self.do,x): > ^ > SyntaxError: invalid syntax > > > `do` is a method in my class ,how to write the code? You don't want to define it with the dot in there. Give it a name like 'func' (or preferably, something more descriptive): def callback(func,x): return func(x) (And I took the superfluous parentheses off 'return'; it's a statement, not a function.) If self is an object, then self.do is an attribute of that object, which in your case is a callable function. You can assign that to anything, pass it around, and so on, and you don't need "self.do" as the name. Try it like this, see if it works... but have a careful look at your design, too. You may well be overthinking this. ChrisA From Seymore4Head at Hotmail.invalid Sun Aug 3 22:38:28 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Sun, 03 Aug 2014 22:38:28 -0400 Subject: CodeSkulptor References: <53dee1e2$0$9505$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5gstt9lf3ui5r6novjof9k0mnim3rqqlhl@4ax.com> On Sun, 03 Aug 2014 22:08:21 -0400, Seymore4Head wrote: >On Mon, 4 Aug 2014 11:43:48 +1000, Chris Angelico >wrote: > >>On Mon, Aug 4, 2014 at 11:29 AM, Steven D'Aprano >> wrote: >>>> Putting that in codeskulptor gets >>>> >>>> Line 4: ImportError: No module named datetime >>> >>> Well that's a bug in CodeSkultor. datetime is a standard Python library, if >>> CodeSkulptor doesn't provide it, that's a serious bug. >> >>I think it's not a bug, but a restriction; since it's letting you run >>code on their server, and since Python sandboxing is a hard problem, >>CodeSkulptor cuts down the available modules. From the docs: >> >>http://www.codeskulptor.org/docs.html#tabs-Python >> BTW Just read the instructions seems like a daunting task at the moment. You knew what instructions you were looking for. I am clueless. Like running Doom doom.exe -noidea :) >>CodeSkulptor implements the following subset of the Python standard >>library. To use these operations, first import the relevant module >>with an import statement, such asimport math. >>""" >> >>Solution: Don't try to run Python code in your browser, but download >>and install an actual interpreter. >> >>ChrisA > >I am just going to run 3.3 remotely. >Thanks From 1248283536 at qq.com Sun Aug 3 21:56:09 2014 From: 1248283536 at qq.com (=?utf-8?B?5rC06Z2Z5rWB5rex?=) Date: Mon, 4 Aug 2014 09:56:09 +0800 Subject: how to call back a method in python3? Message-ID: I want to call back a function which is the method of a class . def callback(self.do,x): return(self.do(x)) That is what i want to write,when i input def callback(self.do,x): error message: File "", line 1 def callback(self.do,x): ^ SyntaxError: invalid syntax `do` is a method in my class ,how to write the code?? -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Sun Aug 3 23:03:26 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 04 Aug 2014 13:03:26 +1000 Subject: CodeSkulptor References: <53dee1e2$0$9505$c3e8da3$5496439d@news.astraweb.com> <5gstt9lf3ui5r6novjof9k0mnim3rqqlhl@4ax.com> Message-ID: <53def7fe$0$29974$c3e8da3$5496439d@news.astraweb.com> Seymore4Head wrote: > On Sun, 03 Aug 2014 22:08:21 -0400, Seymore4Head > wrote: > >>On Mon, 4 Aug 2014 11:43:48 +1000, Chris Angelico >>wrote: >> >>>On Mon, Aug 4, 2014 at 11:29 AM, Steven D'Aprano >>> wrote: >>>>> Putting that in codeskulptor gets >>>>> >>>>> Line 4: ImportError: No module named datetime >>>> >>>> Well that's a bug in CodeSkultor. datetime is a standard Python >>>> library, if CodeSkulptor doesn't provide it, that's a serious bug. >>> >>>I think it's not a bug, but a restriction; since it's letting you run >>>code on their server, and since Python sandboxing is a hard problem, >>>CodeSkulptor cuts down the available modules. From the docs: >>> >>>http://www.codeskulptor.org/docs.html#tabs-Python Excluding datetime seems rather extreme to me. > BTW Just read the instructions seems like a daunting task at the > moment. You knew what instructions you were looking for. I am > clueless. So am I, because I don't know what instructions you're referring to. -- Steven From rosuav at gmail.com Sun Aug 3 23:05:55 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 4 Aug 2014 13:05:55 +1000 Subject: CodeSkulptor In-Reply-To: <5gstt9lf3ui5r6novjof9k0mnim3rqqlhl@4ax.com> References: <53dee1e2$0$9505$c3e8da3$5496439d@news.astraweb.com> <5gstt9lf3ui5r6novjof9k0mnim3rqqlhl@4ax.com> Message-ID: On Mon, Aug 4, 2014 at 12:38 PM, Seymore4Head wrote: > BTW Just read the instructions seems like a daunting task at the > moment. You knew what instructions you were looking for. I am > clueless. Yeah, that's called experience :) Part of that experience is the rather painful one of spending a good few dev hours trying to sandbox Python inside a C++ process, only to find that the sandbox got busted wide open pretty quickly as soon as I asked people to try to. (It was in a safe environment, firewalled off from everything. It was deliberately done as a security test... and the system failed so spectacularly that we had to make a complete change to the core model, among other things not using Python. Which made me sad. We had to go with ECMAScript and its flaws.) But that means that I know straight away what to look for. This is why we have these kinds of mailing lists / newsgroups. Every one of us has some experience; when you put a question out to the collective, there's a high probability that someone will know the answer. It's not that there are "smart people" and "dumb people", and that dumb people ask questions that smart people answer; it's that the whole group is smarter than any one of us. And then the answer gets posted to the whole group, and we all become that bit smarter for it :) ChrisA From rosuav at gmail.com Sun Aug 3 23:09:46 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 4 Aug 2014 13:09:46 +1000 Subject: CodeSkulptor In-Reply-To: <53def7fe$0$29974$c3e8da3$5496439d@news.astraweb.com> References: <53dee1e2$0$9505$c3e8da3$5496439d@news.astraweb.com> <5gstt9lf3ui5r6novjof9k0mnim3rqqlhl@4ax.com> <53def7fe$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Aug 4, 2014 at 1:03 PM, Steven D'Aprano wrote: >>>>I think it's not a bug, but a restriction; since it's letting you run >>>>code on their server, and since Python sandboxing is a hard problem, >>>>CodeSkulptor cuts down the available modules. From the docs: >>>> >>>>http://www.codeskulptor.org/docs.html#tabs-Python > > Excluding datetime seems rather extreme to me. By the look of their docs, they've actually gone the other way: it's not that they've excluded datetime, but that they've carefully vetted a specific set of modules (and maybe not all functionality in them) and that's all they support. In any case, I think that as soon as you hit an ImportError on the sandbox, you should go and download Python for your desktop and start working there. (Idea, for anyone who runs a sandbox like that: Enumerate all packages and modules in the stdlib, and create a little stub for each of them. "import blahblah" will still produce ImportError, but "import datetime" could report back "This interpreter is working with a small subset of the Python standard library" rather than leaving us wondering if there was some weird copy/paste error in the import line. And yes, I did test for that.) ChrisA From v+python at g.nevcal.com Mon Aug 4 00:14:44 2014 From: v+python at g.nevcal.com (Glenn Linderman) Date: Sun, 03 Aug 2014 21:14:44 -0700 Subject: cmd.exe on WIndows - problem with displaying some Unicode characters In-Reply-To: <53DED137.7080907@g.nevcal.com> References: <53DEC4F5.8090805@my.hennepintech.edu> <53DED137.7080907@g.nevcal.com> Message-ID: <53DF08B4.20600@g.nevcal.com> On 8/3/2014 5:17 PM, Glenn Linderman wrote: > On 8/3/2014 4:25 PM, Andrew Berg wrote: >> On 2014.08.03 18:08, Chris Angelico wrote: >>> The best way to do it is to use the Unicode codepage, but cmd.exe just >>> plain has issues. There are underlying Windows APIs for displaying >>> text that have problems with astral characters (I think that's what it >>> is), so ultimately, you're largely stuck. >> That is not quite true. The terminal has these issues, not the shell. Using >> cp65001 does make Unicode in a Windows terminal possible, but using a better >> terminal[1] makes it almost perfect (my experience has been that input can be >> difficult, but output works well). I personally have used an IRC bot written in >> Python with logging output containing Unicode characters that display just fine >> (both locally and over SSH). >> >> [1] I recommend ConEmu:https://code.google.com/p/conemu-maximus5/ > I will be reading more about conemu, thanks for the reference. Having read a bit about ConEmu, it seems that it is a "pretty face" built on top of Windows Console, by screen scraping the real (but hidden) Windows Console, and providing a number of interesting display features and modes. So while it adds functionality to the Windows Console interface, it doesn't seem like it is likely to fix bugs or resolve issues with code pages, font selection, or Unicode character repertoires, which are the issues of this thread and the bug I referenced earlier. Can anyone with ConEmu installed refute this interpretation of its functionality? -------------- next part -------------- An HTML attachment was scrubbed... URL: From aberg010 at my.hennepintech.edu Mon Aug 4 01:06:39 2014 From: aberg010 at my.hennepintech.edu (Andrew Berg) Date: Mon, 4 Aug 2014 00:06:39 -0500 Subject: cmd.exe on WIndows - problem with displaying some Unicode characters In-Reply-To: <53DF08B4.20600@g.nevcal.com> References: <53DEC4F5.8090805@my.hennepintech.edu> <53DED137.7080907@g.nevcal.com> <53DF08B4.20600@g.nevcal.com> Message-ID: <53DF14DF.3090504@my.hennepintech.edu> On 2014.08.03 23:14, Glenn Linderman wrote: > Having read a bit about ConEmu, it seems that it is a "pretty face" built on > top of Windows Console, by screen scraping the real (but hidden) Windows > Console, and providing a number of interesting display features and modes. So > while it adds functionality to the Windows Console interface, it doesn't seem > like it is likely to fix bugs or resolve issues with code pages, font > selection, or Unicode character repertoires, which are the issues of this > thread and the bug I referenced earlier. > > Can anyone with ConEmu installed refute this interpretation of its functionality? > If you run cmd in it, you will still need to use cp65001. This is not necessary for (or applicable to) other applications (such as a Python interpreter) run directly. ConEmu can use any arbitrary font available on the system. As I have said, I have been able to display Unicode output on it from an application written in Python. No mojibake, no replacement characters, just the exact characters one would expect. I do not know the internals of ConEmu and how it interacts with conhost and whatever else, but I have not found a need to since it has just worked for me. From tjreedy at udel.edu Mon Aug 4 01:26:14 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 04 Aug 2014 01:26:14 -0400 Subject: Correct type for a simple "bag of attributes" namespace object In-Reply-To: <53dedfa2$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> <70e5f2f1-661f-40f2-bb7a-76e569c4d092@googlegroups.com> <1407057464.64980.YahooMailNeo@web163806.mail.gq1.yahoo.com> <1407063072.46317.YahooMailNeo@web163803.mail.gq1.yahoo.com> <87wqaplj8h.fsf@elektro.pacujo.net> <53dedfa2$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 8/3/2014 9:19 PM, Steven D'Aprano wrote: stuff based on an understandable misunderstanding of what I wrote. > Terry Reedy wrote: > >> The object class is used to implement duck typing. It is the delegation >> of operations to class instance methods that makes extensible duck >> typing possible. I left off "'s". The object's class ... 'class instance methods' = class attributes that are instance methods. I was alluding to the fact that magic methods are looked up directly on the class and not the instance. Sorry for the confusion. -- Terry Jan Reedy From marko at pacujo.net Mon Aug 4 01:41:07 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 04 Aug 2014 08:41:07 +0300 Subject: Correct type for a simple "bag of attributes" namespace object References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> <70e5f2f1-661f-40f2-bb7a-76e569c4d092@googlegroups.com> <1407057464.64980.YahooMailNeo@web163806.mail.gq1.yahoo.com> <1407063072.46317.YahooMailNeo@web163803.mail.gq1.yahoo.com> <87wqaplj8h.fsf@elektro.pacujo.net> <53ded02e$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8738dclslo.fsf@elektro.pacujo.net> Steven D'Aprano : > Marko Rauhamaa wrote: > >> I've reached a point where I think classes are a superfluous OO concept. >> You only need objects. > > I don't know whether "superfluous" is correct, but they certainly are > *optional*. There are at least two types of object oriented programming: > class-bases, and prototype-based. And I'm talking about a third kind: object-based. It is in active (albeit limited) use in scheme: . I'm currently using the principle in a project of mine. In Java, you use anonymous classes for the same thing. In Python, you can think of the principle as one-time classes. So instead of writing: class A: def __init__(self, x, y, z): self.x = x self.d = y * y + z * z def f(self): return self.x - self.d you write: def A(x, y, z): d = y * y + z * z class Anonymous: def f(self): return x - d return Anonymous() Now, if you always did this, you would notice that classes are unnecessary clutter and would call for syntax like this: def A(x, y, z): d = y * y + z * z return object: def f(): return x - d Marko From marko at pacujo.net Mon Aug 4 01:47:31 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 04 Aug 2014 08:47:31 +0300 Subject: how to call back a method in python3? References: Message-ID: <87y4v4kdqk.fsf@elektro.pacujo.net> "????" <1248283536 at qq.com>: > I want to call back a function which is the method of a class . > > def callback(self.do,x): > return(self.do(x)) > > That is what i want to write,when i input > > def callback(self.do,x): > > error message: Do this: class MyClass: def my_method(self): def callback(x): return self.do(x) return callback def do(self, x): print("done: {}".format(x)) then call: m = MyClass() callback = m.my_method() callback(7) Marko From greg.ewing at canterbury.ac.nz Mon Aug 4 02:18:33 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 04 Aug 2014 18:18:33 +1200 Subject: how to call back a method in python3? In-Reply-To: <87y4v4kdqk.fsf@elektro.pacujo.net> References: <87y4v4kdqk.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa wrote: > Do this: > > class MyClass: > def my_method(self): > def callback(x): > return self.do(x) > return callback > > def do(self, x): > print("done: {}".format(x)) Or more simply: def my_method(self): return self.do -- Greg From bob.martin at excite.com Mon Aug 4 07:30:04 2014 From: bob.martin at excite.com (Bob Martin) Date: Mon, 04 Aug 2014 07:30:04 BST Subject: Python Programing for the Absoulte Beginner References: <0hhrt99lb6hhfh9q7mhra55d8base6eumg@4ax.com> <53ddee30$0$29976$c3e8da3$5496439d@news.astraweb.com> Message-ID: in 726123 20140803 090919 Steven D'Aprano wrote: >Steve Hayes wrote: > >> I've got too big an investment in books on Python 2, and there are no >> books available on Python 3 (I don't regard downloadable PDFs or other >> onlines stuff as "books"). > >I love Python 3, it's way better than Python 2, and there's less and less >reason to stick to Python 2 now. You really should learn Python 3, you >won't be sorry. > >But, if you choose not to, there's nothing to be ashamed of. Python 2.7 has >got at least six years of life left in it, and when you're done with it, >migrating to Python 3 isn't like learning a new language. It's more like >the difference between American and British English. With American English being 2.7 ?? Sorry, but someone had to ask :-) From ian.g.kelly at gmail.com Mon Aug 4 02:41:32 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 4 Aug 2014 00:41:32 -0600 Subject: Correct type for a simple "bag of attributes" namespace object In-Reply-To: <8738dclslo.fsf@elektro.pacujo.net> References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> <70e5f2f1-661f-40f2-bb7a-76e569c4d092@googlegroups.com> <1407057464.64980.YahooMailNeo@web163806.mail.gq1.yahoo.com> <1407063072.46317.YahooMailNeo@web163803.mail.gq1.yahoo.com> <87wqaplj8h.fsf@elektro.pacujo.net> <53ded02e$0$29980$c3e8da3$5496439d@news.astraweb.com> <8738dclslo.fsf@elektro.pacujo.net> Message-ID: On Sun, Aug 3, 2014 at 11:41 PM, Marko Rauhamaa wrote: > Steven D'Aprano : > And I'm talking about a third kind: object-based. It is in active > (albeit limited) use in scheme: . I'm > currently using the principle in a project of mine. > > In Java, you use anonymous classes for the same thing. In Python, you > can think of the principle as one-time classes. So instead of writing: In my experience, 99% of the time when anonymous classes are used, they only contain one method. That's because they're not really being used to implement some interface abstractly; they mostly exist to provide a means of specifying a callback function in a language where functions aren't first-class. > > class A: > def __init__(self, x, y, z): > self.x = x > self.d = y * y + z * z > > def f(self): > return self.x - self.d > > you write: > > def A(x, y, z): > d = y * y + z * z > > class Anonymous: > def f(self): > return x - d > > return Anonymous() And it's the same thing here. This isn't an interface. It's a function, so just return a function and be done with it. And in the rare event that you actually mean to implement more than one method, then you have enough functionality localized that it's probably worthwhile to just name it and make it an actual class. > Now, if you always did this, you would notice that classes are > unnecessary clutter and would call for syntax like this: > > def A(x, y, z): > d = y * y + z * z > return object: > def f(): > return x - d The presence of "object" here feels totally unnecessary to me. If the point is to avoid having a class, then why create a class? In this case you could easily just return a function. To take a more complex case, say the Scheme make-queue constructor that you linked to, you could still just return a function; the same could be implemented in Python 3 as: def make_queue(): front = [] back = [] def queue_command(command, data=None): def exchange(): nonlocal front, back front = back; front.reverse() back = [] if command == 'push': back.append(data) elif command == 'pop': if not front: exchange() return front.pop() elif command == 'peek': if not front: exchange() return front[-1] elif command == 'show': return str(list(reversed(front)) + back) else: raise ValueError('Illegal command to queue object ' + command) queue_command.push = lambda data: queue_command('push', data) queue_command.pop = lambda: queue_command('pop') queue_command.peek = lambda: queue_command('peek') return queue_command >>> queue = make_queue() >>> queue.push(1) >>> queue.push(2) >>> queue.pop() 1 >>> queue.push(3) >>> queue.push(4) >>> queue.pop() 2 >>> queue.peek() 3 >>> queue.pop() 3 >>> queue.pop() 4 From marko at pacujo.net Mon Aug 4 02:57:46 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 04 Aug 2014 09:57:46 +0300 Subject: Correct type for a simple "bag of attributes" namespace object References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> <70e5f2f1-661f-40f2-bb7a-76e569c4d092@googlegroups.com> <1407057464.64980.YahooMailNeo@web163806.mail.gq1.yahoo.com> <1407063072.46317.YahooMailNeo@web163803.mail.gq1.yahoo.com> <87wqaplj8h.fsf@elektro.pacujo.net> <53ded02e$0$29980$c3e8da3$5496439d@news.astraweb.com> <8738dclslo.fsf@elektro.pacujo.net> Message-ID: <87r40wkahh.fsf@elektro.pacujo.net> Ian Kelly : > In my experience, 99% of the time when anonymous classes are used, > they only contain one method. [...] > >> def A(x, y, z): >> d = y * y + z * z >> >> class Anonymous: >> def f(self): >> return x - d >> >> return Anonymous() > > And it's the same thing here. This isn't an interface. It's a > function, so just return a function and be done with it. My one-time classes usually have more than one method: def query(self, domain_name, record_type, listener, xid = None): ... client = self class Operation: def cancel(self): if key in client.opmap and client.opmap[key] is self: del client.opmap[key] def callback(): client.log('CANCELED') listener(client.CANCELED, None) client.mux.schedule(callback) def notify(self, verdict, records): client.log('verdict = {}'.format(verdict)) listener(verdict, records) operation = Operation() self.opmap[key] = operation ... Marko From tjreedy at udel.edu Mon Aug 4 03:02:27 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 04 Aug 2014 03:02:27 -0400 Subject: CodeSkulptor In-Reply-To: <8gqtt9heke2vrk4nl5rbb7lv2p141pm17g@4ax.com> References: <53dee1e2$0$9505$c3e8da3$5496439d@news.astraweb.com> <1pott9lj8bidbfjv0rvc6i24kc5lm7jg91@4ax.com> <8gqtt9heke2vrk4nl5rbb7lv2p141pm17g@4ax.com> Message-ID: On 8/3/2014 10:07 PM, Seymore4Head wrote: > I run Win7 Just get 3.4.1 and install it on win 7. works great. >and like to keep it lean Avoid 25 mb python install is more like keeping it anorexic ;-). Python will not bite or squeeze your machine. > so I also have an XP machine that I use for experimenting. xp is off of MS support, so it is going off of Python support too. -- Terry Jan Reedy From breamoreboy at yahoo.co.uk Mon Aug 4 03:04:53 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 04 Aug 2014 08:04:53 +0100 Subject: Python Programing for the Absoulte Beginner In-Reply-To: References: <0hhrt99lb6hhfh9q7mhra55d8base6eumg@4ax.com> <53ddee30$0$29976$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 04/08/2014 07:30, Bob Martin wrote: > in 726123 20140803 090919 Steven D'Aprano wrote: >> Steve Hayes wrote: >> >>> I've got too big an investment in books on Python 2, and there are no >>> books available on Python 3 (I don't regard downloadable PDFs or other >>> onlines stuff as "books"). >> >> I love Python 3, it's way better than Python 2, and there's less and less >> reason to stick to Python 2 now. You really should learn Python 3, you >> won't be sorry. >> >> But, if you choose not to, there's nothing to be ashamed of. Python 2.7 has >> got at least six years of life left in it, and when you're done with it, >> migrating to Python 3 isn't like learning a new language. It's more like >> the difference between American and British English. > > With American English being 2.7 ?? > Sorry, but someone had to ask :-) > American English is Python 4 :) The original English is Python 0.1. -- 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 Aug 4 04:34:11 2014 From: davea at davea.name (Dave Angel) Date: Mon, 4 Aug 2014 04:34:11 -0400 (EDT) Subject: how to call back a method ? References: <53DEF0E0.4020909@gmail.com> Message-ID: elearn Wrote in message: > I want to call back a function which is the method of a class . > > def callback(self.do,x): > return(self.do(x)) > > That is what i want to write,when i input > > def callback(self.do,x): > > error message: > > > File "", line 1 > def callback(self.do,x): > ^ > SyntaxError: invalid syntax > > > `do` is a method in my class ,how to write the code? > Without some context, answering the question is a shot in the dark. Is callback supposed to be a member function, and is it always going to be calling do () on the same object that it was called on ? Then try def callback (self, x): return self.do (x) But there are many other scenarios. Show us some sample code where it's actually being called, and we might have a better chance of guessing what you need. -- DaveA From tjreedy at udel.edu Mon Aug 4 04:39:36 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 04 Aug 2014 04:39:36 -0400 Subject: cmd.exe on WIndows - problem with displaying some Unicode characters In-Reply-To: References: Message-ID: On 8/3/2014 6:52 PM, Wiktor wrote: > > Hi, > > as OO programming exercise, I'm trying to port to Python one of my favorite > game from early'90 (Atari 65XL/XE) - Kolony (here's video from original > version on C64 https://www.youtube.com/watch?v=UFycYOp2cbE, and here's This appears to be an actual text screen, no graphics. > video from modern rewritten (for Atari emulators) version: Kolony 2106 > https://www.youtube.com/watch?v=eX20Qqqm5eg - you get the idea? ;-)). This appears to be text boxes on a graphics screen. > OO Design is one thing, but I want to make it look as near as possible to > the original (those windows-like menus in console window). Which original? the C64 or Atari. The important characteristic of both is that both have multiple overlapping popup boxes. This means that either you or a widget framework much keep track of stacking order and how to restore what was hidden when a box goes away or is moved down in the stacking order. I would not be surprised if the Atari had at least a rudimentary widget framework. > I tried to use > 'standard' Unicode characters (I can see that most of my Windows monospaced > fonts have them) to draw frame around menu. Something like this: > > ???????????????? > ? Construction ? > ? Production ? > ? Research ? > ? Exploration ? > ???????????????? > ? Next turn ? > ???????????????? > > (I like the look of double lines on right and at the bottom) > But when I try to print those characters, I get an error: > > | Traceback (most recent call last): > | File "E:\Moje dokumenty\python\kolony\menu.py", line 14, in > | """ > | File "C:\Python34\lib\encodings\cp852.py", line 19, in encode > | return codecs.charmap_encode(input,self.errors,encoding_map)[0] > | UnicodeEncodeError: 'charmap' codec can't encode character '\u2556' in position 1 > | 6: character maps to You have two separate problems with running in the windows console. 1. The character issue. If you run a program to just print the above from an Idle editor, so that the output is printed to the Idle shell, there should be no problem. >>> print('\u2556'*10) ?????????? But characters are not your real issue. 2. The random access issue. The MS console in normal use is like a serial printer or terminal. Once a line is printed, it cannot be changed. I looked at the video and the program randomly accesses a 24 or 25 line x 80 column screen, overprinting existing characters at will and reversing black on white versus white of black at will. MSDOS screens recognized standard ANSI screen control codes once the ANSI.SYS driver was installed, which was fairly normal. But cmd.exe is actually a regression from MS-DOS in that it apparently will not allow this. Or it is a hugh pain. You could get a program that emulates a full-screen ANSI terminal, and learn to use ANSI control codes. Or you could use a tkinter (tk) Text widget. People have written at least serial terminal emulators for Text, but I did not find a full-screen. Using tkinter, I would try making each box a separate text box placed in a frameand let tkinter worry about displaying them correctly and detecting which box get a mouse click or key. -- Terry Jan Reedy From tomarshubham24 at gmail.com Mon Aug 4 04:40:51 2014 From: tomarshubham24 at gmail.com (Shubham Tomar) Date: Mon, 4 Aug 2014 14:10:51 +0530 Subject: Python Classes Message-ID: Hi, Python is the first programming language that I'm learning. I'm confused by the idea of classes and intimidated by syntax defining classes. I understand that you define classes to have re-usable methods and procedures, but, don't functions serve the same purpose. Can someone please explain the idea of classes and what *things *like "__init__", "Object" and "self" mean ? Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From kwpolska at gmail.com Mon Aug 4 04:26:36 2014 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Mon, 4 Aug 2014 10:26:36 +0200 Subject: CodeSkulptor In-Reply-To: References: <53dee1e2$0$9505$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Aug 4, 2014 at 4:08 AM, Seymore4Head wrote: > I am just going to run 3.3 remotely. Why and why? 3.3 is an old, outdated version ? the most recent version is v3.4.1. By running 3.3 you are missing out on some new features, and bugfixes. You are better off running v3.4.1. The other ?why? refers to remotely running it on a Windows XP box. This is a waste of time and resources. You are not going to save much disk space, you can?t gain a thing, it?s not going to help: it will just be a burden. Especially because you?re running the remote box on Windows (and an ancient version at that) ? you are not running away from all the issues of running in a Windows environment, and add issues of running in a remote Windows environment. Please stop, for your own good. -- Chris ?Kwpolska? Warrick PGP: 5EAAEA16 stop html mail | always bottom-post | only UTF-8 makes sense From kwpolska at gmail.com Mon Aug 4 04:46:55 2014 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Mon, 4 Aug 2014 10:46:55 +0200 Subject: cmd.exe on WIndows - problem with displaying some Unicode characters In-Reply-To: <53DED137.7080907@g.nevcal.com> References: <53DEC4F5.8090805@my.hennepintech.edu> <53DED137.7080907@g.nevcal.com> Message-ID: On Mon, Aug 4, 2014 at 2:17 AM, Glenn Linderman wrote: > For this OP problem, it is mostly a matter of finding a fixed-width font > that supports the box drawing characters and the Polish characters that are > desired. Lucida Console has a fair repertoire, and Consolas has a fair > repertoire, in the fixed-width font arena. There may be others, documented > on Polish language web sites that I wouldn't know about, and I don't know > enough Polish to be sure those I mentioned suffice. Not really. We haven?t had to play the ?custom fonts for our language? game for quite some time. Consolas and Lucida Console work just fine for Polish (though Consolas sometimes hiccups on capital characters in some environments). The characters are: ????????? ????????? Most fonts ? especially the ones included with modern OSes ? support all 18 of them. So, this is a non-issue. The real issue is Windows being an idiot when it comes to CLI, which is oh so surprising to everyone who had to work with it ? considering the choice of the outdated and quirky cmd.exe interpreter, or PowerShell, which has ultra-verbose human-unfriendly commands and works in the same cmd.exe window (there is a thing named PowerShell ISE, which circumvents cmd.exe; I have no idea whether all the Unicode issues apply to that, too) -- Chris ?Kwpolska? Warrick PGP: 5EAAEA16 stop html mail | always bottom-post | only UTF-8 makes sense From wxjmfauth at gmail.com Mon Aug 4 04:47:18 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Mon, 4 Aug 2014 01:47:18 -0700 (PDT) Subject: cmd.exe on WIndows - problem with displaying some Unicode characters In-Reply-To: References: <53DEC4F5.8090805@my.hennepintech.edu> Message-ID: <61dba87e-724d-4642-8043-440ccde8c417@googlegroups.com> Le lundi 4 ao?t 2014 02:17:59 UTC+2, Glenn Linderman a ?crit?: > On 8/3/2014 4:25 PM, Andrew Berg wrote: > > > > On 2014.08.03 18:08, Chris Angelico wrote: > > > The best way to do it is to use the Unicode codepage, but cmd.exe just > plain has issues. There are underlying Windows APIs for displaying > text that have problems with astral characters (I think that's what it > is), so ultimately, you're largely stuck. > > > That is not quite true. The terminal has these issues, not the shell. Using > cp65001 does make Unicode in a Windows terminal possible, but using a better > terminal[1] makes it almost perfect (my experience has been that input can be > difficult, but output works well). I personally have used an IRC bot written in > Python with logging output containing Unicode characters that display just fine > (both locally and over SSH). > > [1] I recommend ConEmu: https://code.google.com/p/conemu-maximus5/ > > > I will be reading more about conemu, thanks for the reference. > > > > http://bugs.python.org/issue1602? describes 7 years worth of > discussion of the problems with the console/terminal used by default > by cmd.exe and other Windows command line programs, versus Python. > > > > The recent insights in the last couple weeks have given me hope that > Python might be able to be fixed to work properly with the default > Windows console at long last... at least for non-astral characters > (I'm not sure whether or not the Windows console supports non-BMP > characters). > > > > For this OP problem, it is mostly a matter of finding a fixed-width > font that supports the box drawing characters and the Polish > characters that are desired.? Lucida Console has a fair repertoire, > and Consolas has a fair repertoire, in the fixed-width font arena. > There may be others, documented on Polish language web sites that I > wouldn't know about, and I don't know enough Polish to be sure those > I mentioned suffice. > > > > And then, the workarounds mentioned in the above-referenced bug or > on the GitHub or PyPi sites mentioned should provide any needed > additional solutions... and hopefully something along this line > finally integrated into Python so that it can finally be said that > Python supports Unicode properly on Windows (or at least as properly > as Windows allows... but it is pretty clear that Windows supports > Unicode, even for the console, using different APIs that Python is > presently using, and that mismatch between APIs is really the source > of the problems with using Unicode in Python on Windows). > 1) A lot of confusion and imprecisions. 2) Unicode will never work properly because its handling is wrong by design. 3) From my interactive interpreter: >>> me.centralwidget.shell.font().rawName() 'Consolas' >>> me.centralwidget.shell.fontMetrics().width('?') 9 >>> me.centralwidget.shell.fontMetrics().width('?') 17 >>> # note: >>> me.centralwidget.shell.fontMetrics().width('\t') 80 >>> (When I think I will thow away all this work...) 4) Already posted: Fun with win_unicode_console NB Modulo .notdef glyph in font. D:\>D:\conuni\build\exe.win32-3.2\jmtest.exe 3.2.5 (default, May 15 2013, 23:06:03) [MSC v.1500 32 bit (Intel)] Quelques caract?res: ?abc??????????? Loop: empty string => quit ?>for ascii users: abc Votre entr?e ?tait : for ascii users: abc 20 caract?re(s) ?>abc???? Votre entr?e ?tait : abc???? 7 caract?re(s) ?>*?*\u20ac* Votre entr?e ?tait : *?*?* 5 caract?re(s) ?>\\\ Votre entr?e ?tait : \\\ 3 caract?re(s) ?>\\u0066 Votre entr?e ?tait : \f 2 caract?re(s) ?>a???????z Votre entr?e ?tait : a???????z 9 caract?re(s) ?>D:\jm\??????\Z?rich\?????\?dipe Votre entr?e ?tait : D:\jm\??????\Z?rich\?????\?dipe 31 caract?re(s) ?>a\u123z Wahrsheinlich falsches \uxxxx ?>r'\' Votre entr?e ?tait : r'\' 4 caract?re(s) ?>?\u1234\u3456z Votre entr?e ?tait : ???z 4 caract?re(s) ?> Fin Addendum: there is a "but". 5) I'm aware about the discussions on the subject, see 1). jmf From tjreedy at udel.edu Mon Aug 4 05:11:28 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 04 Aug 2014 05:11:28 -0400 Subject: Python Classes In-Reply-To: References: Message-ID: On 8/4/2014 4:40 AM, Shubham Tomar wrote: > Hi, > > Python is the first programming language that I'm learning. > I'm confused by the idea of classes and intimidated by syntax defining > classes. I understand that you define classes to have re-usable methods > and procedures, but, don't functions serve the same purpose. > Can someone please explain the idea of classes and what /things /like > "__init__", "Object" and "self" mean ? If you have not, read and work examples based on our fine tutorial. Classes are intentionally the last chapter about syntax. If you have read up to and into chapter 9, and are stuck on a particular section, tell us. -- Terry Jan Reedy From tomcsanyi at slovanet.sk Mon Aug 4 05:40:14 2014 From: tomcsanyi at slovanet.sk (Peter Tomcsanyi) Date: Mon, 4 Aug 2014 11:40:14 +0200 Subject: Tcl/Tk alpha channel bug on OSX Mavericks is fixeded, but how/when can I use the fix? In-Reply-To: References: Message-ID: "Kevin Walzer" wrote in message news:lrmc0r$suj$1 at dont-email.me... > New releases of Tcl/Tk 8.5 and 8.6 are due out soon; right now they are > undergoing final testing as betas/release candidates. Thanks for the promising news. Where should I look for the announcement that there is something new? Is this the correct place? http://sourceforge.net/projects/tcl/files/Tcl/ But will be the 8.5. branch updated, too? I need 8.5 because CPython on Mac does not yet use 8.6... I cannot see there 8.5.15.1 (at least that is how ActiveTcl is numbered) which solved some oter Mavericks issues in October 2013 (all 8.5. files are older than October 2013)... So will be there a 8.5.16? > you can download the source tarballs for Tcl and Tk when they are > released, untar them to a specific directory, cd to the directory, and run > these commands: > > make -C $insert_tcl_dirname_here/macosx > make -C $insert_tk_dirname_here/macosx > > and then > > sudo make -C $insert_tcl_dirname_here/macosx install > sudo make -C $insert_tk_dirname_here/macosx install I have some command line skills and I have the command line developer tools installed (is that enough?), but I am not sure if I understand which directory's name is $insert_tcl_dirname_here (I suppose that the $ sign belongs to the name of the "variable", am I right?). Is it the directory where I unterd tcl (and which is under the directory where i cd-ed to)? > This will install the updated version of Tcl and Tk in > /Library/Frameworks, and Python should pick them up. Well, should... I will try. But when I followed a similar procedure of installing the tkpng package then after "sudo make install" it seemed to be ok, but it was apparently added to other version of Tk than CPython is using... Can somebody else confirm or disconfirm that the above procedure will install the new Tcl/Tk to that place where CPython (that is already installed) will pick it from? Or do I need to reinstall CPython after this? Or...? Thanks Peter Tomcsanyi From v+python at g.nevcal.com Mon Aug 4 05:46:13 2014 From: v+python at g.nevcal.com (Glenn Linderman) Date: Mon, 04 Aug 2014 02:46:13 -0700 Subject: cmd.exe on WIndows - problem with displaying some Unicode characters In-Reply-To: <53DF14DF.3090504@my.hennepintech.edu> References: <53DEC4F5.8090805@my.hennepintech.edu> <53DED137.7080907@g.nevcal.com> <53DF08B4.20600@g.nevcal.com> <53DF14DF.3090504@my.hennepintech.edu> Message-ID: <53DF5665.9050408@g.nevcal.com> On 8/3/2014 10:06 PM, Andrew Berg wrote: > On 2014.08.03 23:14, Glenn Linderman wrote: >> Having read a bit about ConEmu, it seems that it is a "pretty face" built on >> top of Windows Console, by screen scraping the real (but hidden) Windows >> Console, and providing a number of interesting display features and modes. So >> while it adds functionality to the Windows Console interface, it doesn't seem >> like it is likely to fix bugs or resolve issues with code pages, font >> selection, or Unicode character repertoires, which are the issues of this >> thread and the bug I referenced earlier. >> >> Can anyone with ConEmu installed refute this interpretation of its functionality? >> > If you run cmd in it, you will still need to use cp65001. Or some workaround. The latest workaround in the issue I referenced does not require cp65001 either, for output, at least. > This is not necessary > for (or applicable to) other applications (such as a Python interpreter) run > directly. How does one "directly run" another application using ConEmu? That wasn't clear from what I found to read. It sounded like you run ConEmu, run one or more shells within it, and launch programs from those shells? And so it was also unclear if a program launched from some batch file would have to have the batch file launched from ConEmu, also. Or does ConEmu grab the execution association for batch files to make that work more automatically? > ConEmu can use any arbitrary font available on the system. As I have > said, I have been able to display Unicode output on it from an application > written in Python. No mojibake, no replacement characters, just the exact > characters one would expect. > I do not know the internals of ConEmu and how it interacts with conhost and > whatever else, but I have not found a need to since it has just worked for me. So you may not know the internals of ConEmu, but I presume you know the internals of your Python applications. What encodings do you use for stdout for those applications? Do you set up the Python environment variables that specify some particular encoding, in the ConEmu environment (or does it)? Because the default Python IO encoding in Windows seems to be obtained from the configured code page. Of course the biggest problem with much free and open source software is the documentation; I wasn't able to find specific answers to all my questions by reading the ConEmu wiki. Maybe some of it would be clearer if I installed it, and your "just worked" comment is certainly encouraging me to "just try it", but while trying it may help me figure it out, adding another package to separately install for my users gives more complexity. See if you can push me over the edge :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From v+python at g.nevcal.com Mon Aug 4 05:53:11 2014 From: v+python at g.nevcal.com (Glenn Linderman) Date: Mon, 04 Aug 2014 02:53:11 -0700 Subject: cmd.exe on WIndows - problem with displaying some Unicode characters In-Reply-To: References: Message-ID: <53DF5807.60101@g.nevcal.com> On 8/4/2014 1:39 AM, Terry Reedy wrote: > On 8/3/2014 6:52 PM, Wiktor wrote: >> >> Hi, >> >> as OO programming exercise, I'm trying to port to Python one of my >> favorite >> game from early'90 (Atari 65XL/XE) - Kolony (here's video from original >> version on C64 https://www.youtube.com/watch?v=UFycYOp2cbE, and here's > > This appears to be an actual text screen, no graphics. > >> video from modern rewritten (for Atari emulators) version: Kolony 2106 >> https://www.youtube.com/watch?v=eX20Qqqm5eg - you get the idea? ;-)). > > This appears to be text boxes on a graphics screen. > >> OO Design is one thing, but I want to make it look as near as >> possible to >> the original (those windows-like menus in console window). > > Which original? the C64 or Atari. The important characteristic of > both is that both have multiple overlapping popup boxes. This means > that either you or a widget framework much keep track of stacking > order and how to restore what was hidden when a box goes away or is > moved down in the stacking order. I would not be surprised if the > Atari had at least a rudimentary widget framework. > > > I tried to use >> 'standard' Unicode characters (I can see that most of my Windows >> monospaced >> fonts have them) to draw frame around menu. Something like this: >> >> ???????????????? >> ? Construction ? >> ? Production ? >> ? Research ? >> ? Exploration ? >> ???????????????? >> ? Next turn ? >> ???????????????? >> >> (I like the look of double lines on right and at the bottom) >> But when I try to print those characters, I get an error: >> >> | Traceback (most recent call last): >> | File "E:\Moje dokumenty\python\kolony\menu.py", line 14, in >> | """ >> | File "C:\Python34\lib\encodings\cp852.py", line 19, in encode >> | return codecs.charmap_encode(input,self.errors,encoding_map)[0] >> | UnicodeEncodeError: 'charmap' codec can't encode character '\u2556' >> in position 1 >> | 6: character maps to > > You have two separate problems with running in the windows console. > > 1. The character issue. If you run a program to just print the above > from an Idle editor, so that the output is printed to the Idle shell, > there should be no problem. > >>> print('\u2556'*10) > ?????????? > But characters are not your real issue. > > 2. The random access issue. The MS console in normal use is like a > serial printer or terminal. Once a line is printed, it cannot be > changed. I looked at the video and the program randomly accesses a 24 > or 25 line x 80 column screen, overprinting existing characters at > will and reversing black on white versus white of black at will. > MSDOS screens recognized standard ANSI screen control codes once the > ANSI.SYS driver was installed, which was fairly normal. But cmd.exe is > actually a regression from MS-DOS in that it apparently will not allow > this. Or it is a hugh pain. > > You could get a program that emulates a full-screen ANSI terminal, and > learn to use ANSI control codes. Or you could use a tkinter (tk) Text > widget. People have written at least serial terminal emulators for > Text, but I did not find a full-screen. > > Using tkinter, I would try making each box a separate text box placed > in a frameand let tkinter worry about displaying them correctly and > detecting which box get a mouse click or key. > I've never used the API from Python but random console access is documented at http://msdn.microsoft.com/en-us/library/windows/desktop/ms687404%28v=vs.85%29.aspx -------------- next part -------------- An HTML attachment was scrubbed... URL: From tomcsanyi at slovanet.sk Mon Aug 4 06:17:07 2014 From: tomcsanyi at slovanet.sk (Peter Tomcsanyi) Date: Mon, 4 Aug 2014 12:17:07 +0200 Subject: typo correction In-Reply-To: References: Message-ID: Now I see that I wrote a quite unreadable typo: "unterd". I meant "untared". Peter Tomcsanyi From wolfgang.maier at biologie.uni-freiburg.de Mon Aug 4 06:24:08 2014 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Mon, 04 Aug 2014 12:24:08 +0200 Subject: cmd.exe on WIndows - problem with displaying some Unicode characters In-Reply-To: <53DF5807.60101@g.nevcal.com> References: <53DF5807.60101@g.nevcal.com> Message-ID: <53DF5F48.201@biologie.uni-freiburg.de> On 08/04/2014 11:53 AM, Glenn Linderman wrote: > > I've never used the API from Python but random console access is > documented at > http://msdn.microsoft.com/en-us/library/windows/desktop/ms687404%28v=vs.85%29.aspx > Would using the API from Python involve doing the wrapping yourself or do you know about an existing package for the job ? By the way (and off-topic), how would you do it on Linux? Wolfgang From aberg010 at my.hennepintech.edu Mon Aug 4 06:33:22 2014 From: aberg010 at my.hennepintech.edu (Andrew Berg) Date: Mon, 4 Aug 2014 05:33:22 -0500 Subject: cmd.exe on WIndows - problem with displaying some Unicode characters In-Reply-To: <53DF5665.9050408@g.nevcal.com> References: <53DEC4F5.8090805@my.hennepintech.edu> <53DED137.7080907@g.nevcal.com> <53DF08B4.20600@g.nevcal.com> <53DF14DF.3090504@my.hennepintech.edu> <53DF5665.9050408@g.nevcal.com> Message-ID: <53DF6172.60704@my.hennepintech.edu> On 2014.08.04 04:46, Glenn Linderman wrote: > How does one "directly run" another application using ConEmu? That wasn't clear > from what I found to read. It sounded like you run ConEmu, run one or more > shells within it, and launch programs from those shells? And so it was also > unclear if a program launched from some batch file would have to have the batch > file launched from ConEmu, also. Or does ConEmu grab the execution association > for batch files to make that work more automatically? When you open a new console, the dialog will ask you to supply a path to an executable you want to run. Any arbitrary CLI application will work. I don't understand your question about batch files. If you mean to ask if ConEmu will snatch a console opened by executing a batch file outside of ConEmu, yes, it can do that. I highly suggest actually using the program and doing some tests of your own to see how it works. >> ConEmu can use any arbitrary font available on the system. As I have >> said, I have been able to display Unicode output on it from an application >> written in Python. No mojibake, no replacement characters, just the exact >> characters one would expect. >> I do not know the internals of ConEmu and how it interacts with conhost and >> whatever else, but I have not found a need to since it has just worked for me. > So you may not know the internals of ConEmu, but I presume you know the > internals of your Python applications. What encodings do you use for stdout for > those applications? Do you set up the Python environment variables that specify > some particular encoding, in the ConEmu environment (or does it)? Because the > default Python IO encoding in Windows seems to be obtained from the configured > code page. I use UTF-8. Open the Python interpreter directly in ConEmu and see what you get. > Of course the biggest problem with much free and open source software is the > documentation; I wasn't able to find specific answers to all my questions by > reading the ConEmu wiki. Maybe some of it would be clearer if I installed it, > and your "just worked" comment is certainly encouraging me to "just try it", > but while trying it may help me figure it out, adding another package to > separately install for my users gives more complexity. See if you can push me > over the edge :) It certainly would make things much clearer if you were to actually use the program. Documentation tends to assume (and reasonably so, IMO) that you intend to do some hands-on learning. I can give no advice on deploying this to your users other than to say ConEmu works well as a tool for command line power users on Windows, but does not provide much ROI when it is simply an implementation detail for a single program. If you want to save your users the hassle, I would definitely recommend a graphical environment. If I had realized that you intended your application to be widely deployed, I would have simply recommended that from the start. On a side note, you would have run into similar issues on *nix systems where a significant amount of your users would be using the "C" locale and have no idea what it is, why it causes them problems, or how to change it. From chris at simplistix.co.uk Mon Aug 4 07:43:29 2014 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 04 Aug 2014 12:43:29 +0100 Subject: testfixtures 4.0.1 Released! Message-ID: <53DF71E1.8050506@simplistix.co.uk> Hi All, I'm pleased to announce the release of testfixtures 4.0.1. This is a bugfix release that fixes the following two edge cases: - Fix bugs when string compared equal and options to compare() were used. - Fix bug when strictly comparing two nested structures containing identical objects. The package is on PyPI and a full list of all the links to docs, issue trackers and the like can be found here: http://www.simplistix.co.uk/software/python/testfixtures Any questions, please do ask on the Testing in Python list or on the Simplistix open source mailing list... cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From varun7rs at gmail.com Mon Aug 4 07:51:14 2014 From: varun7rs at gmail.com (varun7rs at gmail.com) Date: Mon, 4 Aug 2014 04:51:14 -0700 (PDT) Subject: Davis putnam algorithm for satisfiability... Message-ID: <8aceb6af-9b72-4e14-8d3e-8e6aea83fa69@googlegroups.com> Hello friends, I have some trouble understanding the davis putnam algorithm for satisfiability. I understood most of the code but I don't know where exactly backtracking is happening here. Your assistance would be very helpful to me. import sys import math import copy final_list = [] def sat(cnf): while( len(cnf) > 1 ): in_item = single_clause(cnf) #in_item: the first single_clause in cnf if in_item != None: del_sat(cnf, in_item) else: break for i in cnf: if len(i) == 0: cnf.remove(i) return if len(cnf) == 1: final_list.extend( [cnf[0][0]] ) # like a watchlist for i in range(0, len(final_list)): if final_list[i] > 0: print "Not equivalent!" sys.exit(0) return final_list deep_copy = copy.deepcopy(cnf) list2 = cnf[0][0] del_sat(deep_copy,list2) # recursion to delete and then find another way and the proceed or delete more like a tree sat(deep_copy) del_sat(cnf,-list2) sat(cnf) return def parseXml(file_1, file_2): global cnf readfile_1 = open(file_1, "r") readfile_2 = open(file_2, "r") sum_a = int(readfile_1.readline()) sum_b = int(readfile_2.readline()) inputs_1 = readfile_1.readline().split() inputs_1.sort() inputs_2 = readfile_2.readline().split() inputs_2.sort() outputs_1 = readfile_1.readline().split() outputs_1.sort() outputs_2 = readfile_2.readline().split() outputs_2.sort() inputmap_1 = {} inputmap_2 = {} outputmap_1 = [] outputmap_2 = [] while True: line = readfile_1.readline().strip() if not line: break net,item = line.split() inputmap_1[item] = int(net) while True: line = readfile_2.readline().strip() if not line: break net,item = line.split() inputmap_2[item] = int(net) #print inputmap_2 for line in readfile_1.readlines(): inp1 = line.split() gate = inp1.pop(0) mapping = map(int, inp1) outputmap_1.extend([(gate, mapping)]) print 'outputmap_1' print outputmap_1 for line in readfile_2.readlines(): inp2 = line.split() gate = inp2.pop(0) mapping = map(int, inp2) outputmap_2.extend([(gate, mapping)]) return inputs_1, inputs_2, outputs_1, outputs_2, inputmap_1, inputmap_2, outputmap_1, outputmap_2 def single_clause(cnf): for i in cnf: if len(i) == 1: return i[0] return None def del_sat(cnf,in_item): cnf2 = cnf[:] for k in cnf2: if k.count(in_item): cnf.remove(k) for i in cnf: if i.count( -in_item): i.remove(-in_item) def cnf_out(miter): miter_len = len(miter) cnf = [] while (miter_len > 0): x = miter.pop(0) if ( x[0] == "and" ): cnf.extend( [[x[1][0], -x[1][2]]] ) cnf.extend( [[x[1][1], -x[1][2]]] ) cnf.extend( [[-x[1][0], -x[1][1], x[1][2]]] ) elif ( x[0] == "or" ): cnf.extend( [[x[1][0], x[1][1], -x[1][2]]] ) cnf.extend( [[-x[1][0], x[1][2]]] ) cnf.extend( [[-x[1][1], x[1][2]]] ) elif ( x[0] == "xor" ): cnf.extend( [[x[1][0], x[1][1], -x[1][2]]] ) cnf.extend( [[-x[1][0], -x[1][1], -x[1][2]]] ) cnf.extend( [[-x[1][0], x[1][1], x[1][2]]] ) cnf.extend( [[x[1][0], -x[1][1], x[1][2]]] ) else: cnf.extend( [[x[1][0], x[1][1]]] ) cnf.extend( [[-x[1][0], -x[1][1]]] ) miter_len = miter_len - 1 return cnf inputs_1, inputs_2, outputs_1, outputs_2, inputmap_1, inputmap_2, outputmap_1, outputmap_2 = parseXml(sys.argv[1], sys.argv[2]) incoming1=[] incoming2=[] outgoing1=[] outgoing2=[] for i in inputs_1: incoming1.extend([inputmap_1[i]]) for j in inputs_2: incoming2.extend([inputmap_2[j]]) for k in outputs_1: outgoing1.extend([inputmap_1[k]]) for l in outputs_2: outgoing2.extend([inputmap_2[l]]) gate_num = 0 for output in outputmap_1: for j in output[1]: if gate_num < j: gate_num = j # gate_num: first line of netlist file. Total number of nets always need max no.. map2 = outputmap_2 num = len( map2 ) #No. of gates in netlist 2 for i in range(1, num + 1): j = len( map2[i-1][1] ) # Total No. of inputs and outputs of a gate for k in range(0, j): if map2[i-1][1][k] not in incoming2: total = 0 for l in incoming2: if map2[i-1][1][k] > l: total = total + 1 # Total no. of nets minus total no. of input nets like an offset map2[i-1][1][k] = map2[i-1][1][k] + gate_num - total else: x = incoming2.index( map2[i-1][1][k] ) map2[i-1][1][k] = incoming1[x] miter = outputmap_1 miter.extend(map2) #Combine gate lists of the two netlists to 'miter' out_len = len(outgoing1) #No. of outputs from each netlist (netlist1's out_len should be equal to netlist2's) for i in range(out_len): total = 0 for j in incoming2: # e.g: incoming2 = [1,2] if outgoing2[i] > j: # e.g outgoing2 = [10] total = total + 1 # should be the size of incoming2 outgoing2[i] = outgoing2[i] + gate_num - total xor_gate = [( 'xor', [outgoing1[i], outgoing2[i], 9000+i] )] miter.extend(xor_gate) if out_len > 1: or_gate_1 = [( 'or', [9000, 9000+1, 9000 + out_len] )] miter.extend(or_gate_1) for i in range(out_len - 2): or_gate=[( 'or', [9000 + out_len + i, 9000 +i + 2, 9000 + i + out_len + 1] )] miter.extend(or_gate) # 9000 just a random no. for the no. of nets used in order to prevent overlap of two nos. built_cnf = cnf_out(miter) count = 0 built_len = len(built_cnf) for i in range(0, built_len): built_leni = len(built_cnf[i]) for j in range(0, built_leni): if abs( built_cnf[i][j] ) > count: #count is the total number of nets in the miter circuit count = abs( built_cnf[i][j]) value = sat(built_cnf) print value print "Equivalent!" From kw at codebykevin.com Mon Aug 4 08:16:53 2014 From: kw at codebykevin.com (Kevin Walzer) Date: Mon, 04 Aug 2014 08:16:53 -0400 Subject: Tcl/Tk alpha channel bug on OSX Mavericks is fixeded, but how/when can I use the fix? In-Reply-To: References: Message-ID: On 8/4/14, 5:40 AM, Peter Tomcsanyi wrote: > "Kevin Walzer" wrote in message > news:lrmc0r$suj$1 at dont-email.me... >> New releases of Tcl/Tk 8.5 and 8.6 are due out soon; right now they >> are undergoing final testing as betas/release candidates. > > Thanks for the promising news. > Where should I look for the announcement that there is something new? > Is this the correct place? > http://sourceforge.net/projects/tcl/files/Tcl/ You can check comp.lang.tcl for an announcement. > > But will be the 8.5. branch updated, too? > I need 8.5 because CPython on Mac does not yet use 8.6... > I cannot see there 8.5.15.1 (at least that is how ActiveTcl is numbered) > which solved some oter Mavericks issues in October 2013 (all 8.5. files > are older than October 2013)... > So will be there a 8.5.16? 8.5 and 8.6 will be updated. > >> you can download the source tarballs for Tcl and Tk when they are >> released, untar them to a specific directory, cd to the directory, and >> run these commands: >> >> make -C $insert_tcl_dirname_here/macosx >> make -C $insert_tk_dirname_here/macosx >> >> and then >> >> sudo make -C $insert_tcl_dirname_here/macosx install >> sudo make -C $insert_tk_dirname_here/macosx install > > I have some command line skills and I have the command line developer > tools installed (is that enough?), but I am not sure if I understand > which directory's name is $insert_tcl_dirname_here (I suppose that the $ > sign belongs to the name of the "variable", am I right?). Is it the > directory where I unterd tcl (and which is under the directory where i > cd-ed to)? $insert_tcl_dirname = something like tcl8.5.16. Just look at the numbering. In other words, you want a directory with two subdirectories: tcl8.5.16 and tk8.5.16 (since you are looking at 8.5). > >> This will install the updated version of Tcl and Tk in >> /Library/Frameworks, and Python should pick them up. > > Well, should... > I will try. But when I followed a similar procedure of installing the > tkpng package then after "sudo make install" it seemed to be ok, but it > was apparently added to other version of Tk than CPython is using... > Can somebody else confirm or disconfirm that the above procedure will > install the new Tcl/Tk to that place where CPython (that is already > installed) will pick it from? Or do I need to reinstall CPython after > this? Or...? Where is your current installation of Python? The above instructions assume that you are using the standard Python from python.org. As I mentioned before, if you have installed things via a package manager (brew, Fink or MacPorts) you will have to follow their instructions. --Kevin -- Kevin Walzer Code by Kevin/Mobile Code by Kevin http://www.codebykevin.com http://www.wtmobilesoftware.com From danwgrace at gmail.com Mon Aug 4 08:17:30 2014 From: danwgrace at gmail.com (danwgrace at gmail.com) Date: Mon, 4 Aug 2014 05:17:30 -0700 (PDT) Subject: Will IronPython / WPF work on Mac OS X? Message-ID: <59db0f1d-31dd-441a-bdb6-413d75ca7c85@googlegroups.com> Hello, I am thinking of using IronPython to build an Python application. Using WPF in Visual Studio to draw the GUI and create the XAML. Can I then run this Python application on a Mac OS X (10.8)? Thanks. From __peter__ at web.de Mon Aug 4 08:39:22 2014 From: __peter__ at web.de (Peter Otten) Date: Mon, 04 Aug 2014 14:39:22 +0200 Subject: CodeSkulptor References: <53dee1e2$0$9505$c3e8da3$5496439d@news.astraweb.com> <5gstt9lf3ui5r6novjof9k0mnim3rqqlhl@4ax.com> <53def7fe$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: Chris Angelico wrote: > On Mon, Aug 4, 2014 at 1:03 PM, Steven D'Aprano > wrote: >>>>>I think it's not a bug, but a restriction; since it's letting you run >>>>>code on their server, and since Python sandboxing is a hard problem, >>>>>CodeSkulptor cuts down the available modules. From the docs: >>>>> >>>>>http://www.codeskulptor.org/docs.html#tabs-Python >> >> Excluding datetime seems rather extreme to me. > > By the look of their docs, they've actually gone the other way: it's > not that they've excluded datetime, but that they've carefully vetted > a specific set of modules (and maybe not all functionality in them) > and that's all they support. In any case, I think that as soon as you > hit an ImportError on the sandbox, you should go and download Python > for your desktop and start working there. > > (Idea, for anyone who runs a sandbox like that: Enumerate all packages > and modules in the stdlib, and create a little stub for each of them. > "import blahblah" will still produce ImportError, but "import > datetime" could report back "This interpreter is working with a small > subset of the Python standard library" rather than leaving us > wondering if there was some weird copy/paste error in the import line. > And yes, I did test for that.) All nice and dandy, but the site seems to use a Python implementation entirely written in javascript: http://www.skulpt.org/ It's not a sandbox on the server, the code runs in your browser. From a.nandagoban at traxens.com Mon Aug 4 08:51:57 2014 From: a.nandagoban at traxens.com (Arulnambi Nandagoban) Date: Mon, 4 Aug 2014 14:51:57 +0200 Subject: creating log file with Python logging module Message-ID: <003d01cfafe2$e0668ac0$a133a040$@traxens.com> Hello all, I am using logging module for my application to log all debug information. I configured it create a new log file every day with "TimedRotatingFileHandler". I display debug message in console as well. But I didn't see creation of new file. Can someone help me to sort out this problem. Following is config code: import logging from logging.handlers import TimedRotatingFileHandler Ffilename = os.path.join(dir_path, 'Pyserverlog') logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', datefmt='%a, %d %b %Y %H:%M:%S', level = logging.DEBUG, filename=Ffilename, filemode='w') logger = logging.getLogger(__name__) hdlr = TimedRotatingFileHandler(Ffilename, when='midnight') logger.addHandler(hdlr) # define a Handler which writes INFO messages or higher to the sys.stderr console = logging.StreamHandler() console.setLevel(logging.DEBUG) formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') # tell the handler to use this format console.setFormatter(formatter) # add the handler to the root logger logging.getLogger('').addHandler(console) -- nambi -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin.kaplan at case.edu Mon Aug 4 09:10:28 2014 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 4 Aug 2014 06:10:28 -0700 Subject: Will IronPython / WPF work on Mac OS X? In-Reply-To: <59db0f1d-31dd-441a-bdb6-413d75ca7c85@googlegroups.com> References: <59db0f1d-31dd-441a-bdb6-413d75ca7c85@googlegroups.com> Message-ID: On Aug 4, 2014 6:23 AM, wrote: > > Hello, > I am thinking of using IronPython to build an Python application. Using WPF in Visual Studio to draw the GUI and create the XAML. Can I then run this Python application on a Mac OS X (10.8)? > Thanks. > -- Nope. IronPython on Mac runs on top of Mono, so it has access to all the libraries that Mono supports. That means there's no support for WPF except for the subset that Silverlight supported (See http://www.mono-project.com/wpf ). -------------- next part -------------- An HTML attachment was scrubbed... URL: From kw at codebykevin.com Mon Aug 4 09:14:50 2014 From: kw at codebykevin.com (Kevin Walzer) Date: Mon, 04 Aug 2014 09:14:50 -0400 Subject: Will IronPython / WPF work on Mac OS X? In-Reply-To: <59db0f1d-31dd-441a-bdb6-413d75ca7c85@googlegroups.com> References: <59db0f1d-31dd-441a-bdb6-413d75ca7c85@googlegroups.com> Message-ID: On 8/4/14, 8:17 AM, danwgrace at gmail.com wrote: > Hello, > I am thinking of using IronPython to build an Python application. Using WPF in Visual Studio to draw the GUI and create the XAML. Can I then run this Python application on a Mac OS X (10.8)? > Thanks. > IronPython is a Windows-only product, I believe...doesn't it run on top of .NET? I don't see how it would work on the Mac unless it also worked with Mono. -- Kevin Walzer Code by Kevin/Mobile Code by Kevin http://www.codebykevin.com http://www.wtmobilesoftware.com From __peter__ at web.de Mon Aug 4 09:24:54 2014 From: __peter__ at web.de (Peter Otten) Date: Mon, 04 Aug 2014 15:24:54 +0200 Subject: creating log file with Python logging module References: <003d01cfafe2$e0668ac0$a133a040$@traxens.com> Message-ID: Arulnambi Nandagoban wrote: > I am using logging module for my application to log all debug information. > I configured it create a new log file every day with > > "TimedRotatingFileHandler". I display debug message in console as well. > But I didn't see creation of new file. Is the script running continuously? You won't see a rollover if you restart it. Working example (with shorter time interval): $ cat rollover.py import logging import logging.handlers import time logger = logging.getLogger() handler = logging.handlers.TimedRotatingFileHandler("logfile", when='S') logger.addHandler(handler) logger.setLevel(logging.INFO) for i in range(100): logger.info("message #%s" % i) time.sleep(.1) $ ls rollover.py $ python rollover.py $ ls logfile logfile.2014-08-04_15-21-26 logfile.2014-08-04_15-21-21 logfile.2014-08-04_15-21-27 logfile.2014-08-04_15-21-22 logfile.2014-08-04_15-21-28 logfile.2014-08-04_15-21-23 logfile.2014-08-04_15-21-29 logfile.2014-08-04_15-21-24 logfile.2014-08-04_15-21-30 logfile.2014-08-04_15-21-25 rollover.py $ cat logfile message #93 message #94 message #95 message #96 message #97 message #98 message #99 $ From __peter__ at web.de Mon Aug 4 09:53:49 2014 From: __peter__ at web.de (Peter Otten) Date: Mon, 04 Aug 2014 15:53:49 +0200 Subject: creating log file with Python logging module References: <003d01cfafe2$e0668ac0$a133a040$@traxens.com> Message-ID: Peter Otten wrote: > You won't see a rollover if you restart it. Sorry, I tried it and the above statement is wrong. From __peter__ at web.de Mon Aug 4 10:03:29 2014 From: __peter__ at web.de (Peter Otten) Date: Mon, 04 Aug 2014 16:03:29 +0200 Subject: creating log file with Python logging module References: <003d01cfafe2$e0668ac0$a133a040$@traxens.com> Message-ID: Peter Otten wrote: > Peter Otten wrote: > >> You won't see a rollover if you restart it. > > Sorry, I tried it and the above statement is wrong. [Arulnambi Nandagoban] > logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - > %(message)s', datefmt='%a, %d %b %Y %H:%M:%S', level = logging.DEBUG, > filename=Ffilename, filemode='w') > > logger = logging.getLogger(__name__) > > hdlr = TimedRotatingFileHandler(Ffilename, when='midnight') My alternative theory about what might be going wrong: you are using the same file in logging.basicConfig() and the TimedRotatingFileHandler. But I cannot replicate the problem on my (linux) system. From rosuav at gmail.com Mon Aug 4 10:18:52 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Aug 2014 00:18:52 +1000 Subject: CodeSkulptor In-Reply-To: References: <53dee1e2$0$9505$c3e8da3$5496439d@news.astraweb.com> <5gstt9lf3ui5r6novjof9k0mnim3rqqlhl@4ax.com> <53def7fe$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Aug 4, 2014 at 10:39 PM, Peter Otten <__peter__ at web.de> wrote: >> (Idea, for anyone who runs a sandbox like that: Enumerate all packages >> and modules in the stdlib, and create a little stub for each of them. >> "import blahblah" will still produce ImportError, but "import >> datetime" could report back "This interpreter is working with a small >> subset of the Python standard library" rather than leaving us >> wondering if there was some weird copy/paste error in the import line. >> And yes, I did test for that.) > > All nice and dandy, but the site seems to use a Python implementation > entirely written in javascript: > > http://www.skulpt.org/ > > It's not a sandbox on the server, the code runs in your browser. It still has to be cut down, at least as regards modules implemented in C. ImportError: No module named decimal on line 1 So, same applies. Adding a bunch of stubs like "decimal.py" to say "This has a subset of the Python standard library and does not provide the decimal module" would be useful. As that one seems to be hosted on github, I'll drop a tracker issue down there with the suggestion. ChrisA From rosuav at gmail.com Mon Aug 4 10:38:29 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Aug 2014 00:38:29 +1000 Subject: Python Programing for the Absoulte Beginner In-Reply-To: References: <0hhrt99lb6hhfh9q7mhra55d8base6eumg@4ax.com> <53ddee30$0$29976$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Aug 4, 2014 at 3:30 PM, Bob Martin wrote: > With American English being 2.7 ?? > Sorry, but someone had to ask :-) A fairer comparison would be American English is IronPython, British English is PyPy. Mostly compatible, and people call them both Python, but not strictly identical. ChrisA From look at signature.invalid Mon Aug 4 11:00:11 2014 From: look at signature.invalid (Wiktor) Date: Mon, 4 Aug 2014 17:00:11 +0200 Subject: cmd.exe on WIndows - problem with displaying some Unicode characters References: Message-ID: Hi, first, thank you all for responses. I decided to just use single line frame around menu. Yes, those double+single line corners work fine in ConEmu, but I don't want this Python script to be dependent on external program. Maybe one day it will be worth of showing to others, and it's silly to tell them 'It is pure console based game/framework but works only in ConEmu'... Now, to Terry's post: On 8/3/2014 6:52 PM, Wiktor wrote: >> as OO programming exercise, I'm trying to port to Python one of my favorite >> game from early'90 (Atari 65XL/XE) - Kolony (here's video from original >> version on C64 https://www.youtube.com/watch?v=UFycYOp2cbE, and here's > > This appears to be an actual text screen, no graphics. > >> video from modern rewritten (for Atari emulators) version: Kolony 2106 >> https://www.youtube.com/watch?v=eX20Qqqm5eg - you get the idea? ;-)). > > This appears to be text boxes on a graphics screen. > >> OO Design is one thing, but I want to make it look as near as possible to >> the original (those windows-like menus in console window). > > Which original? the C64 or Atari. The important characteristic of both > is that both have multiple overlapping popup boxes. This means that > either you or a widget framework much keep track of stacking order and > how to restore what was hidden when a box goes away or is moved down in > the stacking order. I would not be surprised if the Atari had at least a > rudimentary widget framework. Yes, I'm aware that first link is to the text based game, and second to graphic based game. I provided both links, because I couldn't find screen cast from original Atari game (which is also text based, but IMO looks better than C64's version), and this modern game is translated to English, so is better for you to understand character of game. Yes, I'd like to make text game, that looks like window-based, with popup boxes, inactive windows grayed out and all this stuff. And all this running on standard console window (cmd.exe). I'm not starting from scratch. I'm using packages 'termcolor', 'colorama' and 'colorconsole' - they provide functions to print text at desired position on screen, and change color of foreground/background of this text. With those packages I already developed some classes that allow me to construct some simple menus for my console programs. Short demo of silly program calculating degree of n-th root: http://youtu.be/V8ilLhHAT_k (I link to the video, because there's too much code lines to paste them here. Also it's dependent upon those third party packages, and still work-in-progress). So, I'm not worry about randomly access, colors, overprinting existing characters. At this point I know how to do that. I'm taking next step, so I tried to draw nice frame around menu (that's why I posted yesterday). Next step would be to manage those widgets to draw one over another, to keep track which one window opens which, and when the other window must be closed and when only grayed out. At this point I still don't know how to do this right, but I'm thinking about this very hard. :-) Probably one day I'll ask it here, if I don't figure it out. :-) Wiktor -- Best regards, Wiktor Matuszewski 'py{}@wu{}em.pl'.format('wkm', 'ka') From invalid at invalid.invalid Mon Aug 4 11:12:55 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 4 Aug 2014 15:12:55 +0000 (UTC) Subject: try/exception - error block References: Message-ID: On 2014-08-03, Roy Smith wrote: > In article , > Mark Lawrence wrote: > >> How to go about this is at "Short, Self Contained, Correct (Compilable), >> Example" at http://sscce.org/ > > It says there, "most readers will stop reading by 100 lines of code". I > guess I have a short attention span relative to "most readers", because > my tl;dnr threshold is a lot shorter than that. Mine too. My limit is about one screen full -- how many lines that is varies, but is rarely more than 40 lines. > The other advantage to coming up with a minimal example is that often > the exercise of cutting your problem down to a minimal example is enough > to allow you to figure it out for yourself :-) That is very true. -- Grant Edwards grant.b.edwards Yow! I am NOT a nut.... at gmail.com From wolfgang.maier at biologie.uni-freiburg.de Mon Aug 4 11:43:41 2014 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Mon, 04 Aug 2014 17:43:41 +0200 Subject: cmd.exe on WIndows - problem with displaying some Unicode characters In-Reply-To: References: Message-ID: <53DFAA2D.2030009@biologie.uni-freiburg.de> On 08/04/2014 05:00 PM, Wiktor wrote: > Hi, > first, thank you all for responses. I decided to just use single line frame > around menu. Yes, those double+single line corners work fine in ConEmu, but > I don't want this Python script to be dependent on external program. Maybe > one day it will be worth of showing to others, and it's silly to tell them > 'It is pure console based game/framework but works only in ConEmu'... > > > Now, to Terry's post: > > > I'm not starting from scratch. I'm using packages 'termcolor', 'colorama' > and 'colorconsole' - they provide functions to print text at desired > position on screen, and change color of foreground/background of this text. Thanks for pointing out these packages! Since you say you're using all three of them: where do colorama and colorconsole differ. From a quick look, I can see that termcolor is a bit different, but colorama and colorconsole seem pretty similar in scope. Thanks, Wolfgang From look at signature.invalid Mon Aug 4 12:48:32 2014 From: look at signature.invalid (Wiktor) Date: Mon, 4 Aug 2014 18:48:32 +0200 Subject: cmd.exe on WIndows - problem with displaying some Unicode characters References: Message-ID: <1hdz57o67rhxx$.198mzdgo1ztk8.dlg@40tude.net> On Mon, 04 Aug 2014 17:43:41 +0200, Wolfgang Maier wrote: >> I'm not starting from scratch. I'm using packages 'termcolor', 'colorama' >> and 'colorconsole' - they provide functions to print text at desired >> position on screen, and change color of foreground/background of this text. > > Thanks for pointing out these packages! Since you say you're using all > three of them: where do colorama and colorconsole differ. From a quick > look, I can see that termcolor is a bit different, but colorama and > colorconsole seem pretty similar in scope. From colorama I just use one function - init(). Without this initialization all those ansii escape characters (used by colorama itself, but also by termcolor.colored()) don't work in cmd.exe. At least I couldn't make it work. All coloring work I make in termcolor.colored() function, because it returns string, which I can work on (store and/or send it to print_at() function later). And colorconsole is helpful with its screen.print_at() function [where screen = colorconsole.terminal.get_terminal()]. So, yes, it's matter of (probably bad) design, but now I need all three packages. Maybe if I resign from storing my colored strings, and color them just while sending them to printing function, I could get rid of colorama and termcolor... Well, thanks for asking, because now, during writing this response, I see that maybe redesign is worth of trying... Wiktor -- Best regards, Wiktor Matuszewski 'py{}@wu{}em.pl'.format('wkm', 'ka') From rosuav at gmail.com Mon Aug 4 13:06:41 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Aug 2014 03:06:41 +1000 Subject: cmd.exe on WIndows - problem with displaying some Unicode characters In-Reply-To: <1hdz57o67rhxx$.198mzdgo1ztk8.dlg@40tude.net> References: <1hdz57o67rhxx$.198mzdgo1ztk8.dlg@40tude.net> Message-ID: On Tue, Aug 5, 2014 at 2:48 AM, Wiktor wrote: > From colorama I just use one function - init(). Without this > initialization all those ansii escape characters (used by colorama itself, > but also by termcolor.colored()) don't work in cmd.exe. At least I couldn't > make it work. I dug into colorama's source code, and it seems that "just one function" is a little dismissive :) When you call colorama's init(), it replaces stdout with a wrapper that parses ANSI sequences and turns them into API calls. So, yeah, without that anything that outputs ANSI sequences isn't going to work. ChrisA From look at signature.invalid Mon Aug 4 13:22:57 2014 From: look at signature.invalid (Wiktor) Date: Mon, 4 Aug 2014 19:22:57 +0200 Subject: cmd.exe on WIndows - problem with displaying some Unicode characters References: <1hdz57o67rhxx$.198mzdgo1ztk8.dlg@40tude.net> Message-ID: On Tue, 5 Aug 2014 03:06:41 +1000, Chris Angelico wrote: > On Tue, Aug 5, 2014 at 2:48 AM, Wiktor wrote: >> From colorama I just use one function - init(). Without this >> initialization all those ansii escape characters (used by colorama itself, >> but also by termcolor.colored()) don't work in cmd.exe. At least I couldn't >> make it work. > > I dug into colorama's source code, and it seems that "just one > function" is a little dismissive :) When you call colorama's init(), > it replaces stdout with a wrapper that parses ANSI sequences and turns > them into API calls. So, yeah, without that anything that outputs ANSI > sequences isn't going to work. Maybe I didn't write it clear. :-) What I meant was, that even though I don't use any other functions from colorama (I color all the strings with termcolor) - I still have to use init() function from colorama. termcolor doesn't want to work alone, even though its described as OS independent. I guess it works fine on Linux terminal without init() function from colorama. In cmd.exe I need colorama just for this. -- Best regards, Wiktor Matuszewski 'py{}@wu{}em.pl'.format('wkm', 'ka') From v+python at g.nevcal.com Mon Aug 4 14:04:05 2014 From: v+python at g.nevcal.com (Glenn Linderman) Date: Mon, 04 Aug 2014 11:04:05 -0700 Subject: cmd.exe on WIndows - problem with displaying some Unicode characters In-Reply-To: <53DF6172.60704@my.hennepintech.edu> References: <53DEC4F5.8090805@my.hennepintech.edu> <53DED137.7080907@g.nevcal.com> <53DF08B4.20600@g.nevcal.com> <53DF14DF.3090504@my.hennepintech.edu> <53DF5665.9050408@g.nevcal.com> <53DF6172.60704@my.hennepintech.edu> Message-ID: <53DFCB15.7020407@g.nevcal.com> On 8/4/2014 3:33 AM, Andrew Berg wrote: > If you want to save your users the hassle, I would definitely > recommend a graphical environment. If I had realized that you intended your > application to be widely deployed, I would have simply recommended that from > the start. Graphical environments are good for some things, command line environments are good for other things. Unicode capability is beneficial in both. Many of the software tools I create and distribute are command line utilities, for people that use command lines anyway. The problems arise when they are multilingual, and need to use diverse character repertoires. -------------- next part -------------- An HTML attachment was scrubbed... URL: From v+python at g.nevcal.com Mon Aug 4 14:15:47 2014 From: v+python at g.nevcal.com (Glenn Linderman) Date: Mon, 04 Aug 2014 11:15:47 -0700 Subject: cmd.exe on WIndows - problem with displaying some Unicode characters In-Reply-To: <53DF5F48.201@biologie.uni-freiburg.de> References: <53DF5807.60101@g.nevcal.com> <53DF5F48.201@biologie.uni-freiburg.de> Message-ID: <53DFCDD3.7030904@g.nevcal.com> On 8/4/2014 3:24 AM, Wolfgang Maier wrote: > On 08/04/2014 11:53 AM, Glenn Linderman wrote: >> >> I've never used the API from Python but random console access is >> documented at >> http://msdn.microsoft.com/en-us/library/windows/desktop/ms687404%28v=vs.85%29.aspx >> >> > > Would using the API from Python involve doing the wrapping yourself or > do you know about an existing package for the job ? I haven't used the API from Python. I haven't checked PyWin32 to see if it already wraps that API like it wraps so many other APIs. I haven't Googled using "python" and "WriteConsoleOutput" to see if other packages may exist to do the job. But these are the things that I would do if I had a need to write a program like yours, since I know that the console does, in fact, support random access. > > By the way (and off-topic), how would you do it on Linux? Off topic? It is still about doing it using Python, no? I believe that most Unix terminal emulators, which are used for running shells and command lines, support cursor controls, and I believe most of them have a mode that emulates the DEC VT-52 terminal, one of which I had physical access to at the "computer lab" at the university I attended so many years ago. The VT-52 defined escape sequences to move the cursor around on the screen, providing random access. Text-based, screen-oriented programs such as emacs leveraged such capabilities quite effectively. There may be something better today, I haven't used Unix for a dozen years now, and the usage at that time was database development not text-based graphics. I've used Linux only on my web host, and a little experimentation on a local machine I installed it on here, until the machine died, and I didn't do any text-based graphics in either of those circumstances either. So probably college was the last time I used text-based graphics, but that was using RSTS and DECsystem 20 (forget the name of the OS for that machine) on VT-52 terminals. But I've noted with amusement that the VT-52 (and later enhanced models) are still supported by Unix/Linux terminal emulators and X system. Unix abstracts that cursor motion using "curses" and I believe there are curses implementations for Windows as well, but I've not attempted to use curses from Python on either Unix or Windows. > > Wolfgang > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Mon Aug 4 15:17:04 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 04 Aug 2014 15:17:04 -0400 Subject: cmd.exe on WIndows - problem with displaying some Unicode characters In-Reply-To: References: Message-ID: On 8/4/2014 11:00 AM, Wiktor wrote: > Yes, I'd like to make text game, that looks like window-based, with popup > boxes, inactive windows grayed out and all this stuff. And all this running > on standard console window (cmd.exe). Your problem doing this is that cmd.exe is not a standard since 30 years ago full-screen console window, , but is intentionally crippled to stop people from doing what you are trying to do. Some as MS would like to delete it altogether. > I'm not starting from scratch. I'm using packages 'termcolor', 'colorama' > and 'colorconsole' - All on pypi.python.org, I see. > they provide functions to print text at desired > position on screen, and change color of foreground/background of this text. > With those packages I already developed some classes that allow me to > construct some simple menus for my console programs. Short demo of silly > program calculating degree of n-th root: > http://youtu.be/V8ilLhHAT_k I am impressed with what the authors of those packages managed to do. > I'm taking next step, so I tried to draw nice frame around menu (that's > why I posted yesterday). Is there no working codepage with ascii text and the line chars? I suppose I am not surprised if not. > Next step would be to manage those widgets to draw one over another, to > keep track which one window opens which, and when the other window must be > closed and when only grayed out. At this point I still don't know how to do > this right, but I'm thinking about this very hard. :-) Probably one day > I'll ask it here, if I don't figure it out. :-) You may have to settle for using different background colors to delineate different boxes. -- Terry Jan Reedy From tjreedy at udel.edu Mon Aug 4 15:25:07 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 04 Aug 2014 15:25:07 -0400 Subject: cmd.exe on WIndows - problem with displaying some Unicode characters In-Reply-To: <53DF5F48.201@biologie.uni-freiburg.de> References: <53DF5807.60101@g.nevcal.com> <53DF5F48.201@biologie.uni-freiburg.de> Message-ID: On 8/4/2014 6:24 AM, Wolfgang Maier wrote: > On 08/04/2014 11:53 AM, Glenn Linderman wrote: >> >> I've never used the API from Python but random console access is >> documented at >> http://msdn.microsoft.com/en-us/library/windows/desktop/ms687404%28v=vs.85%29.aspx >> >> > > Would using the API from Python involve doing the wrapping yourself or > do you know about an existing package for the job ? The packages Wiktor is using, 'termcolor', 'colorama' and 'colorconsole' - (all on PyPI), must be using WriteConsoleOutput. -- Terry Jan Reedy From invalid at invalid.invalid Mon Aug 4 15:30:37 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 4 Aug 2014 19:30:37 +0000 (UTC) Subject: cmd.exe on WIndows - problem with displaying some Unicode characters References: <53DF5807.60101@g.nevcal.com> <53DF5F48.201@biologie.uni-freiburg.de> Message-ID: On 2014-08-04, Glenn Linderman wrote: > I believe that most Unix terminal emulators, which are used for running > shells and command lines, support cursor controls, and I believe most of > them have a mode that emulates the DEC VT-52 terminal, I'm not aware of any that are in common use, but there may be some niche VT52 emulators somewhere I don't know about. All the widely used terminal emulators are some flavor of ANSI (for you DEC guys, VT100 and later) rather than VT52. -- Grant Edwards grant.b.edwards Yow! All of life is a blur at of Republicans and meat! gmail.com From tomcsanyi at slovanet.sk Mon Aug 4 15:42:24 2014 From: tomcsanyi at slovanet.sk (Peter Tomcsanyi) Date: Mon, 4 Aug 2014 21:42:24 +0200 Subject: Tcl/Tk alpha channel bug on OSX Mavericks is fixeded, but how/when can I use the fix? In-Reply-To: References: Message-ID: Many thanks for all the answers. "Kevin Walzer" wrote in message news:lrntjm$bma$1 at dont-email.me... > Where is your current installation of Python? The above instructions > assume that you are using the standard Python from python.org. As I > mentioned before, if you have installed things via a package manager > (brew, Fink or MacPorts) you will have to follow their instructions. I use the standard Python.org installation, so I assume that it is "where it should be" (I launch IDLE from Launcher or I open .py files by righclicking them and choosing "Open in IDLE"). But it does not contain Tcl/Tk, it uses "somehow" the version of Tcl/Tk that is installed "somewhere". Actually the page: https://www.python.org/download/mac/tcltk says that it is linked dynamically and it looks at first into /Library/Frameworks. So maybe for now I have enough information and I will try your suggestions when the new Tcl/Tk will be available and ask more questions only if it would not work. Thanks Peter Tomcsanyi From tjreedy at udel.edu Mon Aug 4 15:43:49 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 04 Aug 2014 15:43:49 -0400 Subject: cmd.exe on WIndows - problem with displaying some Unicode characters In-Reply-To: References: <1hdz57o67rhxx$.198mzdgo1ztk8.dlg@40tude.net> Message-ID: On 8/4/2014 1:22 PM, Wiktor wrote: > On Tue, 5 Aug 2014 03:06:41 +1000, Chris Angelico wrote: > >> On Tue, Aug 5, 2014 at 2:48 AM, Wiktor wrote: >>> From colorama I just use one function - init(). Without this >>> initialization all those ansii escape characters (used by colorama itself, >>> but also by termcolor.colored()) don't work in cmd.exe. At least I couldn't >>> make it work. >> >> I dug into colorama's source code, and it seems that "just one >> function" is a little dismissive :) When you call colorama's init(), >> it replaces stdout with a wrapper that parses ANSI sequences and turns >> them into API calls. So, yeah, without that anything that outputs ANSI >> sequences isn't going to work. > > Maybe I didn't write it clear. :-) What I meant was, that even though I > don't use any other functions from colorama (I color all the strings with > termcolor) - I still have to use init() function from colorama. > termcolor doesn't want to work alone, even though its described as OS > independent. Termcolor says "ANSI Color formatting for output in terminal." https://pypi.python.org/pypi/termcolor/1.1.0 It is OS-independent but depends on support of standard ANSI screen command codes. Microsoft removed that support from cmd.exe. If you look at the Terminal properties box on the page above, the only thing termcolor can do on Windows, by itself, is reversed text. Colorama.init adds back (at least some of) the ANSI to API translation omitted from cmd.exe. > I guess it works fine on Linux terminal without init() Because linux terminals translate ANSI to whatever api calls are needed. > function from colorama. In cmd.exe I need colorama just for this. -- Terry Jan Reedy From rosuav at gmail.com Mon Aug 4 16:11:43 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Aug 2014 06:11:43 +1000 Subject: cmd.exe on WIndows - problem with displaying some Unicode characters In-Reply-To: References: Message-ID: On Tue, Aug 5, 2014 at 5:17 AM, Terry Reedy wrote: > Is there no working codepage with ascii text and the line chars? I suppose I > am not surprised if not. That would be codepage 437. I grew up with that on DOS, as the one and only 256-character set, and then when we moved to OS/2 and actual codepages, we always configured 437,850 (that is, 437 as primary, with 850 as a secondary if we wanted it). Trouble is, it doesn't have non-basic letters, and the OP needs to write Polish text. I'd be not at all surprised if there are characters he needs that aren't in CP437. ChrisA From look at signature.invalid Mon Aug 4 16:24:33 2014 From: look at signature.invalid (Wiktor) Date: Mon, 4 Aug 2014 22:24:33 +0200 Subject: cmd.exe on WIndows - problem with displaying some Unicode characters References: Message-ID: <1g317psebknmz.3r1n3q3igpkt.dlg@40tude.net> On Mon, 04 Aug 2014 15:17:04 -0400, Terry Reedy wrote: >> I'm taking next step, so I tried to draw nice frame around menu (that's >> why I posted yesterday). > > Is there no working codepage with ascii text and the line chars? I > suppose I am not surprised if not. With single line (???????????) and double line (???????????) - many codepages, CP852 for sure. With corners/crosses where single and double lines meet (????????? ??????????) - I know only one: CP437. But I can't have both - Polish letters and all those line chars, so I can't do this fancy frame from first post with Polish strings inside. There will be simpler version instead. -- Best regards, Wiktor Matuszewski 'py{}@wu{}em.pl'.format('wkm', 'ka') From auriocus at gmx.de Mon Aug 4 16:35:28 2014 From: auriocus at gmx.de (Christian Gollwitzer) Date: Mon, 04 Aug 2014 22:35:28 +0200 Subject: cmd.exe on WIndows - problem with displaying some Unicode characters In-Reply-To: References: Message-ID: Am 04.08.14 01:08, schrieb Chris Angelico: > On Mon, Aug 4, 2014 at 8:52 AM, Wiktor wrote: >> I have to ask - is there a way to make that original concept work? I know, >> that CP437 has symbols "?", "?" and "?", but does not have polish letters - >> and I need to display them too. > > Yeah, that's exactly the problem with codepages :) > > The best way to do it is to use the Unicode codepage, Agreed. > but cmd.exe just > plain has issues. It's not cmd.exe, it's the terminal that is shit. You can't even interactively resize the width in the standard terminal. > There are underlying Windows APIs for displaying > text that have problems with astral characters (I think that's what it > is), so ultimately, you're largely stuck. > > One option would be to render the whole thing graphically, abandoning > cmd.exe altogether. That would be how a lot of telnet and SSH clients > will do the work. Get a proper Unicode-supporting toolkit (Tkinter has > issues with astral characters too, AIUI), and yes, you'll have to do a > lot of work yourself. Tkinter only supports the BMP currently. But neither Polish nor box drawing does require more: All those box drawing symbols are in the BMP: http://www.unicode.org/charts/PDF/U2500.pdf So you could use a Tkinter text widget and put your data there - or even a simple label would do. Christian From g at boffi.net Mon Aug 4 16:53:09 2014 From: g at boffi.net (giacomo boffi) Date: Mon, 04 Aug 2014 22:53:09 +0200 Subject: cmd.exe on WIndows - problem with displaying some Unicode characters References: Message-ID: <878un40yfe.fsf@pascolo.net> Wiktor writes: > I'm not starting from scratch. I'm using packages 'termcolor', 'colorama' > and 'colorconsole' the 'urwid' package could be useful for similar projects but requires Linux, OSX, Cygwin or other unix-like OS so I guess it's of no use for you... ciao g From gordon at panix.com Mon Aug 4 18:44:09 2014 From: gordon at panix.com (John Gordon) Date: Mon, 4 Aug 2014 22:44:09 +0000 (UTC) Subject: Python Classes References: Message-ID: In Shubham Tomar writes: > classes. I understand that you define classes to have re-usable methods and > procedures, but, don't functions serve the same purpose. > Can someone please explain the idea of classes If a function simply accepts some data, does some calculations on that data and then returns a value, then you don't need classes at all. An example of this might be the square-root function: pass it any number and it calculates and returns the square root with no other data needed. But classes do come in handy for other sorts of uses. One classic example is employees at a company. Each employee has a name, ID number, salary, date of hire, home address, etc. You can create an Employee class to store those data items along with methods to manipulate those data items in interesting ways. The data items are specific to each separate Employee object, and the methods are shared among the entire class. > Can someone please explain what *things *like "__init__", "Object" > and "self" mean ? __init__() is the initializer method, which is called as one step of creating a class object. Object is the lowest-level class. All other classes inherit from Object. Within a class, self is a reference to the current class instance. -- 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 cs at zip.com.au Mon Aug 4 19:22:02 2014 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 5 Aug 2014 09:22:02 +1000 Subject: Davis putnam algorithm for satisfiability... In-Reply-To: <8aceb6af-9b72-4e14-8d3e-8e6aea83fa69@googlegroups.com> References: <8aceb6af-9b72-4e14-8d3e-8e6aea83fa69@googlegroups.com> Message-ID: <20140804232202.GA841@cskk.homeip.net> On 04Aug2014 04:51, varun7rs at gmail.com wrote: >I have some trouble understanding the davis putnam algorithm for >satisfiability. I understood most of the code but I don't know where exactly >backtracking is happening here. Your assistance would be very helpful to me. At a glance, in the bottom part of the sat(cnf) function. The top part of the function performs some simple operations and possibly returns. The bottom part, executed if the earlier code does not return, copies cnf to deep_copy, removes list2 from deep_copy and -list2 from cnf, and runs the sat() function on each. To my mind, that constitutes a backtrack: back up, and try a different way (on the modified cnf and deep_copy). Cheers, Cameron Simpson >import sys >import math >import copy > > >final_list = [] > >def sat(cnf): > while( len(cnf) > 1 ): > in_item = single_clause(cnf) #in_item: the first single_clause in cnf > if in_item != None: > del_sat(cnf, in_item) > else: > break > > for i in cnf: > if len(i) == 0: > cnf.remove(i) > return > > if len(cnf) == 1: > final_list.extend( [cnf[0][0]] ) # like a watchlist > for i in range(0, len(final_list)): > if final_list[i] > 0: > print "Not equivalent!" > sys.exit(0) > return final_list > > deep_copy = copy.deepcopy(cnf) > list2 = cnf[0][0] > del_sat(deep_copy,list2) # recursion to delete and then find another way and the proceed or delete more like a tree > sat(deep_copy) > > del_sat(cnf,-list2) > sat(cnf) > return > >def parseXml(file_1, file_2): > global cnf > readfile_1 = open(file_1, "r") > readfile_2 = open(file_2, "r") > > sum_a = int(readfile_1.readline()) > sum_b = int(readfile_2.readline()) > > inputs_1 = readfile_1.readline().split() > inputs_1.sort() > inputs_2 = readfile_2.readline().split() > inputs_2.sort() > > outputs_1 = readfile_1.readline().split() > outputs_1.sort() > outputs_2 = readfile_2.readline().split() > outputs_2.sort() > > inputmap_1 = {} > inputmap_2 = {} > outputmap_1 = [] > outputmap_2 = [] > > while True: > line = readfile_1.readline().strip() > if not line: > break > net,item = line.split() > inputmap_1[item] = int(net) > > while True: > line = readfile_2.readline().strip() > if not line: > break > net,item = line.split() > inputmap_2[item] = int(net) > > #print inputmap_2 > > for line in readfile_1.readlines(): > inp1 = line.split() > gate = inp1.pop(0) > mapping = map(int, inp1) > outputmap_1.extend([(gate, mapping)]) > > print 'outputmap_1' > print outputmap_1 > > for line in readfile_2.readlines(): > inp2 = line.split() > gate = inp2.pop(0) > mapping = map(int, inp2) > outputmap_2.extend([(gate, mapping)]) > > return inputs_1, inputs_2, outputs_1, outputs_2, inputmap_1, inputmap_2, outputmap_1, outputmap_2 > >def single_clause(cnf): > for i in cnf: > if len(i) == 1: > return i[0] > return None > >def del_sat(cnf,in_item): > cnf2 = cnf[:] > for k in cnf2: > if k.count(in_item): > cnf.remove(k) > for i in cnf: > if i.count( -in_item): > i.remove(-in_item) > > >def cnf_out(miter): > miter_len = len(miter) > cnf = [] > while (miter_len > 0): > x = miter.pop(0) > if ( x[0] == "and" ): > cnf.extend( [[x[1][0], -x[1][2]]] ) > cnf.extend( [[x[1][1], -x[1][2]]] ) > cnf.extend( [[-x[1][0], -x[1][1], x[1][2]]] ) > elif ( x[0] == "or" ): > cnf.extend( [[x[1][0], x[1][1], -x[1][2]]] ) > cnf.extend( [[-x[1][0], x[1][2]]] ) > cnf.extend( [[-x[1][1], x[1][2]]] ) > elif ( x[0] == "xor" ): > cnf.extend( [[x[1][0], x[1][1], -x[1][2]]] ) > cnf.extend( [[-x[1][0], -x[1][1], -x[1][2]]] ) > cnf.extend( [[-x[1][0], x[1][1], x[1][2]]] ) > cnf.extend( [[x[1][0], -x[1][1], x[1][2]]] ) > else: > cnf.extend( [[x[1][0], x[1][1]]] ) > cnf.extend( [[-x[1][0], -x[1][1]]] ) > miter_len = miter_len - 1 > > return cnf > > > >inputs_1, inputs_2, outputs_1, outputs_2, inputmap_1, inputmap_2, outputmap_1, outputmap_2 = parseXml(sys.argv[1], sys.argv[2]) > >incoming1=[] >incoming2=[] >outgoing1=[] >outgoing2=[] > >for i in inputs_1: > incoming1.extend([inputmap_1[i]]) > >for j in inputs_2: > incoming2.extend([inputmap_2[j]]) > >for k in outputs_1: > outgoing1.extend([inputmap_1[k]]) > >for l in outputs_2: > outgoing2.extend([inputmap_2[l]]) > >gate_num = 0 >for output in outputmap_1: > for j in output[1]: > if gate_num < j: > gate_num = j # gate_num: first line of netlist file. Total number of nets always need max no.. > >map2 = outputmap_2 > >num = len( map2 ) #No. of gates in netlist 2 > >for i in range(1, num + 1): > > j = len( map2[i-1][1] ) # Total No. of inputs and outputs of a gate > for k in range(0, j): > if map2[i-1][1][k] not in incoming2: > total = 0 > for l in incoming2: > if map2[i-1][1][k] > l: > total = total + 1 # Total no. of nets minus total no. of input nets like an offset > map2[i-1][1][k] = map2[i-1][1][k] + gate_num - total > > > else: > x = incoming2.index( map2[i-1][1][k] ) > map2[i-1][1][k] = incoming1[x] > >miter = outputmap_1 >miter.extend(map2) #Combine gate lists of the two netlists to 'miter' > >out_len = len(outgoing1) #No. of outputs from each netlist (netlist1's out_len should be equal to netlist2's) >for i in range(out_len): > total = 0 > for j in incoming2: # e.g: incoming2 = [1,2] > if outgoing2[i] > j: # e.g outgoing2 = [10] > total = total + 1 # should be the size of incoming2 > > outgoing2[i] = outgoing2[i] + gate_num - total > xor_gate = [( 'xor', [outgoing1[i], outgoing2[i], 9000+i] )] > miter.extend(xor_gate) > >if out_len > 1: > or_gate_1 = [( 'or', [9000, 9000+1, 9000 + out_len] )] > miter.extend(or_gate_1) > for i in range(out_len - 2): > or_gate=[( 'or', [9000 + out_len + i, 9000 +i + 2, 9000 + i + out_len + 1] )] > miter.extend(or_gate) # 9000 just a random no. for the no. of nets used in order to prevent overlap of two nos. > > >built_cnf = cnf_out(miter) >count = 0 >built_len = len(built_cnf) >for i in range(0, built_len): > built_leni = len(built_cnf[i]) > for j in range(0, built_leni): > if abs( built_cnf[i][j] ) > count: #count is the total number of nets in the miter circuit > count = abs( built_cnf[i][j]) > > >value = sat(built_cnf) >print value >print "Equivalent!" >-- >https://mail.python.org/mailman/listinfo/python-list From tjreedy at udel.edu Mon Aug 4 19:26:20 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 04 Aug 2014 19:26:20 -0400 Subject: Python Classes In-Reply-To: References: Message-ID: On 8/4/2014 6:44 PM, John Gordon wrote: > __init__() is the initializer method, which is called as one step of > creating a class object. In fact, it is the last step and usually is the main step for user-defined classes, and the only step one need be concerned with. > Object is the lowest-level class. All other classes inherit from Object. The spelling is 'object', with lowercase 'o'. 'Object' would have been less confusing, but all other builtin classes, are lowercase (some because they started as functions in Python 1.0 or soon thereafter). > Within a class, self is a reference to the current class instance. This is only true within a method definition and only when 'self' is given as the first parameter name. class C: def meth_standard(self, other): pass # 'self' is an object of class C, 'other' to any other object. # Using 'self' is not required, but is the standard convention. def meth_brief(s, o): pass # 's' refers to an instance of class C, 'o' to any other object # ok for quick interactive use that one keeps private def meth_obnoxious(other, self): pass # 'other' is an instance of C, 'self' is any object # Anyone who publishes such code, except to illustrate trollish # behavior, is fishing for heated responses. -- Terry Jan Reedy From cs at zip.com.au Mon Aug 4 19:04:03 2014 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 5 Aug 2014 09:04:03 +1000 Subject: try/exception - error block In-Reply-To: References: Message-ID: <20140804230403.GA77490@cskk.homeip.net> On 03Aug2014 10:39, Roy Smith wrote: >In article , > bruce wrote: >> I'm posting the test code I'm using. Pointers/comments would be >> helpful/useful. > >It would be really helpful if you could post a minimal code example >which demonstrates the problem you're having. Leave out everything >(including the commented-out code) which isn't necessary to demonstrate >the behavior. Just FYI, Bruce posted an earlier version of this question to users at lists.fedoraproject.org in late July, wondering why he didn't get a good error message in the abrt logs. I asked then where the stderr of his python subprocess went, but never heard back. Cheers, Cameron Simpson Reality is that which refuses to go away when I stop believing in it. - Phillip K. Dick From 4kir4.1i at gmail.com Mon Aug 4 20:51:15 2014 From: 4kir4.1i at gmail.com (Akira Li) Date: Tue, 05 Aug 2014 04:51:15 +0400 Subject: cmd.exe on WIndows - problem with displaying some Unicode characters References: <1g317psebknmz.3r1n3q3igpkt.dlg@40tude.net> Message-ID: <8738dbep30.fsf@gmail.com> Wiktor writes: > On Mon, 04 Aug 2014 15:17:04 -0400, Terry Reedy wrote: > >>> I'm taking next step, so I tried to draw nice frame around menu (that's >>> why I posted yesterday). >> >> Is there no working codepage with ascii text and the line chars? I >> suppose I am not surprised if not. > > With single line (???????????) and double line (???????????) - many > codepages, CP852 for sure. > > With corners/crosses where single and double lines meet (????????? > ??????????) - I know only one: CP437. > > But I can't have both - Polish letters and all those line chars, so I > can't do this fancy frame from first post with Polish strings inside. There > will be simpler version instead. Unicode has line drawing characters [1]. win_unicode_console [2] allows to print Unicode in cmd.exe. win_unicode_console and colorama will probably conflict. You could look at the source to see how hard to combine both functionalities. [1] http://en.wikipedia.org/wiki/Box-drawing_character [2] https://pypi.python.org/pypi/win_unicode_console btw, blessings [3] provides an easy-to-use interface if you need to add colors and move text in a terminal. It claims that it also supports colors on Windows if used with colorama. [3] https://pypi.python.org/pypi/blessings/ -- Akira From satishmlwizpro at gmail.com Tue Aug 5 01:47:51 2014 From: satishmlwizpro at gmail.com (Satish ML) Date: Mon, 4 Aug 2014 22:47:51 -0700 (PDT) Subject: TypeError: 'bytes' object is not callable error while trying to converting to bytes. Message-ID: <02baad14-39b1-41a0-a47d-28772c97ea54@googlegroups.com> Hi, >>>import struct >>>file = open('data.bin', 'rb') >>>bytes = file.read() >>> records = [bytes([char] * 8) for char in b'spam'] Traceback (most recent call last): File "", line 1, in records = [bytes([char] * 8) for char in b'spam'] File "", line 1, in records = [bytes([char] * 8) for char in b'spam'] TypeError: 'bytes' object is not callable If we code something like given below, it works. >>> records = [([char] * 8) for char in b'spam'] >>> records [[115, 115, 115, 115, 115, 115, 115, 115], [112, 112, 112, 112, 112, 112, 112, 112], [97, 97, 97, 97, 97, 97, 97, 97], [109, 109, 109, 109, 109, 109, 109, 109]] Could you kindly help me resolve this problem of converting to bytes? From ben+python at benfinney.id.au Tue Aug 5 01:57:13 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 05 Aug 2014 15:57:13 +1000 Subject: TypeError: 'bytes' object is not callable error while trying to converting to bytes. References: <02baad14-39b1-41a0-a47d-28772c97ea54@googlegroups.com> Message-ID: <85r40vbhs6.fsf@benfinney.id.au> Satish ML writes: > >>>import struct > >>>file = open('data.bin', 'rb') Here you re-bind the name ?file? to the return value from that call. > >>>bytes = file.read() Here you re-bind the name ?bytes? to the return value from that call. > >>> records = [bytes([char] * 8) for char in b'spam'] Here you attempt to call ?bytes?, which (as the error says) is not callable. You should choose names which are not already bound:: in_file = open('data.bin', 'rb') in_file_content = in_file.read() records = [bytes([char] * 8) for char in in_file_content] When choosing names, try to communicate the *purpose* of the value, its semantic meaning. The type should be of secondary importance, and almost always should not be part of the name. -- \ ?Institutions will try to preserve the problem to which they | `\ are the solution.? ?Clay Shirky, 2012 | _o__) | Ben Finney From rosuav at gmail.com Tue Aug 5 01:57:32 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Aug 2014 15:57:32 +1000 Subject: TypeError: 'bytes' object is not callable error while trying to converting to bytes. In-Reply-To: <02baad14-39b1-41a0-a47d-28772c97ea54@googlegroups.com> References: <02baad14-39b1-41a0-a47d-28772c97ea54@googlegroups.com> Message-ID: On Tue, Aug 5, 2014 at 3:47 PM, Satish ML wrote: >>>>bytes = file.read() You've just shadowed the built-in type 'bytes' with your own 'bytes'. Pick a different name for this, and you'll be fine. 'data' would work. ChrisA From dieter at handshake.de Tue Aug 5 02:37:11 2014 From: dieter at handshake.de (dieter) Date: Tue, 05 Aug 2014 08:37:11 +0200 Subject: Python Classes References: Message-ID: <87zjfjwig8.fsf@handshake.de> Shubham Tomar writes: > Python is the first programming language that I'm learning. > I'm confused by the idea of classes and intimidated by syntax defining > classes. I understand that you define classes to have re-usable methods and > procedures, but, don't functions serve the same purpose. As often, you may have building blocks at various levels. Thinks of a house - you can build it from individual stones or have large prefabricated parts. Something similar is true with functions and classes. A function is a building block at some level. However, often, you deal not with individual unrelated functions but with a set of related functions designed together. In simple cases, those functions can be collected in a library or a module (Python's "math" module is such an example - containing many interesting "mathematical" functions). In other (slightly more complicated) cases, the relation between the functions is that they all work on the same "object". Those "object"s can be almost anything. An example would be a "window" on your desktop screen. It can be closed, resized, moved around, ... Or a "geometric object" in a drawing application - with operations "delete", "move", "resized", "extend", ... In those cases, it can be helpful to view the object (its data) and the functions operating on it (such as "move", "resize", ...) as a higher level building block -- and this leads to classes. A "class" (in Python) is a collection of related functions (called "method"s) and potentially data definitions (this part is quite weak for Python classes; unlike in other languages, the data part of a class is not stated explicitely at the top class level, but usually indirectly in the so called constructor ("__init__")). Most of these functions operate on the same data. Data and functions together are called an "object" and the "class" defines a set of objects of some common kind: "window"s, "date"s, "server"s, "geometric object"s ... This higher level building block can facilitate the construction of many applications. From harish.chilkoti at gmail.com Tue Aug 5 05:18:11 2014 From: harish.chilkoti at gmail.com (harish.chilkoti at gmail.com) Date: Tue, 5 Aug 2014 02:18:11 -0700 (PDT) Subject: how to fix python logging to not log to stderr Message-ID: I am doing this logging.basiConfig(logleve=Logging.Info) then i create a file log handler and attach to it. i also have propagate as True. My logs are going to the stderr as well. How do i fix so that logs don't go to stdout? From look at signature.invalid Tue Aug 5 05:39:15 2014 From: look at signature.invalid (Wiktor) Date: Tue, 5 Aug 2014 11:39:15 +0200 Subject: cmd.exe on WIndows - problem with displaying some Unicode characters References: <1g317psebknmz.3r1n3q3igpkt.dlg@40tude.net> Message-ID: On Tue, 05 Aug 2014 04:51:15 +0400, Akira Li wrote: > Unicode has line drawing characters [1]. win_unicode_console [2] allows > to print Unicode in cmd.exe. win_unicode_console and colorama will > probably conflict. You could look at the source to see how hard to > combine both functionalities. > > [1] http://en.wikipedia.org/wiki/Box-drawing_character > [2] https://pypi.python.org/pypi/win_unicode_console > > btw, blessings [3] provides an easy-to-use interface if you need to add > colors and move text in a terminal. It claims that it also supports > colors on Windows if used with colorama. > > [3] https://pypi.python.org/pypi/blessings/ [2] - indeed does not work with colorconsole/colorama. And I'm not that smart to combine those two functionalities. :-) [3] - maybe it works with colorama (colorama for coloring, and blessing for positioning text), but now I don't even use colorama. I use colorconsole to color AND position text, and I find it very handy. Don't think that blessing+colorama would be more easy-to-use. Thanks, I really appreciate every proposition to fix original problem you all are giving me - I check them all. But you need to understand, that I'm already OK with those cmd.exe limitations, and really not trying to achieve look of frame from first post. I'm OK with those single-only and double-only lines. Now my game would look like this: https://dl.dropboxusercontent.com/u/10544563/kolony_prntscr.png [*] and I think it's very neat. Wiktor *) it's mocup (I don't have 'window manager' yet, so I have to show/ activate/deactivate/etc. every window by hand), but still -- Best regards, Wiktor Matuszewski 'py{}@wu{}em.pl'.format('wkm', 'ka') From a.nandagoban at traxens.com Tue Aug 5 05:45:27 2014 From: a.nandagoban at traxens.com (Arulnambi Nandagoban) Date: Tue, 5 Aug 2014 11:45:27 +0200 Subject: how to fix python logging to not log to stderr In-Reply-To: References: Message-ID: <000f01cfb091$fd43cfe0$f7cb6fa0$@traxens.com> -----Message d'origine----- De?: Python-list [mailto:python-list-bounces+a.nandagoban=traxens.com at python.org] De la part de harish.chilkoti at gmail.com Envoy??: Tuesday, August 5, 2014 11:18 AM ??: python-list at python.org Objet?: how to fix python logging to not log to stderr I am doing this logging.basiConfig(logleve=Logging.Info) then i create a file log handler and attach to it. i also have propagate as True. My logs are going to the stderr as well. How do i fix so that logs don't go to stdout? -- https://mail.python.org/mailman/listinfo/python-list hello, remove logging.basiConfig, it won't print log in stdout From a.nandagoban at traxens.com Tue Aug 5 05:43:35 2014 From: a.nandagoban at traxens.com (Arulnambi Nandagoban) Date: Tue, 5 Aug 2014 11:43:35 +0200 Subject: creating log file with Python logging module In-Reply-To: References: <003d01cfafe2$e0668ac0$a133a040$@traxens.com> Message-ID: <000d01cfb091$ba2ea7c0$2e8bf740$@traxens.com> -----Message d'origine----- De?: Python-list [mailto:python-list-bounces+a.nandagoban=traxens.com at python.org] De la part de Peter Otten Envoy??: Monday, August 4, 2014 4:03 PM ??: python-list at python.org Objet?: Re: creating log file with Python logging module Peter Otten wrote: > Peter Otten wrote: > >> You won't see a rollover if you restart it. > > Sorry, I tried it and the above statement is wrong. [Arulnambi Nandagoban] > logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - > %(message)s', datefmt='%a, %d %b %Y %H:%M:%S', level = logging.DEBUG, > filename=Ffilename, filemode='w') > > logger = logging.getLogger(__name__) > > hdlr = TimedRotatingFileHandler(Ffilename, when='midnight') My alternative theory about what might be going wrong: you are using the same file in logging.basicConfig() and the TimedRotatingFileHandler. But I cannot replicate the problem on my (linux) system. -- https://mail.python.org/mailman/listinfo/python-list Hello, Thank you for response !!! -- Config.py: import logging from logging.handlers import TimedRotatingFileHandler import os import time logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', datefmt='%a, %d %b %Y %H:%M:%S') logHandler = TimedRotatingFileHandler(Ffilename,when="D") logFormatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s', datefmt='%a, %d %b %Y %H:%M:%S') logHandler.setFormatter( logFormatter ) logger = logging.getLogger(__name__ ) logger.addHandler( logHandler ) logger.setLevel( logging.DEBUG ) The above code works according to my need that is, - print log in console as well as save log in a file every day By adding logging.basicConfig, log is printed in both console and saved in log file. -- nambi From bblais at gmail.com Tue Aug 5 07:36:17 2014 From: bblais at gmail.com (Brian Blais) Date: Tue, 5 Aug 2014 07:36:17 -0400 Subject: 3 Suggestions to Make Python Easier For Children In-Reply-To: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> Message-ID: On Sat, Aug 2, 2014 at 2:45 AM, Mark Summerfield wrote: > Last week I spent a couple of days teaching two children (10 and 13 -- too big an age gap!) how to do some turtle graphics with Python. Neither had programmed Python before -- one is a Minecraft ace and the other had done Scratch. When I've taught children (and adults!) with little programming experience, I usually have a single import for all the things I want them to use, something like: from my_defined_functions import * at the beginning of every script, usually named for the class I'm teaching. > > Suggestion #1: Make IDLE start in the user's home directory. I use the iPython Notebook now for these things. > > Suggestion #2: Make all the turtle examples begin "from turtle import *" so no leading turtle. is needed in the examples. > in my universal import script I have the turtle imports, usually with both from turtle import * and import turtle, so I have a choice. > Suggestion #3: Make object(key=value, ...) legal and equiv of types.SimpleNamespace(key=value, ...). I also make a data structure, a simple wrapper around dict, which I call Struct, defined as: class Struct(dict): def __getattr__(self,name): try: val=self[name] except KeyError: val=super(Struct,self).__getattribute__(name) return val def __setattr__(self,name,val): self[name]=val then I can do: x=Struct(a=5,b=10) x.c=50 x['this']='that' # or access like a dict bb ----------------- bblais at gmail.com http://web.bryant.edu/~bblais From duncan.booth at invalid.invalid Tue Aug 5 07:57:55 2014 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 5 Aug 2014 11:57:55 GMT Subject: eval [was Re: dict to boolean expression, how to?] References: <53db8bd8$0$2976$e4fe514c@news2.news.xs4all.nl> <53dba39e$0$2976$e4fe514c@news2.news.xs4all.nl> <53dc5407$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Consider the namedtuple implementation in the standard library. > There's a lot of criticism of it, some of it justified. It uses exec > extensively, which means the code is dominated by a giant string > template. This defeats your editor's syntax colouring, makes > refactoring harder, and makes how the namedtuple works rather less > understandable. It seems to me that it's only generating the __new__ > method which genuinely needs to use exec, the rest of the namedtuple > could and should use just an ordinary class object (although I concede > that some of this is just a matter of personal taste). > > Raymond Hettinger's original, using exec for the entire inner class: > > http://code.activestate.com/recipes/500261-named-tuples/ > > > My refactoring, with the bare minimum use of exec necessary: > > https://code.activestate.com/recipes/578918-yet-another-namedtuple/ This may be a silly question, but what would stop you moving the exec inside the class? So: ns = {'_new': tuple.__new__} class Inner(tuple): # Work around for annoyance: type __doc__ is read-only :-( __doc__ = ("%(typename)s(%(argtxt)s)" % {'typename': typename, 'argtxt': argtxt}) __slots__ = () _fields = field_names exec """def __new__(_cls, %(argtxt)s): return _new(_cls, (%(argtxt)s))""" % { 'argtxt': argtxt } in ns, locals() ... and so on ... and remove lines from 'ns = ...' to 'Inner.__new__ = ...' The tests at the end of the file still pass so I'm not sure whether there is any situation that wouldn't work. For that matter I don't understand why tuple.__new__ needs to be pre-bound. Just referring to tuple.__new__ directly in the exec simplifies things even more as there is no need to specify any namespaces. exec """def __new__(_cls, %(argtxt)s): return tuple.__new__(_cls, (%(argtxt)s))""" % { 'argtxt': argtxt } also passes the tests. -- Duncan Booth From marko at pacujo.net Tue Aug 5 08:04:27 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 05 Aug 2014 15:04:27 +0300 Subject: 3 Suggestions to Make Python Easier For Children References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> Message-ID: <87k36nxhv8.fsf@elektro.pacujo.net> Brian Blais : > class Struct(dict): > > def __getattr__(self,name): > > try: > val=self[name] > except KeyError: > val=super(Struct,self).__getattribute__(name) > > return val > > def __setattr__(self,name,val): > > self[name]=val Cool. I wonder if that should be built into dict. Why can't I have: >>> d = {} >>> d.x = 3 >>> d {'x': 3} Marko From nicholascannon1 at gmail.com Tue Aug 5 08:15:35 2014 From: nicholascannon1 at gmail.com (Nicholas Cannon) Date: Tue, 5 Aug 2014 05:15:35 -0700 (PDT) Subject: Tkinter menu crash Message-ID: <1a31faea-eea6-4b1d-8dc1-185f13348621@googlegroups.com> Ok so the first part of the program(until the start of the menu) worked fine. It ran and did what I wanted it to do. I wanted to then implement a new menu(for practise) and then it crashes. Don't know why but it just crashes. (also tips on the code will be appreciated and I gave just started Tkinter programming) Here is the code: from Tkinter import * import tkMessageBox as tm def submit(): #message box with yes no tm.askyesno(title='Submit Text', message='Are you sure....') def info(): tm.showinfo(title='About', message='Just a test Tkinter UI sample') #getting the text from the entrybox and #packs it into a label mtext = text.get() label1 = Label(app, text=mtext) label1.pack() #root window setup root = Tk() root.geometry('480x480+200+200') root.title('Basic Tk UI') #frame set up app = Frame(root) app.pack() #variable and entry box set up text = StringVar() entry = Entry(app, textvariable=text) entry.pack() #button set up button1 = Button(app, text='Submit text', command= submit) button1.pack() #menu construction menubar = Menu(root) filemenu = Menu(menubar) filemenu.add_command(label='About', command= info) filemenu.add_command(label='Quit', command= root.destroy) filemenu.add_cascade(label='TK UI Sample', menu=filemenu) root.config(menu=menubar) #loop to listen for events root.mainloop() From danwgrace at gmail.com Tue Aug 5 08:15:41 2014 From: danwgrace at gmail.com (danwgrace at gmail.com) Date: Tue, 5 Aug 2014 05:15:41 -0700 (PDT) Subject: How to pack a string variable of length 1 as a char using struct.pack? Message-ID: <64a5643f-a144-4292-9969-9f1743c40ad7@googlegroups.com> Hi, How to pack a string variable of length 1 as a char using struct.pack? The following works fine: p = struct.pack('c', b'1') Whereas this causes an error "char format requires a bytes object of length 1": s = '1' p = struct.pack('c', s) I need to pack a variable rather than a literal. Thanks. From steve+comp.lang.python at pearwood.info Tue Aug 5 08:28:13 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 05 Aug 2014 22:28:13 +1000 Subject: How to pack a string variable of length 1 as a char using struct.pack? References: <64a5643f-a144-4292-9969-9f1743c40ad7@googlegroups.com> Message-ID: <53e0cdde$0$29992$c3e8da3$5496439d@news.astraweb.com> danwgrace at gmail.com wrote: > Hi, > How to pack a string variable of length 1 as a char using struct.pack? > The following works fine: > p = struct.pack('c', b'1') Here you use a byte string of length 1, b'1'. > Whereas this causes an error "char format requires a bytes object of > length 1": > s = '1' > p = struct.pack('c', s) Here you use a Unicode string of length 1, '1'. Do this instead: s = b'1' p = struct.pack('c', s) -- Steven From skip at pobox.com Tue Aug 5 08:31:05 2014 From: skip at pobox.com (Skip Montanaro) Date: Tue, 5 Aug 2014 07:31:05 -0500 Subject: 3 Suggestions to Make Python Easier For Children In-Reply-To: <87k36nxhv8.fsf@elektro.pacujo.net> References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87k36nxhv8.fsf@elektro.pacujo.net> Message-ID: On Tue, Aug 5, 2014 at 7:04 AM, Marko Rauhamaa wrote: > > I wonder if that should be built into dict. Short answer, no. I'm sure it's been proposed before. Attributes ? keys. When you see something.somethingelse anywhere else in Python, "somethingelse" is an attribute reference. When you see something[somethingelse], "somethingelse" is an index value or key. Why destroy that symmetry in dictionaries? JavaScript objects have that feature. I find it mildly confusing because whenever I see it I have to pause to consider whether the name I am looking at is an attribute or a key. This little JS code I just typed at my console prompt was also mildly surprising: > var x = {}; undefined > x.valueOf(47) Object {} > x["valueOf"] = 12 12 > x.valueOf 12 > x.valueOf(47) TypeError: number is not a function Still, in my own JS code I tend to lapse into that usage, probably because so much other code out in the wild uses dot notation for key references. (Doesn't make it right, just makes me lazy.) Skip From thomas at orozco.fr Tue Aug 5 08:30:24 2014 From: thomas at orozco.fr (Thomas Orozco) Date: Tue, 5 Aug 2014 14:30:24 +0200 Subject: How to pack a string variable of length 1 as a char using struct.pack? In-Reply-To: <64a5643f-a144-4292-9969-9f1743c40ad7@googlegroups.com> References: <64a5643f-a144-4292-9969-9f1743c40ad7@googlegroups.com> Message-ID: On Tue, Aug 5, 2014 at 2:15 PM, wrote: > Hi, > How to pack a string variable of length 1 as a char using struct.pack? > The following works fine: > p = struct.pack('c', b'1') > > Whereas this causes an error "char format requires a bytes object of > length 1": > s = '1' > p = struct.pack('c', s) > > I need to pack a variable rather than a literal. > I assume you are using Python 3. In Python 3, s = '1' is a *unicode string*, not a *bytes object*. You need to convert your string to a bytes object by encoding it. However, be mindful that some characters may actually require multiple bytes to be encoded: struct.pack('c', s.encode('ascii')) (You can of course use e.g. 'utf-8' as the encoding here) -------------- next part -------------- An HTML attachment was scrubbed... URL: From jprashanthan at gmail.com Tue Aug 5 06:19:22 2014 From: jprashanthan at gmail.com (J Prashanthan) Date: Tue, 5 Aug 2014 03:19:22 -0700 Subject: Python-list Digest, Vol 131, Issue 6 Message-ID: <7548489623772708614@unknownmsgid> Sent from my Windows Phone From: python-list-request at python.org Sent: ?05-?08-?2014 15:37 To: python-list at python.org Subject: Python-list Digest, Vol 131, Issue 6 Send Python-list mailing list submissions to python-list at python.org To subscribe or unsubscribe via the World Wide Web, visit https://mail.python.org/mailman/listinfo/python-list or, via email, send a message with subject or body 'help' to python-list-request at python.org You can reach the person managing the list at python-list-owner at python.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Python-list digest..." From steve+comp.lang.python at pearwood.info Tue Aug 5 08:43:12 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 05 Aug 2014 22:43:12 +1000 Subject: 3 Suggestions to Make Python Easier For Children References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87k36nxhv8.fsf@elektro.pacujo.net> Message-ID: <53e0d161$0$29979$c3e8da3$5496439d@news.astraweb.com> Marko Rauhamaa wrote: > Why can't I have: > > >>> d = {} > >>> d.x = 3 > >>> d > {'x': 3} Because it's horrible and a bad idea. d = {'this': 23, 'word': 42, 'frog': 2, 'copy': 15, 'lunch': 93} e = d.copy() Traceback (most recent call last): File "", line 1, in ? TypeError: 'int' object is not callable Conflating keys in a database with object attributes is one of the classic blunders, like getting involved in a land war in Asia. It is, *maybe*, barely acceptable as a quick-and-dirty convenience at the interactive interpreter, in a Bunch or Bag class that has very little in the way of methods or behaviour, but not acceptable for a class as fundamental and important as dict. No matter what Javascript thinks. Consider: d['something else'] = 1 d.something else d.something else ^ SyntaxError: invalid syntax -- Steven From rosuav at gmail.com Tue Aug 5 09:00:56 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Aug 2014 23:00:56 +1000 Subject: 3 Suggestions to Make Python Easier For Children In-Reply-To: References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87k36nxhv8.fsf@elektro.pacujo.net> Message-ID: On Tue, Aug 5, 2014 at 10:31 PM, Skip Montanaro wrote: > JavaScript objects have that feature. I find it mildly confusing > because whenever I see it I have to pause to consider whether the name > I am looking at is an attribute or a key. This little JS code I just > typed at my console prompt was also mildly surprising: > >> var x = {}; > undefined >> x.valueOf(47) > Object {} >> x["valueOf"] = 12 > 12 >> x.valueOf > 12 >> x.valueOf(47) > TypeError: number is not a function This is partly a consequence of prototype-based inheritance; x.valueOf will shadow Object.valueOf. Pike allows a similar "dot or square brackets" notation, but at the expense of not having any methods on the mapping type itself: Pike v8.0 release 3 running Hilfe v3.5 (Incremental Pike Frontend) > mapping a=([]); > a.foo="bar"; (1) Result: "bar" > a.foo; (2) Result: "bar" > a; (3) Result: ([ /* 1 element */ "foo": "bar" ]) Since mappings (broadly equivalent to Python dicts) can't have methods, anything that Python does as a method, Pike has to do as a stand-alone function. (Swings and roundabouts, though, as those functions tend to also accept other types, so they're more akin to Python's len() than dict.pop().) Every design decision has a cost. The convenience of short-handing mapping lookup is pretty handy (especially when you're digging into deeply-nested mappings - imagine parsing an XML or JSON message and then reaching into it for one specific thing), but it means there are functions rather than methods for working with them. Take your pick. ChrisA From rosuav at gmail.com Tue Aug 5 09:08:34 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Aug 2014 23:08:34 +1000 Subject: 3 Suggestions to Make Python Easier For Children In-Reply-To: <53e0d161$0$29979$c3e8da3$5496439d@news.astraweb.com> References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87k36nxhv8.fsf@elektro.pacujo.net> <53e0d161$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Aug 5, 2014 at 10:43 PM, Steven D'Aprano wrote: > Because it's horrible and a bad idea. > > d = {'this': 23, 'word': 42, 'frog': 2, 'copy': 15, 'lunch': 93} > e = d.copy() > > Traceback (most recent call last): > File "", line 1, in ? > TypeError: 'int' object is not callable > > > Conflating keys in a database with object attributes is one of the classic > blunders, like getting involved in a land war in Asia. It is, *maybe*, > barely acceptable as a quick-and-dirty convenience at the interactive > interpreter, in a Bunch or Bag class that has very little in the way of > methods or behaviour, but not acceptable for a class as fundamental and > important as dict. No matter what Javascript thinks. It's not fundamentally bad, just fundamentally incompatible with any other use of methods. Really, what you're pointing out isn't so much a problem with conflating keys and attributes as it is with using attributes for two purposes: key lookup, and method lookup. And that's *always* going to be a bad thing. Imagine this class: class BadDict(dict): def __getitem__(self, key): if key == 'copy': return self.copy return super().__getitem__(key) Now I've just gone the other way - overloading square brackets to sometimes mean key lookup, and sometimes attribute lookup. And it's the two meanings on one notation, not the two notations for one meaning, that's the bad idea. ChrisA From marko at pacujo.net Tue Aug 5 09:19:48 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 05 Aug 2014 16:19:48 +0300 Subject: 3 Suggestions to Make Python Easier For Children References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87k36nxhv8.fsf@elektro.pacujo.net> Message-ID: <87fvhbxedn.fsf@elektro.pacujo.net> Skip Montanaro : > On Tue, Aug 5, 2014 at 7:04 AM, Marko Rauhamaa wrote: >> I wonder if that should be built into dict. > > Short answer, no. I'm sure it's been proposed before. Attributes ? > keys. When you see something.somethingelse anywhere else in Python, > "somethingelse" is an attribute reference. When you see > something[somethingelse], "somethingelse" is an index value or key. > Why destroy that symmetry in dictionaries? I'm not sure I fully appreciate the dichotomy (which you euphemistically refer to as symmetry). > JavaScript objects have that feature. I find it mildly confusing > because whenever I see it I have to pause to consider whether the name > I am looking at is an attribute or a key. What's the inherent difference between an attribute and a key. Marko From duncan.booth at invalid.invalid Tue Aug 5 09:29:26 2014 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 5 Aug 2014 13:29:26 GMT Subject: Python and IDEs [was Re: Python 3 is killing Python] References: <87zjga4j4v.fsf@elektro.pacujo.net> <53c57bae$0$9505$c3e8da3$5496439d@news.astraweb.com> <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Unfortunately, software development on Windows is something of a > ghetto, compared to the wide range of free tools available for Linux. > Outside of a few oases like Microsoft's own commercial development > tools, it's hard to do development on Windows. Hard, but not > impossible, of course, and there are quite a few resources available > for the Windows user willing to download installers from the Internet. > For Python users, the IDEs from Wingware and Activestate are notable: > > https://wingware.com/ > http://komodoide.com/ > > > I missed this thread when it started, so please forgive me if this has been covered, but by dismissing Microsoft you look to have skipped over a very powerful Python IDE for Windows, namely PTVS. Microsoft's PTVS is Windows only :-( and completely free (gratuit), partly free (libre): PTVS itself is Apache licensed and the required Visual Studio is of course closed source but PTVS now runs on the latest free versions of Visual Studio Express 2013 for Web or Visual Studio Express 2013 for Desktop (which includes C++). Some of the features: works with CPython (2.x or 3.x) or IronPython. Full support for virtualenv, packages can be installed directly from PTVS individually or from requirements.txt. Intellisense uses a completion database generated in the background from the standard library and all installed libraries. It offers context sensitive completion which does a pretty good job of inferring the type of local variables based on the types of the values used to call the function. Refactoring (Rename, Extract Method, Add Import, Remove unused imports) Interactive windows for all installed Python versions (can use standard shell or IPython) Debugging locally or remotely including Linux and OS X targets (in fact they claim that anything capable of running Python can be debugged). Mixed mode Python and C++ debugging. Profiling (CPython only). Automatic test discovery for tests using unittest. Support for PyLint. Automatic deployment to Windows Azure. Extensive support for Django (including Intellisense and debugging for templates and various Django specific commands such as sync db and admin shell). -- Duncan Booth From varun7rs at gmail.com Tue Aug 5 10:03:50 2014 From: varun7rs at gmail.com (varun7rs at gmail.com) Date: Tue, 5 Aug 2014 07:03:50 -0700 (PDT) Subject: Davis putnam algorithm for satisfiability... In-Reply-To: References: <8aceb6af-9b72-4e14-8d3e-8e6aea83fa69@googlegroups.com> Message-ID: <45dc6b5a-a4cc-4b02-bec1-fe64768d7786@googlegroups.com> Thank you Cameron. Your post was very helpful. If you don't mind I'd like to ask you the purpose of the final list in the very beginning of the code. It is being updated and then checked for the presence of a literal. If a literal is found it returns not equivalent. Could you brief me the use of a final list? From python at mrabarnett.plus.com Tue Aug 5 10:11:29 2014 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 05 Aug 2014 15:11:29 +0100 Subject: 3 Suggestions to Make Python Easier For Children In-Reply-To: <87fvhbxedn.fsf@elektro.pacujo.net> References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87k36nxhv8.fsf@elektro.pacujo.net> <87fvhbxedn.fsf@elektro.pacujo.net> Message-ID: <53E0E611.6070805@mrabarnett.plus.com> On 2014-08-05 14:19, Marko Rauhamaa wrote: > Skip Montanaro : > >> On Tue, Aug 5, 2014 at 7:04 AM, Marko Rauhamaa wrote: >>> I wonder if that should be built into dict. >> >> Short answer, no. I'm sure it's been proposed before. Attributes ? >> keys. When you see something.somethingelse anywhere else in Python, >> "somethingelse" is an attribute reference. When you see >> something[somethingelse], "somethingelse" is an index value or key. >> Why destroy that symmetry in dictionaries? > > I'm not sure I fully appreciate the dichotomy (which you euphemistically > refer to as symmetry). > >> JavaScript objects have that feature. I find it mildly confusing >> because whenever I see it I have to pause to consider whether the name >> I am looking at is an attribute or a key. > > What's the inherent difference between an attribute and a key. > An attribute is part of a container; a key is part of its contents. From neilc at norwich.edu Tue Aug 5 11:37:29 2014 From: neilc at norwich.edu (Neil D. Cerutti) Date: Tue, 05 Aug 2014 11:37:29 -0400 Subject: Python Classes In-Reply-To: References: Message-ID: On 8/4/2014 6:44 PM, John Gordon wrote: > In Shubham Tomar writes: > >> classes. I understand that you define classes to have re-usable methods and >> procedures, but, don't functions serve the same purpose. >> Can someone please explain the idea of classes > > If a function simply accepts some data, does some calculations on that > data and then returns a value, then you don't need classes at all. An > example of this might be the square-root function: pass it any number > and it calculates and returns the square root with no other data needed. > > But classes do come in handy for other sorts of uses. One classic example > is employees at a company. Each employee has a name, ID number, salary, > date of hire, home address, etc. > > You can create an Employee class to store those data items along with > methods to manipulate those data items in interesting ways. The data > items are specific to each separate Employee object, and the methods are > shared among the entire class. In simple cases like that, functions could do very well by including a little bundle of data (probably a dict) as one of the parameters for each related function. Classes help here by organizing the functions into namespaces, and allowing very convenient and explicit syntax for creating objects and using attributes. In addition, classes provide hooks into almost all of Python's syntax and operations, with special methods like __init__, __add__, etc. If you want your employees to be comparable using the <, >, == you need to use classes. Classes provide a means for objects to be related, substitutable, and interdependent, using inheritance. Properties work only with classes and provide a convenient way to customize attribute retrieval and setting without forcing a change in the syntax required for usage. Classes can be constructed dynamically using metaclasses. Some of these things can be emulated using just functions and mappings--it's what C programmers do--but most of classes in Python can do requires language support. -- Neil Cerutti From rosuav at gmail.com Tue Aug 5 12:08:06 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Aug 2014 02:08:06 +1000 Subject: Python Classes In-Reply-To: References: Message-ID: On Wed, Aug 6, 2014 at 1:37 AM, Neil D. Cerutti wrote: > In simple cases like that, functions could do very well by including a > little bundle of data (probably a dict) as one of the parameters for each > related function. And this is exactly how object orientation is done in C. You just have a structure that holds the object's state, and the (usually) first parameter to each function is a pointer to that structure. Actually, I've done that in high level languages too, specifically to decouple the code from the state (and thus allow me to load new code from the disk while maintaining state via what's already in memory - doing this with classes and objects means importing that state explicitly). The two notations are exactly the same. Compare: list.append(l, 'spam') l.append('spam') One uses namespacing, the other uses object methods. Same thing! ChrisA From steve+comp.lang.python at pearwood.info Tue Aug 5 12:14:49 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 06 Aug 2014 02:14:49 +1000 Subject: 3 Suggestions to Make Python Easier For Children References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87k36nxhv8.fsf@elektro.pacujo.net> <87fvhbxedn.fsf@elektro.pacujo.net> Message-ID: <53e102fa$0$29992$c3e8da3$5496439d@news.astraweb.com> Marko Rauhamaa wrote: > What's the inherent difference between an attribute and a key. Here is my bucket. The handle of the bucket is part of the bucket: bucket.handle The pieces of coal I carry in the bucket is part of its content: bucket['coal'] Of course, we can blur the distinction between part of the object and the object's content, if we so choose. As Lewis Carroll might have written in "Through the Looking Glass" had he been a programmer: ?When I use syntax,? Humpty Dumpty said in rather a scornful tone, ?it means just what I choose it to mean ? neither more nor less.? ?The question is,? said Alice, ?whether you can make syntax mean so many different things.? ?The question is,? said Humpty Dumpty, ?which is to be master ? that?s all.? If anyone wants a language where the same syntax means radically different things, or radically different syntax means the same thing, then you know where to find Perl, PHP and Javascript *wink*. But more seriously, as Humpty might have said, of course the designer is the master (and there are good masters and bad masters...), and sometimes there is good reason to use attribute syntax for content. Sometimes it isn't clear what counts as part of the object and what counts as part of the contents, e.g. record or struct like objects exist in that grey area. In that case, it may be a reasonable design choice to use attribute notation, as namedtuple does, for example. But you'll note the cost: namedtuple is forced to use leading underscore method names as *public* parts of the API, so that they don't clash with field names. If Guido was more like Perl's designer, Larry Wall, Python might have grown a "short cut" notation for keys, say mydict$key, but the proliferation of "many ways to do it" (to paraphrase the Perl motto) has costs of its own. It's harder to learn, read and understand Perl code than Python code, simply because there's more syntax to learn, and more special cases to understand. -- Steven From steve+comp.lang.python at pearwood.info Tue Aug 5 12:25:29 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 06 Aug 2014 02:25:29 +1000 Subject: eval [was Re: dict to boolean expression, how to?] References: <53db8bd8$0$2976$e4fe514c@news2.news.xs4all.nl> <53dba39e$0$2976$e4fe514c@news2.news.xs4all.nl> <53dc5407$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53e1057a$0$30000$c3e8da3$5496439d@news.astraweb.com> Duncan Booth wrote: > Steven D'Aprano wrote: [...] >> My refactoring, with the bare minimum use of exec necessary: >> >> https://code.activestate.com/recipes/578918-yet-another-namedtuple/ > > > This may be a silly question, but what would stop you moving the exec > inside the class? I don't know. I haven't tried it. I didn't think of it at the time. I don't have any specific arguments either against or in favour of your suggestions, except to say that exec is sometimes tricky to get working unless you explicitly specify the namespace to operate in. -- Steven From steve+comp.lang.python at pearwood.info Tue Aug 5 12:50:14 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 06 Aug 2014 02:50:14 +1000 Subject: Python and IDEs [was Re: Python 3 is killing Python] References: <87zjga4j4v.fsf@elektro.pacujo.net> <53c57bae$0$9505$c3e8da3$5496439d@news.astraweb.com> <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53e10b47$0$29991$c3e8da3$5496439d@news.astraweb.com> Duncan Booth wrote: > Steven D'Aprano wrote: > >> Unfortunately, software development on Windows is something of a >> ghetto, compared to the wide range of free tools available for Linux. I remember writing this. But I don't remember when it was. Presumably some time in the last six months :-) >> Outside of a few oases like Microsoft's own commercial development >> tools, it's hard to do development on Windows. Hard, but not >> impossible, of course, and there are quite a few resources available >> for the Windows user willing to download installers from the Internet. >> For Python users, the IDEs from Wingware and Activestate are notable: >> >> https://wingware.com/ >> http://komodoide.com/ >> >> >> > I missed this thread when it started, so please forgive me if this has > been covered, but by dismissing Microsoft you look to have skipped over > a very powerful Python IDE for Windows, namely PTVS. Never heard of it :-) Which is not surprising, since I'm not a Windows developer. [snip feature list] Nice. How does one get it? If I gave the impression that one cannot do development on Windows, that was not my intent. I tried to indicate that the difference was a matter of degree, not impossibility. One of the reasons why so many of the core developers for Python use Linux is that they got frustrated with the speed humps on Windows, the poor "out of the box" experience for developers (compare what dev tools you get with Windows by default versus what you get on Linux by default), but that might also be somewhat self-selecting: people who are happy with Windows development tend to stick to VB, Java, C, .Net etc. while those who prefer lighter weight more agile environments migrate to Linux. I don't know. But I do know that the existence of good quality Windows development tools for Python is good news for the community, so thank you for mentioning this. -- Steven From eldiener at tropicsoft.invalid Tue Aug 5 13:27:44 2014 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Tue, 05 Aug 2014 13:27:44 -0400 Subject: Controlling py.exe launcher on Windows Message-ID: I am trying to control the default version of the py.exe launcher on Windows. I have the Python 2.7.8 and 3.4.1 installed with both the 32 bit and 64 bit versions, all in different directories. I assume that .py and .pyw files are associated with the py.exe launcher. I am trying to control which version starts through a py.ini file in the same directory as the py.exe file in the 3.4.1 version last installed. If I specify in the [defaults] section of py.ini: python=3.4 then launching py.exe will show: Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:45:13) [MSC v.1600 64 bit (AM D64)] on win32 If I specify: python=3.4-32 then launching py.exe will show: Python 2.7.8 (default, Jun 30 2014, 16:08:48) [MSC v.1500 64 bit (AMD64)] on win 32 Is it really true that I cannot specify the 32 bit version in the .ini file or am I doing something wrong here ? From duncan.booth at invalid.invalid Tue Aug 5 15:25:26 2014 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 5 Aug 2014 19:25:26 GMT Subject: Python and IDEs [was Re: Python 3 is killing Python] References: <87zjga4j4v.fsf@elektro.pacujo.net> <53c57bae$0$9505$c3e8da3$5496439d@news.astraweb.com> <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <53e10b47$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Duncan Booth wrote: > >> Steven D'Aprano wrote: >> >>> Unfortunately, software development on Windows is something of a >>> ghetto, compared to the wide range of free tools available for >>> Linux. > > I remember writing this. But I don't remember when it was. Presumably > some time in the last six months :-) > >>> Outside of a few oases like Microsoft's own commercial development >>> tools, it's hard to do development on Windows. Hard, but not >>> impossible, of course, and there are quite a few resources available >>> for the Windows user willing to download installers from the >>> Internet. For Python users, the IDEs from Wingware and Activestate >>> are notable: >>> >>> https://wingware.com/ >>> http://komodoide.com/ >>> >>> >>> >> I missed this thread when it started, so please forgive me if this >> has been covered, but by dismissing Microsoft you look to have >> skipped over a very powerful Python IDE for Windows, namely PTVS. > > Never heard of it :-) > > Which is not surprising, since I'm not a Windows developer. > > [snip feature list] > > Nice. How does one get it? 1) Get a Windows 8.1 VM, or a real PC if that's more convenient. 2) Download and install either "Microsoft Visual Studio Express 2013 with Update 3 for Web" or "Microsoft Visual Studio Express 2013 with Update 3 for Windows Desktop" from http://www.visualstudio.com/downloads/download-visual-studio-vs N.B. If you just download the original versions without update 3 you'll have to apply all updates before proceeding so easier to use the latest versions from the get go. 3) Download and install PTVS 2.1 Beta 2 from https://pytools.codeplex.com/releases Note that you need at least PTVS 2.1 Beta and VS Express 2013 with at least Update 2 to be able to install with just free tools. Earlier versions will refuse to install. There may be more intermediate steps of applying updates, but that's par for the Microsoft course. If you try this out in conjunction with a Microsoft Azure account then be sure to also install the Azure SDK. Documentation is at https://pytools.codeplex.com/documentation There's a Django tutorial at http://pytools.codeplex.com/wikipage? title=Django%20Web%20Site/Cloud%20Service%20Tutorial which gives quite a good walkthrough. > > If I gave the impression that one cannot do development on Windows, > that was not my intent. I tried to indicate that the difference was a > matter of degree, not impossibility. One of the reasons why so many of > the core developers for Python use Linux is that they got frustrated > with the speed humps on Windows, the poor "out of the box" experience > for developers (compare what dev tools you get with Windows by default > versus what you get on Linux by default), but that might also be > somewhat self-selecting: people who are happy with Windows development > tend to stick to VB, Java, C, .Net etc. while those who prefer lighter > weight more agile environments migrate to Linux. I don't know. > > But I do know that the existence of good quality Windows development > tools for Python is good news for the community, so thank you for > mentioning this. > So far they seem to have kept a pretty low profile; I suspect largely because until recently PTVS only worked with the pay versions of Visual Studio. -- Duncan Booth From eldiener at tropicsoft.invalid Tue Aug 5 15:36:25 2014 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Tue, 05 Aug 2014 15:36:25 -0400 Subject: Python 3.4.1 install does not create a file association for .py files on Windows Message-ID: I install Python 3.4.1 64-bit on Windows. After the install I type: assoc .py and I get back: File association not found for extension .py Why does not the Python install to associate extension .py with the Python Launcher for Windows ? From fpm at u.washington.edu Tue Aug 5 16:06:05 2014 From: fpm at u.washington.edu (Frank Miles) Date: Tue, 5 Aug 2014 20:06:05 +0000 (UTC) Subject: Pythonic way to iterate through multidimensional space? Message-ID: I need to evaluate a complicated function over a multidimensional space as part of an optimization problem. This is a somewhat general problem in which the number of dimensions and the function being evaluated can vary from problem to problem. I've got a working version (with loads of conditionals, and it only works to #dimensions <= 10), but I'd like something simpler and clearer and less hard-coded. I've web-searched for some plausible method, but haven't found anything "nice". Any recommendations where I should look, or what technique should be used? TIA! From invalid at invalid.invalid Tue Aug 5 16:41:42 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 5 Aug 2014 20:41:42 +0000 (UTC) Subject: cmd.exe on WIndows - problem with displaying some Unicode characters References: <53e13ddf$0$7267$c3e8da3$76a7c58f@news.astraweb.com> Message-ID: On 2014-08-05, Tony the Tiger wrote: > On Mon, 04 Aug 2014 00:52:29 +0200, Wiktor wrote: > >> okumenty\python\kolony\menu.py", line 14, in > > This works for me on Linux: > > ---8<----------------- > # coding:utf-8 > > test = """ > ???????????????? > ? Construction ? > ? Production ? > ? Research ? > ? Exploration ? > ???????????????? > ? Next turn ? > ???????????????? > """ But can you do Polish as well? IIRC, that was the catch: encodings that the windows terminal emulator understood that could do Polish couldn't do double-lines and vice-versa. I was a bit surprised when all that stuff rendered properly in slrn runnnig in a terminal emulator. I must have done a better job with locales and fonts that I thought... -- Grant Edwards grant.b.edwards Yow! Did you move a lot of at KOREAN STEAK KNIVES this gmail.com trip, Dingy? From __peter__ at web.de Tue Aug 5 16:48:10 2014 From: __peter__ at web.de (Peter Otten) Date: Tue, 05 Aug 2014 22:48:10 +0200 Subject: Pythonic way to iterate through multidimensional space? References: Message-ID: Frank Miles wrote: > I need to evaluate a complicated function over a multidimensional space > as part of an optimization problem. This is a somewhat general problem > in which the number of dimensions and the function being evaluated can > vary from problem to problem. > > I've got a working version (with loads of conditionals, and it only works > to #dimensions <= 10), but I'd like something simpler and clearer and > less hard-coded. > > I've web-searched for some plausible method, but haven't found anything > "nice". Any recommendations where I should look, or what technique should > be used? Not sure this is what you want, but if you have nested for loops -- these can be replaced with itertools.product(): >>> a = [1, 2] >>> b = [10, 20, 30] >>> c = [100] >>> for x in a: ... for y in b: ... for z in c: ... print(x, y, z) ... 1 10 100 1 20 100 1 30 100 2 10 100 2 20 100 2 30 100 >>> for xyz in product(a, b, c): ... print(*xyz) ... 1 10 100 1 20 100 1 30 100 2 10 100 2 20 100 2 30 100 From calderon.christian760 at gmail.com Tue Aug 5 15:39:18 2014 From: calderon.christian760 at gmail.com (Christian Calderon) Date: Tue, 5 Aug 2014 12:39:18 -0700 Subject: Making every no-arg method a property? Message-ID: I have been using python for 4 years now, and I just started learning ruby. I like that in ruby I don't have to type parenthesis at the end of each function call if I don't need to provide extra arguments. I just realized right now that I can do something similar in python, if I make all methods with only the implicitly passed 'self' into properties. Which means I can either do some fancy coding and make a metaclass that does this auto-magically, or I have to have property decorators all over the place :-P . I was wondering what other thought of this, is it an overly fanciful way of coding python, or is it an acceptable thing to do in a real project? Also, would anyone be interested in helping me make this metaclass? -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue Aug 5 16:56:11 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Aug 2014 06:56:11 +1000 Subject: Making every no-arg method a property? In-Reply-To: References: Message-ID: On Wed, Aug 6, 2014 at 5:39 AM, Christian Calderon wrote: > I have been using python for 4 years now, and I just started learning ruby. > I like that in ruby I don't have to type parenthesis at the end of each > function call if I don't need to provide extra arguments. I just realized > right now that I can do something similar in python, if I make all methods > with only the implicitly passed 'self' into properties. Which means I can > either do some fancy coding and make a metaclass that does this > auto-magically, or I have to have property decorators all over the place :-P > . I was wondering what other thought of this, is it an overly fanciful way > of coding python, or is it an acceptable thing to do in a real project? > Also, would anyone be interested in helping me make this metaclass? It's not a Pythonic style of coding. A property is generally assumed to be a cheap and simple lookup that cannot change anything - that is, it should be 'safe'. A no-arg method could mutate the object, could be expensive, could do just about anything. The parentheses make it clear that something's now happening - code's being called. Properties should be reserved for those cases where it's conceptually an attribute lookup, but for whatever reason you need a bit of code on it - and that's a pretty unusual case, compared to zero-argument methods. Strong recommendation that you don't do this. Of course, Python's "consenting adults" policy says that you're most welcome to - but you'll find that it's much more friendly to subsequent maintainers to keep attribute lookup and method call different. ChrisA From fpm at u.washington.edu Tue Aug 5 16:57:49 2014 From: fpm at u.washington.edu (Frank Miles) Date: Tue, 5 Aug 2014 20:57:49 +0000 (UTC) Subject: Pythonic way to iterate through multidimensional space? References: Message-ID: On Tue, 05 Aug 2014 20:06:05 +0000, Frank Miles wrote: > I need to evaluate a complicated function over a multidimensional space > as part of an optimization problem. This is a somewhat general problem > in which the number of dimensions and the function being evaluated can > vary from problem to problem. > > I've got a working version (with loads of conditionals, and it only works > to #dimensions <= 10), but I'd like something simpler and clearer and > less hard-coded. > > I've web-searched for some plausible method, but haven't found anything > "nice". Any recommendations where I should look, or what technique should > be used? > > TIA! Ahhhh.... should have waited. The answer: itertools.product! very nice From rgaddi at technologyhighland.invalid Tue Aug 5 16:57:58 2014 From: rgaddi at technologyhighland.invalid (Rob Gaddi) Date: Tue, 5 Aug 2014 13:57:58 -0700 Subject: Making every no-arg method a property? References: Message-ID: <20140805135758.5eef4114@rg.highlandtechnology.com> On Tue, 5 Aug 2014 12:39:18 -0700 Christian Calderon wrote: > I have been using python for 4 years now, and I just started learning ruby. > I like that in ruby I don't have to type parenthesis at the end of each > function call if I don't need to provide extra arguments. I just realized > right now that I can do something similar in python, if I make all methods > with only the implicitly passed 'self' into properties. Which means I can > either do some fancy coding and make a metaclass that does this > auto-magically, or I have to have property decorators all over the place > :-P . I was wondering what other thought of this, is it an overly fanciful > way of coding python, or is it an acceptable thing to do in a real project? > Also, would anyone be interested in helping me make this metaclass? > Overly fanciful to my mind. Also, you'd eliminate the ability to talk about the function itself rather than the value thereof. No more help from the interactive console. No more passing the function as an argument. All to save '()', which is what tells other programmers that you're calling a function. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From invalid at invalid.invalid Tue Aug 5 17:14:15 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 5 Aug 2014 21:14:15 +0000 (UTC) Subject: Making every no-arg method a property? References: Message-ID: On 2014-08-05, Christian Calderon wrote: > I have been using python for 4 years now, and I just started learning > ruby. I like that in ruby I don't have to type parenthesis at the end > of each function call if I don't need to provide extra arguments. Did I miss a news story? Have the parentesis mines all exploded causing the price of parenthesis to skyrocket? > I just realized right now that I can do something similar in python, > if I make all methods with only the implicitly passed 'self' into > properties. Which means I can either do some fancy coding and make a > metaclass that does this auto-magically, or I have to have property > decorators all over the place :-P Here's an idea: when using Python, write Python. Just type the parens. I know it requires hitting the shift key and all, but it's not that hard -- especially if you have two hands. If you want to write Ruby, then use Ruby. > I was wondering what other thought of this, is it an overly fanciful > way of coding python, IMO, it's a huge waste of time and an excellent way to reduce both readability and maintainability of your code. > or is it an acceptable thing to do in a real project? No. It's not acceptable. Not even a tiny bit. > Also, would anyone be interested in helping me make this metaclass? Um... [I have the nagging feeling I've been trolled...] -- Grant Edwards grant.b.edwards Yow! Everywhere I look I at see NEGATIVITY and ASPHALT gmail.com ... From wingusr at gmail.com Tue Aug 5 17:28:12 2014 From: wingusr at gmail.com (TP) Date: Tue, 5 Aug 2014 14:28:12 -0700 Subject: Python and IDEs [was Re: Python 3 is killing Python] In-Reply-To: References: <87zjga4j4v.fsf@elektro.pacujo.net> <53c57bae$0$9505$c3e8da3$5496439d@news.astraweb.com> <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <53e10b47$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Aug 5, 2014 at 12:25 PM, Duncan Booth wrote: > So far they seem to have kept a pretty low profile; I suspect largely > because until recently PTVS only worked with the pay versions of Visual > Studio. > Not true. When it didn't work with the free express versions of VS, it worked with the free Visual Studio Shell (that people have also not heard about :) So there has always been some free way of running PTVS. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Tue Aug 5 17:43:08 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 05 Aug 2014 17:43:08 -0400 Subject: Tkinter menu crash In-Reply-To: <1a31faea-eea6-4b1d-8dc1-185f13348621@googlegroups.com> References: <1a31faea-eea6-4b1d-8dc1-185f13348621@googlegroups.com> Message-ID: On 8/5/2014 8:15 AM, Nicholas Cannon wrote: > Ok so the first part of the program(until the start of the menu) worked fine. It ran and did what I wanted it to do. What x.y.z version of Python. How did you run it, exactly? > I wanted to then implement a new menu(for practise) and then it crashes. Don't know why but it just crashes. If you ran from Idle editor on Windows, start Idle with 'python -m idlelib' in Command Prompt to see tk error messages. However, when I pasted code into 3.4.1 Idle Editor, changed first two lines to from tkinter import * from tkinter import messagebox as tm and ran -- no crash, no error message, no menu. I entered text into box, clicked Submit text, and OK on popup, and nothing happens. See below for why no menu. When you ask about a problem, please reduce code to the minimum that exhibits the problem for you. > (also tips on the code will be appreciated and I gave just started Tkinter programming) A different issue. > Here is the code: > > > from Tkinter import * > import tkMessageBox as tm > > def submit(): > #message box with yes no > tm.askyesno(title='Submit Text', message='Are you sure....') > > def info(): > tm.showinfo(title='About', message='Just a test Tkinter UI sample') > > #getting the text from the entrybox and > #packs it into a label > mtext = text.get() > label1 = Label(app, text=mtext) > label1.pack() > > #root window setup > root = Tk() > root.geometry('480x480+200+200') > root.title('Basic Tk UI') > > #frame set up > app = Frame(root) > app.pack() > > #variable and entry box set up > text = StringVar() > entry = Entry(app, textvariable=text) > entry.pack() > > #button set up > button1 = Button(app, text='Submit text', command= submit) > button1.pack() > > #menu construction > menubar = Menu(root) > > filemenu = Menu(menubar) > filemenu.add_command(label='About', command= info) > filemenu.add_command(label='Quit', command= root.destroy) > filemenu.add_cascade(label='TK UI Sample', menu=filemenu) Adding filemenu as a submenu of filemenu leads to infinite loop regress. On 3.4.1 with tcl/tk 8.6, this does not crash, but it might on an earlier version of Python and tcl/tk. Since menubar is left empty, it is not displayed. Fix both problems with menubar.add_cascade(label='TK UI Sample', menu=filemenu) > root.config(menu=menubar) > > > > #loop to listen for events > root.mainloop() > -- Terry Jan Reedy From ian.g.kelly at gmail.com Tue Aug 5 17:53:34 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 5 Aug 2014 15:53:34 -0600 Subject: Making every no-arg method a property? In-Reply-To: References: Message-ID: On Tue, Aug 5, 2014 at 1:39 PM, Christian Calderon wrote: > I have been using python for 4 years now, and I just started learning ruby. > I like that in ruby I don't have to type parenthesis at the end of each > function call if I don't need to provide extra arguments. I just realized > right now that I can do something similar in python, if I make all methods > with only the implicitly passed 'self' into properties. Which means I can > either do some fancy coding and make a metaclass that does this > auto-magically, or I have to have property decorators all over the place :-P > . I was wondering what other thought of this, is it an overly fanciful way > of coding python, or is it an acceptable thing to do in a real project? > Also, would anyone be interested in helping me make this metaclass? The metaclass to do this is easy: import inspect import types class autoprop(type): def __init__(cls, name, bases, attrs): for name, value in attrs.items(): if (name.startswith('__') and name.endswith('__') or not isinstance(value, types.FunctionType)): continue argspec = inspect.getfullargspec(value) if (len(argspec.args) == 1 and not any([argspec.varargs, argspec.varkw, argspec.kwonlyargs])): setattr(cls, name, property(value)) But I'm in agreement with the others in this thread that it's not really a good idea. In addition to the arguments made by others, note that this doesn't actually make the parentheses optional; it makes their absence required. That's a fundamental limitation, because it's up to the descriptor to automatically call the method or not, and the descriptor has no way of knowing whether the thing it's returning is about to be called or not. Also, as a consequence of the above, note that this only works for methods that take no arguments at all (except self). If the method has optional arguments, and you replace it with a property, then you no longer have any way to pass those optional arguments. From tjreedy at udel.edu Tue Aug 5 18:16:15 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 05 Aug 2014 18:16:15 -0400 Subject: Python 3.4.1 install does not create a file association for .py files on Windows In-Reply-To: References: Message-ID: On 8/5/2014 3:36 PM, Edward Diener wrote: > I install Python 3.4.1 64-bit on Windows. After the install I type: I have done the same, on Win 7, but I had previous installs going back 3 years on this machine. > assoc .py > > and I get back: > > File association not found for extension .py I get C:\Users\Terry>assoc .py .py=Python.File C:\Users\Terry>assoc .pyw .pyw=Python.NoConFile C:\Users\Terry>assoc .pyo .pyo=Python.CompiledFile C:\Users\Terry>assoc .pyc .pyc=Python.CompiledFile None of this specifies the program, which is currently Python Launcher for Windows (console). (See Control Panel / Default Programs / Set Associations.) > Why does not the Python install to associate extension .py with the > Python Launcher for Windows ? Somewhere during the install, there is a checkbox or something about grabbing file associations or about making the install the default version. I do not remember. -- Terry Jan Reedy From look at signature.invalid Tue Aug 5 18:16:37 2014 From: look at signature.invalid (Wiktor) Date: Wed, 6 Aug 2014 00:16:37 +0200 Subject: cmd.exe on WIndows - problem with displaying some Unicode characters References: <53e13ddf$0$7267$c3e8da3$76a7c58f@news.astraweb.com> Message-ID: On 05 Aug 2014 20:26:08 GMT, Tony the Tiger wrote: > On Mon, 04 Aug 2014 00:52:29 +0200, Wiktor wrote: > >> okumenty\python\kolony\menu.py", line 14, in > > This works for me on Linux: I believe you, but I use Windows and its cmd.exe (as mentioned in subject). -- Best regards, Wiktor Matuszewski 'py{}@wu{}em.pl'.format('wkm', 'ka') From eldiener at tropicsoft.invalid Tue Aug 5 18:24:06 2014 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Tue, 05 Aug 2014 18:24:06 -0400 Subject: Python 3.4.1 install does not create a file association for .py files on Windows In-Reply-To: References: Message-ID: On 8/5/2014 6:16 PM, Terry Reedy wrote: > On 8/5/2014 3:36 PM, Edward Diener wrote: >> I install Python 3.4.1 64-bit on Windows. After the install I type: > > I have done the same, on Win 7, but I had previous installs going back 3 > years on this machine. > >> assoc .py >> >> and I get back: >> >> File association not found for extension .py > > I get > C:\Users\Terry>assoc .py > .py=Python.File > > C:\Users\Terry>assoc .pyw > .pyw=Python.NoConFile > > C:\Users\Terry>assoc .pyo > .pyo=Python.CompiledFile > > C:\Users\Terry>assoc .pyc > .pyc=Python.CompiledFile > > None of this specifies the program, which is currently Python Launcher > for Windows (console). (See Control Panel / Default Programs / Set > Associations.) > >> Why does not the Python install to associate extension .py with the >> Python Launcher for Windows ? > > Somewhere during the install, there is a checkbox or something about > grabbing file associations or about making the install the default > version. I do not remember. > I uninstalled all my Python versions and then re-installed each one. Now the correct file association has been made. Something was fouled up in the installation process which is now fixed. From eldiener at tropicsoft.invalid Tue Aug 5 18:25:32 2014 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Tue, 05 Aug 2014 18:25:32 -0400 Subject: Controlling py.exe launcher on Windows In-Reply-To: References: Message-ID: On 8/5/2014 1:27 PM, Edward Diener wrote: > I am trying to control the default version of the py.exe launcher on > Windows. I have the Python 2.7.8 and 3.4.1 installed with both the 32 > bit and 64 bit versions, all in different directories. I assume that .py > and .pyw files are associated with the py.exe launcher. > > I am trying to control which version starts through a py.ini file in the > same directory as the py.exe file in the 3.4.1 version last installed. > > If I specify in the [defaults] section of py.ini: > > python=3.4 > > then launching py.exe will show: > > Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:45:13) [MSC v.1600 64 > bit (AM > D64)] on win32 > > If I specify: > > python=3.4-32 > > then launching py.exe will show: > > Python 2.7.8 (default, Jun 30 2014, 16:08:48) [MSC v.1500 64 bit > (AMD64)] on win > 32 > > Is it really true that I cannot specify the 32 bit version in the .ini > file or am I doing something wrong here ? After uninstalling my Python versions and re-installing them, everything works properly and I can control the version which py.exe starts from the py.ini file. From nicholascannon1 at gmail.com Tue Aug 5 18:28:08 2014 From: nicholascannon1 at gmail.com (Nicholas Cannon) Date: Tue, 5 Aug 2014 15:28:08 -0700 (PDT) Subject: Tkinter menu crash In-Reply-To: References: <1a31faea-eea6-4b1d-8dc1-185f13348621@googlegroups.com> Message-ID: Ok so I am on 2.7.8. > What x.y.z version of Python. How did you run it, exactly? > Adding filemenu as a submenu of filemenu leads to infinite loop regress. > > On 3.4.1 with tcl/tk 8.6, this does not crash, but it might on an > > earlier version of Python and tcl/tk. > Since menubar is left empty, it is not displayed. Fix both problems with > >menubar.add_cascade(label='TK UI Sample', menu=filemenu) > > root.config(menu=menubar) Yeah this fixed the problem. So the main menu object needs to be cascade instead of the filemenu. Will this need to be done every I create a new menu? >and ran -- no crash, no error message, no menu. I entered text into box, >clicked Submit text, and OK on popup, and nothing happens. Im not quite sure what is happening here. Oh I just looked at the code and the part that sends the entry box text is in the wrong place or must have been unindented I have fixed this now and it works great. From greg.ewing at canterbury.ac.nz Tue Aug 5 18:34:04 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 06 Aug 2014 10:34:04 +1200 Subject: Making every no-arg method a property? In-Reply-To: References: Message-ID: Grant Edwards wrote: > Did I miss a news story? Have the parentesis mines all exploded > causing the price of parenthesis to skyrocket? The Unicode Consortium has been secretly buying them up for some time now. Pretty soon you won't be able to get cheap ASCII parentheses any more, only the fancy high-priced ones like U+2045/U+2046, U+2772/U+2773 and U+27E6/U+27E7. -- Greg From tjreedy at udel.edu Tue Aug 5 19:02:56 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 05 Aug 2014 19:02:56 -0400 Subject: Controlling py.exe launcher on Windows In-Reply-To: References: Message-ID: On 8/5/2014 1:27 PM, Edward Diener wrote: > I am trying to control the default version of the py.exe launcher on > Windows. I have the Python 2.7.8 and 3.4.1 installed with both the 32 > bit and 64 bit versions, all in different directories. I assume that .py > and .pyw files are associated with the py.exe launcher. > > I am trying to control which version starts through a py.ini file in the > same directory as the py.exe file in the 3.4.1 version last installed. > > If I specify in the [defaults] section of py.ini: > > python=3.4 > > then launching py.exe will show: > > Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:45:13) [MSC v.1600 64 > bit (AM > D64)] on win32 > > If I specify: > > python=3.4-32 This looks correct according to the manual. > > then launching py.exe will show: > > Python 2.7.8 (default, Jun 30 2014, 16:08:48) [MSC v.1500 64 bit > (AMD64)] on win > 32 > > Is it really true that I cannot specify the 32 bit version in the .ini > file or am I doing something wrong here ? First try > py -3.4-32 on the command line to make sure that py can find and launch that version. -- Terry Jan Reedy From tjreedy at udel.edu Tue Aug 5 19:27:33 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 05 Aug 2014 19:27:33 -0400 Subject: Tkinter menu crash In-Reply-To: References: <1a31faea-eea6-4b1d-8dc1-185f13348621@googlegroups.com> Message-ID: On 8/5/2014 6:28 PM, Nicholas Cannon wrote: > Ok so I am on 2.7.8. >> What x.y.z version of Python. How did you run it, exactly? > >> Adding filemenu as a submenu of filemenu leads to infinite loop regress. >> >> On 3.4.1 with tcl/tk 8.6, this does not crash, but it might on an >> >> earlier version of Python and tcl/tk. >> Since menubar is left empty, it is not displayed. Fix both problems with >> >> menubar.add_cascade(label='TK UI Sample', menu=filemenu) >> >> root.config(menu=menubar) > Yeah this fixed the problem. So the main menu object needs to be cascade instead of the filemenu. Will this need to be done every I create a new menu? I am not sure what you mean here. The main menu bar menubar is not a cascade. Added to root as the menu attribute, it displays horizonatally. You add filemenu to menebar as a cascade. It then displays vertically under its label on the main menu. It is fairly conventional that all the entries on the main menu are cascades, but apparently not necessary. It is also fairly conventional that most items on drop down menus are not cascades, but you could add a third menu to filemenu as a cascade. >> and ran -- no crash, no error message, no menu. I entered text into box, >> clicked Submit text, and OK on popup, and nothing happens. > Im not quite sure what is happening here. Oh I just looked at the code and the part that sends the entry box text is in the wrong place or must have been unindented I have fixed this now and it works great. > -- Terry Jan Reedy From tjreedy at udel.edu Tue Aug 5 19:29:26 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 05 Aug 2014 19:29:26 -0400 Subject: Controlling py.exe launcher on Windows In-Reply-To: References: Message-ID: On 8/5/2014 7:02 PM, Terry Reedy wrote: > On 8/5/2014 1:27 PM, Edward Diener wrote: >> I am trying to control the default version of the py.exe launcher on >> Windows. I have the Python 2.7.8 and 3.4.1 installed with both the 32 >> bit and 64 bit versions, all in different directories. I assume that .py >> and .pyw files are associated with the py.exe launcher. >> >> I am trying to control which version starts through a py.ini file in the >> same directory as the py.exe file in the 3.4.1 version last installed. >> >> If I specify in the [defaults] section of py.ini: >> >> python=3.4 >> >> then launching py.exe will show: >> >> Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:45:13) [MSC v.1600 64 >> bit (AM >> D64)] on win32 >> >> If I specify: >> >> python=3.4-32 > > This looks correct according to the manual. > >> >> then launching py.exe will show: >> >> Python 2.7.8 (default, Jun 30 2014, 16:08:48) [MSC v.1500 64 bit >> (AMD64)] on win >> 32 >> >> Is it really true that I cannot specify the 32 bit version in the .ini >> file or am I doing something wrong here ? > > First try > py -3.4-32 on the command line to make sure that py can find > and launch that version. I see you already fixed things by reinstalling. -- Terry Jan Reedy From nicholascannon1 at gmail.com Tue Aug 5 19:33:31 2014 From: nicholascannon1 at gmail.com (Nicholas Cannon) Date: Tue, 5 Aug 2014 16:33:31 -0700 (PDT) Subject: Tkinter menu crash In-Reply-To: References: <1a31faea-eea6-4b1d-8dc1-185f13348621@googlegroups.com> Message-ID: <98374ac7-7777-4963-a9a9-3fd70803ea74@googlegroups.com> I am confused. When I did menu bar.add_cascade why don't I do filemenu.add_cascade. Is it because I am adding a cascade to the main menubar? From ben+python at benfinney.id.au Tue Aug 5 19:49:06 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 06 Aug 2014 09:49:06 +1000 Subject: Making every no-arg method a property? References: Message-ID: <85ha1qbiq5.fsf@benfinney.id.au> Christian Calderon writes: > I like that in ruby I don't have to type parenthesis at the end of > each function call if I don't need to provide extra arguments. Whereas I like the opposite: there is a clear syntactic distinction between ?get the value of ?foo.bar.baz?? versus ?get the value returned when calling ?foo.bar.baz??. Having the same name sometimes refer to ?get this as a value? and other times ?call this as a function and get the return value? imposes a cognitive load on the reader, IMO an unnecessary one. -- \ ?If this is your first visit to the USSR, you are welcome to | `\ it.? ?hotel room, Moscow | _o__) | Ben Finney From steve+comp.lang.python at pearwood.info Tue Aug 5 20:49:24 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 06 Aug 2014 10:49:24 +1000 Subject: Making every no-arg method a property? References: Message-ID: <53e17b95$0$29981$c3e8da3$5496439d@news.astraweb.com> Christian Calderon wrote: > I have been using python for 4 years now, and I just started learning > ruby. I like that in ruby I don't have to type parenthesis at the end of > each function call if I don't need to provide extra arguments. That's one of the things which I dislike most about Ruby. Python has a nice, clean design: obj.method returns the method object, x() on any object calls it. (Possibly not successfully, if it is not a type, function or method, but it makes the attempt.) Making the parentheses optional just confuses the two, just for the sake of saving a couple of keystrokes. > I just > realized right now that I can do something similar in python, if I make > all methods with only the implicitly passed 'self' into properties. I wouldn't expect that there should be very many of such methods (except in, say, a type like str, where you have a bunch of transformation methods like str.upper() etc. -- but they shouldn't be treated as properties at all). A plethora of argument-less methods is a code smell -- that doesn't mean it's *necessarily* a bad idea, but the class design really needs a careful review. The problem with argument-less methods is that things which should be temporary arguments are being stored as permanent state instead. E.g. if you're calling methods just for their side-effect of setting up a bunch of attributes, just so you can then do what you really want which is call another method, that's a bad design which should be refactored to pass arguments direct to the method: # Bad class SandwichMaker: def prepare_sandwich_ingredients(self, bread, butter, fillings, openface=False): self._bread = bread self.butter = butter self.fillings = fillings self.openface = openface def make_sandwich(self): base = self.bread if not self.openface: cover = self.bread else: cover = None if self.butter in ('butter', 'margarine', 'mayo'): base += self.butter if cover: cover += self.butter for filling in self.fillings: self.thing_to_get = filling base += self.get_ingredient() if cover: # butter goes on the inside, not the top self.thing_to_flip = cover self.flip_the_thing_that_needs_flipping() base += self.thing_to_flip return base Obviously this is a fanciful example, but I've seen too much real code where too many methods existed solely to stuff data into an attribute so another method could get to it, after which that attribute was unneeded. It's the OOP equivalent of writing functions which communicate only by global variable. > Which > means I can either do some fancy coding and make a metaclass that does > this auto-magically, or I have to have property decorators all over the > place > :-P . I was wondering what other thought of this, is it an overly fanciful > way of coding python, or is it an acceptable thing to do in a real > project? Also, would anyone be interested in helping me make this > metaclass? Personally, I think it's a horrible idea, but if you must do it, I'd suggest doing it with a class decorator, not a metaclass. Something like this: # Untested. def make_zero_arg_methods_into_properties(cls): for name, obj in vars(cls).items(): if inspect.isfunction(obj): if inspect.getargspec(obj) == (['self'], None, None, ()): setattr(cls, name, property(obj)) return cls @make_zero_arg_methods_into_properties class Spam: def eggs(self): ... -- Steven From rosuav at gmail.com Tue Aug 5 22:07:58 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Aug 2014 12:07:58 +1000 Subject: Making every no-arg method a property? In-Reply-To: <53e17b95$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <53e17b95$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Aug 6, 2014 at 10:49 AM, Steven D'Aprano wrote: > A > plethora of argument-less methods is a code smell -- that doesn't mean it's > *necessarily* a bad idea, but the class design really needs a careful > review. There are plenty of no-argument mutator methods, where the name of the method (and the target object, obviously) is all the info you need. You can clear() or copy() something with any more info, reverse() a list, pop() from a list, etc. (Okay, the last one has a default argument, but that raises an even worse point: adding a defaulted argument to a no-argument method suddenly stops it from being a property, which violates the usual rule that you can add a defaulted argument to anything without breaking anything.) ChrisA From tjreedy at udel.edu Wed Aug 6 00:13:56 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 06 Aug 2014 00:13:56 -0400 Subject: Tkinter menu crash In-Reply-To: <98374ac7-7777-4963-a9a9-3fd70803ea74@googlegroups.com> References: <1a31faea-eea6-4b1d-8dc1-185f13348621@googlegroups.com> <98374ac7-7777-4963-a9a9-3fd70803ea74@googlegroups.com> Message-ID: On 8/5/2014 7:33 PM, Nicholas Cannon wrote: > I am confused. When I did menu bar.add_cascade why don't I do filemenu.add_cascade. Is it because I am adding a cascade to the main menubar? Let us start with a widget, that can 'contain' other widgets (and possibly other things). We create a child widget (which keeps a reference to the parent. Now we want to put it into the parent. How? The generic grid, pack, and place geometry methods are called on the child, with no mention of the parent. (The child reference to the parent is used instead.) Do note, however, that child-independent geometry configure methods, like grid rowconfigure, are called on the parent. Widget-specific geometry methods, however, are (mostly at least) called on the parent, with the child passed as a parameter. Menus can contain both commands, which are not widgets, and submenus, which are. They are packed with add_command and add_cascade. Canvases have add methods that place items, which again may or may not be widgets. I initially found child.pack(args) confusing, because I expected the pattern to be (child.parent).pack(child, args). But now that I think about it, the shortcut is similar to instance.method(args) sometimes meaning (instance.__class__).method(instance, args). The convenience in both cases is about the same. -- Terry Jan Reedy From wuwei23 at gmail.com Wed Aug 6 01:02:34 2014 From: wuwei23 at gmail.com (alex23) Date: Wed, 06 Aug 2014 15:02:34 +1000 Subject: Making every no-arg method a property? In-Reply-To: References: Message-ID: On 6/08/2014 9:49 AM, Ben Finney wrote: > Christian Calderon writes: >> I like that in ruby I don't have to type parenthesis at the end of >> each function call if I don't need to provide extra arguments. > Having the same name sometimes refer to ?get this as a value? and other > times ?call this as a function and get the return value? imposes a > cognitive load on the reader, IMO an unnecessary one. It also makes it impossible to use such methods in dispatch patterns or as callbacks. From invalid at invalid.invalid Wed Aug 6 01:13:07 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 6 Aug 2014 05:13:07 +0000 (UTC) Subject: Making every no-arg method a property? References: Message-ID: On 2014-08-05, Gregory Ewing wrote: > Grant Edwards wrote: >> Did I miss a news story? Have the parentesis mines all exploded >> causing the price of parenthesis to skyrocket? > > The Unicode Consortium has been secretly buying them > up for some time now. Pretty soon you won't be able > to get cheap ASCII parentheses any more, only the > fancy high-priced ones like U+2045/U+2046, > U+2772/U+2773 and U+27E6/U+27E7. Damn. Time to buy some options... -- Grant From travisgriggs at gmail.com Wed Aug 6 01:31:58 2014 From: travisgriggs at gmail.com (Travis Griggs) Date: Tue, 5 Aug 2014 22:31:58 -0700 Subject: TypeError: 'bytes' object is not callable error while trying to converting to bytes. In-Reply-To: References: <02baad14-39b1-41a0-a47d-28772c97ea54@googlegroups.com> Message-ID: <77C4289C-FBCD-449F-8460-B33029A4A236@gmail.com> > On Aug 4, 2014, at 22:57, Chris Angelico wrote: > > On Tue, Aug 5, 2014 at 3:47 PM, Satish ML wrote: >>>>> bytes = file.read() > > You've just shadowed the built-in type 'bytes' with your own 'bytes'. > Pick a different name for this, and you'll be fine. 'data' would work. Until python4 introduces the 'data' built in. :) From rosuav at gmail.com Wed Aug 6 01:37:10 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Aug 2014 15:37:10 +1000 Subject: TypeError: 'bytes' object is not callable error while trying to converting to bytes. In-Reply-To: <77C4289C-FBCD-449F-8460-B33029A4A236@gmail.com> References: <02baad14-39b1-41a0-a47d-28772c97ea54@googlegroups.com> <77C4289C-FBCD-449F-8460-B33029A4A236@gmail.com> Message-ID: On Wed, Aug 6, 2014 at 3:31 PM, Travis Griggs wrote: >> On Aug 4, 2014, at 22:57, Chris Angelico wrote: >> >> On Tue, Aug 5, 2014 at 3:47 PM, Satish ML wrote: >>>>>> bytes = file.read() >> >> You've just shadowed the built-in type 'bytes' with your own 'bytes'. >> Pick a different name for this, and you'll be fine. 'data' would work. > > Until python4 introduces the 'data' built in. :) Python 3.6 could introduce that, no need to wait for Python 4. :) However, it wouldn't be critical to this code, unless the builtin's meaning is also wanted; it'd be on par with the shadowing of 'file' earlier - given how rarely Python programs actually need 'file' (rather than 'open'), it's not a big deal to shadow that one. ChrisA From usethisid2014 at gmail.com Wed Aug 6 01:34:13 2014 From: usethisid2014 at gmail.com (Gayathri J) Date: Wed, 6 Aug 2014 11:04:13 +0530 Subject: Pythonic way to iterate through multidimensional space? In-Reply-To: References: Message-ID: Dear Peter Below is the code I tried to check if itertools.product() was faster than normal nested loops... they arent! arent they supposed to be...or am i making a mistake? any idea? *############################################################* *# -*- coding: utf-8 -*-* *import numpy as np* *import time* *from itertools import product,repeat* *def main():* * # N - size of grid* * # nvel - number of velocities* * # times - number of times to run the functions* * N=256* * times=3* * f=np.random.rand(N,N,N)* * # using loops* * print "normal nested loop"* * python_dot_loop1(f,times,N)* * print "nested loop using itertools.product()"* * python_dot_loop2(f,times,N)* *def python_dot_loop1(f,times,N):* * for t in range(times):* * t1=time.time()* * for i in range(N):* * for j in range(N):* * for k in range(N):* * f[i,j,k] = 0.0* * print "python dot loop " + str(time.time()-t1)* *def python_dot_loop2(f,times,N):* * rangeN=range(N)* * for t in range(times):* * t1=time.time()* * for i,j,k in product(rangeN,repeat=3):* * f[i,j,k]=0.0* * print "python dot loop " + str(time.time()-t1)* *if __name__=='__main__':* * main()* *############################################################* -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Wed Aug 6 02:25:44 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Aug 2014 16:25:44 +1000 Subject: Pythonic way to iterate through multidimensional space? In-Reply-To: References: Message-ID: On Wed, Aug 6, 2014 at 3:34 PM, Gayathri J wrote: > Below is the code I tried to check if itertools.product() was faster than > normal nested loops... > > they arent! arent they supposed to be...or am i making a mistake? any idea? Don't worry about what's faster. That almost never matters. Worry, instead, about how you would code it if you can't be sure how many dimensions there'll be until run time (which the OP said can happen). With product(), you can give it a variable number of arguments (eg with *args notation), but with loops, you'd need to compile up some code with that many nested loops - or at best, something where you cap the number of loops and thus dimensions, and have a bunch of them iterate over a single iterable. ChrisA From wxjmfauth at gmail.com Wed Aug 6 02:30:00 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Tue, 5 Aug 2014 23:30:00 -0700 (PDT) Subject: cmd.exe on WIndows - problem with displaying some Unicode characters In-Reply-To: <53e13ddf$0$7267$c3e8da3$76a7c58f@news.astraweb.com> References: <53e13ddf$0$7267$c3e8da3$76a7c58f@news.astraweb.com> Message-ID: <7a351aa1-5943-4b98-8414-d209d3c3b0e2@googlegroups.com> Le mardi 5 ao?t 2014 22:26:08 UTC+2, Tony the Tiger a ?crit?: > > This works for me on Linux: > > It works on *your* linux, because *your* linux is automagically configured in the way the device that hosts "unicode" (the console in that case) "works in utf-8" (most probably). On a "Russian" linux using koi8 or a "French" linux using iso-8859-15, the problem is exacly similar as on Windows. This is valid for any OS. In essence, assuming the hosting device is "in utf-8" is as wrong as assuming it is in, eg. cp852 or any encoding. This has nothing to do with Unicode. jmf From breamoreboy at yahoo.co.uk Wed Aug 6 03:33:20 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 06 Aug 2014 08:33:20 +0100 Subject: Pythonic way to iterate through multidimensional space? In-Reply-To: References: Message-ID: On 06/08/2014 06:34, Gayathri J wrote: > Dear Peter > > Below is the code I tried to check if itertools.product() was faster > than normal nested loops... > > they arent! arent they supposed to be...or am i making a mistake? any idea? > * > * > *############################################################ > * > *# -*- coding: utf-8 -*- > * > *import numpy as np* > *import time* > *from itertools import product,repeat* > *def main():* > * # N - size of grid* > * # nvel - number of velocities* > * # times - number of times to run the functions* > * N=256* > * times=3* > * f=np.random.rand(N,N,N)* > ** > * # using loops* > * print "normal nested loop"* > * python_dot_loop1(f,times,N)* > * > * > * print "nested loop using itertools.product()"* > * python_dot_loop2(f,times,N)* > * > * > *def python_dot_loop1(f,times,N):* > * for t in range(times):* > * t1=time.time()* > * for i in range(N):* > * for j in range(N):* > * for k in range(N):* > * f[i,j,k] = 0.0* > * print "python dot loop " + str(time.time()-t1)* > ** > *def python_dot_loop2(f,times,N):* > * rangeN=range(N)* > * for t in range(times):* > * t1=time.time()* > * for i,j,k in product(rangeN,repeat=3):* > * f[i,j,k]=0.0* > * print "python dot loop " + str(time.time()-t1)* > * > * > * > * > *if __name__=='__main__':* > * main()* > *############################################################* > > Who cares, well not I for one? Give me slower but accurate code over faster but inaccurate code 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 __peter__ at web.de Wed Aug 6 03:39:42 2014 From: __peter__ at web.de (Peter Otten) Date: Wed, 06 Aug 2014 09:39:42 +0200 Subject: Pythonic way to iterate through multidimensional space? References: Message-ID: Gayathri J wrote: > Dear Peter > > Below is the code I tried to check if itertools.product() was faster than > normal nested loops... > > they arent! arent they supposed to be... I wouldn't have expected product() to be significantly faster, but neither did I expect it to be slower. > or am i making a mistake? any > idea? For your testcase you can shave off a small amount by avoiding the tuple- unpacking for t in product(...): f[t] = 0.0 but that may be cheating, and the effect isn't big. When you are working with numpy there may be specialised approaches, but f[:,:,:] = 0.0 is definitely cheating I suppose... From wojtekgiel at gmail.com Wed Aug 6 04:04:16 2014 From: wojtekgiel at gmail.com (Wojciech Giel) Date: Wed, 06 Aug 2014 09:04:16 +0100 Subject: Pythonic way to iterate through multidimensional space? In-Reply-To: References: Message-ID: <53E1E180.6070308@gmail.com> You might check numpy it is really powerful tool for working with multi dimensional arrays: ex. >>> a = arange(81).reshape(3,3,3,3) >>> a array([[[[ 0, 1, 2], [ 3, 4, 5], [ 6, 7, 8]], [[ 9, 10, 11], [12, 13, 14], [15, 16, 17]], [[18, 19, 20], [21, 22, 23], [24, 25, 26]]], [[[27, 28, 29], [30, 31, 32], [33, 34, 35]], [[36, 37, 38], [39, 40, 41], [42, 43, 44]], [[45, 46, 47], [48, 49, 50], [51, 52, 53]]], [[[54, 55, 56], [57, 58, 59], [60, 61, 62]], [[63, 64, 65], [66, 67, 68], [69, 70, 71]], [[72, 73, 74], [75, 76, 77], [78, 79, 80]]]]) >>> f = a.flat >>> for i in f: ... print(i) 0 1 2 .. 98 99 cheers Wojciech On 05/08/14 21:06, Frank Miles wrote: > I need to evaluate a complicated function over a multidimensional space > as part of an optimization problem. This is a somewhat general problem > in which the number of dimensions and the function being evaluated can > vary from problem to problem. > > I've got a working version (with loads of conditionals, and it only works > to #dimensions <= 10), but I'd like something simpler and clearer and > less hard-coded. > > I've web-searched for some plausible method, but haven't found anything > "nice". Any recommendations where I should look, or what technique should > be used? > > TIA! From elearn2014 at gmail.com Wed Aug 6 05:02:30 2014 From: elearn2014 at gmail.com (elearn) Date: Wed, 06 Aug 2014 17:02:30 +0800 Subject: How to delete letters automatically with imaplib? Message-ID: <53E1EF26.4020508@gmail.com> I have a gmail account 'xxx at gmail.com' which subscripted python maillist. To take part in python discussion is the only target for my xxx at gmail.com. There are so many emails in my xxx at gmail.com,it is a good idea for me to auto delete all emails whose body contain no . I write some codes to do the job. |import imaplib user="xxx" password="yyyyyy" con=imaplib.IMAP4_SSL('imap.gmail.com') con.login(user,password) con.select('INBOX') status, data= con.search(None, "ALL") print(len(data[0].split())) 48 typ, data= con.search(None, 'Body', '"xxx at gmail.com"') >>> data [b'1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 32 33 34 35 36 37 44'] len(data[0].split()) 36| How can i delete 48-36=12 letters? -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Wed Aug 6 05:14:34 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 06 Aug 2014 19:14:34 +1000 Subject: How to delete letters automatically with imaplib? References: <53E1EF26.4020508@gmail.com> Message-ID: <85d2ceasjp.fsf@benfinney.id.au> elearn writes: > status, data= con.search(None, "ALL") > print(len(data[0].split())) > 48 > typ, data= con.search(None, 'Body', '"xxx at gmail.com"') > >>> data > [b'1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 > 32 33 34 35 36 37 44'] > > len(data[0].split()) > 36 > > How can i delete 48-36=12 letters? Set operations are designed for this:: # Construct a set of all message numbers. status, data = con.search(None, "ALL") ids_of_all_messages = set(data[0].split()) # Construct a set of messages mentioning the address. status, data = con.search(None, 'Body', '"xxx at gmail.com"') ids_of_messages_containing_address = set(data[0].split()) # Get the messages to delete. ids_of_messages_to_delete = ( ids_of_all_messages - ids_of_messages_containing_address) -- \ ?Too many pieces of music finish too long after the end.? ?Igor | `\ Stravinskey | _o__) | Ben Finney From steve at pearwood.info Wed Aug 6 05:15:32 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 06 Aug 2014 09:15:32 GMT Subject: Making every no-arg method a property? References: <53e17b95$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53e1f234$0$11111$c3e8da3@news.astraweb.com> On Wed, 06 Aug 2014 12:07:58 +1000, Chris Angelico wrote: > On Wed, Aug 6, 2014 at 10:49 AM, Steven D'Aprano > wrote: >> A >> plethora of argument-less methods is a code smell -- that doesn't mean >> it's *necessarily* a bad idea, but the class design really needs a >> careful review. > > There are plenty of no-argument mutator methods, where the name of the > method (and the target object, obviously) is all the info you need. You > can clear() or copy() something with any more info, reverse() a list, > pop() from a list, etc. They don't have to be mutator methods. The same applies to string methods like upper(), lower(), isalpha() and many others. I'm not sure if you're agreeing or disagreeing with me. All these examples shouldn't be treated as properties either. This should be grounds for being slapped with a large herring: mydict.clear # returns None, operates by side-effect Some things are conceptually either methods or attributes: mydict.keys # could be okay I suppose but I digress. As I said, zero-argument (one-argument, if you count self) methods are a code smell, not an error. As is so often the case in programming, the fundamental sin here is *coupling* -- zero-argument methods are bad if they require coupling to temporary attributes which exist only to communicate an argument to the method. In other words, one of the sins of zero-argument methods is the same as that of zero-argument functions. We wouldn't write this: def double(): return number_to_operate_on*2 number_to_operate_on = 23 print double() number_to_operate_on = 42 print double() Turning it into a method on an instance, and turning the global into a "per instance global" (instead of per module, or application-wide) doesn't make it any better. -- Steven From alister.nospam.ware at ntlworld.com Wed Aug 6 06:09:36 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Wed, 06 Aug 2014 10:09:36 GMT Subject: Making every no-arg method a property? References: Message-ID: On Wed, 06 Aug 2014 10:34:04 +1200, Gregory Ewing wrote: > Grant Edwards wrote: >> Did I miss a news story? Have the parentesis mines all exploded >> causing the price of parenthesis to skyrocket? > > The Unicode Consortium has been secretly buying them up for some time > now. Pretty soon you won't be able to get cheap ASCII parentheses any > more, only the fancy high-priced ones like U+2045/U+2046, U+2772/U+2773 > and U+27E6/U+27E7. Perhaps that will make JMF rich enough to retire ;-) -- Live long and prosper. -- Spock, "Amok Time", stardate 3372.7 From alister.nospam.ware at ntlworld.com Wed Aug 6 06:12:31 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Wed, 06 Aug 2014 10:12:31 GMT Subject: Making every no-arg method a property? References: Message-ID: On Tue, 05 Aug 2014 12:39:18 -0700, Christian Calderon wrote: > I have been using python for 4 years now, and I just started learning > ruby. > I like that in ruby I don't have to type parenthesis at the end of each > function call if I don't need to provide extra arguments. I just > realized right now that I can do something similar in python, if I make > all methods with only the implicitly passed 'self' into properties. > Which means I can either do some fancy coding and make a metaclass that > does this auto-magically, or I have to have property decorators all over > the place :-P . I was wondering what other thought of this, is it an > overly fanciful way of coding python, or is it an acceptable thing to do > in a real project? > Also, would anyone be interested in helping me make this metaclass? >
I have been using python for 4 years now, and I just > started learning ruby. I like that in ruby I don't have to type > parenthesis at the end of each function call if I don't need to > provide extra arguments. I just realized right now that I can do > something similar in python, if I make all methods with only the > implicitly passed 'self' into properties. Which means I can > either do some fancy coding and make a metaclass that does this > auto-magically, or I have to have property decorators all over the place > :-P . I was wondering what other thought of this, is it an overly > fanciful way of coding python, or is it an acceptable thing to do in a > real project? Also, would anyone be interested in helping me make this > metaclass?
import this Special Cases are not special enough This is a horrible idea for python code -- Once is happenstance, Twice is coincidence, Three times is enemy action. -- Auric Goldfinger From elearn2014 at gmail.com Wed Aug 6 07:19:18 2014 From: elearn2014 at gmail.com (elearn) Date: Wed, 06 Aug 2014 19:19:18 +0800 Subject: How to delete letters automatically with imaplib? In-Reply-To: <85d2ceasjp.fsf@benfinney.id.au> References: <53E1EF26.4020508@gmail.com> <85d2ceasjp.fsf@benfinney.id.au> Message-ID: <53E20F36.70508@gmail.com> and how to write the delete command with imaplib? On 8/6/2014 5:14 PM, Ben Finney wrote: > elearn writes: > >> status, data= con.search(None, "ALL") >> print(len(data[0].split())) >> 48 >> typ, data= con.search(None, 'Body', '"xxx at gmail.com"') >>>>> data >> [b'1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 >> 32 33 34 35 36 37 44'] >> >> len(data[0].split()) >> 36 >> >> How can i delete 48-36=12 letters? > Set operations are designed for this:: > > # Construct a set of all message numbers. > status, data = con.search(None, "ALL") > ids_of_all_messages = set(data[0].split()) > > # Construct a set of messages mentioning the address. > status, data = con.search(None, 'Body', '"xxx at gmail.com"') > ids_of_messages_containing_address = set(data[0].split()) > > # Get the messages to delete. > ids_of_messages_to_delete = ( > ids_of_all_messages - ids_of_messages_containing_address) > From rosuav at gmail.com Wed Aug 6 07:26:47 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Aug 2014 21:26:47 +1000 Subject: Making every no-arg method a property? In-Reply-To: <53e1f234$0$11111$c3e8da3@news.astraweb.com> References: <53e17b95$0$29981$c3e8da3$5496439d@news.astraweb.com> <53e1f234$0$11111$c3e8da3@news.astraweb.com> Message-ID: On Wed, Aug 6, 2014 at 7:15 PM, Steven D'Aprano wrote: > On Wed, 06 Aug 2014 12:07:58 +1000, Chris Angelico wrote: > >> On Wed, Aug 6, 2014 at 10:49 AM, Steven D'Aprano >> wrote: >>> A >>> plethora of argument-less methods is a code smell -- that doesn't mean >>> it's *necessarily* a bad idea, but the class design really needs a >>> careful review. >> >> There are plenty of no-argument mutator methods, where the name of the >> method (and the target object, obviously) is all the info you need. You >> can clear() or copy() something with any more info, reverse() a list, >> pop() from a list, etc. > > They don't have to be mutator methods. The same applies to string methods > like upper(), lower(), isalpha() and many others. > > I'm not sure if you're agreeing or disagreeing with me. Agreeing with your primary point, disagreeing with this subpoint. > All these > examples shouldn't be treated as properties either. This should be > grounds for being slapped with a large herring: > > mydict.clear # returns None, operates by side-effect Wholeheartedly agree. These should NOT be properties. A property should not mutate state, normally (I can imagine exceptions, but they are *definitely* code smell, unless they're doing basic logging or something). What I disagree with is that argument-less methods, even a plethora thereof, are *themselves* code smell. Mutator methods, and the string methods that construct a "this string only different" result (which in many ways are the immutable object's equivalent of mutators), will often take no args, and are most definitely not properties, but IMO aren't code smell. Something like isalpha() is borderline, but making upper() a property implies that, conceptually, the upper-case version of a string is an attribute the string already has, rather than something that you construct from that string. It's debatable, but IMO it makes perfect sense to keep that as a method - and it's fine for it to take no args other than the object it's working on. > As I said, zero-argument (one-argument, if you count self) > methods are a code smell, not an error. As is so often the case in > programming, the fundamental sin here is *coupling* -- zero-argument > methods are bad if they require coupling to temporary attributes which > exist only to communicate an argument to the method. > > In other words, one of the sins of zero-argument methods is the same as > that of zero-argument functions. We wouldn't write this: > > def double(): > return number_to_operate_on*2 > > number_to_operate_on = 23 > print double() > number_to_operate_on = 42 > print double() > > > Turning it into a method on an instance, and turning the global into a > "per instance global" (instead of per module, or application-wide) > doesn't make it any better. But if it were written as: class float(float): pass # allow more attributes on float def double(self): return self*2 float.double = double number = float(23) print(number.double()) Then it's not hidden global state any more, but it's still a zero-argument method. Is that really just as bad? Surely it's the same as "print(double(number))"? ChrisA From ben+python at benfinney.id.au Wed Aug 6 07:29:41 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 06 Aug 2014 21:29:41 +1000 Subject: How to delete letters automatically with imaplib? References: <53E1EF26.4020508@gmail.com> <85d2ceasjp.fsf@benfinney.id.au> <53E20F36.70508@gmail.com> Message-ID: <858un1c0uy.fsf@benfinney.id.au> elearn writes: > and how to write the delete command with imaplib? (Please don't top-post. Instead, compose your responses interleaved so the conversation is easier to follow in the message.) I'm not familiar with the API of the ?imaplib? module. Start with and remember that it is a library designed to work intimately with the IMAP command-response protocol. If, instead, you wish to manipulate mailboxes without needing to know much about the detailed features of the storage format, use the ?mailbox? module for that purpose. -- \ ?No matter how cynical you become, it's never enough to keep | `\ up.? ?Jane Wagner, via Lily Tomlin | _o__) | Ben Finney From usethisid2014 at gmail.com Wed Aug 6 08:13:43 2014 From: usethisid2014 at gmail.com (Gayathri J) Date: Wed, 6 Aug 2014 17:43:43 +0530 Subject: Pythonic way to iterate through multidimensional space? In-Reply-To: <53E1E180.6070308@gmail.com> References: <53E1E180.6070308@gmail.com> Message-ID: Dear Peter Yes the f[t] or f[:,:,:] might give a marginal increase, but then i need to do further operations using the indices, in which case this wouldnt help Dear Wojciech np.flat() works if u dont care about the indices and only the matrix/array values matter. but if the matters, flatten wouldnt work On Wed, Aug 6, 2014 at 1:34 PM, Wojciech Giel wrote: > You might check numpy it is really powerful tool for working with multi > dimensional arrays: > > ex. > >>> a = arange(81).reshape(3,3,3,3) > >>> a > > array([[[[ 0, 1, 2], > [ 3, 4, 5], > [ 6, 7, 8]], > > [[ 9, 10, 11], > [12, 13, 14], > [15, 16, 17]], > > [[18, 19, 20], > [21, 22, 23], > [24, 25, 26]]], > > > [[[27, 28, 29], > [30, 31, 32], > [33, 34, 35]], > > [[36, 37, 38], > [39, 40, 41], > [42, 43, 44]], > > [[45, 46, 47], > [48, 49, 50], > [51, 52, 53]]], > > > [[[54, 55, 56], > [57, 58, 59], > [60, 61, 62]], > > [[63, 64, 65], > [66, 67, 68], > [69, 70, 71]], > > [[72, 73, 74], > [75, 76, 77], > [78, 79, 80]]]]) > > >>> f = a.flat > >>> for i in f: > ... print(i) > 0 > 1 > 2 > .. > 98 > 99 > > cheers > Wojciech > > > > > On 05/08/14 21:06, Frank Miles wrote: > >> I need to evaluate a complicated function over a multidimensional space >> as part of an optimization problem. This is a somewhat general problem >> in which the number of dimensions and the function being evaluated can >> vary from problem to problem. >> >> I've got a working version (with loads of conditionals, and it only works >> to #dimensions <= 10), but I'd like something simpler and clearer and >> less hard-coded. >> >> I've web-searched for some plausible method, but haven't found anything >> "nice". Any recommendations where I should look, or what technique should >> be used? >> >> TIA! >> > > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Wed Aug 6 08:39:36 2014 From: __peter__ at web.de (Peter Otten) Date: Wed, 06 Aug 2014 14:39:36 +0200 Subject: Pythonic way to iterate through multidimensional space? References: <53E1E180.6070308@gmail.com> Message-ID: Gayathri J wrote: > Dear Peter > > Yes the f[t] or f[:,:,:] might give a marginal increase, The speedup compared itertools.product() is significant: $ python -m timeit -s 'from itertools import product; from numpy.random import rand; N = 100; a = rand(N, N, N); r = range(N)' 'for x in product(r, repeat=3): a[x] = 0.0' 10 loops, best of 3: 290 msec per loop $ python -m timeit -s 'from itertools import product; from numpy.random import rand; N = 100; a = rand(N, N, N); r = range(N)' 'a[:,:,:] = 0.0' 100 loops, best of 3: 3.58 msec per loop But normally you'd just make a new array with numpy.zeros(). > but then i need > to do further operations using the indices, in which case this wouldnt > help Which is expected and also the crux of such micro-benchmarks. They distract from big picture. From feliphil at gmx.net Wed Aug 6 08:38:53 2014 From: feliphil at gmx.net (Wolfgang Keller) Date: Wed, 6 Aug 2014 14:38:53 +0200 Subject: Python and IDEs [was Re: Python 3 is killing Python] References: <87zjga4j4v.fsf@elektro.pacujo.net> <53c57bae$0$9505$c3e8da3$5496439d@news.astraweb.com> <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> Message-ID: <20140806143853.4ae3c37a34f8f9a482d3ce2e@gmx.net> > > Thankfully, all actually user-friendly operating systems (MacOS, > > TOS, RiscOS, probably AmigaOS, MacOS X) spare(d) their users the > > bottomless cesspit of "package management" and/or "installers". > > > > Because on such operating systems, each and every application is an > > entirely self-contained package that doesn't need any "packages" or > > "installers" to use it. > > You mean everyone has to reinvent the proverbial wheel AND worry about > dependency collisions? Yeah, that's a heavenly thought. You should get a clue in stead of just fantasizing up assumptions based on ignorance. Sincerely, Wolfgang From feliphil at gmx.net Wed Aug 6 08:47:17 2014 From: feliphil at gmx.net (Wolfgang Keller) Date: Wed, 6 Aug 2014 14:47:17 +0200 Subject: Python and IDEs [was Re: Python 3 is killing Python] References: <87zjga4j4v.fsf@elektro.pacujo.net> <53c57bae$0$9505$c3e8da3$5496439d@news.astraweb.com> <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> Message-ID: <20140806144717.8847deb8b0bea888b89d814b@gmx.net> > > Because on such operating systems, each and every application is an > > entirely self-contained package that doesn't need any "packages" or > > "installers" to use it. > For people who have never used such a system it's probably difficult > to see the advantages. That's the whole point. The problem is that the ones who "decide" (well, they pretend to, but actually can't, because they don't know the alternatives) are always people who are "not even clueless". I.e. they are totally clueless, *and* psychotically self-convinced of their omnicompetence. Sincerely, Wolfgang From feliphil at gmx.net Wed Aug 6 08:47:58 2014 From: feliphil at gmx.net (Wolfgang Keller) Date: Wed, 6 Aug 2014 14:47:58 +0200 Subject: Python and IDEs [was Re: Python 3 is killing Python] References: <87zjga4j4v.fsf@elektro.pacujo.net> <53c57bae$0$9505$c3e8da3$5496439d@news.astraweb.com> <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> Message-ID: <20140806144758.f5817ee60d0e98ff30172a2a@gmx.net> > I've worked with both. Quite honestly, I really wish that other > operating systems had gone down this route. MS didn't possibly to make > it harder to steal software, >From the perspective of the computer-literate, proficient screenworker, MS always got and gets everything completely wrong. > and Unix...well, *nix has the concept of the "distribution" that will > manage all of this for you. We all know the problems that this > causes. Linux was made by geeks who didn't have a clue of ergonomics for screenworkers and didn't care to get one. Sincerely, Wolfgang From rosuav at gmail.com Wed Aug 6 08:51:42 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Aug 2014 22:51:42 +1000 Subject: Python and IDEs [was Re: Python 3 is killing Python] In-Reply-To: <20140806143853.4ae3c37a34f8f9a482d3ce2e@gmx.net> References: <87zjga4j4v.fsf@elektro.pacujo.net> <53c57bae$0$9505$c3e8da3$5496439d@news.astraweb.com> <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> <20140806143853.4ae3c37a34f8f9a482d3ce2e@gmx.net> Message-ID: On Wed, Aug 6, 2014 at 10:38 PM, Wolfgang Keller wrote: >> > Thankfully, all actually user-friendly operating systems (MacOS, >> > TOS, RiscOS, probably AmigaOS, MacOS X) spare(d) their users the >> > bottomless cesspit of "package management" and/or "installers". >> > >> > Because on such operating systems, each and every application is an >> > entirely self-contained package that doesn't need any "packages" or >> > "installers" to use it. >> >> You mean everyone has to reinvent the proverbial wheel AND worry about >> dependency collisions? Yeah, that's a heavenly thought. > > You should get a clue in stead of just fantasizing up assumptions based > on ignorance. I've worked with a number of operating systems, a number of dependency management systems, and a number of absences of such systems. I stand by my earlier statements in this thread, and I think I have a fairly good clue about what does and doesn't work in terms of installers. There is one way to avoid most of the duplication and still make every application perfectly self-contained. You simply decree that there are no dependencies permitted except for the base OS itself and what it provides. As long as that's a rich enough set of tools, everything can work (that's what seems to be happening on mobile platforms, for instance). But it does mean that any unusual dependencies have to be considered part of the app, and that means duplication. ChrisA From python.list at tim.thechases.com Wed Aug 6 07:39:23 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 6 Aug 2014 06:39:23 -0500 Subject: Pythonic way to iterate through multidimensional space? In-Reply-To: References: Message-ID: <20140806063923.750b81d6@bigbox.christie.dr> On 2014-08-06 11:04, Gayathri J wrote: > Below is the code I tried to check if itertools.product() was > faster than normal nested loops... > > they arent! arent they supposed to be...or am i making a mistake? I believe something like this was discussed a while ago and there was a faster-but-uglier solution so you might want to consult this thread: https://mail.python.org/pipermail/python-list/2008-January/516109.html I believe this may have taken place before itertools.product() came into existence. -tkc From usethisid2014 at gmail.com Wed Aug 6 09:27:25 2014 From: usethisid2014 at gmail.com (Gayathri J) Date: Wed, 6 Aug 2014 18:57:25 +0530 Subject: Pythonic way to iterate through multidimensional space? In-Reply-To: References: <53E1E180.6070308@gmail.com> Message-ID: Dear Peter thanks . But thats what I was trying to say just taking them to zero by f[:,:,:] = 0.0 or using np.zeros is surely going to give me a time gain... but my example of using the itertools.product() and doing f[x] =0.0 is just to compare the looping timing with the traditional nested loops and not to distract us to the operation done inside the loop. right? On Wed, Aug 6, 2014 at 6:09 PM, Peter Otten <__peter__ at web.de> wrote: > Gayathri J wrote: > > > Dear Peter > > > > Yes the f[t] or f[:,:,:] might give a marginal increase, > > The speedup compared itertools.product() is significant: > > $ python -m timeit -s 'from itertools import product; from numpy.random > import rand; N = 100; a = rand(N, N, N); r = range(N)' 'for x in product(r, > repeat=3): a[x] = 0.0' > 10 loops, best of 3: 290 msec per loop > > $ python -m timeit -s 'from itertools import product; from numpy.random > import rand; N = 100; a = rand(N, N, N); r = range(N)' 'a[:,:,:] = 0.0' > 100 loops, best of 3: 3.58 msec per loop > > But normally you'd just make a new array with numpy.zeros(). > > > but then i need > > to do further operations using the indices, in which case this wouldnt > > help > > Which is expected and also the crux of such micro-benchmarks. They distract > from big picture. > > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From beliavsky at aol.com Wed Aug 6 09:47:24 2014 From: beliavsky at aol.com (beliavsky at aol.com) Date: Wed, 6 Aug 2014 06:47:24 -0700 (PDT) Subject: Python 3 is killing Python In-Reply-To: References: <7xha49wumw.fsf@ruckus.brouhaha.com> Message-ID: <88649f2d-76c2-41af-a509-23486bd06dff@googlegroups.com> On Wednesday, May 28, 2014 6:38:22 PM UTC-4, Ben Finney wrote: > Larry Martell writes: > > > > > No company that I work for is using python 3 - they just have too much > > > of an investment in a python 2 code base to switch. > > > > There are many large companies still using FORTRAN and COBOL because of > > a large investment in those languages, which are far more outdated than > > Python 2. What's your point? Fortran compiler vendors such as Intel, IBM, Oracle/SUN and open source projects such as gfortran are updating their compilers to the Fortran 2003 and 2008 standards while also keeping the ability to compile all the old Fortran code. FORTRAN 77 programmers and programs will not be forced to move to modern Fortran, but I'm not sure that Python 2.x users can be as confident that Python 2.x will be supported on future operating systems. From elearn2014 at gmail.com Wed Aug 6 10:03:22 2014 From: elearn2014 at gmail.com (elearn) Date: Wed, 06 Aug 2014 22:03:22 +0800 Subject: why i can not delete my email with imaplib? Message-ID: <53E235AA.2010105@gmail.com> I have a gmail account 'xxx at gmail.com' which subscripted python maillist. I want to delete any emails which is sent to python-list at python.org . |import imaplib user="xxx" password="yyyyyy" con=imaplib.IMAP4_SSL('imap.gmail.com') con.login(user,password) con.select('[Gmail]/&YkBnCZCuTvY-') type, data= con.search(None, "All") type1, data1= con.search(None, '(TO "python-list at python.org")') ids_all= set(data[0].split()) ids1=set(data1[0].split()) ids_deleted=set(ids_all-ids1) for numin ids_deleted: con.store(num, '+FLAGS', '\\Deleted') con.expunge()| When i open my gmail with thunderbird ,the emails which are sent to python-list at python.org are still in my gmail,Why i can't delete them? -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: Untitled.png Type: image/png Size: 78779 bytes Desc: not available URL: From skip at pobox.com Wed Aug 6 11:34:05 2014 From: skip at pobox.com (Skip Montanaro) Date: Wed, 6 Aug 2014 10:34:05 -0500 Subject: why i can not delete my email with imaplib? In-Reply-To: <53E235AA.2010105@gmail.com> References: <53E235AA.2010105@gmail.com> Message-ID: My apologies. I must be dense. Why do you want to do this from Python? Can't you accomplish the same thing more easily with a Gmail filter which deletes all messages sent to python-list at python.org? Also, I assume that if you use "xxx at gmail.com" only so you can send mail to the list, why not just disable message delivery altogether through the Mailman interface. That would avoid the necessity of deleting the mail at all. > When i open my gmail with thunderbird ,the emails which are sent to > python-list at python.org are still in my gmail... Do you perhaps need to force Thunderbird to refresh its view of your mailbox? Skip From rgaddi at technologyhighland.invalid Wed Aug 6 12:53:16 2014 From: rgaddi at technologyhighland.invalid (Rob Gaddi) Date: Wed, 6 Aug 2014 09:53:16 -0700 Subject: Making every no-arg method a property? References: Message-ID: <20140806095316.4fece04e@rg.highlandtechnology.com> On Wed, 6 Aug 2014 05:13:07 +0000 (UTC) Grant Edwards wrote: > On 2014-08-05, Gregory Ewing wrote: > > Grant Edwards wrote: > >> Did I miss a news story? Have the parentesis mines all exploded > >> causing the price of parenthesis to skyrocket? > > > > The Unicode Consortium has been secretly buying them > > up for some time now. Pretty soon you won't be able > > to get cheap ASCII parentheses any more, only the > > fancy high-priced ones like U+2045/U+2046, > > U+2772/U+2773 and U+27E6/U+27E7. > > Damn. Time to buy some options... > > -- > Grant > No, no. Options use up commas, not parentheses. Maybe equals signs if you're feeling particularly verbose. Clearly there's a market for some sort of well-diversified punctuation fund. The only problem becomes listing it. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From maximesteisel at gmail.com Wed Aug 6 13:03:38 2014 From: maximesteisel at gmail.com (Maxime Steisel) Date: Wed, 6 Aug 2014 19:03:38 +0200 Subject: asyncio with map&reduce flavor and without flooding the event loop In-Reply-To: References: Message-ID: 2014-08-03 16:01 GMT+02:00 Valery Khamenya : > Hi all > > [snip] > > Consider a task like crawling the web starting from some web-sites. Each > site leads to generation of new downloading tasks in exponential(!) > progression. However we don't want neither to flood the event loop nor to > overload our network. We'd like to control the task flow. This is what I > achieve well with modification of nice Maxime's solution proposed here: > https://mail.python.org/pipermail/python-list/2014-July/675048.html > > Well, but I'd need as well a very natural thing, kind of map() & reduce() or > functools.reduce() if we are on python3 already. That is, I'd need to call a > "summarizing" function for all the downloading tasks completed on links from > a page. This is where i fail :( Hi Valery, With the modified as_completed, you can write map and reduce primitives quite naturally. It could look like that: ======== def async_map(corofunc, *iterables): """ Equivalent to map(corofunc, *iterables) except that corofunc must be a coroutine function and is executed asynchronously. This is not a coroutine, just a normal generator yielding Task instances. """ for args in zip(*iterables): yield asyncio.async(corofunc(*args)) @asyncio.coroutine def async_reduce(corofunc, futures, initial=0): """ Equivalent to functools.reduce(corofunc, [f.result() for f in futures]) except that corofunc must be a coroutine function and future results can be evaluated out-of order. This function is a coroutine. """ result = initial for f in as_completed(futures, max_workers=50): new_value = (yield from f) result = (yield from corofunc(result, new_value)) return result ======= Best, Maxime From joel.goldstick at gmail.com Wed Aug 6 14:31:19 2014 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Wed, 6 Aug 2014 14:31:19 -0400 Subject: converting ISO8601 date and time string representations to datetime In-Reply-To: <8738df7gav.fsf@gmail.com> References: <53DB3931.8070406@biologie.uni-freiburg.de> <8738df7gav.fsf@gmail.com> Message-ID: On Fri, Aug 1, 2014 at 10:53 PM, Akira Li <4kir4.1i at gmail.com> wrote: > Wolfgang Maier writes: > >> On 08/01/2014 01:30 AM, Roy Smith wrote: >>> In article , >>> Albert-Jan Roskam wrote: >>> >>>>> In article , >>>>> Wolfgang Maier wrote: >>>>> >>>>>> Hi, >>>>>> I'm trying to convert ISO8601-compliant strings representing dates or >>>>>> dates and times into datetime.datetime objects. >>>>> >>>>> https://pypi.python.org/pypi/iso8601 >>>> >>>> Yikes, what a regex. It must have been painstaking to get that right. >>>> https://bitbucket.org/micktwomey/pyiso8601/src/2bd28b5d6cd2481674a8b0c54a8bba6 >>>> 4ab775f81/iso8601/iso8601.py?at=default >>> >>> It is a thing of beauty. >>> >> >> No wonder I found it hard to write something that seemed bulletproof ! > > It seems it supports only some custom subset of ISO 8601. There is rfc > 3339 [1] that describes a profile of the ISO 8601 standard. > > rfc 3339 combines human readability with the simplicity of machine parsing. > > [1] http://tools.ietf.org/html/rfc3339 > > > -- > Akira > > -- > https://mail.python.org/mailman/listinfo/python-list I just came across this package: http://crsmithdev.com/arrow/ Among other features it lists this: Gaps in functionality: ISO-8601 parsing, timespans, humanization -- Joel Goldstick http://joelgoldstick.com From tjreedy at udel.edu Wed Aug 6 14:42:54 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 06 Aug 2014 14:42:54 -0400 Subject: Python 3 is killing Python In-Reply-To: <88649f2d-76c2-41af-a509-23486bd06dff@googlegroups.com> References: <7xha49wumw.fsf@ruckus.brouhaha.com> <88649f2d-76c2-41af-a509-23486bd06dff@googlegroups.com> Message-ID: On 8/6/2014 9:47 AM, beliavsky at aol.com.dmarc.invalid wrote: > Fortran compiler vendors such as Intel, IBM, Oracle/SUN and open *Vendors* sell compilers for money, which they can then use to *pay* people to do unfun stuff that volunteers don't want and should not have to do. Actually, I am beginning to think that 2.7 should be split off for 3.x development and charged for. > source projects such as gfortran are updating their compilers to the > Fortran 2003 and 2008 standards while also keeping the ability to > compile all the old Fortran code. FORTRAN 77 programmers and programs According to https://gcc.gnu.org/fortran/ , gfortran is a standard Fortran 95 compiler with legacy (F77) support where practical and 'significant' F2003 and F2008 support. Since it is free, one takes what one gets. In multiple ways, Gfortran, as a whole, is significantly simpler to develop than Python. It is an alternate front end to the gcc compiler (a very smart decision). The GNU projects distributes source code, which I presume consists of C code aimed at the GCC compiler. > will not be forced to move to modern Fortran, but I'm not sure that > Python 2.x users can be as confident that Python 2.x will be > supported on future operating systems. It will be for as long as 2.x users are willing to pay for support. -- Terry Jan Reedy From tjreedy at udel.edu Wed Aug 6 15:04:46 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 06 Aug 2014 15:04:46 -0400 Subject: Making every no-arg method a property? In-Reply-To: References: Message-ID: On 8/6/2014 6:09 AM, alister wrote: > On Wed, 06 Aug 2014 10:34:04 +1200, Gregory Ewing wrote: > >> Grant Edwards wrote: >>> Did I miss a news story? Have the parentesis mines all exploded >>> causing the price of parenthesis to skyrocket? >> >> The Unicode Consortium has been secretly buying them up for some time >> now. Pretty soon you won't be able to get cheap ASCII parentheses any >> more, only the fancy high-priced ones like U+2045/U+2046, U+2772/U+2773 >> and U+27E6/U+27E7. > > Perhaps that will make JMF rich enough to retire ;-) Gratuitous personal digs are disrespectful and out of place on this list, especially when the target has not even participated in the thread. -- Terry Jan Reedy From skip at pobox.com Wed Aug 6 15:05:29 2014 From: skip at pobox.com (Skip Montanaro) Date: Wed, 6 Aug 2014 14:05:29 -0500 Subject: converting ISO8601 date and time string representations to datetime In-Reply-To: References: <53DB3931.8070406@biologie.uni-freiburg.de> <8738df7gav.fsf@gmail.com> Message-ID: On Wed, Aug 6, 2014 at 1:31 PM, Joel Goldstick wrote: > Among other features it lists this: Gaps in functionality: ISO-8601 > parsing, timespans, humanization What is "humanization"? Skip From vs at it.uu.se Wed Aug 6 17:46:18 2014 From: vs at it.uu.se (Virgil Stokes) Date: Wed, 06 Aug 2014 23:46:18 +0200 Subject: Test for an empty directory that could be very large if it is not empty? Message-ID: <53E2A22A.10906@it.uu.se> Suppose I have a directory C:/Test that is either empty or contains more than 2000000 files, all with the same extension (e.g. *.txt). How can I determine if the directory is empty WITHOUT the generation of a list of the file names in it (e.g. using os.listdir('C:/Test')) when it is not empty? From ben+python at benfinney.id.au Wed Aug 6 18:26:49 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 07 Aug 2014 08:26:49 +1000 Subject: Test for an empty directory that could be very large if it is not empty? References: <53E2A22A.10906@it.uu.se> Message-ID: <854mxpb6fq.fsf@benfinney.id.au> Virgil Stokes writes: > Suppose I have a directory C:/Test that is either empty or contains > more than 2000000 files, all with the same extension (e.g. *.txt). How > can I determine if the directory is empty WITHOUT the generation of a > list of the file names in it (e.g. using os.listdir('C:/Test')) when > it is not empty? What is your goal for that? Have you measured the performance difference and decided *based on objective observation* that it's too expensive? Certainly ?os.listdir(foo)? is the simplest way to determine the entries in a directory, and thereby to test whether it is empty. That simplicity is very valuable, and you should have a compelling, *measured* reason to do something more complicated. What is it? -- \ ?The most dangerous man to any government is the man who is | `\ able to think things out for himself, without regard to the | _o__) prevailing superstitions and taboos.? ?Henry L. Mencken | Ben Finney From python.list at tim.thechases.com Wed Aug 6 18:44:41 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 6 Aug 2014 17:44:41 -0500 Subject: Test for an empty directory that could be very large if it is not empty? In-Reply-To: <854mxpb6fq.fsf@benfinney.id.au> References: <53E2A22A.10906@it.uu.se> <854mxpb6fq.fsf@benfinney.id.au> Message-ID: <20140806174441.3a2e16e1@bigbox.christie.dr> On 2014-08-07 08:26, Ben Finney wrote: > Virgil Stokes writes: > > Suppose I have a directory C:/Test that is either empty or > > contains more than 2000000 files, all with the same extension > > (e.g. *.txt). How can I determine if the directory is empty > > WITHOUT the generation of a list of the file names in it (e.g. > > using os.listdir('C:/Test')) when it is not empty? > > Certainly ?os.listdir(foo)? is the simplest way to determine the > entries in a directory, and thereby to test whether it is empty. > That simplicity is very valuable, and you should have a compelling, > *measured* reason to do something more complicated. What is it? With all the changes in 2->3 where many listy things were made into iteratory things (e.g. range()), I was surprised that os.listdir() didn't do likewise since I believe that just about every OS uses some iterator-like call behind the scenes anyways. The difference in timings when serving a web-request are noticeable (in my use-case, I had to change my algorithm and storage structure to simplify/avoid heavily-populated directories) -tkc From cs at zip.com.au Wed Aug 6 19:09:06 2014 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 7 Aug 2014 09:09:06 +1000 Subject: Davis putnam algorithm for satisfiability... In-Reply-To: <45dc6b5a-a4cc-4b02-bec1-fe64768d7786@googlegroups.com> References: <45dc6b5a-a4cc-4b02-bec1-fe64768d7786@googlegroups.com> Message-ID: <20140806230906.GA97452@cskk.homeip.net> On 05Aug2014 07:03, varun7rs at gmail.com wrote: >Thank you Cameron. Your post was very helpful. If you don't mind I'd like to ask you the purpose of the final list in the very beginning of the code. It is being updated and then checked for the presence of a literal. If a literal is found it returns not equivalent. Could you brief me the use of a final list? Not entirely, no. The python code is not very good, so the subtleties of the algorithm are harder to see on inspection. We can talk about those issues later if you like. It looks to me as though this is a truncated version of the full algorithm. It is currently written to abort the whole program if it decides that the cnf is not satisfiable. Maybe. In the (I am guessing hacked) code in your email, any single element sub-cnf has its components appended to the final_list and then the list is scanned for nonempty items; if one is found the whole program aborts. Otherwise the list itself is returned (and universally ignored, which is why I think this code is modified from a more complete original). I think in the original the final_list is supposed to be a list of things to examine later, possibly a list of subexpressions not yet determined to be satisfiable. In this code it is never examined and you could possibly get away with a direct examination of cnf[0][0] at that point, ignoring final_list. The only reason I have any uncertainty is that the cnf trees get modified by the del_sat() function, and so I'm not sure that the stuff put on final_list is unchanged later. So the short answer is: final_list is almost unused in this version of the code and could possibly be removed, but the code is sufficiently uncommented and clearly not the original algorithm, and the cnf structured modified in place, that I am not entirely sure. It is further complicated by the fact that this is not just the davis-putnam algorithm on its own, it is that algorithm being used (I think) to compare two boolean logic circuits for equivalence, possibly by assembling a cnf representing circuit1 xor circuit2: if they are equivalent then I would expect that to be not satisfiable but I have not thought it through completely. You'd better hope those two circuits have no loops; I would not expect the algorithm to be sufficient in the face of a loop. Cheers, Cameron Simpson If I had thought about it, I wouldn't have done the experiment. The literature was full of examples that said you can't do this. --Spencer Silver on the work that led to the unique adhesives for 3-M "Post-It" Notepads. From tjreedy at udel.edu Wed Aug 6 21:15:04 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 06 Aug 2014 21:15:04 -0400 Subject: Test for an empty directory that could be very large if it is not empty? In-Reply-To: <20140806174441.3a2e16e1@bigbox.christie.dr> References: <53E2A22A.10906@it.uu.se> <854mxpb6fq.fsf@benfinney.id.au> <20140806174441.3a2e16e1@bigbox.christie.dr> Message-ID: On 8/6/2014 6:44 PM, Tim Chase wrote: > On 2014-08-07 08:26, Ben Finney wrote: >> Virgil Stokes writes: >>> Suppose I have a directory C:/Test that is either empty or >>> contains more than 2000000 files, all with the same extension >>> (e.g. *.txt). How can I determine if the directory is empty >>> WITHOUT the generation of a list of the file names in it (e.g. >>> using os.listdir('C:/Test')) when it is not empty? >> >> Certainly ?os.listdir(foo)? is the simplest way to determine the >> entries in a directory, and thereby to test whether it is empty. >> That simplicity is very valuable, and you should have a compelling, >> *measured* reason to do something more complicated. What is it? > > With all the changes in 2->3 where many listy things were made into > iteratory things (e.g. range()), I was surprised that os.listdir() > didn't do likewise since I believe that just about every OS uses some > iterator-like call behind the scenes anyways. I expect 3.5 will have a scandir generator function. > The difference in timings when serving a web-request are noticeable > (in my use-case, I had to change my algorithm and storage structure > to simplify/avoid heavily-populated directories) > > -tkc > > -- Terry Jan Reedy From ben+python at benfinney.id.au Wed Aug 6 21:27:11 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 07 Aug 2014 11:27:11 +1000 Subject: Test for an empty directory that could be very large if it is not empty? References: <53E2A22A.10906@it.uu.se> <854mxpb6fq.fsf@benfinney.id.au> <20140806174441.3a2e16e1@bigbox.christie.dr> Message-ID: <85ppgd9jio.fsf@benfinney.id.au> Tim Chase writes: > The difference in timings when serving a web-request are noticeable > (in my use-case, I had to change my algorithm and storage structure to > simplify/avoid heavily-populated directories) So, if the requirement is ?test whether the directory is empty faster than N microseconds?, that's quite different from ?without the generation of a list of the file names?. The former may entail the latter, but that's not to be assumed, and chasing an optimisation prematurely is a common cause of terrible code. Therefore, I'm asking the OP what is their (so far unstated) reason for caring about the implementation of a standard library call. Without that, it would be folly to try to suggest a solution. With that, it may turn out the stated requirement isn't relevant for satisfying the actual requirement. I don't know (and it's possible the OP doesn't know) the relevance of the ?create a list of entries? part, so I asked. -- \ ?Science is a way of trying not to fool yourself. The first | `\ principle is that you must not fool yourself, and you are the | _o__) easiest person to fool.? ?Richard P. Feynman, 1964 | Ben Finney From steve+comp.lang.python at pearwood.info Wed Aug 6 22:42:22 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 07 Aug 2014 12:42:22 +1000 Subject: Python 3 is killing Python References: <7xha49wumw.fsf@ruckus.brouhaha.com> <88649f2d-76c2-41af-a509-23486bd06dff@googlegroups.com> Message-ID: <53e2e78f$0$30002$c3e8da3$5496439d@news.astraweb.com> Terry Reedy wrote: > On 8/6/2014 9:47 AM, beliavsky at aol.com.dmarc.invalid wrote: > >> Fortran compiler vendors such as Intel, IBM, Oracle/SUN and open > > *Vendors* sell compilers for money, which they can then use to *pay* > people to do unfun stuff that volunteers don't want and should not have > to do. Red Hat does this, and will offer support for 2.7 until 2023. But even Red Hat doesn't offer to support software forever -- Python 2.3 has just reached end of life with paid Red Hat support earlier this year. Anyone still using 2.3 now has two choices, keep using it without support, or upgrade. The same will apply to 2.7 users. It's not like their computer will suddenly stop running 2.7. Come 2020 when Python 2.7 stops receiving free support from the core developers, there's a business opportunity for the 2.7-naysayers. Red Hat support is Red Hat Enterprise Linux only. There may be paid support from companies like ActiveState, but that's likely to be Windows only (I could be wrong about that). So there's the opportunity: in 2020, those naysayers who are convinced that Python 3 is a mistake can offer paid support on whatever platforms they like. > Actually, I am beginning to think that 2.7 should be split off for 3.x > development and charged for. Python is open source. Anyone can fork it, and release 2.8, 2.9, 2.10, as many versions they like. The only thing they can't do is call it "Python 2.8" without agreement from the PSF, which they won't get. But they won't fork it, for two reasons: Complaining is cheap, actually maintaining a programming language is hard work. And deep down they know that a fork will be just a waste of time. This is not like the fork of the X-11 windowing system a few years back, for all the complaints and whinging about Python 3 even the nay-sayers know that the world will remain full behind Guido, the core developers and the PSF, who are all committed to Python 3. Let me be frank here: the core developers are committed to making the process of migrating from 2 to 3 as easy as possible without compromising Python 3 in any serious manner. E.g. minor cosmetic warts, like the re-introduction of u"" syntax just for backwards compatibility reasons, may be allowed, reversing design decisions like strings being Unicode rather than bytes will not be. But ultimately, people will need to make a choice: - spend the time and effort and money to migrate from Python 2 to 3; - spend an order of magnitude more time and effort and money to re-write their applications in another language; - pay somebody to support Python 2.7 for as long as needed; - or do without bug fixes and security updates. If you want bug fixes, security updates AND feature enhancements, for free, you have have to migrate to Python 3 (or another language). If you're unhappy with that, write to Oprah, I'm sure she'll listen. -- Steven From Seymore4Head at Hotmail.invalid Wed Aug 6 22:58:51 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Wed, 06 Aug 2014 22:58:51 -0400 Subject: Wikibooks example doesn't work Message-ID: number = 7 guess = -1 count = 0 print("Guess the number!") while guess != number: guess = int(input("Is it... ")) count = count + 1 if guess == number: print("Hooray! You guessed it right!") elif guess < number: print("It's bigger...") elif guess > number: print("It's not so big.") if count > 3: print("That must have been complicated.") else: print("Good job!") http://en.wikibooks.org/wiki/Non-Programmer%27s_Tutorial_for_Python_3/Decisions Why not? I think I know why it isn't working, but I don't know enough yet on how it should work. The If statement isn't getting read. From rosuav at gmail.com Wed Aug 6 23:11:18 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Aug 2014 13:11:18 +1000 Subject: Wikibooks example doesn't work In-Reply-To: References: Message-ID: On Thu, Aug 7, 2014 at 12:58 PM, Seymore4Head wrote: > Why not? > I think I know why it isn't working, but I don't know enough yet on > how it should work. > The If statement isn't getting read. One thing you need to learn about Python... or, for that matter, pretty much any language. "It isn't working" is not very helpful; what you need to do is show what you expect and what it does. If the script throws an exception, post the full traceback. ChrisA From gordon at panix.com Wed Aug 6 23:18:35 2014 From: gordon at panix.com (John Gordon) Date: Thu, 7 Aug 2014 03:18:35 +0000 (UTC) Subject: Wikibooks example doesn't work References: Message-ID: In Seymore4Head writes: > number = 7 > guess = -1 > count = 0 > > print("Guess the number!") > while guess != number: > guess = int(input("Is it... ")) > count = count + 1 > if guess == number: > print("Hooray! You guessed it right!") > elif guess < number: > print("It's bigger...") > elif guess > number: > print("It's not so big.") > > if count > 3: > print("That must have been complicated.") > else: > print("Good job!") > http://en.wikibooks.org/wiki/Non-Programmer%27s_Tutorial_for_Python_3/Decisions > Why not? > I think I know why it isn't working, but I don't know enough yet on > how it should work. > The If statement isn't getting read. It would help tremendously if you gave us more detail than "it doesn't work". Do you get an error message? Does the program not execute at all? Does it execute, but give unexpected results? -- 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 steve+comp.lang.python at pearwood.info Wed Aug 6 23:25:38 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 07 Aug 2014 13:25:38 +1000 Subject: Test for an empty directory that could be very large if it is not empty? References: <53E2A22A.10906@it.uu.se> Message-ID: <53e2f1b3$0$29980$c3e8da3$5496439d@news.astraweb.com> Ben Finney wrote: > Virgil Stokes writes: > >> Suppose I have a directory C:/Test that is either empty or contains >> more than 2000000 files, all with the same extension (e.g. *.txt). How >> can I determine if the directory is empty WITHOUT the generation of a >> list of the file names in it (e.g. using os.listdir('C:/Test')) when >> it is not empty? > > What is your goal for that? Have you measured the performance difference > and decided *based on objective observation* that it's too expensive? Normally I would agree with you, but this is one case where there is no need to measure, we can tell in advance that at least sometimes there will be a severe performance hit simply by considering the nature of file systems. In particular, consider the case where the directory is a remote file system on the other side of the world over a link with many dropped packets or other noise. Waiting for 200 thousand file names to be transmitted, only to throw them away, is surely going to be slower than (say) the results of a call to os.stat. (Assuming that gives the answer.) The difficult question then becomes: is it reasonable to (potentially) slow down the common case of local file systems by a tiny amount, in order to protect against the (rare) case where it will give a big speed things up? -- Steven From Seymore4Head at Hotmail.invalid Wed Aug 6 23:25:27 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Wed, 06 Aug 2014 23:25:27 -0400 Subject: Wikibooks example doesn't work References: Message-ID: On Wed, 06 Aug 2014 22:58:51 -0400, Seymore4Head wrote: >number = 7 >guess = -1 >count = 0 > >print("Guess the number!") >while guess != number: > guess = int(input("Is it... ")) > count = count + 1 > if guess == number: > print("Hooray! You guessed it right!") > elif guess < number: > print("It's bigger...") > elif guess > number: > print("It's not so big.") The part to here is supposed to be an example to allow the user to guess at a number (7) with an infinite amount of tries. This part was added as an exercise. A counter is added to give 3 tries to guess the number. It is supposed to stop after count gets to 3. It doesn't. It just keeps looping back and asking for another guess. >if count > 3: > print("That must have been complicated.") >else: > print("Good job!") > >http://en.wikibooks.org/wiki/Non-Programmer%27s_Tutorial_for_Python_3/Decisions > >Why not? >I think I know why it isn't working, but I don't know enough yet on >how it should work. >The If statement isn't getting read. From steve+comp.lang.python at pearwood.info Wed Aug 6 23:31:53 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 07 Aug 2014 13:31:53 +1000 Subject: Wikibooks example doesn't work References: Message-ID: <53e2f32a$0$29979$c3e8da3$5496439d@news.astraweb.com> Seymore4Head wrote: [snip code that looks fine to me] > Why not? I don't know. What does "doesn't work" mean? "It didn't do what I expected." (What did you expect? What did it do?) "It printed an error message." (Care to tell it what it was?) "It crashed the computer." (Some more details might help.) "My computer caught fire when I ran it." (I'm sorry to hear that.) Don't expect us to read your mind and know what you know. And don't expect us to run the code and see for ourselves -- we might, but we normally shouldn't need to, if you give as the details you already have. And of course just because it "doesn't work" on your system, doesn't mean it won't work on ours. -- Steven From steve+comp.lang.python at pearwood.info Wed Aug 6 23:32:08 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 07 Aug 2014 13:32:08 +1000 Subject: Python and IDEs [was Re: Python 3 is killing Python] References: <87zjga4j4v.fsf@elektro.pacujo.net> <53c57bae$0$9505$c3e8da3$5496439d@news.astraweb.com> <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> <20140806144758.f5817ee60d0e98ff30172a2a@gmx.net> Message-ID: <53e2f338$0$29979$c3e8da3$5496439d@news.astraweb.com> Wolfgang Keller wrote: > Linux was made by geeks who didn't have a clue of ergonomics for > screenworkers and didn't care to get one. I can only repeat what you said earlier: "You should get a clue in stead [sic] of just fantasizing up assumptions based on ignorance." I daresay that Linus Torvalds spends more time in front of a computer screen than most 9 to 5 "screenworkers". By the way, you keep replying to people, and quoting them, but deleting their name. Please leave the attribution in place, so we know who you are replying to. -- Steven From steve+comp.lang.python at pearwood.info Wed Aug 6 23:37:29 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 07 Aug 2014 13:37:29 +1000 Subject: Python 3 is killing Python References: <7xha49wumw.fsf@ruckus.brouhaha.com> <88649f2d-76c2-41af-a509-23486bd06dff@googlegroups.com> Message-ID: <53e2f47a$0$6512$c3e8da3$5496439d@news.astraweb.com> beliavsky at aol.com wrote: > Fortran compiler vendors such as Intel, IBM, Oracle/SUN and open source > projects such as gfortran are updating their compilers to the Fortran 2003 > and 2008 standards while also keeping the ability to compile all the old > Fortran code. FORTRAN 77 programmers and programs will not be forced to > move to modern Fortran, How about FORTRAN IV and FORTRAN 66 users? Where's their support? Why aren't they moaning and gnashing their teeth that they're so cruelly and unreasonably forced to upgrade? > but I'm not sure that Python 2.x users can be as > confident that Python 2.x will be supported on future operating systems. Oh well, life wasn't meant to be easy. Fortunately they can run it under Windows 98 or Centos 3.5 in a virtual machine. -- Steven From steve+comp.lang.python at pearwood.info Wed Aug 6 23:43:40 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 07 Aug 2014 13:43:40 +1000 Subject: Wikibooks example doesn't work References: Message-ID: <53e2f5ed$0$29965$c3e8da3$5496439d@news.astraweb.com> Seymore4Head wrote: > On Wed, 06 Aug 2014 22:58:51 -0400, Seymore4Head > wrote: > >>number = 7 >>guess = -1 >>count = 0 >> >>print("Guess the number!") >>while guess != number: >> guess = int(input("Is it... ")) >> count = count + 1 >> if guess == number: >> print("Hooray! You guessed it right!") >> elif guess < number: >> print("It's bigger...") >> elif guess > number: >> print("It's not so big.") > > The part to here is supposed to be an example to allow the user to > guess at a number (7) with an infinite amount of tries. > > > This part was added as an exercise. Ah, now things make sense! Your subject line is misleading! It's not that the wikibooks example doesn't work, the example works fine. It's that the code you added to it doesn't do what you expected. You should have said. > A counter is added to give 3 tries to guess the number. > It is supposed to stop after count gets to 3. It doesn't. It just > keeps looping back and asking for another guess. You don't check the counter until after the loop has finished. It needs to be inside the loop, not outside: while looping: # See the indent? # this is inside the loop # No indent. # This is outside the loop. Also, having reached the count of three, you will want to break out of the loop. The "break" command does that. Is this enough of a hint to continue? Please feel free to ask any further questions you need. -- Steven From Seymore4Head at Hotmail.invalid Wed Aug 6 23:48:09 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Wed, 06 Aug 2014 23:48:09 -0400 Subject: Wikibooks example doesn't work References: <53e2f5ed$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7dt5u9pplvjpqvjegj39tes9ainr8ugsmi@4ax.com> On Thu, 07 Aug 2014 13:43:40 +1000, Steven D'Aprano wrote: >Seymore4Head wrote: > >> On Wed, 06 Aug 2014 22:58:51 -0400, Seymore4Head >> wrote: >> >>>number = 7 >>>guess = -1 >>>count = 0 >>> >>>print("Guess the number!") >>>while guess != number: >>> guess = int(input("Is it... ")) >>> count = count + 1 >>> if guess == number: >>> print("Hooray! You guessed it right!") >>> elif guess < number: >>> print("It's bigger...") >>> elif guess > number: >>> print("It's not so big.") >> >> The part to here is supposed to be an example to allow the user to >> guess at a number (7) with an infinite amount of tries. >> >> >> This part was added as an exercise. > > >Ah, now things make sense! Your subject line is misleading! It's not that >the wikibooks example doesn't work, the example works fine. It's that the >code you added to it doesn't do what you expected. You should have said. > I copied it verbatim from the web page's solution. After indenting as you suggested, it does work now though. Thanks > >> A counter is added to give 3 tries to guess the number. >> It is supposed to stop after count gets to 3. It doesn't. It just >> keeps looping back and asking for another guess. > >You don't check the counter until after the loop has finished. It needs to >be inside the loop, not outside: > >while looping: > # See the indent? > # this is inside the loop > ># No indent. ># This is outside the loop. > > >Also, having reached the count of three, you will want to break out of the >loop. The "break" command does that. > >Is this enough of a hint to continue? Please feel free to ask any further >questions you need. From wuwei23 at gmail.com Thu Aug 7 00:09:30 2014 From: wuwei23 at gmail.com (alex23) Date: Thu, 07 Aug 2014 14:09:30 +1000 Subject: Wikibooks example doesn't work In-Reply-To: References: Message-ID: On 7/08/2014 1:25 PM, Seymore4Head wrote: > This part was added as an exercise. > A counter is added to give 3 tries to guess the number. > It is supposed to stop after count gets to 3. It doesn't. It just > keeps looping back and asking for another guess. You've misread the exercise: Modify the higher or lower program from this section to keep track of how many times the user has entered the wrong number. If it is more than 3 times, print "That must have been complicated." at the end, otherwise print "Good job!" There's nothing there about breaking out of the loop after 3 attempts, just producing a different end message on successful completion based on how many attempts were made. The Wikibooks example works as specified. From orgnut at yahoo.com Thu Aug 7 00:59:12 2014 From: orgnut at yahoo.com (Larry Hudson) Date: Wed, 06 Aug 2014 21:59:12 -0700 Subject: Wikibooks example doesn't work In-Reply-To: <7dt5u9pplvjpqvjegj39tes9ainr8ugsmi@4ax.com> References: <53e2f5ed$0$29965$c3e8da3$5496439d@news.astraweb.com> <7dt5u9pplvjpqvjegj39tes9ainr8ugsmi@4ax.com> Message-ID: On 08/06/2014 08:48 PM, Seymore4Head wrote: > On Thu, 07 Aug 2014 13:43:40 +1000, Steven D'Aprano > wrote: > >> Seymore4Head wrote: >> >>> On Wed, 06 Aug 2014 22:58:51 -0400, Seymore4Head >>> wrote: >>> [snip] >> Ah, now things make sense! Your subject line is misleading! It's not that >> the wikibooks example doesn't work, the example works fine. It's that the >> code you added to it doesn't do what you expected. You should have said. >> > I copied it verbatim from the web page's solution. After indenting as > you suggested, it does work now though. > Thanks > >> >>> A counter is added to give 3 tries to guess the number. >>> It is supposed to stop after count gets to 3. It doesn't. It just >>> keeps looping back and asking for another guess. >> I just took a look at that web page, and I see what your problem actually is... You are misunderstanding the problem. The problem does NOT say to end the loop at three tries, just to keep track of the number of tries. It's not actually specific, but the implication is that AFTER the loop display a message depending on the number of actual tires. The wikibooks solution IS correct, you understanding of the stated problem is not. My response here may sound harsh but I don't mean it to be, so please don't take it that way. Python is a great language to learn -- keep it up, you'll get it! :-) -=- Larry -=- From Andrew.Christianson at Ipsos.com Wed Aug 6 23:43:00 2014 From: Andrew.Christianson at Ipsos.com (Andrew Christianson) Date: Thu, 7 Aug 2014 03:43:00 +0000 Subject: Wikibooks example doesn't work8 In-Reply-To: References: , Message-ID: <3l7tclbc0tp1hsu4r661t8tp.1407382818739@email.android.com> The if statement in question isn't inside the while loop. White space and indentation is meaningful in python, so putting the if count > 3 block at same indentation as the while statement effectively places it outside the loop. Regards, Drew -------- Original message -------- From: Seymore4Head Date:08/06/2014 20:32 (GMT-08:00) To: python-list at python.org Subject: Re: Wikibooks example doesn't work On Wed, 06 Aug 2014 22:58:51 -0400, Seymore4Head wrote: >number = 7 >guess = -1 >count = 0 > >print("Guess the number!") >while guess != number: > guess = int(input("Is it... ")) > count = count + 1 > if guess == number: > print("Hooray! You guessed it right!") > elif guess < number: > print("It's bigger...") > elif guess > number: > print("It's not so big.") The part to here is supposed to be an example to allow the user to guess at a number (7) with an infinite amount of tries. This part was added as an exercise. A counter is added to give 3 tries to guess the number. It is supposed to stop after count gets to 3. It doesn't. It just keeps looping back and asking for another guess. >if count > 3: > print("That must have been complicated.") >else: > print("Good job!") > >http://en.wikibooks.org/wiki/Non-Programmer%27s_Tutorial_for_Python_3/Decisions > >Why not? >I think I know why it isn't working, but I don't know enough yet on >how it should work. >The If statement isn't getting read. -- https://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Thu Aug 7 01:06:46 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 07 Aug 2014 15:06:46 +1000 Subject: Wikibooks example doesn't work References: <53e2f5ed$0$29965$c3e8da3$5496439d@news.astraweb.com> <7dt5u9pplvjpqvjegj39tes9ainr8ugsmi@4ax.com> Message-ID: <85ha1oanx5.fsf@benfinney.id.au> Larry Hudson writes: > I just took a look at that web page, and I see what your problem > actually is... > You are misunderstanding the problem. The problem does NOT say to end > the loop at three tries, just to keep track of the number of tries. > It's not actually specific, but the implication is that AFTER the loop > display a message depending on the number of actual tires. Could it be re-phrased to state the exercise requirements more clearly? Maybe you could edit the wiki page to prevent future confusion on this exercise. -- \ ?Are you pondering what I'm pondering?? ?I think so, Brain, but | `\ wouldn't his movies be more suitable for children if he was | _o__) named Jean-Claude van Darn?? ?_Pinky and The Brain_ | Ben Finney From greg.ewing at canterbury.ac.nz Thu Aug 7 02:14:54 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 07 Aug 2014 18:14:54 +1200 Subject: Test for an empty directory that could be very large if it is not empty? In-Reply-To: References: Message-ID: Virgil Stokes wrote: > How can I > determine if the directory is empty WITHOUT the generation of a list of > the file names Which platform? On Windows, I have no idea. On Unix you can't really do this properly without access to opendir() and readdir(), which Python doesn't currently wrap. Will the empty directories be newly created, or could they be ones that *used* to contain 200000 files that have since been deleted? If they're new or nearly new, you could probably tell from looking at the size reported by stat() on the directory. The difference between a fresh empty directory and one with 200000 files in it should be fairly obvious. A viable strategy might be: If the directory is very large, assume it's not empty. If it's smallish, list its contents to find out for sure. -- Greg From satishmlwizpro at gmail.com Thu Aug 7 02:44:28 2014 From: satishmlwizpro at gmail.com (Satish ML) Date: Wed, 6 Aug 2014 23:44:28 -0700 (PDT) Subject: AttributeError: 'module' object has no attribute 'fork' Message-ID: <7bd83ac7-17e6-49c2-b5c7-3236c900d005@googlegroups.com> Hi, Code: import os, time def child(pipeout): zzz = 0 while True: time.sleep(zzz) msg = ('Spam %03d' % zzz).encode() os.write(pipeout, msg) zzz = (zzz+1) % 5 def parent(): pipein, pipeout = os.pipe() if os.fork() == 0: child(pipeout) else: while True: line = os.read(pipein, 32) print('Parent %d got [%s] at %s' % (os.getpid(), line, time.time())) parent() Output: Traceback (most recent call last): File "C:/Python34/pipe1.py", line 17, in parent() File "C:/Python34/pipe1.py", line 11, in parent if os.fork() == 0: AttributeError: 'module' object has no attribute 'fork' Why does this error appear? Module os provides fork(). How to solve this problem? Kindly help. From __peter__ at web.de Thu Aug 7 03:00:23 2014 From: __peter__ at web.de (Peter Otten) Date: Thu, 07 Aug 2014 09:00:23 +0200 Subject: AttributeError: 'module' object has no attribute 'fork' References: <7bd83ac7-17e6-49c2-b5c7-3236c900d005@googlegroups.com> Message-ID: Satish ML wrote: > Hi, > > Code: > import os, time > def child(pipeout): > zzz = 0 > while True: > time.sleep(zzz) > msg = ('Spam %03d' % zzz).encode() > os.write(pipeout, msg) > zzz = (zzz+1) % 5 > def parent(): > pipein, pipeout = os.pipe() > if os.fork() == 0: > child(pipeout) > else: > while True: > line = os.read(pipein, 32) > print('Parent %d got [%s] at %s' % (os.getpid(), line, > time.time())) > parent() > > Output: > Traceback (most recent call last): > File "C:/Python34/pipe1.py", line 17, in > parent() > File "C:/Python34/pipe1.py", line 11, in parent > if os.fork() == 0: > AttributeError: 'module' object has no attribute 'fork' > > Why does this error appear? Module os provides fork(). How to solve this > problem? Kindly help. Quoting : """ os.fork() Fork a child process. ... Availability: Unix. """ You are using the wrong operating system ;) From cs at zip.com.au Thu Aug 7 03:08:55 2014 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 7 Aug 2014 17:08:55 +1000 Subject: Test for an empty directory that could be very large if it is not empty? In-Reply-To: References: Message-ID: <20140807070855.GA79496@cskk.homeip.net> On 07Aug2014 18:14, Greg Ewing wrote: >Virgil Stokes wrote: >>How can I determine if the directory is empty WITHOUT the generation >>of a list of the file names > >Which platform? > >On Windows, I have no idea. > >On Unix you can't really do this properly without access >to opendir() and readdir(), which Python doesn't currently >wrap. [...] On UNIX (the OP seemed to be using Windows, alas), if you are prepared to be destructive you can just do an rmdir. It will fail if the directory is not empty, and performs ok on the hypothesised remote once-ginormous directory. The commonest reason for wanting to know if a directory is empty that I can imagine is when you want to remove it, and if that applies here it is better to just try to remove it and ask for forgiveness later. Disclaimer: Windows may not offer this handy safety net. Cheers, Cameron Simpson Of course no description of a Ducati engine is complete without mentioning the sound. That deep bass exhaust rumble along with the mechanical music of the desmodromic valves...too bad it isn't available on compact disc. - Sport Rider, evidently before the release of the "Ducati Passions" CD From ethan at stoneleaf.us Thu Aug 7 03:30:27 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 07 Aug 2014 00:30:27 -0700 Subject: Test for an empty directory that could be very large if it is not empty? In-Reply-To: <854mxpb6fq.fsf@benfinney.id.au> References: <53E2A22A.10906@it.uu.se> <854mxpb6fq.fsf@benfinney.id.au> Message-ID: <53E32B13.3010301@stoneleaf.us> On 08/06/2014 03:26 PM, Ben Finney wrote: > Virgil Stokes writes: > >> Suppose I have a directory C:/Test that is either empty or contains >> more than 2000000 files, all with the same extension (e.g. *.txt). How >> can I determine if the directory is empty WITHOUT the generation of a >> list of the file names in it (e.g. using os.listdir('C:/Test')) when >> it is not empty? > > What is your goal for that? Have you measured the performance difference > and decided *based on objective observation* that it's too expensive? > > Certainly ?os.listdir(foo)? is the simplest way to determine the entries > in a directory, and thereby to test whether it is empty. That simplicity > is very valuable, and you should have a compelling, *measured* reason to > do something more complicated. What is it? Plenty of people have measured the slowdown of getting a list of files when the directory has thousands upon thousands. It's why the scandir PEP exists at all, and the slowdown is present even on local file systems. While it may not be objective, walking away to get a cup of your favorite beverage, coming back and seeing the operation is still not done, is certainly sufficient to realize that the simple, easy way is not going to be sufficient. -- ~Ethan~ From python.list at tim.thechases.com Thu Aug 7 07:07:37 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 7 Aug 2014 06:07:37 -0500 Subject: Test for an empty directory that could be very large if it is not empty? In-Reply-To: <85ppgd9jio.fsf@benfinney.id.au> References: <53E2A22A.10906@it.uu.se> <854mxpb6fq.fsf@benfinney.id.au> <20140806174441.3a2e16e1@bigbox.christie.dr> <85ppgd9jio.fsf@benfinney.id.au> Message-ID: <20140807060737.7a2418af@bigbox.christie.dr> On 2014-08-07 11:27, Ben Finney wrote: > > The difference in timings when serving a web-request are > > noticeable (in my use-case, I had to change my algorithm and > > storage structure to simplify/avoid heavily-populated > > directories) > > So, if the requirement is ?test whether the directory is empty > faster than N microseconds?, that's quite different from ?without > the generation of a list of the file names?. > > The former may entail the latter, but that's not to be assumed, and > chasing an optimisation prematurely is a common cause of terrible > code. I guess my surprise in the 2->3 non-iterator'ization of os.listdir() is that it's very easy to wrap an iterable in list() if you want the whole bunch, but it's much harder to get the performance characteristics of interruptible iteration (e.g. "is the directory empty" or "look at files until you find one matching $CRITERIA"). Looking forward to scandir() arriving for just those reasons. -tkc (who sees Ethan Furman's excellent followup-post as I'm about to hit Send) From patil.jay2009 at gmail.com Thu Aug 7 07:24:09 2014 From: patil.jay2009 at gmail.com (Jaydeep Patil) Date: Thu, 7 Aug 2014 04:24:09 -0700 (PDT) Subject: Keep one GUI always on TOP while python code is running Message-ID: Hi all, I have one query. I have did some programming which copies and paste data using system clipboard. I need to keep one GUI always on top till my python code is running. Can we do like this? Regards Jaydeep From roy at panix.com Thu Aug 7 07:49:05 2014 From: roy at panix.com (Roy Smith) Date: Thu, 07 Aug 2014 07:49:05 -0400 Subject: AttributeError: 'module' object has no attribute 'fork' References: <7bd83ac7-17e6-49c2-b5c7-3236c900d005@googlegroups.com> Message-ID: In article , Peter Otten <__peter__ at web.de> wrote: > os.fork() > Fork a child process. > ... > Availability: Unix. > """ > > You are using the wrong operating system ;) To be honest, this could be considered a buglet in the os module. It really should raise: NotImplementedError("fork() is only available on unix") or perhaps even, as Peter suggests: NotImplementedError("You are using the wrong operating system") either of those would be better than AttributeError. From roy at panix.com Thu Aug 7 07:54:48 2014 From: roy at panix.com (Roy Smith) Date: Thu, 07 Aug 2014 07:54:48 -0400 Subject: Test for an empty directory that could be very large if it is not empty? References: Message-ID: In article , Gregory Ewing wrote: > Virgil Stokes wrote: > > How can I > > determine if the directory is empty WITHOUT the generation of a list of > > the file names > > Which platform? > > On Windows, I have no idea. > > On Unix you can't really do this properly without access > to opendir() and readdir(), which Python doesn't currently > wrap. > > Will the empty directories be newly created, or could they > be ones that *used* to contain 200000 files that have since > been deleted? > > If they're new or nearly new, you could probably tell from > looking at the size reported by stat() on the directory. > The difference between a fresh empty directory and one with > 200000 files in it should be fairly obvious. > > A viable strategy might be: If the directory is very large, > assume it's not empty. If it's smallish, list its contents > to find out for sure. I wonder if glob.iglob('*') might help here? From __peter__ at web.de Thu Aug 7 08:06:14 2014 From: __peter__ at web.de (Peter Otten) Date: Thu, 07 Aug 2014 14:06:14 +0200 Subject: Test for an empty directory that could be very large if it is not empty? References: Message-ID: Roy Smith wrote: > In article , > Gregory Ewing wrote: > >> Virgil Stokes wrote: >> > How can I >> > determine if the directory is empty WITHOUT the generation of a list of >> > the file names >> >> Which platform? >> >> On Windows, I have no idea. >> >> On Unix you can't really do this properly without access >> to opendir() and readdir(), which Python doesn't currently >> wrap. >> >> Will the empty directories be newly created, or could they >> be ones that *used* to contain 200000 files that have since >> been deleted? >> >> If they're new or nearly new, you could probably tell from >> looking at the size reported by stat() on the directory. >> The difference between a fresh empty directory and one with >> 200000 files in it should be fairly obvious. >> >> A viable strategy might be: If the directory is very large, >> assume it's not empty. If it's smallish, list its contents >> to find out for sure. > > I wonder if glob.iglob('*') might help here? No, the glob module uses os.listdir() under the hood. Therefore iglob() is lazy for multiple directories only. From python.list at tim.thechases.com Thu Aug 7 08:05:21 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 7 Aug 2014 07:05:21 -0500 Subject: Test for an empty directory that could be very large if it is not empty? In-Reply-To: References: Message-ID: <20140807070521.6c0b5e0d@bigbox.christie.dr> On 2014-08-07 07:54, Roy Smith wrote: > I wonder if glob.iglob('*') might help here? My glob.iglob() uses os.listdir() behind the scenes (see glob1() in glob.py) -tkc From 4kir4.1i at gmail.com Thu Aug 7 08:19:19 2014 From: 4kir4.1i at gmail.com (Akira Li) Date: Thu, 07 Aug 2014 16:19:19 +0400 Subject: Test for an empty directory that could be very large if it is not empty? References: <53E2A22A.10906@it.uu.se> Message-ID: <8738d8bigo.fsf@gmail.com> Virgil Stokes writes: > Suppose I have a directory C:/Test that is either empty or contains > more than 2000000 files, all with the same extension (e.g. *.txt). How > can I determine if the directory is empty WITHOUT the generation of a > list of the file names in it (e.g. using os.listdir('C:/Test')) when > it is not empty? def is_empty_dir(dirpath): return next(scandir(dirpath), None) is None https://github.com/benhoyt/scandir -- Akira From roy at panix.com Thu Aug 7 08:19:07 2014 From: roy at panix.com (Roy Smith) Date: Thu, 07 Aug 2014 08:19:07 -0400 Subject: Test for an empty directory that could be very large if it is not empty? References: Message-ID: In article , Tim Chase wrote: > On 2014-08-07 07:54, Roy Smith wrote: > > I wonder if glob.iglob('*') might help here? > > My glob.iglob() uses os.listdir() behind the scenes (see glob1() in > glob.py) > > -tkc In which case, the documentation for iglob() is broken. It says: "Return an iterator which yields the same values as glob() without actually storing them all simultaneously." If it's calling something which does store them all simultaneously, that's like contracting with somebody to commit a crime, and then trying to claim you're innocent because you didn't commit the crime yourself. From rosuav at gmail.com Thu Aug 7 08:57:48 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Aug 2014 22:57:48 +1000 Subject: Keep one GUI always on TOP while python code is running In-Reply-To: References: Message-ID: On Thu, Aug 7, 2014 at 9:24 PM, Jaydeep Patil wrote: > I have one query. I have did some programming which copies and paste data using system clipboard. I need to keep one GUI always on top till my python code is running. > "till" or "while"? If you mean "while", then yes. But it depends on your GUI toolkit. Are you using Tkinter, wxpython, PyGTK, etc, etc, etc? Check the docs for that toolkit and see how to make a window stay on top. ChrisA From EYN2K at outlook.com Thu Aug 7 09:41:34 2014 From: EYN2K at outlook.com (EYN2K at outlook.com) Date: Thu, 7 Aug 2014 06:41:34 -0700 (PDT) Subject: Infinite Mandelbrot Set Tutorial - Video Message-ID: Created a cool Infinite (16 trillion zoom) Mandelbrot set in Python. Only two for loops, one while loop and one if-elif-else for control flow. I hope you enjoy Free video link : https://www.youtube.com/watch?v=WqfbDAzA1Sw Thank you From eyn2k at outlook.com Thu Aug 7 09:44:42 2014 From: eyn2k at outlook.com (Everything You Need To Know) Date: Thu, 7 Aug 2014 06:44:42 -0700 (PDT) Subject: 33 Video free Course - Python Message-ID: <56f6d638-f15a-469a-bb81-80b99b71902d@googlegroups.com> We have put together a neat playlist to learn python, with some really neat tricks and exercises. Playlist Link : https://www.youtube.com/channel/UCad91ea17ynqc0cTokBG3bg/playlists exercises include : Graphics Calculator with check for zeros Zoom Function for Graphics Window Mandelbrot set Game of Life (To come) Thank you From Seymore4Head at Hotmail.invalid Thu Aug 7 11:11:55 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Thu, 07 Aug 2014 11:11:55 -0400 Subject: Wikibooks example doesn't work References: <53e2f5ed$0$29965$c3e8da3$5496439d@news.astraweb.com> <7dt5u9pplvjpqvjegj39tes9ainr8ugsmi@4ax.com> Message-ID: <6j57u99erojtibttpedh35053mgllmqdd0@4ax.com> On Wed, 06 Aug 2014 21:59:12 -0700, Larry Hudson wrote: >On 08/06/2014 08:48 PM, Seymore4Head wrote: >> On Thu, 07 Aug 2014 13:43:40 +1000, Steven D'Aprano >> wrote: >> >>> Seymore4Head wrote: >>> >>>> On Wed, 06 Aug 2014 22:58:51 -0400, Seymore4Head >>>> wrote: >>>> > >[snip] >>> Ah, now things make sense! Your subject line is misleading! It's not that >>> the wikibooks example doesn't work, the example works fine. It's that the >>> code you added to it doesn't do what you expected. You should have said. >>> >> I copied it verbatim from the web page's solution. After indenting as >> you suggested, it does work now though. >> Thanks >> >>> >>>> A counter is added to give 3 tries to guess the number. >>>> It is supposed to stop after count gets to 3. It doesn't. It just >>>> keeps looping back and asking for another guess. >>> > >I just took a look at that web page, and I see what your problem actually is... >You are misunderstanding the problem. The problem does NOT say to end the loop at three tries, >just to keep track of the number of tries. It's not actually specific, but the implication is >that AFTER the loop display a message depending on the number of actual tires. > >The wikibooks solution IS correct, you understanding of the stated problem is not. > >My response here may sound harsh but I don't mean it to be, so please don't take it that way. >Python is a great language to learn -- keep it up, you'll get it! :-) > > -=- Larry -=- It is OK. I have a thick skin. I also have a thick skull and need all the help I can get. Thanks From breamoreboy at yahoo.co.uk Thu Aug 7 11:20:56 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 07 Aug 2014 16:20:56 +0100 Subject: cinspect Message-ID: I'd never heard of this. I thought it might be of interest to those of you who like to know what goes on under the bonnet in cPython. Find it here https://github.com/punchagan/cinspect -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From steve+comp.lang.python at pearwood.info Thu Aug 7 12:56:56 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 08 Aug 2014 02:56:56 +1000 Subject: AttributeError: 'module' object has no attribute 'fork' References: <7bd83ac7-17e6-49c2-b5c7-3236c900d005@googlegroups.com> Message-ID: <53e3afd9$0$29970$c3e8da3$5496439d@news.astraweb.com> Roy Smith wrote: > In article , > Peter Otten <__peter__ at web.de> wrote: > >> os.fork() >> Fork a child process. >> ... >> Availability: Unix. >> """ >> >> You are using the wrong operating system ;) > > To be honest, this could be considered a buglet in the os module. It > really should raise: > > NotImplementedError("fork() is only available on unix") > > or perhaps even, as Peter suggests: > > NotImplementedError("You are using the wrong operating system") > > either of those would be better than AttributeError. I disagree. How would you tell if fork is implemented? With the current behaviour, telling whether fork is implemented or not is simple: is_implemented = hasattr(os, "fork") With your suggestion: try: pid = os.fork() except NotImplementedError: is_implemented = False else: if pid == 0: # In the child process. os._exit(0) # Unconditionally exit, right now, no excuses. is_implemented = True which is not obvious, simple or cheap. -- Steven From python.list at tim.thechases.com Thu Aug 7 13:37:41 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 7 Aug 2014 12:37:41 -0500 Subject: Test for an empty directory that could be very large if it is not empty? In-Reply-To: References: Message-ID: <20140807123741.2bf950c6@bigbox.christie.dr> On 2014-08-07 08:19, Roy Smith wrote: > > My glob.iglob() uses os.listdir() behind the scenes (see glob1() > > in glob.py) > > > > -tkc > > In which case, the documentation for iglob() is broken. It says: > > "Return an iterator which yields the same values as glob() without > actually storing them all simultaneously." I'd tend to agree that iglob() is broken and should use the proposed .scandir() instead for exactly those reasons. Unfortunately, it seems that it might not get back-ported until .scandir() hits. -tkc From gordon at panix.com Thu Aug 7 16:15:33 2014 From: gordon at panix.com (John Gordon) Date: Thu, 7 Aug 2014 20:15:33 +0000 (UTC) Subject: Test for an empty directory that could be very large if it is not empty? References: Message-ID: In Virgil Stokes writes: > Suppose I have a directory C:/Test that is either empty or contains more > than 2000000 files, all with the same extension (e.g. *.txt). How can I > determine if the directory is empty WITHOUT the generation of a list of > the file names in it (e.g. using os.listdir('C:/Test')) when it is not > empty? Is it one directory that is sometimes empty and other times teeming with files, or is it a series of directories which are created afresh and then await arrival of the files? If the latter, you could try looking at the size of the directory entry itself. On the system I'm writing from, a freshly-created directory is 4K in size, and will grow in 4K chunks as more and more files are created within the directory. However, the directory entry does not shrink when files are removed. -- 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 elearn2014 at gmail.com Thu Aug 7 20:23:06 2014 From: elearn2014 at gmail.com (elearn) Date: Fri, 08 Aug 2014 08:23:06 +0800 Subject: more simple to split the string? Message-ID: <53E4186A.5020201@gmail.com> str='(\\HasNoChildren \\Junk) "/" "[Gmail]/&V4NXPpCuTvY-"' x=str.split(' "') [i.replace('"','') for i in x] ['(\\HasNoChildren \\Junk)', '/', '[Gmail]/&V4NXPpCuTvY-'] x.strip(" ") will create four parts. is there more simple to do that ? From roy at panix.com Thu Aug 7 21:10:52 2014 From: roy at panix.com (Roy Smith) Date: Thu, 07 Aug 2014 21:10:52 -0400 Subject: Test for an empty directory that could be very large if it is not empty? References: Message-ID: In article , Tim Chase wrote: > On 2014-08-07 08:19, Roy Smith wrote: > > > My glob.iglob() uses os.listdir() behind the scenes (see glob1() > > > in glob.py) > > > > > > -tkc > > > > In which case, the documentation for iglob() is broken. It says: > > > > "Return an iterator which yields the same values as glob() without > > actually storing them all simultaneously." > > I'd tend to agree that iglob() is broken and should use the > proposed .scandir() instead for exactly those reasons. > Unfortunately, it seems that it might not get back-ported > until .scandir() hits. > > -tkc I opened a bug against the 2.7 docs: http://bugs.python.org/issue22167 From cjwelborn at live.com Thu Aug 7 21:29:37 2014 From: cjwelborn at live.com (Christopher Welborn) Date: Thu, 07 Aug 2014 20:29:37 -0500 Subject: more simple to split the string? In-Reply-To: <53E4186A.5020201@gmail.com> References: <53E4186A.5020201@gmail.com> Message-ID: On 08/07/2014 07:23 PM, elearn wrote: > str='(\\HasNoChildren \\Junk) "/" "[Gmail]/&V4NXPpCuTvY-"' > x=str.split(' "') > [i.replace('"','') for i in x] > ['(\\HasNoChildren \\Junk)', '/', '[Gmail]/&V4NXPpCuTvY-'] > > x.strip(" ") will create four parts. > > is there more simple to do that ? There are many different ways to do this. I don't usually recommend regex, but I thought I would present you with this: import re s ='(\\HasNoChildren \\Junk) "/" "[Gmail]/&V4NXPpCuTvY-"' partpat = re.compile(r'(\(.+\)) "(.+)" "(.+)"') partsmatch = partpat.search(s) if partsmatch is None: print('No matches.') else: print(partsmatch.groups()) # Results (a Tuple of strings): ('(\\HasNoChildren \\Junk)', '/', '[Gmail]/&V4NXPpCuTvY-') The pattern says you're looking for: (this thing) "this" "this" -- \?\ /?/\ \ \/??\/ / / Christopher Welborn (cj) \__/\__/ / cjwelborn at live?com \__/\__/ http://welbornprod.com From elearn2014 at gmail.com Thu Aug 7 21:11:43 2014 From: elearn2014 at gmail.com (elearn) Date: Fri, 08 Aug 2014 09:11:43 +0800 Subject: How to get mac address of bluetooth with python in win7? Message-ID: <53E423CF.3090009@gmail.com> How to get mac address of bluetooth with python in win7? From ben+python at benfinney.id.au Thu Aug 7 22:47:36 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 08 Aug 2014 12:47:36 +1000 Subject: How to get mac address of bluetooth with python in win7? References: <53E423CF.3090009@gmail.com> Message-ID: <8561i3ae9j.fsf@benfinney.id.au> elearn writes: > How to get mac address of bluetooth with python in win7? This may not be a Python-specific question. How would you get the MAC adress of a Bluetooth device in Windows, in any programming language? My advice is for you to do a web search . -- \ ?You could augment an earwig to the point where it understood | `\ nuclear physics, but it would still be a very stupid thing to | _o__) do!? ?The Doctor, _The Two Doctors_ | Ben Finney From rustompmody at gmail.com Fri Aug 8 01:19:27 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 7 Aug 2014 22:19:27 -0700 (PDT) Subject: AttributeError: 'module' object has no attribute 'fork' In-Reply-To: <53e3afd9$0$29970$c3e8da3$5496439d@news.astraweb.com> References: <7bd83ac7-17e6-49c2-b5c7-3236c900d005@googlegroups.com> <53e3afd9$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thursday, August 7, 2014 10:26:56 PM UTC+5:30, Steven D'Aprano wrote: > Roy Smith wrote: > > Peter Otten wrote: > >> os.fork() > >> Fork a child process. > >> ... > >> Availability: Unix. > >> """ > >> You are using the wrong operating system ;) > > To be honest, this could be considered a buglet in the os module. It > > really should raise: > > NotImplementedError("fork() is only available on unix") > > or perhaps even, as Peter suggests: > > NotImplementedError("You are using the wrong operating system") > > either of those would be better than AttributeError. > I disagree. How would you tell if fork is implemented? With the current > behaviour, telling whether fork is implemented or not is simple: > is_implemented = hasattr(os, "fork") > With your suggestion: > try: > pid = os.fork() > except NotImplementedError: > is_implemented = False > else: > if pid == 0: > # In the child process. > os._exit(0) # Unconditionally exit, right now, no excuses. > is_implemented = True > which is not obvious, simple or cheap. Surely I am missing something but why not check os.fork before checking os.fork() ? Something along these lines >>> try: ... os.fork ... except AttributeError: ... ii = False ... else: ... ii = True Of course more appropriate would be something along the lines: catch AttributeError and re-raise NotImplementedError From rustompmody at gmail.com Fri Aug 8 01:35:30 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 7 Aug 2014 22:35:30 -0700 (PDT) Subject: AttributeError: 'module' object has no attribute 'fork' In-Reply-To: References: <7bd83ac7-17e6-49c2-b5c7-3236c900d005@googlegroups.com> <53e3afd9$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Friday, August 8, 2014 10:49:27 AM UTC+5:30, Rustom Mody wrote: > On Thursday, August 7, 2014 10:26:56 PM UTC+5:30, Steven D'Aprano wrote: > > Roy Smith wrote: > > > Peter Otten wrote: > > >> os.fork() > > >> Fork a child process. > > >> ... > > >> Availability: Unix. > > >> """ > > >> You are using the wrong operating system ;) > > > To be honest, this could be considered a buglet in the os module. It > > > really should raise: > > > NotImplementedError("fork() is only available on unix") > > > or perhaps even, as Peter suggests: > > > NotImplementedError("You are using the wrong operating system") > > > either of those would be better than AttributeError. > > I disagree. How would you tell if fork is implemented? With the current > > behaviour, telling whether fork is implemented or not is simple: > > is_implemented = hasattr(os, "fork") > > With your suggestion: > > try: > > pid = os.fork() > > except NotImplementedError: > > is_implemented = False > > else: > > if pid == 0: > > # In the child process. > > os._exit(0) # Unconditionally exit, right now, no excuses. > > is_implemented = True > > which is not obvious, simple or cheap. > Surely I am missing something but why not check os.fork before > checking os.fork() ? > Something along these lines > >>> try: > ... os.fork > ... except AttributeError: > ... ii = False > ... else: > ... ii = True > Of course more appropriate would be something along the lines: > catch AttributeError and re-raise NotImplementedError Thinking about this a bit more I see that NotImplemented is under RuntimeError. Probably a subclass of AttributeError -- PortabilityError?? Cant think of a good name -- is what is desired From steve+comp.lang.python at pearwood.info Fri Aug 8 01:48:17 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 08 Aug 2014 15:48:17 +1000 Subject: AttributeError: 'module' object has no attribute 'fork' References: <7bd83ac7-17e6-49c2-b5c7-3236c900d005@googlegroups.com> <53e3afd9$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53e464a3$0$30003$c3e8da3$5496439d@news.astraweb.com> Rustom Mody wrote: > On Thursday, August 7, 2014 10:26:56 PM UTC+5:30, Steven D'Aprano wrote: >> Roy Smith wrote: > >> > Peter Otten wrote: >> >> os.fork() >> >> Fork a child process. >> >> ... >> >> Availability: Unix. >> >> """ >> >> You are using the wrong operating system ;) >> > To be honest, this could be considered a buglet in the os module. It >> > really should raise: >> > NotImplementedError("fork() is only available on unix") >> > or perhaps even, as Peter suggests: >> > NotImplementedError("You are using the wrong operating system") >> > either of those would be better than AttributeError. > >> I disagree. How would you tell if fork is implemented? With the current >> behaviour, telling whether fork is implemented or not is simple: > >> is_implemented = hasattr(os, "fork") [...] > Surely I am missing something but why not check os.fork before > checking os.fork() ? Yes, you're missing something. That's what hasattr does. But with Roy's suggestion, testing for the existence of os.fork is not sufficient, because it will exist even on platforms where fork doesn't exist. So testing that os.fork exists is not sufficient to tell whether or not you can actually fork. Let's put it another way: code should, when possible, use feature detection rather than version (or platform) detection: # No, bad: if os.name.startswith('linux'): pid = os.fork() else: do_something_else() That's harmful, because: - perhaps there are other OSes apart from Linux which allow forking; - maybe some day even Windows; - and hypothetically there could even be a kind of Linux that doesn't allow forking. Feature detection is much more reliable and future-proof: if hasattr(os, 'fork'): # we don't care what OS, so long as it allows forking pid = os.fork() else: do_something_else() provided os.fork only exists when it does something. Roy's suggestion means that os.fork will exist even when useless. Now, many times you can avoid the Look Before You Leap test: try: pid = os.fork() except AttributeError: # Or NotImplementedError, in Roy's suggestion. do_something_else() and that's fine too. In this specific scenario, catching NotImplementedError is no harder than catching AttributeError. But sometimes you want to know up front whether you can fork later, without committing to forking right now, and that's where Roy's suggestion becomes painful: >> try: >> pid = os.fork() >> except NotImplementedError: >> is_implemented = False >> else: >> if pid == 0: >> # In the child process. >> os._exit(0) # Unconditionally exit, right now, no excuses. >> is_implemented = True Eight lines of tricky, potentially expensive code, versus a cheap hasattr test. > Something along these lines > >>>> try: > ... os.fork > ... except AttributeError: > ... ii = False > ... else: > ... ii = True That's just a much more verbose way of writing ii = hasattr(os, 'fork'). -- Steven From patil.jay2009 at gmail.com Fri Aug 8 01:57:57 2014 From: patil.jay2009 at gmail.com (Jaydeep Patil) Date: Thu, 7 Aug 2014 22:57:57 -0700 (PDT) Subject: Keep one GUI always on TOP while python code is running In-Reply-To: References: Message-ID: <32f85c79-17a1-4d2f-a926-43812b8083ed@googlegroups.com> Chris, I mean to say, One GUI should be always on top from start to end of code running. So that user cant do any other operation. I am using wxpython Regards Jay From rosuav at gmail.com Fri Aug 8 02:02:39 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Aug 2014 16:02:39 +1000 Subject: Keep one GUI always on TOP while python code is running In-Reply-To: <32f85c79-17a1-4d2f-a926-43812b8083ed@googlegroups.com> References: <32f85c79-17a1-4d2f-a926-43812b8083ed@googlegroups.com> Message-ID: On Fri, Aug 8, 2014 at 3:57 PM, Jaydeep Patil wrote: > I mean to say, One GUI should be always on top from start to end of code running. > So that user cant do any other operation. > I am using wxpython Ah, that would be called "System Modal", and should be reserved for absolutely critical system-wide alerts. It's also a feature that's simply not available to most user-space programs, and not available in most GUI toolkits. Short answer: Don't. ChrisA From rustompmody at gmail.com Fri Aug 8 03:17:25 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 8 Aug 2014 00:17:25 -0700 (PDT) Subject: AttributeError: 'module' object has no attribute 'fork' In-Reply-To: <53e464a3$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <7bd83ac7-17e6-49c2-b5c7-3236c900d005@googlegroups.com> <53e3afd9$0$29970$c3e8da3$5496439d@news.astraweb.com> <53e464a3$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Friday, August 8, 2014 11:18:17 AM UTC+5:30, Steven D'Aprano wrote: > Rustom Mody wrote: > > On Thursday, August 7, 2014 10:26:56 PM UTC+5:30, Steven D'Aprano wrote: > >> Roy Smith wrote: > >> > Peter Otten wrote: > >> >> os.fork() > >> >> Fork a child process. > >> >> ... > >> >> Availability: Unix. > >> >> """ > >> >> You are using the wrong operating system ;) > >> > To be honest, this could be considered a buglet in the os module. It > >> > really should raise: > >> > NotImplementedError("fork() is only available on unix") > >> > or perhaps even, as Peter suggests: > >> > NotImplementedError("You are using the wrong operating system") > >> > either of those would be better than AttributeError. > >> I disagree. How would you tell if fork is implemented? With the current > >> behaviour, telling whether fork is implemented or not is simple: > >> is_implemented = hasattr(os, "fork") > [...] > > Surely I am missing something but why not check os.fork before > > checking os.fork() ? > Yes, you're missing something. That's what hasattr does. > But with Roy's suggestion, testing for the existence of os.fork is not > sufficient, because it will exist even on platforms where fork doesn't > exist. So testing that os.fork exists is not sufficient to tell whether or > not you can actually fork. Windows: Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> import os >>> os.fork Traceback (most recent call last): File "", line 1, in os.fork AttributeError: 'module' object has no attribute 'fork' Linux: $ python Python 2.7.8 (default, Jul 4 2014, 13:08:34) [GCC 4.9.0] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> os.fork >>> So yes, I continue to miss something... From rosuav at gmail.com Fri Aug 8 03:32:54 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Aug 2014 17:32:54 +1000 Subject: AttributeError: 'module' object has no attribute 'fork' In-Reply-To: References: <7bd83ac7-17e6-49c2-b5c7-3236c900d005@googlegroups.com> <53e3afd9$0$29970$c3e8da3$5496439d@news.astraweb.com> <53e464a3$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Aug 8, 2014 at 5:17 PM, Rustom Mody wrote: >> But with Roy's suggestion, testing for the existence of os.fork is not >> sufficient, because it will exist even on platforms where fork doesn't >> exist. So testing that os.fork exists is not sufficient to tell whether or >> not you can actually fork. > > Windows: > > Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on win32 > Type "copyright", "credits" or "license()" for more information. >>>> import os >>>> os.fork > > Traceback (most recent call last): > File "", line 1, in > os.fork > AttributeError: 'module' object has no attribute 'fork' > > > Linux: > > $ python > Python 2.7.8 (default, Jul 4 2014, 13:08:34) > [GCC 4.9.0] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import os >>>> os.fork > >>>> > > > So yes, I continue to miss something... I think the bit you're missing is the "with Roy's suggestion" bit, at which os.fork() would be callable and would raise a different error. It's of course possible for fork() to fail (no memory, ulimit hit, etc etc etc), but I would expect that the presence of os.fork should correspond perfectly to the API's availability (at least as detected by Python's compilation testing). ChrisA From breamoreboy at yahoo.co.uk Fri Aug 8 04:43:35 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 08 Aug 2014 09:43:35 +0100 Subject: more simple to split the string? In-Reply-To: <53E4186A.5020201@gmail.com> References: <53E4186A.5020201@gmail.com> Message-ID: On 08/08/2014 01:23, elearn wrote: > str='(\\HasNoChildren \\Junk) "/" "[Gmail]/&V4NXPpCuTvY-"' First up it's not usually a good idea to override the builtin name str. > x=str.split(' "') > [i.replace('"','') for i in x] > ['(\\HasNoChildren \\Junk)', '/', '[Gmail]/&V4NXPpCuTvY-'] > > x.strip(" ") will create four parts. I assume you meant x=str.split(" ") ? Even so I don't see how you can get four parts so please explain. > > is there more simple to do that ? No loop needed that I can see. >>> oldstr='(\\HasNoChildren \\Junk) "/" "[Gmail]/&V4NXPpCuTvY-"';oldstr '(\\HasNoChildren \\Junk) "/" "[Gmail]/&V4NXPpCuTvY-"' >>> newstr=oldstr.replace('"', '');newstr '(\\HasNoChildren \\Junk) / [Gmail]/&V4NXPpCuTvY-' >>> substrings=newstr.split();substrings ['(\\HasNoChildren', '\\Junk)', '/', '[Gmail]/&V4NXPpCuTvY-'] -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From paulwolf333 at gmail.com Fri Aug 8 05:01:47 2014 From: paulwolf333 at gmail.com (Paul Wolf) Date: Fri, 8 Aug 2014 02:01:47 -0700 (PDT) Subject: Template language for random string generation Message-ID: <14d94692-2257-4dfb-a82f-f1674a839233@googlegroups.com> This is a proposal with a working implementation for a random string generation template syntax for Python. `strgen` is a module for generating random strings in Python using a regex-like template language. Example: >>> from strgen import StringGenerator as SG >>> SG("[\l\d]{8:15}&[\d]&[\p]").render() u'F0vghTjKalf4^mGLk' The template ([\l\d]{8:15}&[\d]&[\p]) generates a string from 8 to 15 characters in length with letters, digits. It is guaranteed to have at least one digit (maybe more) and exactly one punctuation character. If you look at various forums, like Stackoverflow, on how to generate random strings with Python, especially for passwords and other hopefully secure tokens, you will see dozens of variations of this: >>> import random >>> import string >>> mypassword = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(10)) There is nothing wrong with this (it's the right answer and is very fast), but it leads developers to constantly: * Use cryptographically weak methods * Forget that the above does not guarantee a result that includes the different classes of characters * Doesn't include variable length or minimum length output * It's a lot of typing and the resulting code is vastly different each time making it hard to understand what features were implemented, especially for those new to the language * You can extend the above to include whatever requirements you want, but it's a constant exercise in wheel reinvention that is extremely verbose, error prone and confusing for exactly the same purposes each time This application (generation of random strings for passwords, vouchers, secure ids, test data, etc.) is so general, it seems to beg for a general solution. So, why not have a standard way of expressing these using a simple template language? strgen: * Is far less verbose than commonly offered solutions * Trivial editing of the pattern lets you incorporate additional important features (variable length, minimum length, additional character classes, etc.) * Uses a pattern language superficially similar to regular expressions, so it's easy to learn * Uses SystemRandom class (if available, or falls back to Random) * Supports > 2.6 through 3.3 * Supports unicode * Uses a parse tree, so you can have complex - nested - expressions to do tricky data generation tasks, especially for test data generation In my opinion, it would make using Python for this application much easier and more consistent for very common requirements. The template language could easily be a cross-language standard like regex. You can `pip install strgen`. It's on Github: https://github.com/paul-wolf/strgen From paul.nospam at rudin.co.uk Fri Aug 8 04:57:51 2014 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Fri, 08 Aug 2014 09:57:51 +0100 Subject: Keep one GUI always on TOP while python code is running References: <32f85c79-17a1-4d2f-a926-43812b8083ed@googlegroups.com> Message-ID: <85fvh7icj4.fsf@rudin.co.uk> Chris Angelico writes: > On Fri, Aug 8, 2014 at 3:57 PM, Jaydeep Patil wrote: >> I mean to say, One GUI should be always on top from start to end of code running. >> So that user cant do any other operation. >> I am using wxpython > > Ah, that would be called "System Modal", and should be reserved for > absolutely critical system-wide alerts. It's also a feature that's > simply not available to most user-space programs, and not available in > most GUI toolkits. > > Short answer: Don't. There are commercial software packages that do this sort of thing. Examsoft is one - the idea being that people can take exams without access to other software at the same time (so that, for example, they could look at previously prepared notes). From rosuav at gmail.com Fri Aug 8 05:22:33 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Aug 2014 19:22:33 +1000 Subject: Template language for random string generation In-Reply-To: <14d94692-2257-4dfb-a82f-f1674a839233@googlegroups.com> References: <14d94692-2257-4dfb-a82f-f1674a839233@googlegroups.com> Message-ID: On Fri, Aug 8, 2014 at 7:01 PM, Paul Wolf wrote: > This is a proposal with a working implementation for a random string generation template syntax for Python. `strgen` is a module for generating random strings in Python using a regex-like template language. Looks good! One thing, though: > * Supports > 2.6 through 3.3 The implication of a simple reading of this statement is that your code should run on 2.6, 2.7, 3.0, 3.1, 3.2, and 3.3, and hasn't been tested on 3.4. But I eyeballed your code, and I'm seeing a lot of u'string' prefixes, which aren't supported on 3.0-3.2 (they were reinstated in 3.3 as per PEP 414), so a more likely version set would be 2.6+, 3.3+. What's the actual version support? Apologies for making such a minor quibble! But I'm curious as to what you actually support. ChrisA From rosuav at gmail.com Fri Aug 8 05:32:22 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Aug 2014 19:32:22 +1000 Subject: Keep one GUI always on TOP while python code is running In-Reply-To: <85fvh7icj4.fsf@rudin.co.uk> References: <32f85c79-17a1-4d2f-a926-43812b8083ed@googlegroups.com> <85fvh7icj4.fsf@rudin.co.uk> Message-ID: On Fri, Aug 8, 2014 at 6:57 PM, Paul Rudin wrote: > Chris Angelico writes: > >> On Fri, Aug 8, 2014 at 3:57 PM, Jaydeep Patil wrote: >>> I mean to say, One GUI should be always on top from start to end of code running. >>> So that user cant do any other operation. >>> I am using wxpython >> >> Ah, that would be called "System Modal", and should be reserved for >> absolutely critical system-wide alerts. It's also a feature that's >> simply not available to most user-space programs, and not available in >> most GUI toolkits. >> >> Short answer: Don't. > > There are commercial software packages that do this sort of > thing. Examsoft is one - the idea being that people can take exams > without access to other software at the same time (so that, for example, > they could look at previously prepared notes). Yeah; like I said, "Don't" is the short answer. There will be exceptions, some extremely rare situations when system modality is correct; but fundamentally, it's impossible to use GUI software to control what a person does with a computer (for instance, on all my Linux systems, I can hit Ctrl-Alt-F1 to switch away from the GUI altogether). So I'm dubious about its value for anything that isn't an absolutely critical alert. With the OS/2 Presentation Manager, I had SystemModal available as a window flag, and I used it for two purposes: an out-of-memory alert (or similarly critical resource shortage), and a pseudo-login screen (it just asked for a name, no password or anything, and it didn't change what you had access to - it was for the purposes of logging and messaging identification, nothing more); and the latter didn't really need to be system modal, it was just for convenience. If there's no way to make a wxpython window system modal, I would say it's no great loss. The chances of the feature being misused are extremely high; the cases where it's actually needed are extremely rare. Hence my short answer of "Don't"; honestly, there are more times when you need to optimize Python code for performance than there are times to create system modal windows. ChrisA From paulwolf333 at gmail.com Fri Aug 8 05:42:11 2014 From: paulwolf333 at gmail.com (Paul Wolf) Date: Fri, 8 Aug 2014 02:42:11 -0700 (PDT) Subject: Template language for random string generation In-Reply-To: References: <14d94692-2257-4dfb-a82f-f1674a839233@googlegroups.com> Message-ID: <1fc4393c-7d70-495e-ac10-a51acfb56d99@googlegroups.com> On Friday, 8 August 2014 10:22:33 UTC+1, Chris Angelico wrote: > But I eyeballed your code, and I'm seeing a lot of > u'string' prefixes, which aren't supported on 3.0-3.2 (they were > reinstated in 3.3 as per PEP 414), so a more likely version set would > > be 2.6+, 3.3+. What's the actual version support? > ChrisA I'm going to have to assume you are right that I only tested on 3.3, skipping > 2.7 and < 3.3. I'll create an issue for that. From ned at nedbatchelder.com Fri Aug 8 07:20:36 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 08 Aug 2014 07:20:36 -0400 Subject: Template language for random string generation In-Reply-To: <1fc4393c-7d70-495e-ac10-a51acfb56d99@googlegroups.com> References: <14d94692-2257-4dfb-a82f-f1674a839233@googlegroups.com> <1fc4393c-7d70-495e-ac10-a51acfb56d99@googlegroups.com> Message-ID: On 8/8/14 5:42 AM, Paul Wolf wrote: > On Friday, 8 August 2014 10:22:33 UTC+1, Chris Angelico wrote: >> But I eyeballed your code, and I'm seeing a lot of >> u'string' prefixes, which aren't supported on 3.0-3.2 (they were >> reinstated in 3.3 as per PEP 414), so a more likely version set would >> >> be 2.6+, 3.3+. What's the actual version support? >> ChrisA > > I'm going to have to assume you are right that I only tested on 3.3, skipping > 2.7 and < 3.3. I'll create an issue for that. > Don't bother trying to support <=3.2. It will be far more difficult than it is worth in terms of adoption of the library. Also, you don't need to write a "proposal" for your library. You've written the library, and it's on PyPI. You aren't trying to add it to the stdlib, so there's no agreement you need to get from anyone else. It can simply succeed on its merits with people using it. -- Ned Batchelder, http://nedbatchelder.com From rosuav at gmail.com Fri Aug 8 07:29:09 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Aug 2014 21:29:09 +1000 Subject: Template language for random string generation In-Reply-To: References: <14d94692-2257-4dfb-a82f-f1674a839233@googlegroups.com> <1fc4393c-7d70-495e-ac10-a51acfb56d99@googlegroups.com> Message-ID: On Fri, Aug 8, 2014 at 9:20 PM, Ned Batchelder wrote: > On 8/8/14 5:42 AM, Paul Wolf wrote: >> >> On Friday, 8 August 2014 10:22:33 UTC+1, Chris Angelico wrote: >>> >>> But I eyeballed your code, and I'm seeing a lot of >>> u'string' prefixes, which aren't supported on 3.0-3.2 (they were >>> reinstated in 3.3 as per PEP 414), so a more likely version set would >>> >>> be 2.6+, 3.3+. What's the actual version support? >>> ChrisA >> >> >> I'm going to have to assume you are right that I only tested on 3.3, >> skipping > 2.7 and < 3.3. I'll create an issue for that. >> > > Don't bother trying to support <=3.2. It will be far more difficult than it > is worth in terms of adoption of the library. Agreed. I would be looking at the solution here being "test on 3.4, then (assuming no problems) declare that it works on 3.3+". Anyone on Debian Wheezy can spin up a Python 3 from source anyway, and presumably ditto for any other Linux distro that's distributing 3.1 or 3.2; most other platforms should have a more modern Python available one way or another. ChrisA From ram.rachum at gmail.com Fri Aug 8 07:51:45 2014 From: ram.rachum at gmail.com (cool-RR) Date: Fri, 8 Aug 2014 04:51:45 -0700 (PDT) Subject: Specifying `blocking` and `timeout` when acquiring lock as a context manager Message-ID: Hi all, If I want to acquire a `threading.Lock` using the context manager protocol, is it possible to specify the `blocking` and `timeout` arguments that `acquire` would usually take? Thanks, Ram. From paulwolf333 at gmail.com Fri Aug 8 09:02:59 2014 From: paulwolf333 at gmail.com (Paul Wolf) Date: Fri, 8 Aug 2014 06:02:59 -0700 (PDT) Subject: Template language for random string generation In-Reply-To: References: <14d94692-2257-4dfb-a82f-f1674a839233@googlegroups.com> <1fc4393c-7d70-495e-ac10-a51acfb56d99@googlegroups.com> Message-ID: <5f1d7430-03da-4972-a649-acc7b6cc8fa4@googlegroups.com> On Friday, 8 August 2014 12:20:36 UTC+1, Ned Batchelder wrote: > On 8/8/14 5:42 AM, Paul Wolf wrote: > > Don't bother trying to support <=3.2. It will be far more difficult > > than it is worth in terms of adoption of the library. > > Also, you don't need to write a "proposal" for your library. You've > > written the library, and it's on PyPI. You aren't trying to add it to Thanks for that. I'll follow that advice. From paulwolf333 at gmail.com Fri Aug 8 09:03:51 2014 From: paulwolf333 at gmail.com (Paul Wolf) Date: Fri, 8 Aug 2014 06:03:51 -0700 (PDT) Subject: Template language for random string generation In-Reply-To: References: <14d94692-2257-4dfb-a82f-f1674a839233@googlegroups.com> <1fc4393c-7d70-495e-ac10-a51acfb56d99@googlegroups.com> Message-ID: <252cd452-24ad-4ee7-b5e6-a992741f9eb5@googlegroups.com> On Friday, 8 August 2014 12:29:09 UTC+1, Chris Angelico wrote: > Debian Wheezy can spin up a Python 3 from source anyway, and > > presumably ditto for any other Linux distro that's distributing 3.1 or > > 3.2; most other platforms should have a more modern Python available > > one way or another. > > > > ChrisA Yes, agreed. I'll update the version info. From ethan at stoneleaf.us Fri Aug 8 09:25:45 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 08 Aug 2014 06:25:45 -0700 Subject: Specifying `blocking` and `timeout` when acquiring lock as a context manager In-Reply-To: References: Message-ID: <53E4CFD9.4080209@stoneleaf.us> On 08/08/2014 04:51 AM, cool-RR wrote: > > If I want to acquire a `threading.Lock` using the context manager protocol, > is it possible to specify the `blocking` and `timeout` arguments that > `acquire` would usually take? Not that I know of, but why would you want to? There's no built-in 'if' with a 'with' block -- how would your code know whether it ran or not? -- ~Ethan~ From rustompmody at gmail.com Fri Aug 8 09:44:54 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 8 Aug 2014 06:44:54 -0700 (PDT) Subject: Keep one GUI always on TOP while python code is running In-Reply-To: References: Message-ID: <446aa6dd-ff18-472b-82b8-ba99d59bf112@googlegroups.com> On Thursday, August 7, 2014 4:54:09 PM UTC+5:30, Jaydeep Patil wrote: > Hi all, > I have one query. I have did some programming which copies and paste data using system clipboard. I need to keep one GUI always on top till my python code is running. In linux you can do (at shell level) $ wmctrl -r "window" -b add,above Note: In place of window you will need a string that is in your window title You can get these with $ wmctrl -l You can then stuff this into python with os.system Windows: No idea From rosuav at gmail.com Fri Aug 8 09:51:35 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Aug 2014 23:51:35 +1000 Subject: Keep one GUI always on TOP while python code is running In-Reply-To: <446aa6dd-ff18-472b-82b8-ba99d59bf112@googlegroups.com> References: <446aa6dd-ff18-472b-82b8-ba99d59bf112@googlegroups.com> Message-ID: On Fri, Aug 8, 2014 at 11:44 PM, Rustom Mody wrote: > On Thursday, August 7, 2014 4:54:09 PM UTC+5:30, Jaydeep Patil wrote: >> Hi all, > >> I have one query. I have did some programming which copies and paste data using system clipboard. I need to keep one GUI always on top till my python code is running. > > In linux you can do (at shell level) > $ wmctrl -r "window" -b add,above AIUI that just sets the "always on top" flag, which isn't what he's asking for. Also, his toolkit should offer that directly. ChrisA From steve+comp.lang.python at pearwood.info Fri Aug 8 09:58:56 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 08 Aug 2014 23:58:56 +1000 Subject: Keep one GUI always on TOP while python code is running References: <32f85c79-17a1-4d2f-a926-43812b8083ed@googlegroups.com> <85fvh7icj4.fsf@rudin.co.uk> Message-ID: <53e4d7a0$0$24963$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > On Fri, Aug 8, 2014 at 6:57 PM, Paul Rudin > wrote: >> Chris Angelico writes: >> >>> On Fri, Aug 8, 2014 at 3:57 PM, Jaydeep Patil >>> wrote: >>>> I mean to say, One GUI should be always on top from start to end of >>>> code running. So that user cant do any other operation. >>>> I am using wxpython >>> >>> Ah, that would be called "System Modal", and should be reserved for >>> absolutely critical system-wide alerts. It's also a feature that's >>> simply not available to most user-space programs, and not available in >>> most GUI toolkits. >>> >>> Short answer: Don't. >> >> There are commercial software packages that do this sort of >> thing. Examsoft is one - the idea being that people can take exams >> without access to other software at the same time (so that, for example, >> they could look at previously prepared notes). > > Yeah; like I said, "Don't" is the short answer. There will be > exceptions, some extremely rare situations when system modality is > correct; but fundamentally, it's impossible to use GUI software to > control what a person does with a computer There are exceptions, but it's impossible? Impossible except for the exceptions, I presume :-P > (for instance, on all my > Linux systems, I can hit Ctrl-Alt-F1 to switch away from the GUI > altogether). Does that work when xscreensaver or equivalent has locked the system? If so, that's a security vulnerability. > So I'm dubious about its value for anything that isn't an > absolutely critical alert. Well, there's at least two use-cases I can think of: * screen locking, as in screen savers; * login screens; * exam software; Eh, that is, at least three use-cases: * screen locking; * login screens; * exam software; * emulating full screen arcade games; Um, among the use-cases are, screen locking, login screens, exam software, full-screen games, critical system alerts, and, of course, the most popular reason of all: * my application is SOOOOO SPECIAL that it deserves to take over the entire GUI Just Because I Can. I don't know any platform-independent GUI toolkits which offer this out of the box, but I expect that there's probably a way to do it in a platform specific way on each platform you wish to support. Either that, or the OP can google for (including the quotes) and see what comes up. I'd do so myself, except some damn fool Javascript code running on some rubbish web site just crashed my browser. Again. -- Steven From marko at pacujo.net Fri Aug 8 10:06:42 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 08 Aug 2014 17:06:42 +0300 Subject: Keep one GUI always on TOP while python code is running References: <32f85c79-17a1-4d2f-a926-43812b8083ed@googlegroups.com> <85fvh7icj4.fsf@rudin.co.uk> <53e4d7a0$0$24963$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87mwbfvzwt.fsf@elektro.pacujo.net> Steven D'Aprano : > Does that work when xscreensaver or equivalent has locked the system? > If so, that's a security vulnerability. Depends on the semantics of the screensaver. Its scope is the current X11 session. In my home, different family members have different VTs. Locking one VT shouldn't prevent you from switching over to a different one. Marko From steve+comp.lang.python at pearwood.info Fri Aug 8 10:08:51 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 09 Aug 2014 00:08:51 +1000 Subject: Template language for random string generation References: <14d94692-2257-4dfb-a82f-f1674a839233@googlegroups.com> Message-ID: <53e4d9f4$0$6574$c3e8da3$5496439d@news.astraweb.com> Paul Wolf wrote: > This is a proposal with a working implementation for a random string > generation template syntax for Python. `strgen` is a module for generating > random strings in Python using a regex-like template language. Example: > > >>> from strgen import StringGenerator as SG > >>> SG("[\l\d]{8:15}&[\d]&[\p]").render() > u'F0vghTjKalf4^mGLk' Nice! Although very specialised :-) I second what Ned and Chris have to say. > If you look at various forums, like Stackoverflow, on how to generate > random strings with Python, especially for passwords and other hopefully > secure tokens, you will see dozens of variations of this: [...] > There is nothing wrong with this (it's the right answer and is very fast), > but it leads developers to constantly: > > * Use cryptographically weak methods > * Forget that the above does not guarantee a result that includes the > different classes of characters > * Doesn't include variable length or minimum length output > * It's a lot of typing and the resulting code is vastly different each > time making it hard to understand what features were > implemented, especially for those new to the language > * You can extend the above to include whatever requirements you want, > but it's a constant exercise in wheel reinvention that is extremely > verbose, error prone and confusing for exactly the same purposes > each time So, there's nothing wrong with it, except for the five things you list which are wrong with it :-) Seriously, if you're going to compete with the Stackoverflow ad hoc solutions, you have to be more assertive that there is a problem with the ad hoc solutions. -- Steven From rosuav at gmail.com Fri Aug 8 10:20:31 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 9 Aug 2014 00:20:31 +1000 Subject: Keep one GUI always on TOP while python code is running In-Reply-To: <53e4d7a0$0$24963$c3e8da3$5496439d@news.astraweb.com> References: <32f85c79-17a1-4d2f-a926-43812b8083ed@googlegroups.com> <85fvh7icj4.fsf@rudin.co.uk> <53e4d7a0$0$24963$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Aug 8, 2014 at 11:58 PM, Steven D'Aprano wrote: > Chris Angelico wrote: > >> Yeah; like I said, "Don't" is the short answer. There will be >> exceptions, some extremely rare situations when system modality is >> correct; but fundamentally, it's impossible to use GUI software to >> control what a person does with a computer > > There are exceptions, but it's impossible? Impossible except for the > exceptions, I presume :-P There are exceptions to the rule "you shouldn't use system modal windows". It is, however, fundamentally impossible for GUI software to completely control what the person does - system modality is defined only to the extent of the GUI. >> (for instance, on all my >> Linux systems, I can hit Ctrl-Alt-F1 to switch away from the GUI >> altogether). > > Does that work when xscreensaver or equivalent has locked the system? If so, > that's a security vulnerability. Absolutely it works! However, what you get to is a terminal with a login prompt. If you don't know a valid userid and password, you can't get in. (And if you *do* know them, you can probably get in through the GUI, too, although it's possible for a screen saver to lock such that no other account can log in.) >> So I'm dubious about its value for anything that isn't an >> absolutely critical alert. > > Well, there's at least two use-cases I can think of: > > * screen locking, as in screen savers; > > * login screens; With these two, it's deliberately locking only the GUI, so system modality could be correct. But really, it's more about covering the whole screen; system modality is more about disabling the whole screen. So they're still not a perfect match. > * exam software; This is what I'm dubious about. Since you can always log in via some other method, or brute-force something (eg replace one of the system accessibility programs with your own tool), it's impossible for the software to stop you from running something else. And if the computer you're doing this on is so locked down that you can't pull up your notes in some other app, it may as well simply be so locked down that you can't get your notes onto that computer in the first place. > * emulating full screen arcade games; Why should that disable access to everything else? Most full screen games let you alt-tab away from them (preferably auto-pausing the game). If a game goes system modal on me, I would not be happy. > * my application is SOOOOO SPECIAL that it deserves to take over the > entire GUI Just Because I Can. And that one is definitely not a reason, as I'm sure you agree :) > I don't know any platform-independent GUI toolkits which offer this out of > the box, but I expect that there's probably a way to do it in a platform > specific way on each platform you wish to support. There may be; there also may not (that is to say, there may be platform-specific ways on some, but not all, platforms - I'm not sure Windows has the functionality). But that's par for the course... if every platform had the exact same features, we wouldn't need multiple platforms. ChrisA From rustompmody at gmail.com Fri Aug 8 10:23:53 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 8 Aug 2014 07:23:53 -0700 (PDT) Subject: Keep one GUI always on TOP while python code is running In-Reply-To: References: <446aa6dd-ff18-472b-82b8-ba99d59bf112@googlegroups.com> Message-ID: <7a3b1122-8251-4702-ab61-0eeb767e9f44@googlegroups.com> On Friday, August 8, 2014 7:21:35 PM UTC+5:30, Chris Angelico wrote: > On Fri, Aug 8, 2014 at 11:44 PM, Rustom Mody wrote: > > On Thursday, August 7, 2014 4:54:09 PM UTC+5:30, Jaydeep Patil wrote: > >> Hi all, > > > >> I have one query. I have did some programming which copies and paste data using system clipboard. I need to keep one GUI always on top till my python code is running. > > > > In linux you can do (at shell level) > > $ wmctrl -r "window" -b add,above > > > > AIUI that just sets the "always on top" flag, which isn't what he's > > asking for. Also, his toolkit should offer that directly. A windows equivalent for linux's wmctrl seems to be nir http://www.nirsoft.net/utils/nircmd2.html#using Search for 'settopmost' From rosuav at gmail.com Fri Aug 8 10:34:05 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 9 Aug 2014 00:34:05 +1000 Subject: Keep one GUI always on TOP while python code is running In-Reply-To: <7a3b1122-8251-4702-ab61-0eeb767e9f44@googlegroups.com> References: <446aa6dd-ff18-472b-82b8-ba99d59bf112@googlegroups.com> <7a3b1122-8251-4702-ab61-0eeb767e9f44@googlegroups.com> Message-ID: On Sat, Aug 9, 2014 at 12:23 AM, Rustom Mody wrote: > A windows equivalent for linux's wmctrl seems to be nir > http://www.nirsoft.net/utils/nircmd2.html#using > > Search for 'settopmost' No need; both of those are just setting the "always on top" flag, which wxpython can do directly. It may be unobvious, as there seem to be a lot of questions asked about it (lots of StackOverflow and forums posts), but ultimately, there's a wx.STAY_ON_TOP flag that will do the same thing. However, the OP wasn't asking about visually keeping a window on top, which is pretty easy. Trying to actually prevent access to any other window is significantly harder to do, plus it's never going to be more broad than one X session, plus it's almost always a bad UI idea. ChrisA From skip at pobox.com Fri Aug 8 10:35:12 2014 From: skip at pobox.com (Skip Montanaro) Date: Fri, 8 Aug 2014 09:35:12 -0500 Subject: Template language for random string generation In-Reply-To: <14d94692-2257-4dfb-a82f-f1674a839233@googlegroups.com> References: <14d94692-2257-4dfb-a82f-f1674a839233@googlegroups.com> Message-ID: One suggestion, though perhaps nothing actually needs changing. I occasionally run into sites which define their password constraints as something like "minimum 8 characters, at least one number, one uppercase letter, and one special character." Their notion of "special" (which in my mind means any printable character which isn't a letter, whitespace, or digit) is only a subset. You include a "/" or a ";" and they kick your nice random password back at you, sometimes without telling you what you actually did wrong, only repeating, "minimum 8 characters, at least one number and one special character." You are left to discover through trial-and-error which "special" characters are actually allowed. Once you figure that out, I suppose you could use something like "[.-,()&@]" or whatever is actually allowed, but it would be nice if perhaps there was a way to figure out what some of these sites actually mean by "special" characters and define a \-escape which represents the lowest common denominator set of "special" characters. Definitely a small point though. Skip P.S. Probably a topic for a separate thread, and not actually Python-related, but on a related note, I have never found a free password keeper which works on all my platforms (Mac, Android, Unix). That is one stumbling block (for me) to actually using extremely strong passwords. If you have some thoughts, please contact me off-list. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rustompmody at gmail.com Fri Aug 8 10:45:46 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 8 Aug 2014 07:45:46 -0700 (PDT) Subject: Keep one GUI always on TOP while python code is running In-Reply-To: References: <446aa6dd-ff18-472b-82b8-ba99d59bf112@googlegroups.com> <7a3b1122-8251-4702-ab61-0eeb767e9f44@googlegroups.com> Message-ID: <1d7d60c5-e63e-496b-83ef-07843cf9732d@googlegroups.com> On Friday, August 8, 2014 8:04:05 PM UTC+5:30, Chris Angelico wrote: > On Sat, Aug 9, 2014 at 12:23 AM, Rustom Mody wrote: > > A windows equivalent for linux's wmctrl seems to be nir > > http://www.nirsoft.net/utils/nircmd2.html#using > > > > Search for 'settopmost' > > > No need; both of those are just setting the "always on top" flag, > which wxpython can do directly. It may be unobvious, as there seem to > be a lot of questions asked about it (lots of StackOverflow and forums > posts), but ultimately, there's a wx.STAY_ON_TOP flag that will do the > same thing. > > > > However, the OP wasn't asking about visually keeping a window on top, > which is pretty easy. Trying to actually prevent access to any other > window is significantly harder to do, plus it's never going to be more > broad than one X session, plus it's almost always a bad UI idea. > This is the OP: > I have one query. I have did some programming which copies and > paste data using system clipboard. I need to keep one GUI always > on top till my python code is running. [I am of course assuming that 'did' means 'done' and 'GUI' means 'window' or 'widget'] I dont see anything about preventing access. From rosuav at gmail.com Fri Aug 8 10:52:47 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 9 Aug 2014 00:52:47 +1000 Subject: Keep one GUI always on TOP while python code is running In-Reply-To: <1d7d60c5-e63e-496b-83ef-07843cf9732d@googlegroups.com> References: <446aa6dd-ff18-472b-82b8-ba99d59bf112@googlegroups.com> <7a3b1122-8251-4702-ab61-0eeb767e9f44@googlegroups.com> <1d7d60c5-e63e-496b-83ef-07843cf9732d@googlegroups.com> Message-ID: On Sat, Aug 9, 2014 at 12:45 AM, Rustom Mody wrote: > I dont see anything about preventing access. That came from his next post, in which he said "So that user cant do any other operation.". That's the preventing access bit. Of course, if "Always On Top" is sufficient, then it's (a) easy, even across platforms, and (b) not the UI annoyance that misused system modality would be. There's plenty of use for always-on-top. ChrisA From alister.nospam.ware at ntlworld.com Fri Aug 8 10:50:21 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Fri, 08 Aug 2014 14:50:21 GMT Subject: Keep one GUI always on TOP while python code is running References: <32f85c79-17a1-4d2f-a926-43812b8083ed@googlegroups.com> <85fvh7icj4.fsf@rudin.co.uk> <53e4d7a0$0$24963$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, 08 Aug 2014 23:58:56 +1000, Steven D'Aprano wrote: > >> (for instance, on all my Linux systems, I can hit Ctrl-Alt-F1 to switch >> away from the GUI altogether). > > Does that work when xscreensaver or equivalent has locked the system? If > so, > that's a security vulnerability. I have not tried b=ut is should not be a security risk as you still have to log into the virtual terminal. this may even be desirable if multiple people may administer the PC. -- I never met a piece of chocolate I didn't like. From rustompmody at gmail.com Fri Aug 8 10:58:50 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 8 Aug 2014 07:58:50 -0700 (PDT) Subject: Keep one GUI always on TOP while python code is running In-Reply-To: References: <446aa6dd-ff18-472b-82b8-ba99d59bf112@googlegroups.com> <7a3b1122-8251-4702-ab61-0eeb767e9f44@googlegroups.com> <1d7d60c5-e63e-496b-83ef-07843cf9732d@googlegroups.com> Message-ID: <7140ddd2-c038-4447-b7e8-c505731b2592@googlegroups.com> On Friday, August 8, 2014 8:22:47 PM UTC+5:30, Chris Angelico wrote: > On Sat, Aug 9, 2014 at 12:45 AM, Rustom Mody wrote: > > I dont see anything about preventing access. > > > That came from his next post, in which he said "So that user cant do > any other operation.". > That's the preventing access bit. > > > Of course, if "Always On Top" is sufficient, then it's (a) easy, even > across platforms, and (b) not the UI annoyance that misused system > modality would be. There's plenty of use for always-on-top. > Um... Ok Now I seem to remember this same questioner (??) asking a few months ago about: I have an excel program running for 20 minutes and I want to lock the machine or something like that And you proscribing similarly then :-) Yeah 'On top' can be useful. 'Modal' is a PITA. From rosuav at gmail.com Fri Aug 8 11:01:32 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 9 Aug 2014 01:01:32 +1000 Subject: Keep one GUI always on TOP while python code is running In-Reply-To: References: <32f85c79-17a1-4d2f-a926-43812b8083ed@googlegroups.com> <85fvh7icj4.fsf@rudin.co.uk> <53e4d7a0$0$24963$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Aug 9, 2014 at 12:50 AM, alister wrote: > On Fri, 08 Aug 2014 23:58:56 +1000, Steven D'Aprano wrote: >> >>> (for instance, on all my Linux systems, I can hit Ctrl-Alt-F1 to switch >>> away from the GUI altogether). >> >> Does that work when xscreensaver or equivalent has locked the system? If >> so, >> that's a security vulnerability. > > I have not tried b=ut is should not be a security risk as you still have > to log into the virtual terminal. > > this may even be desirable if multiple people may administer the PC. Right. Unix has as its underlying philosophy that users and processes are the most important things, not interfaces. I can log in to a computer at a virtual terminal by pressing Ctrl-Alt-F1, or with a graphical login manager like lightdm, or via ssh, or something else, and everything works. And if I leave something running under my user name that allows me to connect remotely, or maybe have something running as root that can hook in to some sort of user event (off a USB device, or a secondary mouse, or whatever) that can then display something on the screen, then no amount of login prevention will change that. ChrisA From rosuav at gmail.com Fri Aug 8 11:05:49 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 9 Aug 2014 01:05:49 +1000 Subject: Keep one GUI always on TOP while python code is running In-Reply-To: <7140ddd2-c038-4447-b7e8-c505731b2592@googlegroups.com> References: <446aa6dd-ff18-472b-82b8-ba99d59bf112@googlegroups.com> <7a3b1122-8251-4702-ab61-0eeb767e9f44@googlegroups.com> <1d7d60c5-e63e-496b-83ef-07843cf9732d@googlegroups.com> <7140ddd2-c038-4447-b7e8-c505731b2592@googlegroups.com> Message-ID: On Sat, Aug 9, 2014 at 12:58 AM, Rustom Mody wrote: > Now I seem to remember this same questioner (??) asking a few months ago > about: > > I have an excel program running for 20 minutes and I want to lock > the machine or something like that > > And you proscribing similarly then :-) > > Yeah 'On top' can be useful. 'Modal' is a PITA. Yeah, that sounds about right. "Always on top", incidentally, is very often used for windows which won't have input focus - maybe a small window showing a status graph, or maybe a short-lived popup alert - rather than as a means of keeping the user's attention on something. But whatever it's used for, it doesn't affect input focus. ChrisA From neilc at norwich.edu Fri Aug 8 12:05:58 2014 From: neilc at norwich.edu (Neil D. Cerutti) Date: Fri, 08 Aug 2014 12:05:58 -0400 Subject: Specifying `blocking` and `timeout` when acquiring lock as a context manager In-Reply-To: <53E4CFD9.4080209@stoneleaf.us> References: <53E4CFD9.4080209@stoneleaf.us> Message-ID: On 8/8/2014 9:25 AM, Ethan Furman wrote: > On 08/08/2014 04:51 AM, cool-RR wrote: >> >> If I want to acquire a `threading.Lock` using the context manager >> protocol, >> is it possible to specify the `blocking` and `timeout` arguments that >> `acquire` would usually take? > > Not that I know of, but why would you want to? There's no built-in 'if' > with a 'with' block -- how would your code know whether it ran or not? Perhaps defer release, a la a common Go pattern: with contextlib.ExitStack() as stack: acquired = lock.acquire(blocking=False) if acquired: stack.callback(lock.release) do_stuff -- Neil Cerutti From rosuav at gmail.com Fri Aug 8 12:16:54 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 9 Aug 2014 02:16:54 +1000 Subject: Specifying `blocking` and `timeout` when acquiring lock as a context manager In-Reply-To: References: <53E4CFD9.4080209@stoneleaf.us> Message-ID: On Sat, Aug 9, 2014 at 2:05 AM, Neil D. Cerutti wrote: > Perhaps defer release, a la a common Go pattern: > > with contextlib.ExitStack() as stack: > acquired = lock.acquire(blocking=False) > if acquired: > stack.callback(lock.release) > do_stuff There's a race condition in that - an unexpected exception could happen between those two. Are you able to set the callback to be a "release if acquired" atomic operation? ChrisA From steve+comp.lang.python at pearwood.info Fri Aug 8 14:04:27 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 09 Aug 2014 04:04:27 +1000 Subject: Keep one GUI always on TOP while python code is running References: <32f85c79-17a1-4d2f-a926-43812b8083ed@googlegroups.com> <85fvh7icj4.fsf@rudin.co.uk> <53e4d7a0$0$24963$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53e5112d$0$30000$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > On Fri, Aug 8, 2014 at 11:58 PM, Steven D'Aprano > wrote: >> Chris Angelico wrote: >> >>> Yeah; like I said, "Don't" is the short answer. There will be >>> exceptions, some extremely rare situations when system modality is >>> correct; but fundamentally, it's impossible to use GUI software to >>> control what a person does with a computer >> >> There are exceptions, but it's impossible? Impossible except for the >> exceptions, I presume :-P > > There are exceptions to the rule "you shouldn't use system modal > windows". It is, however, fundamentally impossible for GUI software to > completely control what the person does - system modality is defined > only to the extent of the GUI. *Fundamentally* impossible? You've never used classic Mac OS, I take it. Or a non-jail-broken iPhone. There is nothing *fundamental* that says that a GUI interface is necessarily a second-class interface, or that a non-GUI interface is always available. >>> (for instance, on all my >>> Linux systems, I can hit Ctrl-Alt-F1 to switch away from the GUI >>> altogether). You're assuming that there are any virtual terminals running on the system, which is not a given. Windows doesn't have them at all. Even in Linux, they can be turned off(?) or at least access to them disabled. For that matter, you're assuming the machine has a keyboard attached. Have you never seen a machine running in kiosk mode with only a touchscreen or trackball? http://wiki.tldp.org/Kiosk-HOWTO >> Does that work when xscreensaver or equivalent has locked the system? If >> so, that's a security vulnerability. > > Absolutely it works! However, what you get to is a terminal with a > login prompt. I don't think so. I think you get a terminal which may or may not be already logged in. Hence the security vulnerability: if you leave a virtual terminal logged in, then locking the X terminal alone via xscreensaver is useless. I haven't tried it with xscreensaver itself, but I've just tried it with whatever screensaver KDE under Centos uses, and sure enough, it locks the X session but allows access to any virtual terminals that happen to already be logged in with no authentication needed. [...] >> * exam software; > > This is what I'm dubious about. Since you can always log in via some > other method, Always? You're saying it is impossible to disable telnet and ssh? Or unplug the network cable? But really, now we're getting silly. No, exam software isn't going to prevent you from ssh'ing into the computer from another computer, assuming ssh is allowed. Nor is it going to prevent you from using another computer, getting answers from handwritten notes or books, or asking somebody to help you. That's hardly the point. > or brute-force something (eg replace one of the system > accessibility programs with your own tool), And how am I supposed to do that, from the exam software itself, without access to a shell? > it's impossible for the > software to stop you from running something else. And if the computer > you're doing this on is so locked down that you can't pull up your > notes in some other app, it may as well simply be so locked down that > you can't get your notes onto that computer in the first place. Um, yes? Although not necessarily. We're getting further and further from the OP's question, which should be interpreted in the most reasonable manner, not the least reasonable: - he probably only cares about blocking access to the rest of the GUI environment, not virtual terminals (assuming he is even using a system with virtual terminals); - or he's trying to build a kiosk application. It is unreasonable to interpret his comment "user cant [sic] do any other operation" so broadly that we have to care about (e.g.): - ssh'ing into the computer from another machine; - rebooting into single user mode; - walking away from the computer to do something else. All those things can be solved (e.g. by turning off the ssh daemon, or blocking access at the firewall, using a custom BIOS, and chaining the user to the computer), but likely not by the GUI toolkit itself. -- Steven From skip at pobox.com Fri Aug 8 14:08:27 2014 From: skip at pobox.com (Skip Montanaro) Date: Fri, 8 Aug 2014 13:08:27 -0500 Subject: Comparisons of Python's module/import system with JavaScript? Message-ID: I'm struggling with some JavaScript issues related to it's lack of good support for modules. I know RequireJS exists (and appears to be the most widely used add-on for this stuff), but as a novice JS programmer, I'm having trouble wrapping my head around just what it does. In particular, I don't see how it injects names into the scope which calls require(). I'm hoping someone here understands both the Python and JS models (preferably as represented by RequireJS) and can provide some advice, perhaps a pointer to a blog post? I've not found anything yet. Thanks Skip From neilc at norwich.edu Fri Aug 8 14:35:28 2014 From: neilc at norwich.edu (Neil D. Cerutti) Date: Fri, 08 Aug 2014 14:35:28 -0400 Subject: Specifying `blocking` and `timeout` when acquiring lock as a context manager In-Reply-To: References: <53E4CFD9.4080209@stoneleaf.us> Message-ID: On 8/8/2014 12:16 PM, Chris Angelico wrote: > On Sat, Aug 9, 2014 at 2:05 AM, Neil D. Cerutti wrote: >> Perhaps defer release, a la a common Go pattern: >> >> with contextlib.ExitStack() as stack: >> acquired = lock.acquire(blocking=False) >> if acquired: >> stack.callback(lock.release) >> do_stuff > > There's a race condition in that - an unexpected exception could > happen between those two. Are you able to set the callback to be a > "release if acquired" atomic operation? Doesn't any natural looking use of blocking=False suffer from the same race condition? What's the correct way to use it? Here's another attempt at context managing: @contextlib.contextmanager def release_if_acquired(lock, blocking=True, timeout=-1): acquired = lock.acquire(blocking, timeout) if acquired: yield acquired lock.release() else: yield acquired with release_if_acquired(lock, blocking=False) as acquired: if acquired: do_stuff -- Neil Cerutti From cwolf.algo at gmail.com Fri Aug 8 14:43:59 2014 From: cwolf.algo at gmail.com (cwolf.algo at gmail.com) Date: Fri, 8 Aug 2014 11:43:59 -0700 (PDT) Subject: Template language for random string generation In-Reply-To: References: <14d94692-2257-4dfb-a82f-f1674a839233@googlegroups.com> Message-ID: On Friday, August 8, 2014 10:35:12 AM UTC-4, Skip Montanaro wrote: > One suggestion, though perhaps nothing actually needs changing. > > > I occasionally run into sites which define their password constraints as something like "minimum 8 characters, at least one number, one uppercase letter, and one special character." Their notion of "special" (which in my mind means any printable character which isn't a letter, whitespace, or digit) is only a subset. ?You include a "/" or a ";" and they kick your nice random password back at you, sometimes without telling you what you actually did wrong, only repeating,?"minimum 8 characters, at least one number and one special character." You are left to discover through trial-and-error which "special" characters are actually allowed. Once you figure that out, I suppose you could use something like "[.-,()&@]" or whatever is actually allowed, but it would be nice if perhaps there was a way to figure out what some of these sites actually mean by "special" characters and define a \-escape which represents the lowest common denominator set of "special" characters. > > > > Definitely a small point though. > > > Skip > > > > P.S. Probably a topic for a separate thread, and not actually Python-related, but on a related note, I have never found a free password keeper which works on all my platforms (Mac, Android, Unix). That is one stumbling block (for me) to actually using extremely strong passwords. If you have some thoughts, please contact me off-list. Skip - try "lastpass.com" it's cross platform, include Win, Mac, Linux, Android and iOS. From neilc at norwich.edu Fri Aug 8 14:57:10 2014 From: neilc at norwich.edu (Neil D. Cerutti) Date: Fri, 08 Aug 2014 14:57:10 -0400 Subject: Specifying `blocking` and `timeout` when acquiring lock as a context manager In-Reply-To: References: <53E4CFD9.4080209@stoneleaf.us> Message-ID: On 8/8/2014 2:35 PM, Neil D. Cerutti wrote: > Here's another attempt at context managing: > @contextlib.contextmanager > def release_if_acquired(lock, blocking=True, timeout=-1): > acquired = lock.acquire(blocking, timeout) > if acquired: > yield acquired > lock.release() > else: > yield acquired I should not have used a temporary. @contextlib.contextmanager def release_if_acquired(lock, blocking=True, timeout=-1): if lock.acquire(blocking, timeout) yield True lock.release() else: yield False -- Neil Cerutti From ckaynor at zindagigames.com Fri Aug 8 15:07:30 2014 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Fri, 8 Aug 2014 12:07:30 -0700 Subject: Specifying `blocking` and `timeout` when acquiring lock as a context manager In-Reply-To: References: <53E4CFD9.4080209@stoneleaf.us> Message-ID: On Fri, Aug 8, 2014 at 11:35 AM, Neil D. Cerutti wrote: > On 8/8/2014 12:16 PM, Chris Angelico wrote: > >> On Sat, Aug 9, 2014 at 2:05 AM, Neil D. Cerutti >> wrote: >> >>> Perhaps defer release, a la a common Go pattern: >>> >>> with contextlib.ExitStack() as stack: >>> acquired = lock.acquire(blocking=False) >>> if acquired: >>> stack.callback(lock.release) >>> do_stuff >>> >> >> There's a race condition in that - an unexpected exception could >> happen between those two. Are you able to set the callback to be a >> "release if acquired" atomic operation? >> > > Doesn't any natural looking use of blocking=False suffer from the same > race condition? What's the correct way to use it? > > Here's another attempt at context managing: > > @contextlib.contextmanager > def release_if_acquired(lock, blocking=True, timeout=-1): > acquired = lock.acquire(blocking, timeout) > if acquired: > yield acquired > lock.release() > else: > yield acquired > What I'd probably do is: @contextlib.contextmanager def release_if_acquired(lock, blocking=True, timeout=-1): acquired = lock.acquire(blocking, timeout) try: yield acquired finally: if acquired: lock.release() However, there is still the chance that a interrupt signal (ctrl+c) could prevent the lock from being released, but I think the only 100% solution would be to write the code in C where it cannot be interrupted within Python. The OS could still interrupt or kill the thread, but in that case, I don't think there is anything you can do... > with release_if_acquired(lock, blocking=False) as acquired: > if acquired: > > do_stuff > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Fri Aug 8 15:21:45 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 8 Aug 2014 13:21:45 -0600 Subject: Specifying `blocking` and `timeout` when acquiring lock as a context manager In-Reply-To: <53E4CFD9.4080209@stoneleaf.us> References: <53E4CFD9.4080209@stoneleaf.us> Message-ID: On Fri, Aug 8, 2014 at 7:25 AM, Ethan Furman wrote: > On 08/08/2014 04:51 AM, cool-RR wrote: >> >> >> If I want to acquire a `threading.Lock` using the context manager >> protocol, >> is it possible to specify the `blocking` and `timeout` arguments that >> `acquire` would usually take? > > > Not that I know of, but why would you want to? There's no built-in 'if' > with a 'with' block -- how would your code know whether it ran or not? @contextmanager def locking(lock, blocking=False, timeout=-1): try: yield lock.acquire(blocking, timeout) finally: lock.release() with locking(lock, timeout=5) as acquired: if acquired: print('yay!') From smithmm at tblc.org Fri Aug 8 15:07:48 2014 From: smithmm at tblc.org (Matt Smith) Date: Fri, 8 Aug 2014 15:07:48 -0400 Subject: Newbie needing some help Message-ID: I am trying to write a program that will loop through a text file and delete rows in a mysql database. It seemingly runs but I don't see anything getting deleted in the db. Is there anything apparent that I am missing? This is the code: #!/usr/bin/python import mysql.connector # f=open('/home/smithm/email-list.txt', 'r') for line in f: # # Open database connection db = mysql.connector.connect(user="xx", password="xx", host="localhost", database="xx") # prepare a cursor object using cursor() method cursor = db.cursor() # Prepare SQL query to DELETE required records sql = "DELETE FROM tblc_users WHERE user_email=%s, % (line)" try: # Execute the SQL command cursor.execute(sql) # Commit your changes in the database db.commit() except: # Rollback in case there is any error db.rollback() # disconnect from server db.close() -- Matthew Smith -------------- next part -------------- An HTML attachment was scrubbed... URL: From larry.martell at gmail.com Fri Aug 8 17:43:55 2014 From: larry.martell at gmail.com (Larry Martell) Date: Fri, 8 Aug 2014 17:43:55 -0400 Subject: Newbie needing some help In-Reply-To: References: Message-ID: On Fri, Aug 8, 2014 at 3:07 PM, Matt Smith wrote: > I am trying to write a program that will loop through a text file and delete > rows in a mysql database. > > It seemingly runs but I don't see anything getting deleted in the db. > Is there anything apparent that I am missing? > > This is the code: > #!/usr/bin/python > import mysql.connector > # > f=open('/home/smithm/email-list.txt', 'r') > for line in f: > # > # Open database connection > db = mysql.connector.connect(user="xx", password="xx", > host="localhost", database="xx") > > # prepare a cursor object using cursor() method > cursor = db.cursor() > > # Prepare SQL query to DELETE required records > sql = "DELETE FROM tblc_users WHERE user_email=%s, % (line)" > try: > # Execute the SQL command > cursor.execute(sql) > # Commit your changes in the database > db.commit() > except: > # Rollback in case there is any error > db.rollback() > > # disconnect from server > db.close() Run it in the debugger, set a BP after you create the sql, print it out, and cut and paste it into an interactive sql session and you'll see what the issues are. From breamoreboy at yahoo.co.uk Fri Aug 8 17:54:27 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 08 Aug 2014 22:54:27 +0100 Subject: Newbie needing some help In-Reply-To: References: Message-ID: On 08/08/2014 20:07, Matt Smith wrote: > I am trying to write a program that will loop through a text file and > delete rows in a mysql database. > > It seemingly runs but I don't see anything getting deleted in the db. > Is there anything apparent that I am missing? > > This is the code: > #!/usr/bin/python > import mysql.connector > # > f=open('/home/smithm/email-list.txt', 'r') The modern idiom is:- with open(...) as f: but that doesn't matter here. > for line in f: > # > # Open database connection > db = mysql.connector.connect(user="xx", password="xx", > host="localhost", database="xx") > > # prepare a cursor object using cursor() method > cursor = db.cursor() Are you aware that you're connecting to your db and setting up the cursor in every iteration of the loop? > > # Prepare SQL query to DELETE required records > sql = "DELETE FROM tblc_users WHERE user_email=%s, % (line)" > try: > # Execute the SQL command > cursor.execute(sql) > # Commit your changes in the database > db.commit() > except: This bare except is masking every possible thing that can go wrong. Strip it out and I expect you'll find your mistake in seconds. Once you've corrected your code add back in the bare minimum number of exceptions that you really should catch. > # Rollback in case there is any error > db.rollback() > > # disconnect from server > db.close() > > -- > Matthew Smith > -- 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 Fri Aug 8 18:03:18 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 8 Aug 2014 16:03:18 -0600 Subject: Template language for random string generation In-Reply-To: <14d94692-2257-4dfb-a82f-f1674a839233@googlegroups.com> References: <14d94692-2257-4dfb-a82f-f1674a839233@googlegroups.com> Message-ID: On Fri, Aug 8, 2014 at 3:01 AM, Paul Wolf wrote: > * Uses SystemRandom class (if available, or falls back to Random) A simple improvement would be to also allow the user to pass in a Random object, in case they have their own source of randomness they want to use, or for fake Randoms used for writing unit tests that invoke strgen. Have you given any thought to adding a validation mode, where the user provides a template and a string and wants to know if the string matches the template? From nick.cash at npcinternational.com Fri Aug 8 16:28:43 2014 From: nick.cash at npcinternational.com (Nick Cash) Date: Fri, 8 Aug 2014 20:28:43 +0000 Subject: Template language for random string generation References: <14d94692-2257-4dfb-a82f-f1674a839233@googlegroups.com> Message-ID: <49f4f58c3e5c4edca9a1dfdc62efe53a@DM2PR06MB542.namprd06.prod.outlook.com> On 08/08/2014 01:45 PM, cwolf.algo at gmail.com wrote: > On Friday, August 8, 2014 10:35:12 AM UTC-4, Skip Montanaro wrote: >> P.S. Probably a topic for a separate thread, and not actually Python-related, but on a related note, I have never found a free password keeper which works on all my platforms (Mac, Android, Unix). That is one stumbling block (for me) to actually using extremely strong passwords. If you have some thoughts, please contact me off-list. > Skip - try "lastpass.com" it's cross platform, include Win, Mac, Linux, Android and iOS. LastPass is pretty nice (and I use it on Windows, Mac, Linux and Android myself), but the mobile versions aren't free: https://lastpass.com/misc_download2.php From rosuav at gmail.com Fri Aug 8 18:31:40 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 9 Aug 2014 08:31:40 +1000 Subject: Keep one GUI always on TOP while python code is running In-Reply-To: <53e5112d$0$30000$c3e8da3$5496439d@news.astraweb.com> References: <32f85c79-17a1-4d2f-a926-43812b8083ed@googlegroups.com> <85fvh7icj4.fsf@rudin.co.uk> <53e4d7a0$0$24963$c3e8da3$5496439d@news.astraweb.com> <53e5112d$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Aug 9, 2014 at 4:04 AM, Steven D'Aprano wrote: > Chris Angelico wrote: > >> On Fri, Aug 8, 2014 at 11:58 PM, Steven D'Aprano >> wrote: >>> Chris Angelico wrote: >>> >>>> Yeah; like I said, "Don't" is the short answer. There will be >>>> exceptions, some extremely rare situations when system modality is >>>> correct; but fundamentally, it's impossible to use GUI software to >>>> control what a person does with a computer >>> >>> There are exceptions, but it's impossible? Impossible except for the >>> exceptions, I presume :-P >> >> There are exceptions to the rule "you shouldn't use system modal >> windows". It is, however, fundamentally impossible for GUI software to >> completely control what the person does - system modality is defined >> only to the extent of the GUI. > > *Fundamentally* impossible? You've never used classic Mac OS, I take it. Or > a non-jail-broken iPhone. > > There is nothing *fundamental* that says that a GUI interface is necessarily > a second-class interface, or that a non-GUI interface is always available. What I mean is that GUI software can't control the entire computer. It's impossible for a system-modal flag to prevent access to non-GUI parts of the computer. Now, if there happen to be none of them (that you're aware of - certain OSes are rife with unexpected backdoors), then for all practical purposes, it's controlling the whole computer - but technically it still isn't. > You're assuming that there are any virtual terminals running on the system, > which is not a given. Windows doesn't have them at all. Even in Linux, they > can be turned off(?) or at least access to them disabled. For that matter, > you're assuming the machine has a keyboard attached. Have you never seen a > machine running in kiosk mode with only a touchscreen or trackball? > > http://wiki.tldp.org/Kiosk-HOWTO This is what I was saying about the system being so locked down already that there's no point going system modal. If you can't invoke other programs, what's it matter if you could switch to other running programs? So system modality is still pointless on a kiosk. >>> Does that work when xscreensaver or equivalent has locked the system? If >>> so, that's a security vulnerability. >> >> Absolutely it works! However, what you get to is a terminal with a >> login prompt. > > I don't think so. I think you get a terminal which may or may not be already > logged in. Hence the security vulnerability: if you leave a virtual > terminal logged in, then locking the X terminal alone via xscreensaver is > useless. > > I haven't tried it with xscreensaver itself, but I've just tried it with > whatever screensaver KDE under Centos uses, and sure enough, it locks the X > session but allows access to any virtual terminals that happen to already > be logged in with no authentication needed. Oh, sorry. I thought you were talking about the "oops you got around my security" problem. If you leave something logged in, that's a security vulnerability; whether that's on a VT or in a web browser tab, someone (you or someone else) can then use it. As far as I'm concerned, the vulnerability has nothing to do with a locked GUI. If you're trying to ensure that someone can't get around your program, you have to make sure there's no available logins. > [...] >>> * exam software; >> >> This is what I'm dubious about. Since you can always log in via some >> other method, > > Always? You're saying it is impossible to disable telnet and ssh? Or unplug > the network cable? I'm assuming here that the student has some control of the computer the software's being run on. If the student has absolutely no control over the computer, then it's the kiosk situation; there's no point locking the GUI because you'll already have locked everything else. What you're basically saying is "Hey look, I have a perfect lock on my front door - backed up by a moat full of angry crocodiles". The crocs make the lock superfluous. >> or brute-force something (eg replace one of the system >> accessibility programs with your own tool), > > And how am I supposed to do that, from the exam software itself, without > access to a shell? Again, this would be something you'd do beforehand, making use of some measure of control over the computer. If you can't do anything like that, it's kiosk mode. I'm thinking here of the time I had a Windows 7 VM that I'd forgotten the password to. The solution? Boot a rescue disk (I could probably have done this with a Linux live CD and an ntfs mount), copy cmd.exe over the top of some accessibility program (backing it up first), and reboot. The same can be done with Linux; if you can boot your own media, you can change anything and give yourself access (put yourself in sudoers, give yourself some groups, create a setuid root shell, etc, etc, etc). So the *only* way to prevent access to a physical machine is to prevent *all* access. And at that point, any lesser control is utterly superfluous. > We're getting further and further from > the OP's question, which should be interpreted in the most reasonable > manner, not the least reasonable: > > - he probably only cares about blocking access to the rest of the > GUI environment, not virtual terminals (assuming he is even using > a system with virtual terminals); In that case, a (possibly maximized) always-on-top window is probably all he needs. Which is why that was my very first response to him. > - or he's trying to build a kiosk application. In that case, he needs to learn a lot about how to build a kiosk, and it's way WAY beyond the scope of python-list. > It is unreasonable to interpret his comment "user cant [sic] do any other > operation" so broadly that we have to care about (e.g.): > > - ssh'ing into the computer from another machine; > > - rebooting into single user mode; > > - walking away from the computer to do something else. > > All those things can be solved (e.g. by turning off the ssh daemon, or > blocking access at the firewall, using a custom BIOS, and chaining the user > to the computer), but likely not by the GUI toolkit itself. Definitely. I don't think there's a wxpython flag wx.CHAIN_USER_TO_CHAIR. That said, though: it is conceivable to have students use their own computers for exams, while under approximate observation by a human. That would prevent them from using external devices or paper notes, but would make all the rest of this thread exactly correct. And that's what I'm saying is fundamentally impossible; if the students have any prior access to the computers, they can get around the problem - and if they have no prior access (or they get HD wiped before the exam), then there's nothing to access anyway, and thus no problem. (Presumably, anyone who would go to the effort of wiping the drives to keep notes away will also isolate them from the network.) Personally, though, I think the whole concept of exams is pretty pointless. I heard somewhere that the final qualifying test for certain Cisco certifications is to be put in a room with a router that someone's broken in some way, and told "You have X minutes. Fix it.". No need to lock out a GUI, this is absolutely accurate to real life. Of course, it's a bit hard to put someone in a room with allgebra and say "I've broken something. Fix it."... :) ChrisA From rosuav at gmail.com Fri Aug 8 18:36:13 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 9 Aug 2014 08:36:13 +1000 Subject: Newbie needing some help In-Reply-To: References: Message-ID: On Sat, Aug 9, 2014 at 5:07 AM, Matt Smith wrote: > # Prepare SQL query to DELETE required records > sql = "DELETE FROM tblc_users WHERE user_email=%s, % (line)" > try: > # Execute the SQL command > cursor.execute(sql) > # Commit your changes in the database > db.commit() > except: > # Rollback in case there is any error > db.rollback() By not even logging your errors, you mask everything that could go wrong. There is an error in the block of code that I've highlighted here, but the biggest problem is the bare except (as Mark pointed out). Suggestions: 1) Use a better subject line, which actually describes your problem. 2) As Mark said, don't use try/except here at all. Let exceptions abort the whole process with a nice useful traceback. 3) Open a database connection once, right at the top, and don't commit until the very end of your program. 4) If this isn't a toy program, consider doing the entire set of deletions in a single statement - it'll allow the database to do a single pass over the data. But if this is part of a "learn to use SQL" course or something, ignore that, keep going the way you are. ChrisA From rosuav at gmail.com Fri Aug 8 18:57:26 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 9 Aug 2014 08:57:26 +1000 Subject: Specifying `blocking` and `timeout` when acquiring lock as a context manager In-Reply-To: References: <53E4CFD9.4080209@stoneleaf.us> Message-ID: On Sat, Aug 9, 2014 at 4:35 AM, Neil D. Cerutti wrote: > Doesn't any natural looking use of blocking=False suffer from the same race > condition? What's the correct way to use it? Actually, I don't know. I try to avoid any form of thread locking where possible, and I don't remember the last time I used blocking=False at all. Generally, in those rare occasions when I want to lock, I want to lock reliably, and it's around something so narrow that the simple option will be the best. So you're quite probably right. ChrisA From ckaynor at zindagigames.com Fri Aug 8 18:01:12 2014 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Fri, 8 Aug 2014 15:01:12 -0700 Subject: Newbie needing some help In-Reply-To: References: Message-ID: On Fri, Aug 8, 2014 at 12:07 PM, Matt Smith wrote: > I am trying to write a program that will loop through a text file and > delete rows in a mysql database. > > It seemingly runs but I don't see anything getting deleted in the db. > Is there anything apparent that I am missing? > > This is the code: > #!/usr/bin/python > import mysql.connector > # > f=open('/home/smithm/email-list.txt', 'r') > You probably should use the with statement to make sure the file closes, like follows: with open('/home/smithm/email-list.txt', 'r') as f: # Code needing the file goes here. > for line in f: > # > # Open database connection > db = mysql.connector.connect(user="xx", password="xx", > host="localhost", database="xx") > > # prepare a cursor object using cursor() method > cursor = db.cursor() > You probably want you connect to the database outside the line for performance reasons. > # Prepare SQL query to DELETE required records > sql = "DELETE FROM tblc_users WHERE user_email=%s, % (line)" > This line also seems suspect - you are not merging in the line to the SQL statement. If you meant: sql = "DELETE FROM tblc_users WHERE user_email=%s" % (line) you would have a SQL injection attack possible. The sql library should have support for this type of loading the code. I do not know the exact syntax for how to do this within the mysql connector library, but typically you pass the arguments to the execute command (in this case, line) with some formatting in the sql command line.. > try: > # Execute the SQL command > cursor.execute(sql) > # Commit your changes in the database > db.commit() > except: > As a heads up, bare exceptions are generally a bad idea, however in this case they are acceptable. However, I'd recommend re-raising the exception after rolling back the transaction with a bare "raise" statement right after the db.rollback() - at the absolute minimum, you should log the error. This will likely let you see what your problem is. > # Rollback in case there is any error > db.rollback() > > I'd probably put the close inside of a finally block (especially if you re-raise the exception as suggested above). > # disconnect from server > db.close() > Overall, I'd suggest restructing your code to look like (untested): import mysql.connector with open('/home/smithm/email-list.txt', 'r') as f: # Open database connection db = mysql.connector.connect(user="xx", password="xx", host="localhost", database="xx") try: # prepare a cursor object using cursor() method cursor = db.cursor() for line in f: # # NOTE: the mysql library might support the with statement like above, removing the need for the try...finally. try: # Prepare SQL query to DELETE required records sql = "DELETE FROM tblc_users WHERE user_email=%s" ## --I do not know if "%s" is the correct syntax for this library.-- # Execute the SQL command cursor.execute(sql, line) ## --I do not know if this is the correct syntax for this library.-- # Commit your changes in the database db.commit() except: # Rollback in case there is any error db.rollback() raise finally: # disconnect from server db.close() Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: From elearn2014 at gmail.com Sat Aug 9 10:25:20 2014 From: elearn2014 at gmail.com (luofeiyu) Date: Sat, 09 Aug 2014 07:25:20 -0700 Subject: more simple to split the string? In-Reply-To: References: <53E4186A.5020201@gmail.com> Message-ID: <53E62F50.3040702@gmail.com> Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:25:23) [MSC v.1600 64 bit (AM D64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> str='(\\HasNoChildren \\Junk) "/" "[Gmail]/&V4NXPpCuTvY-"' >>> str.split(" ") ['(\\HasNoChildren', '\\Junk)', '"/"', '"[Gmail]/&V4NXPpCuTvY-"'] >>> it can be split into four parts,you can see. On 8/8/2014 1:43 AM, Mark Lawrence wrote: > On 08/08/2014 01:23, elearn wrote: >> str='(\\HasNoChildren \\Junk) "/" "[Gmail]/&V4NXPpCuTvY-"' > > First up it's not usually a good idea to override the builtin name str. > >> x=str.split(' "') >> [i.replace('"','') for i in x] >> ['(\\HasNoChildren \\Junk)', '/', '[Gmail]/&V4NXPpCuTvY-'] >> >> x.strip(" ") will create four parts. > > I assume you meant x=str.split(" ") ? Even so I don't see how you can > get four parts so please explain. > >> >> is there more simple to do that ? > > No loop needed that I can see. > > >>> oldstr='(\\HasNoChildren \\Junk) "/" "[Gmail]/&V4NXPpCuTvY-"';oldstr > '(\\HasNoChildren \\Junk) "/" "[Gmail]/&V4NXPpCuTvY-"' > >>> newstr=oldstr.replace('"', '');newstr > '(\\HasNoChildren \\Junk) / [Gmail]/&V4NXPpCuTvY-' > >>> substrings=newstr.split();substrings > ['(\\HasNoChildren', '\\Junk)', '/', '[Gmail]/&V4NXPpCuTvY-'] > From rosuav at gmail.com Fri Aug 8 19:38:19 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 9 Aug 2014 09:38:19 +1000 Subject: Newbie needing some help In-Reply-To: References: Message-ID: On Sat, Aug 9, 2014 at 8:01 AM, Chris Kaynor wrote: > However, I'd recommend re-raising the exception after rolling back the > transaction with a bare "raise" statement right after the db.rollback() - at > the absolute minimum, you should log the error. This will likely let you see > what your problem is. AIUI, aborting the process with an uncaught exception would roll back implicitly, so there's no need to "bare except, roll back, bare raise". But even if that's not the case, I would be looking at a try/finally for this, rather than a try/except/raise. ChrisA From rosuav at gmail.com Fri Aug 8 20:13:24 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 9 Aug 2014 10:13:24 +1000 Subject: Newbie needing some help In-Reply-To: References: Message-ID: On Sat, Aug 9, 2014 at 9:55 AM, Chris Kaynor wrote: > try: > action > commit > finally: > rollback If commit/rollback automatically opens a new transaction, this would just roll back an empty transaction - not a big deal. But yes, I do see what you're looking at here. However, structures like this are necessary only if you're hanging onto the database connection. Python gives you a well-defined unhandled-exception handler, and it's easy to just let exceptions happen - if something goes wrong, you won't commit, and you'll get a helpful traceback on the console. My recommended model for Python databasing is: Create database connection, get cursor while "work to do": do work Commit Until such time as you have a demonstrable need for more complexity, this model is safe, simple, and easy to work with. And less code generally means less bugs :) ChrisA From rosuav at gmail.com Fri Aug 8 20:39:20 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 9 Aug 2014 10:39:20 +1000 Subject: Newbie needing some help In-Reply-To: References: Message-ID: On Sat, Aug 9, 2014 at 10:32 AM, Chris Kaynor wrote: > The main issue I can see with that idea is that the exception will keep a > reference to the database connection (as with all locals), so unless you > explicitly close it within a finally clause, the database connection could > still be left hanging, and thus no rollback will occur. To clarify: The simple example I used there was assumed to be the entire program, meaning that the process will terminate on exception. No worries about resource release then! This kind of model works nicely for anything that reads from one source and writes into the database, or processes data from the database back into the database, or anything like that. The general assumption is that an unexpected exception should be treated as fatal - just write to the console and terminate. While this might seem like the simplest 1% of cases, it's able to handle a lot of real-world situations. And since it takes no extra code, it's the perfect way to start :) ChrisA From nicholascannon1 at gmail.com Fri Aug 8 20:38:06 2014 From: nicholascannon1 at gmail.com (Nicholas Cannon) Date: Fri, 8 Aug 2014 17:38:06 -0700 (PDT) Subject: Tkinter frame reset Message-ID: Ok so I am working on a little project and I cant seem to solve something with it. I have a label and then a clear button and I want all the numbers in the label to clear when I push the button. This button is on a separate frame to the buttons. I would like to clear the frame and then set all the widgits back to how they were one you first open the app(Label being blank). I have tried to destroy it with frame.destry() and then try re create it in a function but it never recreates its self. Also when I tried grid_forget() on it, it never came back either when I tried to frame it and then grid it back on there. I can clear the label by just adding a long blank string to it to overwrite the numbers behind because I would like to have the user add more numbers in there like starting fresh. This long blank string wont work because the buttons add on to the existing string so the label keeps getting updated with the new buttons pressed. I tried to remove the label but that never came back either. Please help me with trying to clear the label or the whole window back to its original blank settings From ckaynor at zindagigames.com Fri Aug 8 20:32:23 2014 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Fri, 8 Aug 2014 17:32:23 -0700 Subject: Newbie needing some help In-Reply-To: References: Message-ID: On Fri, Aug 8, 2014 at 5:13 PM, Chris Angelico wrote: > On Sat, Aug 9, 2014 at 9:55 AM, Chris Kaynor > wrote: > > try: > > action > > commit > > finally: > > rollback > > If commit/rollback automatically opens a new transaction, this would > just roll back an empty transaction - not a big deal. But yes, I do > see what you're looking at here. > > However, structures like this are necessary only if you're hanging > onto the database connection. Python gives you a well-defined > unhandled-exception handler, and it's easy to just let exceptions > happen - if something goes wrong, you won't commit, and you'll get a > helpful traceback on the console. My recommended model for Python > databasing is: > > Create database connection, get cursor > while "work to do": > do work > Commit > > Until such time as you have a demonstrable need for more complexity, > this model is safe, simple, and easy to work with. And less code > generally means less bugs :) > The main issue I can see with that idea is that the exception will keep a reference to the database connection (as with all locals), so unless you explicitly close it within a finally clause, the database connection could still be left hanging, and thus no rollback will occur. With just: openConnection while workToDo: doWork commit If at any time, doWork throws an exception, the connection could be left hanging, especially if the code is being run as an interactive script, and not as an application. I believe this is one case where explicit is better than implicit :) - its better to explicitly free the external resources, at the minimum, with something like: openConnection try: while worktoDo: doWork commit finally: closeConnection But, depending on the needs of the system (longer living connections, for example), that may need to have explicit rollback as well. As a rule of thumb, I have a context manger to deal with the specific needs (either just a "with transition" or a "with connection"). Keeps the code cleaner :). Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: From elearn2014 at gmail.com Sat Aug 9 13:22:21 2014 From: elearn2014 at gmail.com (luofeiyu) Date: Sat, 09 Aug 2014 10:22:21 -0700 Subject: how to get the ordinal number in list Message-ID: <53E658CD.5020904@gmail.com> >>> x=["x1","x3","x7","x5"] >>> y="x3" how can i get the ordinal number by some codes? for id ,value in enumerate(x): if y==value : print(id) Is more simple way to do that? From larry.martell at gmail.com Fri Aug 8 22:25:40 2014 From: larry.martell at gmail.com (Larry Martell) Date: Fri, 8 Aug 2014 22:25:40 -0400 Subject: how to get the ordinal number in list In-Reply-To: <53E658CD.5020904@gmail.com> References: <53E658CD.5020904@gmail.com> Message-ID: On Sat, Aug 9, 2014 at 1:22 PM, luofeiyu wrote: >>>> x=["x1","x3","x7","x5"] >>>> y="x3" > > how can i get the ordinal number by some codes? > > for id ,value in enumerate(x): > if y==value : print(id) > > Is more simple way to do that? print x.index(y) From ckaynor at zindagigames.com Fri Aug 8 19:55:39 2014 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Fri, 8 Aug 2014 16:55:39 -0700 Subject: Newbie needing some help In-Reply-To: References: Message-ID: On Fri, Aug 8, 2014 at 4:38 PM, Chris Angelico wrote: > On Sat, Aug 9, 2014 at 8:01 AM, Chris Kaynor > wrote: > > However, I'd recommend re-raising the exception after rolling back the > > transaction with a bare "raise" statement right after the db.rollback() > - at > > the absolute minimum, you should log the error. This will likely let you > see > > what your problem is. > > AIUI, aborting the process with an uncaught exception would roll back > implicitly, so there's no need to "bare except, roll back, bare > raise". But even if that's not the case, I would be looking at a > try/finally for this, rather than a try/except/raise. > I would imagine that on connection close, the server would rollback any uncommitted transactions, however that presumes that the connection close is completed in a reasonably timely manner (with a try...finally for closing, it should be). This is one case where I think try...except/raise is better than try...finally. If you use try...finally to rollback, you'd have to either track whether you committed, or you'd rollback with no actions (or possibly a committed action, which could have odd behavior, depending on the implementation) try: action commit except: rollback raise I feel is better than: try: action commit finally: rollback or: success = False try: action commit success = True finally: if success: rollback and is very different than: try: action finally: commit -------------- next part -------------- An HTML attachment was scrubbed... URL: From elearn2014 at gmail.com Sat Aug 9 13:33:51 2014 From: elearn2014 at gmail.com (luofeiyu) Date: Sat, 09 Aug 2014 10:33:51 -0700 Subject: how to print with given font and size? Message-ID: <53E65B7F.9060600@gmail.com> print("hallo") is so simple. how can print word "hallo" in console with courier New font 16 pound? From elearn2014 at gmail.com Sat Aug 9 13:35:58 2014 From: elearn2014 at gmail.com (luofeiyu) Date: Sat, 09 Aug 2014 10:35:58 -0700 Subject: how to get the ordinal number in list In-Reply-To: References: <53E658CD.5020904@gmail.com> Message-ID: <53E65BFE.1060309@gmail.com> >>> x=["x1","x3","x7","x5","x3"] >>> x.index("x3") 1 if i want the result of 1 and 4 ? On 8/8/2014 7:25 PM, Larry Martell wrote: > On Sat, Aug 9, 2014 at 1:22 PM, luofeiyu wrote: >>>>> x=["x1","x3","x7","x5"] >>>>> y="x3" >> how can i get the ordinal number by some codes? >> >> for id ,value in enumerate(x): >> if y==value : print(id) >> >> Is more simple way to do that? > print x.index(y) From rosuav at gmail.com Fri Aug 8 22:46:43 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 9 Aug 2014 12:46:43 +1000 Subject: how to get the ordinal number in list In-Reply-To: <53E65BFE.1060309@gmail.com> References: <53E658CD.5020904@gmail.com> <53E65BFE.1060309@gmail.com> Message-ID: On Sun, Aug 10, 2014 at 3:35 AM, luofeiyu wrote: >>>> x=["x1","x3","x7","x5","x3"] >>>> x.index("x3") > 1 > if i want the result of 1 and 4 ? Want to know what you can do with some object? Try this: >>> help(x) In this case, though, I suspect there's no built-in to search for *all* of the occurrences of something, so you're best doing your own loop. You can either iterate straight over the list with enumerate, as you were doing, or you can use index() with its start argument: >>> def find_all(lst, obj): indices = [-1] try: while True: indices.append(lst.index(obj, indices[-1]+1)) except ValueError: return indices[1:] >>> x=["x1","x3","x7","x5","x3"] >>> find_all(x, "x3") [1, 4] It's probably cleaner to just iterate over the list once, though, and you already know how to do that. ChrisA From rosuav at gmail.com Fri Aug 8 22:50:52 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 9 Aug 2014 12:50:52 +1000 Subject: how to print with given font and size? In-Reply-To: <53E65B7F.9060600@gmail.com> References: <53E65B7F.9060600@gmail.com> Message-ID: On Sun, Aug 10, 2014 at 3:33 AM, luofeiyu wrote: > print("hallo") is so simple. > > how can print word "hallo" in console with courier New font 16 pound? You'd have to look to your console's settings; generally, you can't change fonts. For that kind of work, what you want is an actual GUI; there are a number of good Python GUI toolkits, including PyGTK, Tkinter, wxPython, PyQt, and others. Pick one (Tkinter's probably a good choice for starting out, as it comes with Python on several platforms; personally, I quite like GTK; but really, any will do), and work through its tutorial, which should take you through a basic graphical Hello, World. But at a regular console, you don't have fonts - all you have is a stream of text. ChrisA From gordon at panix.com Fri Aug 8 22:51:01 2014 From: gordon at panix.com (John Gordon) Date: Sat, 9 Aug 2014 02:51:01 +0000 (UTC) Subject: Newbie needing some help References: Message-ID: In Matt Smith writes: > I am trying to write a program that will loop through a text file and > delete rows in a mysql database. > It seemingly runs but I don't see anything getting deleted in the db. > Is there anything apparent that I am missing? > This is the code: > #!/usr/bin/python > import mysql.connector > # > f=open('/home/smithm/email-list.txt', 'r') > for line in f: > # > # Open database connection > db = mysql.connector.connect(user="xx", password="xx", > host="localhost", database="xx") > # prepare a cursor object using cursor() method > cursor = db.cursor() As others have said, this code connects to the database and prepares a cursor *every time* through the loop. You probably only want to do those things once. > # Prepare SQL query to DELETE required records > sql = "DELETE FROM tblc_users WHERE user_email=%s, % (line)" You don't have the sql command constructed quite right. As written, the sql command will be, literally: DELETE FROM tblc_users WHERE user_email=%s, % (line) And of course that likely won't match anything. (As a very simple debugging step, you could have printed the sql statement each time through the loop. That would have alerted you immediately as to what was going on.) You probably meant something like this instead: sql = "DELETE FROM tblc_users WHERE user_email=%s" % line This will substitute the value of line for the %s. However, most (all?) SQL databases require string values to be enclosed in single quotes, and your databse likely defines user_email as a string value. So you probably actually want something like this: sql = "DELETE FROM tblc_users WHERE user_email='%s'" % line And even this solution isn't very good, because it allows SQL injection attacks if your text file contains something nasty. If this is anything other than a toy program, please take the time to look up prepared statements. > try: > # Execute the SQL command > cursor.execute(sql) > # Commit your changes in the database > db.commit() > except: > # Rollback in case there is any error > db.rollback() Again, as others have said, using a bare 'except:' statement will catch and hide any possible error, leaving you mystified as to why nothing happened. > # disconnect from server > db.close() -- 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 elearn2014 at gmail.com Sat Aug 9 13:56:15 2014 From: elearn2014 at gmail.com (luofeiyu) Date: Sat, 09 Aug 2014 10:56:15 -0700 Subject: how to write file into my android phone? Message-ID: <53E660BF.7080401@gmail.com> When i input usb line with my android phone into the pc , there are two disks j: and k: (type :removable disk) displayed in win7. i can get my android phone bluetooth mac address . import bluetooth nearby_devices = bluetooth.discover_devices(lookup_names = True) for addr, phoneName in nearby_devices: print(addr) it is 6C:8B:2F:CE:5B:59 Now how can i write a file into the disk j: of my android phone(bluetooth mac is 6C:8B:2F:CE:5B:59 )? From rosuav at gmail.com Fri Aug 8 23:03:24 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 9 Aug 2014 13:03:24 +1000 Subject: Newbie needing some help In-Reply-To: References: Message-ID: On Sat, Aug 9, 2014 at 12:51 PM, John Gordon wrote: > You probably meant something like this instead: > > sql = "DELETE FROM tblc_users WHERE user_email=%s" % line > > This will substitute the value of line for the %s. > > However, most (all?) SQL databases require string values to be enclosed > in single quotes, and your databse likely defines user_email as a string > value. So you probably actually want something like this: > > sql = "DELETE FROM tblc_users WHERE user_email='%s'" % line > > And even this solution isn't very good, because it allows SQL injection > attacks if your text file contains something nasty. If this is anything > other than a toy program, please take the time to look up prepared > statements. All SQL databases require strings to be quoted (it's part of the SQL spec), although some broken database engines (which I shall not name) do allow other forms of quote than the apostrophe. But I would advise against even suggesting the interpolation method; there's absolutely no reason ever to do this sort of thing - it's just way too fragile. (Even if you think you can get it perfectly right now, do you really want to inflict the headache on the code's next maintainer?) Parameterized queries are a part of the Python database API, so go ahead and use them. ChrisA From steve+comp.lang.python at pearwood.info Fri Aug 8 23:06:28 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 09 Aug 2014 13:06:28 +1000 Subject: how to get the ordinal number in list References: <53E658CD.5020904@gmail.com> Message-ID: <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> luofeiyu wrote: > >>> x=["x1","x3","x7","x5","x3"] > >>> x.index("x3") > 1 > if i want the result of 1 and 4 ? def index_all(source, target): results = [] for i, obj in enumerate(source): if obj == target: results.append(i) return results index_all(x, "x3") => returns [1, 3] -- Steven From rustompmody at gmail.com Fri Aug 8 23:48:44 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 8 Aug 2014 20:48:44 -0700 (PDT) Subject: how to get the ordinal number in list In-Reply-To: <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> On Saturday, August 9, 2014 8:36:28 AM UTC+5:30, Steven D'Aprano wrote: > luofeiyu wrote: > > >>> x=["x1","x3","x7","x5","x3"] > > >>> x.index("x3") > > 1 > > if i want the result of 1 and 4 ? > def index_all(source, target): > results = [] > for i, obj in enumerate(source): > if obj == target: > results.append(i) > return results > index_all(x, "x3") > => returns [1, 3] Heh! And the OP asked for a simplification! >>> def index_all(lst, val): return (i for i,v in enumerate(lst) if v == val) ... >>> index_all("abcdeaga", "a") at 0x7f21884797d0> >>> list(index_all("abcdeaga", "a")) [0, 5, 7] [To the OP] Yeah I am in the minority at least out here in considering comprehensions simpler than loops. Take your pick From paulwolf333 at gmail.com Sat Aug 9 02:52:09 2014 From: paulwolf333 at gmail.com (Paul Wolf) Date: Fri, 8 Aug 2014 23:52:09 -0700 (PDT) Subject: Template language for random string generation In-Reply-To: References: <14d94692-2257-4dfb-a82f-f1674a839233@googlegroups.com> Message-ID: <58187503-1651-4eca-a131-49f474148f62@googlegroups.com> On Friday, 8 August 2014 23:03:18 UTC+1, Ian wrote: > On Fri, Aug 8, 2014 at 3:01 AM, Paul Wolf wrote: > > > * Uses SystemRandom class (if available, or falls back to Random) > A simple improvement would be to also allow the user to pass in a > Random object That is not a bad idea. I'll create an issue for it. It is a design goal to use the standard library within the implementation so users have a guarantee about exactly how the data is generated. But your suggestion is not inconsistent with that. > > Have you given any thought to adding a validation mode, where the user > provides a template and a string and wants to know if the string > matches the template? Isn't that what regular expressions are? Or do you have a clarifying use case? strgen is provided as the converse of regular expressions. From __peter__ at web.de Sat Aug 9 03:15:50 2014 From: __peter__ at web.de (Peter Otten) Date: Sat, 09 Aug 2014 09:15:50 +0200 Subject: more simple to split the string? References: <53E4186A.5020201@gmail.com> Message-ID: elearn wrote: > str='(\\HasNoChildren \\Junk) "/" "[Gmail]/&V4NXPpCuTvY-"' > x=str.split(' "') > [i.replace('"','') for i in x] > ['(\\HasNoChildren \\Junk)', '/', '[Gmail]/&V4NXPpCuTvY-'] > > x.strip(" ") will create four parts. > > is there more simple to do that ? Here's another way: >>> s = '(\\HasNoChildren \\Junk) "/" "[Gmail]/&V4NXPpCuTvY-"' >>> s.replace("(", '"').replace(")", '"').split('"')[1::2] ['\\HasNoChildren \\Junk', '/', '[Gmail]/&V4NXPpCuTvY-'] But you should rather worry about correctness. Can '"' occur inside the parentheses and vice versa? Is there a way to escape '"'? Can parentheses be nested? Etc. The example is not sufficient to specify the problem. From ian.g.kelly at gmail.com Sat Aug 9 03:49:54 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 9 Aug 2014 01:49:54 -0600 Subject: Template language for random string generation In-Reply-To: <58187503-1651-4eca-a131-49f474148f62@googlegroups.com> References: <14d94692-2257-4dfb-a82f-f1674a839233@googlegroups.com> <58187503-1651-4eca-a131-49f474148f62@googlegroups.com> Message-ID: On Sat, Aug 9, 2014 at 12:52 AM, Paul Wolf wrote: > On Friday, 8 August 2014 23:03:18 UTC+1, Ian wrote: >> Have you given any thought to adding a validation mode, where the user >> provides a template and a string and wants to know if the string >> matches the template? > > Isn't that what regular expressions are? Or do you have a clarifying use case? > > strgen is provided as the converse of regular expressions. The syntax is not equivalent though. You can't take a strgen template, pass it into the re module, and just expect it to work. Also, I'm not sure how best to go about writing a regular expression for, e.g. "12 or more letters, digits, and punctuation, including at least one each of uppercase letter, lowercase letter, digit, and punctuation". I'm fairly certain that language is regular, but actually matching it with a regular expression would be a nightmare. From ian.g.kelly at gmail.com Sat Aug 9 03:57:18 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 9 Aug 2014 01:57:18 -0600 Subject: Template language for random string generation In-Reply-To: References: <14d94692-2257-4dfb-a82f-f1674a839233@googlegroups.com> <58187503-1651-4eca-a131-49f474148f62@googlegroups.com> Message-ID: On Sat, Aug 9, 2014 at 1:49 AM, Ian Kelly wrote: > On Sat, Aug 9, 2014 at 12:52 AM, Paul Wolf wrote: >> On Friday, 8 August 2014 23:03:18 UTC+1, Ian wrote: >>> Have you given any thought to adding a validation mode, where the user >>> provides a template and a string and wants to know if the string >>> matches the template? >> >> Isn't that what regular expressions are? Or do you have a clarifying use case? >> >> strgen is provided as the converse of regular expressions. > > The syntax is not equivalent though. You can't take a strgen template, > pass it into the re module, and just expect it to work. > > Also, I'm not sure how best to go about writing a regular expression > for, e.g. "12 or more letters, digits, and punctuation, including at > least one each of uppercase letter, lowercase letter, digit, and > punctuation". I'm fairly certain that language is regular, but > actually matching it with a regular expression would be a nightmare. To clarify further, validating that *without* using a regular expression is not too terribly difficult, but the value that I see in validating it with a strgen is that one could then be sure that one's string generation and validation were equivalent. In contrast, if you have a strgen for generation and a series of string manipulations for validation, then it's hard to be certain there aren't any differences. From kwpolska at gmail.com Sat Aug 9 06:49:08 2014 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Sat, 9 Aug 2014 12:49:08 +0200 Subject: how to write file into my android phone? In-Reply-To: <53E660BF.7080401@gmail.com> References: <53E660BF.7080401@gmail.com> Message-ID: On Sat, Aug 9, 2014 at 7:56 PM, luofeiyu wrote: > When i input usb line with my android phone into the pc , there are two > disks j: and k: (type :removable disk) displayed in win7. > > i can get my android phone bluetooth mac address . > > import bluetooth > nearby_devices = bluetooth.discover_devices(lookup_names = True) > for addr, phoneName in nearby_devices: > print(addr) > > > it is 6C:8B:2F:CE:5B:59 > > Now how can i write a file into the disk j: of my android phone(bluetooth > mac is 6C:8B:2F:CE:5B:59 )? > > -- > https://mail.python.org/mailman/listinfo/python-list You mixed up two very different interfaces. Bluetooth and USB are completely separate. If you want to write a file to the USB drive, you can just open a file, using the regular open() function (specify a path somewhere benath J:\): https://docs.python.org/2/tutorial/inputoutput.html#reading-and-writing-files However, if you want to do it via Bluetooth for some reason, you need to find a library that does OBEX ? Google hints at http://lightblue.sourceforge.net/ . -- Chris ?Kwpolska? Warrick PGP: 5EAAEA16 stop html mail | always bottom-post | only UTF-8 makes sense From elearn2014 at gmail.com Sat Aug 9 17:01:53 2014 From: elearn2014 at gmail.com (luofeiyu) Date: Sat, 09 Aug 2014 14:01:53 -0700 Subject: attendance system in pybluez Message-ID: <53E68C41.2010202@gmail.com> I want to write a program to help my teacher to take attendence. There are 300 students in a big room,everyone has android phone. I have matched them with my pc in win7 . when all of them seated on the classroom, import bluetooth nearby_devices = bluetooth.discover_devices(lookup_names = True) print("found %d devices" % len(nearby_devices)) The function can discover all of them ? 300 bluetooth mac address? can i search for a given bluetooth mac? blue_mac=[] (i can write it in a list in advance,it is not blank,full of strings) for add in blue_mac: print(bluetooth.seacrh_given_mac) #result is true or false Is there a function to run? From fabien.maussion at gmail.com Sat Aug 9 07:48:17 2014 From: fabien.maussion at gmail.com (Fabien) Date: Sat, 09 Aug 2014 13:48:17 +0200 Subject: The "right" way to use config files Message-ID: Folks, I am not a computer scientist (just a scientist) and I'd like to ask your opinion about a design problem I have. It's not that I can't get my program to work, but rather that I have trouble to find an "elegant" solution to the problem of passing information to my program's elements. I have trouble to be clear in my request so my apologies for the long text... The tool I am developing is a classical data-analysis workflow. Ideally, all the program's configurations are located in a single .cfg file which I parse with ConfigObg. The file contains I/O informations (path_to_input, path_to_output) as well as internal options (use_this_function, dont_use_this_one, function1_paramx = y), etc... Currently, my program is a "super-object" which is initialized once and work schematically as follows: main(): obj = init_superobj(config file) obj.preprocess() obj.process() obj.write() the superobj init routine parses the config files and reads the input data. and a processing step can be, for example: def process(): if self.configfile.as_bool('do_funcion1'): params = config.parse_function1_params() call_function1(self.data, params) if self.configfile.as_bool('do_funcion2'): params = config.parse_function2_params() call_function2(self.data2, params) The functions themselves do not know about the superobject or about the configfile. They are "standalone" functions which take data and parameters as input and produce output with it. I thought that the standalone functions will be clearer and easier to maintain, since they do not rely on some external data structure such as the configobj or anything. BUT, my "problem" is that several options really are "universal" options to the program, such as the output directory for example. This information (where to write their results) is given to most of the functions as parameter. So I had the idea to define a super-object which parses the config file and input data and is given as a single parameter to the processing functions, and the functions take the information they need from it. This is tempting because there is no need for refactoring when I decide to change something in the config, but I am afraid that the program may become unmaintainable by someone else than myself. Another possibility would be at least to give all the functions access to the configfile. To get to the point: is it good practice to give all elements of a program access to the configfile and if yes, how is it done "properly"? I hope at least someone will understand what I mean ;-) Cheers and thanks, Fabien From steve+comp.lang.python at pearwood.info Sat Aug 9 07:53:11 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 09 Aug 2014 21:53:11 +1000 Subject: attendance system in pybluez References: Message-ID: <53e60ba8$0$29968$c3e8da3$5496439d@news.astraweb.com> luofeiyu wrote: > I want to write a program to help my teacher to take attendence. > > There are 300 students in a big room,everyone has android phone. If your students allow strange devices to connect to their android phones, then they won't remain their android phones for very long. They will belong to whatever hacker takes control of them first. http://blog.kaspersky.com/bluetooth-security/ > I have matched them with my pc in win7 . > when all of them seated on the classroom, > > import bluetooth > nearby_devices = bluetooth.discover_devices(lookup_names = True) > print("found %d devices" % len(nearby_devices)) > > > The function can discover all of them ? 300 bluetooth mac address? You will have to ask the author of the bluetooth module. Where did you find it? Does it come with documentation? Did you read it? -- Steven From elearn2014 at gmail.com Sat Aug 9 23:07:23 2014 From: elearn2014 at gmail.com (luofeiyu) Date: Sat, 09 Aug 2014 20:07:23 -0700 Subject: attendance system in pybluez In-Reply-To: <53e60ba8$0$29968$c3e8da3$5496439d@news.astraweb.com> References: <53e60ba8$0$29968$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53E6E1EB.20109@gmail.com> in the http://homepages.ius.edu/rwisman/C490/html/PythonandBluetooth.htm *Discovery* The address and name of enabled devices within range can be discovered by other Bluetooth devices. Discovery can take some time to complete, given that radio communications is unreliable. The following displays address and name of all enabled devices nearby. from bluetooth import * print "performing inquiry..." *nearby_devices = discover_devices(lookup_names = True)* print "found %d devices" % len(nearby_devices) for name, addr in nearby_devices: print " %s - %s" % (addr, name) performing inquiry... found 2 devices Ray's Nokia - 00:12:D2:5A:BD:E4 Ray's MacBook - 00:1E:C2:93:DA:6F On 8/9/2014 4:53 AM, Steven D'Aprano wrote: > luofeiyu wrote: > >> I want to write a program to help my teacher to take attendence. >> >> There are 300 students in a big room,everyone has android phone. > If your students allow strange devices to connect to their android phones, > then they won't remain their android phones for very long. They will belong > to whatever hacker takes control of them first. > > http://blog.kaspersky.com/bluetooth-security/ > > >> I have matched them with my pc in win7 . >> when all of them seated on the classroom, >> >> import bluetooth >> nearby_devices = bluetooth.discover_devices(lookup_names = True) >> print("found %d devices" % len(nearby_devices)) >> >> >> The function can discover all of them ? 300 bluetooth mac address? > You will have to ask the author of the bluetooth module. Where did you find > it? Does it come with documentation? Did you read it? > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dfnsonfsduifb at gmx.de Sat Aug 9 08:13:13 2014 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Sat, 09 Aug 2014 14:13:13 +0200 Subject: how to get the ordinal number in list In-Reply-To: References: Message-ID: On 09.08.2014 19:22, luofeiyu wrote: >>>> x=["x1","x3","x7","x5"] >>>> y="x3" > > how can i get the ordinal number by some codes? > > for id ,value in enumerate(x): > if y==value : print(id) > > Is more simple way to do that? print(x.index(y)) HTH, Johannes -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht ?ffentlich! Ah, der neueste und bis heute genialste Streich unsere gro?en Kosmologen: Die Geheim-Vorhersage. - Karl Kaos ?ber R?diger Thomas in dsa From ned at nedbatchelder.com Sat Aug 9 08:16:08 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 09 Aug 2014 08:16:08 -0400 Subject: how to get the ordinal number in list In-Reply-To: <53E65BFE.1060309@gmail.com> References: <53E658CD.5020904@gmail.com> <53E65BFE.1060309@gmail.com> Message-ID: On 8/9/14 1:35 PM, luofeiyu wrote: > >>> x=["x1","x3","x7","x5","x3"] > >>> x.index("x3") > 1 > if i want the result of 1 and 4 ? If you tell us more about your problem, and what you will do with the 1 and 4, there might be an even better way to do what you want. > > On 8/8/2014 7:25 PM, Larry Martell wrote: >> On Sat, Aug 9, 2014 at 1:22 PM, luofeiyu wrote: >>>>>> x=["x1","x3","x7","x5"] >>>>>> y="x3" >>> how can i get the ordinal number by some codes? >>> >>> for id ,value in enumerate(x): >>> if y==value : print(id) >>> >>> Is more simple way to do that? >> print x.index(y) > -- Ned Batchelder, http://nedbatchelder.com From ben+python at benfinney.id.au Sat Aug 9 08:17:25 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 09 Aug 2014 22:17:25 +1000 Subject: The "right" way to use config files References: Message-ID: <85vbq197sa.fsf@benfinney.id.au> Fabien writes: > So I had the idea to define a super-object which parses the config > file and input data and is given as a single parameter to the > processing functions, and the functions take the information they need > from it. That's not a bad idea, you could do that without embarrassment. A better technique, though, is to make use of modules as namespaces. Have one module of your application be responsible for the configuration of the application:: # app/config.py import configparser parser = configparser.ConfigParser() parser.read("app.conf") and import that module everywhere else that needs it:: # app/wibble.py from . import config def frobnicate(): do_something_with(config.foo) By using an imported module, the functions don't need to be parameterised by application-wide configuration; they can simply access the module from the global scope and thereby get access to that module's attributes. > To get to the point: is it good practice to give all elements of a > program access to the configfile and if yes, how is it done > "properly"? There should be an encapsulation of the responsibility for parsing and organising the configuration options, and the rest of the application should access it only via that encapsulation. Putting that encapsuation in a module is an appropriately Pythonic technique. -- \ ?Now Maggie, I?ll be watching you too, in case God is busy | `\ creating tornadoes or not existing.? ?Homer, _The Simpsons_ | _o__) | Ben Finney From fabien.maussion at gmail.com Sat Aug 9 08:33:54 2014 From: fabien.maussion at gmail.com (Fabien) Date: Sat, 09 Aug 2014 14:33:54 +0200 Subject: The "right" way to use config files References: Message-ID: Hi Ben, On 09.08.2014 14:17, Ben Finney wrote: > Have one module of your application be responsible for the configuration > of the application:: > > # app/config.py > > import configparser > > parser = configparser.ConfigParser() > parser.read("app.conf") Thanks for the suggestion. This way to do is new to me, and I didn't come to the idea myself. It seems like a good way to do this. But how to give an argument to this config namespace? i.e I want "app.conf" to be given as argument. Currently my program starts like this: def main(): # See if the user gave a configfile if len(sys.argv) == 2: # file was given as argument cfg = str(sys.argv[1]) else: # default file taken in the resource directory cfg = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir,'res','default.cfg')) obj = superobj(cfg) obj.preprocess() obj.process() obj.write() From vlastimil.brom at gmail.com Sat Aug 9 08:46:01 2014 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sat, 9 Aug 2014 14:46:01 +0200 Subject: Tkinter frame reset In-Reply-To: References: Message-ID: 2014-08-09 2:38 GMT+02:00 Nicholas Cannon : > Ok so I am working on a little project and I cant seem to solve something with it. I have a label and then a clear button and I want all the numbers in the label to clear when I push the button. This button is on a separate frame to the buttons. I would like to clear the frame and then set all the widgits back to how they were one you first open the app(Label being blank). ... > -- > https://mail.python.org/mailman/listinfo/python-list Hi, I haven't been doing anything more complex for some time now with tkinter, but could you maybe just associate the appropriate variables, keep them in a list and change the values in a loop as appropriate - without recreating the gui? cf. the basic recipe: http://effbot.org/tkinterbook/label.htm v = StringVar() Label(master, textvariable=v).pack() v.set("New Text!") hth, vbr From roy at panix.com Sat Aug 9 11:34:22 2014 From: roy at panix.com (Roy Smith) Date: Sat, 09 Aug 2014 11:34:22 -0400 Subject: how to get the ordinal number in list References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> Message-ID: In article <338e8fb0-c9ec-462a-b560-1c1ff77de17e at googlegroups.com>, Rustom Mody wrote: > [To the OP] > Yeah I am in the minority at least out here in considering > comprehensions simpler than loops. Take your pick When comprehensions first came out, I stubbornly refused to get my head around them. Now, I'm totally addicted. To the extent that I consider dict comprehensions to the THE killer feature of 2.7 :-) But, putting on my instructor's hat, I think it's important to answer questions at a level that can be understood by the student. Painting with a broad brush, there's three or four kinds of people asking questions on this list: 1) People who are totally new to programming, and are learning Python as their first language. These are the people who are still struggling to understand fundamental concepts. They haven't figured out yet that the first step to solving a problem is to decide what algorithms you're going to use, and only then can you start translating that into code. They need to be led in small steps towards basic knowledge. 2) People who are (at least somewhat) experienced programmers, and are learning Python as a second language. Their experiential background is limited to one way of doing things (i.e. the Java way, or the PHP way, or whatever language way they learned first). They mostly should be shown how translate the things they already know into familiar feeling constructs. You already know how to write a loop, this is how we do it in Python. You already know how build a data structure that maps keys to values, this is how we do it in Python. Only after they've become comfortable with that, should they start exploring the really cool features of Python. 3) People who already know many languages, and are learning Python as their n-th. These folks have seen multiple ways of doing things, and can understand concepts at a higher level. Oh, Python dicts are more like C++ STL maps than PHP arrays. Oh, variables have function scope and don't have to be explicitly declared. Oh, RAII is spelled "with" in this language. Oh, functions are first-class objects, but code blocks are not. 4) People who are already proficient Python programmers and are looking to explore deeper topics. I think suggesting comprehensions in an answer should be reserved for people at levels 3 and 4. Maybe level 2-1/2. Certainly not level 1. From python.list at tim.thechases.com Sat Aug 9 13:08:23 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 9 Aug 2014 12:08:23 -0500 Subject: The "right" way to use config files In-Reply-To: References: Message-ID: <20140809120823.21109509@bigbox.christie.dr> On 2014-08-09 13:48, Fabien wrote: > So I had the idea to define a super-object which parses the config > file and input data and is given as a single parameter to the > processing functions, and the functions take the information they > need from it. This is tempting because there is no need for > refactoring when I decide to change something in the config, but I > am afraid that the program may become unmaintainable by someone > else than myself. Another possibility would be at least to give all > the functions access to the configfile. > > To get to the point: is it good practice to give all elements of a > program access to the configfile and if yes, how is it done > "properly"? Though I don't like how it looks/feels to pass around the config in just about any function-call that needs it, I've found that doing so allows me to test more readily. The alternative (putting it in a global or some module) usually means that it's harder for me to test in isolation. -tkc From fabien.maussion at gmail.com Sat Aug 9 13:17:30 2014 From: fabien.maussion at gmail.com (Fabien) Date: Sat, 09 Aug 2014 19:17:30 +0200 Subject: The "right" way to use config files References: Message-ID: Hi, On 09.08.2014 18:16, Dennis Lee Bieber wrote: > Better, in my view, is to have the import module set up default values > for everything, AND have a function at the bottom of the form > > def initialize(fid=None): > if fid: > # parse file "fid" replacing the module level items > # this may require making a them all globals since > # assignments inside this function would be locals > > And then your main program > > import myconfig > ... > myconfig.initialize(sys.argv[1]) Yes ok I think got it. Thanks! I like the idea and will implement it, this will avoid the useless superobject and allow to have to configfile available to anyone. Fabien From tjreedy at udel.edu Sat Aug 9 13:29:59 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 09 Aug 2014 13:29:59 -0400 Subject: The "right" way to use config files In-Reply-To: References: Message-ID: On 8/9/2014 7:48 AM, Fabien wrote: > BUT, my "problem" is that several options really are "universal" options > to the program, such as the output directory for example. This > information (where to write their results) is given to most of the > functions as parameter. If possible, functions should *return* their results, or yield their results in chunks (as generators). Let the driver function decide where to put results. Aside from separating concerns, this makes testing much easier. -- Terry Jan Reedy From tjreedy at udel.edu Sat Aug 9 13:43:33 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 09 Aug 2014 13:43:33 -0400 Subject: attendance system in pybluez In-Reply-To: References: <53E68C41.2010202@gmail.com> Message-ID: On 8/9/2014 12:26 PM, Dennis Lee Bieber wrote: > On Sat, 09 Aug 2014 14:01:53 -0700, luofeiyu > declaimed the following: > >> I want to write a program to help my teacher to take attendence. >> >> There are 300 students in a big room,everyone has android phone. >> I have matched them with my pc in win7 . >> when all of them seated on the classroom, >> > As soon as I learned someone was using bluetooth presence to determine > I was in such a class -- I'd turn the bluetooth feature off! And if attendance was part of your grade? Actually, I agree with you and Steven that the premise that all have an android phone, with battery charge, turned on, with bluetooth enabled, is a bit dubious. At the Univesity of Delaware, students buy a 'clicker', about $20, with an ID (I presume) and a few buttons for answering pop quizzes. I can only guess that they use bluetooth, but with extremely limited function and probably no writable memory, power draw is minimal and hijacking not an issue. -- Terry Jan Reedy From renatooliveira.cin at gmail.com Sat Aug 9 10:30:35 2014 From: renatooliveira.cin at gmail.com (Renato Oliveira) Date: Sat, 9 Aug 2014 11:30:35 -0300 Subject: Python Brasil [10] - Call for papers Message-ID: Hi all, You have until tomorrow to submit your talk to Python Brasil [10]. http://2014.pythonbrasil.org.br/dashboard/proposals/ The conference will be amazing! See why: Our Keynotes -> http://2014.pythonbrasil.org.br/speakers/ Our Venue -> http://2014.pythonbrasil.org.br/news/the-conference-venue/ And on November 9th were going to have some activities (TBA) like scuba diving, standup paddle and others! Thanks and see you in Porto de Galinhas! Renato Oliveira @_renatooliveira Labcodes - www.labcodes.com.br -------------- next part -------------- An HTML attachment was scrubbed... URL: From fabien.maussion at gmail.com Sat Aug 9 14:14:20 2014 From: fabien.maussion at gmail.com (Fabien) Date: Sat, 09 Aug 2014 20:14:20 +0200 Subject: The "right" way to use config files References: Message-ID: On 09.08.2014 19:29, Terry Reedy wrote: > If possible, functions should *return* their results, or yield their > results in chunks (as generators). Let the driver function decide where > to put results. Aside from separating concerns, this makes testing much > easier. I see. But then this is also true for parameters, right? And yet we return to my original question ;-) Let's say my configfile looks like this: ----------------- ### app/config.cfg # General params output_dir = '..' input_file = '..' # Func 1 params [func1] enable = True threshold = 0.1 maxite = 1 ----------------- And I have a myconfig module which looks like: ----------------- ### app/myconfig.py import ConfigObj parser = obj() # parser will be instanciated by initialize def initialize(cfgfile=None): global parser parser = ConfigObj(cfgfile, file_error=True) ----------------- My main program could look like this: ----------------- ### app/mainprogram_1.py import myconfig def func1(): # the params are in the cfg threshold = myconfig.parser['func1'].as_float('threshold') maxite = myconfig.parser['func1'].as_long('maxite') # dummy operations score = 100. ite = 1 while (score > threshold) and (ite < maxite): score /= 10 ite += 1 # dummy return return score def main(): myconfig.initialize(sys.argv[1]) if myconfig.parser['func1'].as_bool('enable'): results = func1() if __name__ == '__main__': main() ----------------- Or like this: ----------------- ### app/mainprogram_2.py import myconfig def func1(threshold=None, maxite=None): # dummy operations score = 100. ite = 1 while (score > threshold) and (ite < maxite): score /= 10 ite += 1 # dummy return return score def main(): myconfig.initialize(sys.argv[1]) if myconfig.parser['func1'].as_bool('enable'): # the params are in the cfg threshold = myconfig.parser['func1'].as_float('threshold') maxite = myconfig.parser['func1'].as_long('maxite') results = func1(threshold=threshold, maxite=maxite) if __name__ == '__main__': main() ----------------- In this case, program2 is easier to test/understand, but if the parameters become numerous it could be a pain... As always, I guess I'l have to decide on a case by case basis what is best. From rosuav at gmail.com Sat Aug 9 18:18:34 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 10 Aug 2014 08:18:34 +1000 Subject: attendance system in pybluez In-Reply-To: References: <53E68C41.2010202@gmail.com> Message-ID: On Sun, Aug 10, 2014 at 3:43 AM, Terry Reedy wrote: > And if attendance was part of your grade? > Then it'd be easy enough to prove that you were actually there, and therefore that the "find a Bluetooth device" method is flawed. ChrisA From davea at davea.name Sat Aug 9 18:23:08 2014 From: davea at davea.name (Dave Angel) Date: Sat, 9 Aug 2014 18:23:08 -0400 (EDT) Subject: how to write file into my android phone? References: <53E660BF.7080401@gmail.com> Message-ID: Chris ?Kwpolska? Warrick Wrote in message: > On Sat, Aug 9, 2014 at 7:56 PM, luofeiyu wrote: >> When i input usb line with my android phone into the pc , there are two >> disks j: and k: (type :removable disk) displayed in win7. >> >> i can get my android phone bluetooth mac address . >> >> import bluetooth >> nearby_devices = bluetooth.discover_devices(lookup_names = True) >> for addr, phoneName in nearby_devices: >> print(addr) >> >> >> it is 6C:8B:2F:CE:5B:59 >> >> Now how can i write a file into the disk j: of my android phone(bluetooth >> mac is 6C:8B:2F:CE:5B:59 )? >> >> -- >> https://mail.python.org/mailman/listinfo/python-list > > You mixed up two very different interfaces. Bluetooth and USB are > completely separate. If you want to write a file to the USB drive, > you can just open a file, using the regular open() function (specify a > path somewhere benath J:\): 1) it's not necessarily j: And not necessarily a single drive. 2) the phone isn't necessarily visible on a pc as a drive at all. For example the Samsung gs4. > -- DaveA From tjreedy at udel.edu Sat Aug 9 18:30:17 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 09 Aug 2014 18:30:17 -0400 Subject: The "right" way to use config files In-Reply-To: References: Message-ID: On 8/9/2014 2:14 PM, Fabien wrote: > On 09.08.2014 19:29, Terry Reedy wrote: >> If possible, functions should *return* their results, or yield their >> results in chunks (as generators). Let the driver function decide where >> to put results. Aside from separating concerns, this makes testing much >> easier. > > I see. But then this is also true for parameters, right? And yet we > return to my original question ;-) > > > Let's say my configfile looks like this: > > ----------------- > ### app/config.cfg > # General params > output_dir = '..' > input_file = '..' > > # Func 1 params > [func1] > enable = True > threshold = 0.1 > maxite = 1 > ----------------- > > And I have a myconfig module which looks like: > > ----------------- > ### app/myconfig.py > > import ConfigObj > > parser = obj() # parser will be instanciated by initialize Try parser = object() to actually run, but the line is not needed. Instead put "parser: instantiated by initialize" in the docstring. > > def initialize(cfgfile=None): > global parser > parser = ConfigObj(cfgfile, file_error=True) > ----------------- > > My main program could look like this: > > ----------------- > ### app/mainprogram_1.py > > import myconfig > > def func1(): > # the params are in the cfg > threshold = myconfig.parser['func1'].as_float('threshold') > maxite = myconfig.parser['func1'].as_long('maxite') > > # dummy operations > score = 100. > ite = 1 > while (score > threshold) and (ite < maxite): > score /= 10 > ite += 1 > > # dummy return > return score > > def main(): > myconfig.initialize(sys.argv[1]) > > if myconfig.parser['func1'].as_bool('enable'): > results = func1() > > if __name__ == '__main__': > main() > ----------------- The advantage of TDD is that it forces one to make code testable as you do. Old code may not be designed to be so easily testable, as I have learned trying to add tests to idlelib. For the above, I would consider def func1_algo(threshhold, maxite): # possible separte file score = 100. ite = 1 while (score > threshold) and (ite < maxite): score /= 10 ite += 1 return score def func1(): # interface wrapper threshold = myconfig.parser['func1'].as_float('threshold') maxite = myconfig.parser['func1'].as_long('maxite') return func1_algo(threshhold, maxite) This is a slight bit of extra work, but now you can separately test (and modify) the algorithm and the interfacing. Testing the algorithm is easy, which encourages testing multiple i/o pairs. for in, out in iopairs: assert func1_algo(in) == out # or self.assertEqual, or ... (or close enough for float outputs) As for the interfacing: you can write and read multiple versions of config.cfg (relatively slow), use something like unittest.mock to mock the myconfig module, or write something fairly simple (py3 code). class Entry(dict): def as_bool(self, name): s = self[name] return True if s == 'True' else False if s == 'False' else None def as_int(self, name): return int(self[name]) as_long = as_int def as_float(self, name): return float(self[name]) class Config(object): def initialize(self, argv): pass myconfig = Config() # a module is like a singleton class myconfig.initialize('a') # test that does not raise # In use for testing, uncomment the following two lines # import mainprogram_1.py as mp1 # mp1.myconfig = myconfig f1_cfg = Entry({ 'enable': 'True', 'threshold': '0.1', 'maxite': '1', }) myconfig.parser = {'func1': f1_cfg} print(myconfig.parser['func1'].as_float('threshold') == 0.1) print(myconfig.parser['func1'].as_long('maxite') == 1) print(myconfig.parser['func1'].as_bool('enable') == True) f1_cfg['maxite'] = 5 print(myconfig.parser['func1'].as_int('maxite') == 5) # prints True 4 times Notice that you inject the mock myconfig into the tested module just one. After that, you can change anything within parser or replace parser with a new dict. > Or like this: > > ----------------- > ### app/mainprogram_2.py > > import myconfig > > def func1(threshold=None, maxite=None): These should not have defaults; avoid extra work! > # dummy operations > score = 100. > ite = 1 > while (score > threshold) and (ite < maxite): > score /= 10 > ite += 1 > > # dummy return > return score > > def main(): > myconfig.initialize(sys.argv[1]) > > if myconfig.parser['func1'].as_bool('enable'): > # the params are in the cfg > threshold = myconfig.parser['func1'].as_float('threshold') > maxite = myconfig.parser['func1'].as_long('maxite') > results = func1(threshold=threshold, maxite=maxite) > > if __name__ == '__main__': > main() > ----------------- > > In this case, program2 is easier to test/understand, but if the > parameters become numerous it could be a pain... This is equivalent to what i wrote except for putting the wrapper inline in main(). Testing is the same for either. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Sat Aug 9 19:43:44 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 10 Aug 2014 09:43:44 +1000 Subject: how to get the ordinal number in list References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> Message-ID: <53e6b231$0$6599$c3e8da3$5496439d@news.astraweb.com> Roy Smith wrote: > But, putting on my instructor's hat, I think it's important to answer > questions at a level that can be understood by the student. Painting > with a broad brush, there's three or four kinds of people asking > questions on this list: [...] > I think suggesting comprehensions in an answer should be reserved for > people at levels 3 and 4. Maybe level 2-1/2. Certainly not level 1. Yes, this! Strongly agreed. -- Steven From mikemixonrei at gmail.com Sat Aug 9 21:27:15 2014 From: mikemixonrei at gmail.com (mikemixonrei at gmail.com) Date: Sat, 9 Aug 2014 18:27:15 -0700 (PDT) Subject: Ground Up Python/Xpath lessons Message-ID: I need a tutorial or lesson on Xpath syntax from the ground up. I am totally confused on how to assemble an Xpath. All the //a[wizardmojo]::stuffgoeshere is confusing as hell, and all the information I find, only tells you very basic examples, they don't really teach you assuming you know nothing. Thanks in advance, Mike From xuyuanchao37 at gmail.com Sat Aug 9 21:44:56 2014 From: xuyuanchao37 at gmail.com (Yuanchao Xu) Date: Sun, 10 Aug 2014 03:44:56 +0200 Subject: Fwd: How to draw a map using python In-Reply-To: References: Message-ID: To kind whom it may concern: I want to draw a map using python, not really a map with full information, just a get together of a series of small shapes to reflect land use. The data is like below 1 2 2 3 3 22 3 3 1 1 21 1 1 1 3 33 3 3 3 4 1 Each number represents one land use type. and their positions in the matrix are their coordinates. I used VBA to do that before, the whole map consists many small square shapes representing land use, but since the data was so large, it took a long time to generate the map, also delete the map. My question are : 1. I wonder in python, is there any more fast way to generate this kind of map, as a whole, not a series of shapes, i think that would be faster?? 2. I have tried using contourf, as below, but it says "out of bounds for axis 1", but actually, I printed X,Y and cordi, they have the same shape, why still out of bounds? 1. y = np.arange(0, 4 , 1) x = np.arange(0, 6 , 1) X,Y = np.meshgrid(x,y) # cordi is the matrix containing all the data# pyplot is imported before plt.contourf(X,Y, Cordi[X,Y], 8, alpha=.75, cmap='jet') 3. Some kind person has suggested me to use imshow to plot. I checked the explanation of imshow, it deals more about images not plots, and it needs a 3D array to plot, in which for each pixel it needs 3 values to show the color. I also tried, not so acceptable. The interfaces of each color are so vague, and besides, when the data is large, it just failed to present. So, if I use imshow, could I have some way to avoid those two problems? Thank you very much for answering! -------------- next part -------------- An HTML attachment was scrubbed... URL: From elearn2014 at gmail.com Sat Aug 9 21:41:44 2014 From: elearn2014 at gmail.com (luofeiyu) Date: Sat, 09 Aug 2014 18:41:44 -0700 Subject: how to get the subject of email? Message-ID: <53E6CDD8.50406@gmail.com> I am in python3.4 typ, data = x.con.fetch(b'1', '(RFC822)') #get the first email text = data[0][1] message = email.message_from_string(text).get('subject') Traceback (most recent call last): File "", line 1, in File "D:\Python34\lib\email\__init__.py", line 40, in message_from_string return Parser(*args, **kws).parsestr(s) File "D:\Python34\lib\email\parser.py", line 70, in parsestr return self.parse(StringIO(text), headersonly=headersonly) TypeError: initial_value must be str or None, not bytes message = email.message_from_string(str(text)).get('subject') message # nothing displayed From gordon at panix.com Sat Aug 9 21:55:24 2014 From: gordon at panix.com (John Gordon) Date: Sun, 10 Aug 2014 01:55:24 +0000 (UTC) Subject: Ground Up Python/Xpath lessons References: Message-ID: In mikemixonrei at gmail.com writes: > I need a tutorial or lesson on Xpath syntax from the ground up. I am > totally confused on how to assemble an Xpath. All the > //a[wizardmojo]::stuffgoeshere is confusing as hell, and all the > information I find, only tells you very basic examples, I'm confused -- don't you *want* very basic examples? > they don't really teach you assuming you know nothing. Try http://www.w3schools.com/xpath/xpath_intro.asp -- 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 gordon at panix.com Sat Aug 9 22:01:06 2014 From: gordon at panix.com (John Gordon) Date: Sun, 10 Aug 2014 02:01:06 +0000 (UTC) Subject: how to get the subject of email? References: Message-ID: In luofeiyu writes: > message = email.message_from_string(str(text)).get('subject') > message # nothing displayed Try using email.message_from_bytes() instead. Also have a look at http://stackoverflow.com/questions/19508393/python-email-parsing-issue for a question very similar to yours. Perhaps something in the code will help. -- 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 mikemixonrei at gmail.com Sat Aug 9 22:41:08 2014 From: mikemixonrei at gmail.com (mikemixonrei at gmail.com) Date: Sat, 9 Aug 2014 19:41:08 -0700 (PDT) Subject: Ground Up Python/Xpath lessons In-Reply-To: References: Message-ID: <53e5af68-7ff2-4712-b24a-a847b385a65b@googlegroups.com> On Saturday, August 9, 2014 8:27:15 PM UTC-5, mikemi... at gmail.com wrote: > I need a tutorial or lesson on Xpath syntax from the ground up. I am totally confused on how to assemble an Xpath. All the //a[wizardmojo]::stuffgoeshere is confusing as hell, and all the information I find, only tells you very basic examples, they don't really teach you assuming you know nothing. > > > > Thanks in advance, Mike Yes, those examples are good, for about 5 minutes, but then how I do learn to do the more advanced stuff? Like find all the "a" tags and then extract the "href" out of each one? Or look in each "tr" and extract all the "hrefs" in "td 1" when "td 4" contains the text "5 star rating" I haven't found anything that teaches you to string together complex xpaths, just simple ones like //form[1]/input From dieter at handshake.de Sun Aug 10 01:34:44 2014 From: dieter at handshake.de (dieter) Date: Sun, 10 Aug 2014 07:34:44 +0200 Subject: Ground Up Python/Xpath lessons References: Message-ID: <874mxkj4az.fsf@handshake.de> mikemixonrei at gmail.com writes: > I need a tutorial or lesson on Xpath syntax from the ground up. I am totally confused on how to assemble an Xpath. All the //a[wizardmojo]::stuffgoeshere is confusing as hell "XPath" is a public standard. You can find its specification at "http://www.w3.org/TR/xpath/". In my view, it is very well written; you find there all relevant details. Of course, it is not a tutorial: the information is very concise and assumes, that the reader copes well with abstract descriptions. From elearn2014 at gmail.com Sun Aug 10 01:37:22 2014 From: elearn2014 at gmail.com (luofeiyu) Date: Sat, 09 Aug 2014 22:37:22 -0700 Subject: how to get the subject of email? In-Reply-To: References: Message-ID: <53E70512.5020500@gmail.com> message = email.message_from_bytes(text) I get it , print(message['Subject']) #can get the subject But how can i get the body content of message? no , message['Body'] or message['Content'] On 8/9/2014 7:01 PM, John Gordon wrote: > In luofeiyu writes: > >> message = email.message_from_string(str(text)).get('subject') >> message # nothing displayed > Try using email.message_from_bytes() instead. > > Also have a look at > http://stackoverflow.com/questions/19508393/python-email-parsing-issue > for a question very similar to yours. Perhaps something in the code > will help. > From elearn2014 at gmail.com Sun Aug 10 01:52:01 2014 From: elearn2014 at gmail.com (luofeiyu) Date: Sat, 09 Aug 2014 22:52:01 -0700 Subject: how to get the subject of email? In-Reply-To: References: Message-ID: <53E70881.6020302@gmail.com> think you ,i get it . message = email.message_from_bytes(text) print(message['Subject']) #can get the subject But how can i get the body content of message? message['Body'] or message['Content'] can get none. On 8/9/2014 7:01 PM, John Gordon wrote: > In luofeiyu writes: > >> message = email.message_from_string(str(text)).get('subject') >> message # nothing displayed > Try using email.message_from_bytes() instead. > > Also have a look at > http://stackoverflow.com/questions/19508393/python-email-parsing-issue > for a question very similar to yours. Perhaps something in the code > will help. > From fabien.maussion at gmail.com Sun Aug 10 04:33:15 2014 From: fabien.maussion at gmail.com (Fabien) Date: Sun, 10 Aug 2014 10:33:15 +0200 Subject: The "right" way to use config files References: Message-ID: On 10.08.2014 00:30, Terry Reedy wrote: > The advantage of TDD is that it forces one to make code testable as you do. Thanks a lot, Terry, for your comprehensive example! From kwpolska at gmail.com Sun Aug 10 05:08:07 2014 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Sun, 10 Aug 2014 11:08:07 +0200 Subject: how to write file into my android phone? In-Reply-To: References: <53E660BF.7080401@gmail.com> Message-ID: On Sun, Aug 10, 2014 at 12:23 AM, Dave Angel wrote: > 1) it's not necessarily j: And not necessarily a single drive. The OP claims it is a J: drive they want to write to. > 2) the phone isn't necessarily visible on a pc as a drive at all. > For example the Samsung gs4. This is actually true for ALL android devices, starting with Android 3.0. It?s possible that the OP is running an ancient device, or a modern one that appears as a USB drive for some reason (eg. custom ROM from the manufacturer). -- Chris ?Kwpolska? Warrick PGP: 5EAAEA16 stop html mail | always bottom-post | only UTF-8 makes sense From ian.g.kelly at gmail.com Sun Aug 10 05:25:51 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 10 Aug 2014 03:25:51 -0600 Subject: How to draw a map using python In-Reply-To: References: Message-ID: On Sat, Aug 9, 2014 at 7:44 PM, Yuanchao Xu wrote: > 1. I wonder in python, is there any more fast way to generate this kind of > map, as a whole, not a series of shapes, i think that would be faster?? You mean like collecting all the shapes into a single sparse array and passing the single array to contourf? Why would that be faster? > 2. I have tried using contourf, as below, but it says "out of bounds for > axis 1", but actually, I printed X,Y and cordi, they have the same shape, > why still out of bounds? I don't know. If you're going to ask about an error, it would be helpful if you would include the full stack trace. > 3. Some kind person has suggested me to use imshow to plot. I checked the > explanation of imshow, it deals more about images not plots, and it needs a > 3D array to plot, in which for each pixel it needs 3 values to show the > color. I also tried, not so acceptable. According to the documentation, it will also accept an MxN array of greyscale or colormapped data. > The interfaces of each color are so > vague, and besides, when the data is large, it just failed to present. So, > if I use imshow, could I have some way to avoid those two problems? Failed how? As posed, this question is too vague to answer. From steve+comp.lang.python at pearwood.info Sun Aug 10 05:39:51 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 10 Aug 2014 19:39:51 +1000 Subject: how to write file into my android phone? References: <53E660BF.7080401@gmail.com> Message-ID: <53e73de8$0$24963$c3e8da3$5496439d@news.astraweb.com> Chris ?Kwpolska? Warrick wrote: > On Sun, Aug 10, 2014 at 12:23 AM, Dave Angel wrote: >> 1) it's not necessarily j: And not necessarily a single drive. > > The OP claims it is a J: drive they want to write to. > >> 2) the phone isn't necessarily visible on a pc as a drive at all. >> For example the Samsung gs4. > > This is actually true for ALL android devices, starting with Android 3.0. o_O Android phones don't mount as storage devices? Oh well, that's Android crossed off my list. -- Steven From auriocus at gmx.de Sun Aug 10 05:46:29 2014 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sun, 10 Aug 2014 11:46:29 +0200 Subject: how to write file into my android phone? In-Reply-To: <53e73de8$0$24963$c3e8da3$5496439d@news.astraweb.com> References: <53E660BF.7080401@gmail.com> <53e73de8$0$24963$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 10.08.14 11:39, schrieb Steven D'Aprano: > Android phones don't mount as storage devices? > > Oh well, that's Android crossed off my list. > Not any longer. They used to, but the support for mass storage was dropped in favour of MTP to allow concurrent access from both the computer and the phone. It is still possible to activate the mass storage driver in current Android using custom firmware. Christian From marko at pacujo.net Sun Aug 10 05:56:50 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 10 Aug 2014 12:56:50 +0300 Subject: how to write file into my android phone? References: <53E660BF.7080401@gmail.com> <53e73de8$0$24963$c3e8da3$5496439d@news.astraweb.com> Message-ID: <871tsohdlp.fsf@elektro.pacujo.net> Christian Gollwitzer : > Am 10.08.14 11:39, schrieb Steven D'Aprano: >> Android phones don't mount as storage devices? >> Oh well, that's Android crossed off my list. > > Not any longer. They used to, but the support for mass storage was > dropped in favour of MTP I don't see anything inherently wrong with an open protocol like MTP. > to allow concurrent access from both the computer and the phone. I don't know MTP at all, but MTP allows no parallelism; unlike USB mass storage, MTP has been built to only allow a single operation at a time (for example, read, write or delete operation), while no other operation can be executed until the previous operation is complete. Marko From breamoreboy at yahoo.co.uk Sun Aug 10 06:13:32 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 10 Aug 2014 11:13:32 +0100 Subject: Fwd: How to draw a map using python In-Reply-To: References: Message-ID: On 10/08/2014 02:44, Yuanchao Xu wrote: > To kind whom it may concern: > > I want to draw a map using python, not really a map with full > information, just a get together of a series of small shapes to reflect > land use. > > The data is like below > > > |1 2 2 3 3 2 > 2 3 3 1 1 2 > 1 1 1 1 3 3 > 3 3 3 3 4 1| > > Each number represents one land use type. and their positions in the > matrix are their coordinates. > > I used VBA to do that before, the whole map consists many small square > shapes representing land use, but since the data was so large, it took a > long time to generate the map, also delete the map. > > My question are : > > 1. I wonder in python, is there any more fast way to generate this kind > of map, as a whole, not a series of shapes, i think that would be faster?? > > 2. I have tried using contourf, as below, but it says "out of bounds for > axis 1", but actually, I printed X,Y and cordi, they have the same > shape, why still out of bounds? > > 1. > > > |y= np.arange(0, 4 , 1) > x= np.arange(0, 6 , 1) > X,Y= np.meshgrid(x,y) > > # cordi is the matrix containing all the data > # pyplot is imported before > > plt.contourf(X,Y, Cordi[X,Y], 8, alpha=.75, cmap='jet')| > > 3. Some kind person has suggested me to use imshow to plot. I checked > the explanation of imshow, it deals more about images not plots, and it > needs a 3D array to plot, in which for each pixel it needs 3 values to > show the color. I also tried, not so acceptable. The interfaces of each > color are so vague, and besides, when the data is large, it just failed > to present. So, if I use imshow, could I have some way to avoid those > two problems? > > > Thank you very much for answering! > See http://matplotlib.org/ specifically http://matplotlib.org/basemap/users/examples.html -- 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 Aug 10 06:28:06 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 10 Aug 2014 11:28:06 +0100 Subject: how to get the subject of email? In-Reply-To: <53E6CDD8.50406@gmail.com> References: <53E6CDD8.50406@gmail.com> Message-ID: On 10/08/2014 02:41, luofeiyu wrote: > I am in python3.4 > > typ, data = x.con.fetch(b'1', '(RFC822)') #get the first email > text = data[0][1] > message = email.message_from_string(text).get('subject') > > Traceback (most recent call last): > File "", line 1, in > File "D:\Python34\lib\email\__init__.py", line 40, in > message_from_string > return Parser(*args, **kws).parsestr(s) > File "D:\Python34\lib\email\parser.py", line 70, in parsestr > return self.parse(StringIO(text), headersonly=headersonly) > TypeError: initial_value must be str or None, not bytes > > message = email.message_from_string(str(text)).get('subject') > message # nothing displayed Could the answer to your numerous questions be in the docs, in this case https://docs.python.org/3/library/email.html ? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From elearn2014 at gmail.com Sun Aug 10 03:14:19 2014 From: elearn2014 at gmail.com (luofeiyu) Date: Sun, 10 Aug 2014 00:14:19 -0700 Subject: get the min date from a list Message-ID: <53E71BCB.7060307@gmail.com> >>> date ['Sat, 09 Aug 2014 07:36:46 -0700', 'Fri, 8 Aug 2014 22:25:40 -0400', 'Sat, 9 Au g 2014 12:46:43 +1000', 'Sat, 9 Aug 2014 12:50:52 +1000', 'Sat, 9 Aug 2014 02:51 :01 +0000 (UTC)', 'Sat, 9 Aug 2014 13:03:24 +1000', 'Sat, 09 Aug 2014 13:06:28 + 1000', 'Fri, 8 Aug 2014 20:48:44 -0700 (PDT)', 'Fri, 8 Aug 2014 23:52:09 -0700 ( PDT)', 'Sat, 09 Aug 2014 09:15:50 +0200', 'Sat, 9 Aug 2014 01:49:54 -0600', 'Sat , 9 Aug 2014 01:57:18 -0600', 'Sat, 9 Aug 2014 17:54:23 +0800 (CST)', 'Sat, 9 Au g 2014 12:49:08 +0200', 'Sat, 9 Aug 2014 07:31:09 -0400', 'Sat, 9 Aug 2014 07:34 :16 -0400', 'Sat, 09 Aug 2014 11:39:16 +0000', 'Sat, 9 Aug 2014 07:40:41 -0400', 'Sat, 9 Aug 2014 11:46:54 +0000', 'Sat, 09 Aug 2014 13:48:17 +0200', 'Sat, 09 A ug 2014 21:53:11 +1000', 'Sat, 09 Aug 2014 14:13:13 +0200', 'Sat, 09 Aug 2014 08 :16:08 -0400', 'Sat, 09 Aug 2014 22:17:25 +1000', 'Sat, 09 Aug 2014 14:33:54 +02 00', 'Sat, 9 Aug 2014 14:46:01 +0200', 'Sat, 09 Aug 2014 10:34:58 -0300', 'Sat, 09 Aug 2014 11:34:22 -0400', 'Sat, 09 Aug 2014 12:16:56 -0400', 'Sat, 09 Aug 201 4 12:26:38 -0400', 'Sat, 09 Aug 2014 13:29:59 -0400', 'Sat, 09 Aug 2014 13:43:33 -0400', 'Sat, 9 Aug 2014 11:30:35 -0300', 'Sat, 09 Aug 2014 20:14:20 +0200', 'S un, 10 Aug 2014 08:18:34 +1000', 'Sat, 9 Aug 2014 18:23:08 -0400 (EDT)', 'Sat, 0 9 Aug 2014 18:30:17 -0400', 'Sat, 09 Aug 2014 18:31:38 -0400', 'Sun, 10 Aug 2014 09:43:44 +1000', 'Sat, 9 Aug 2014 18:27:15 -0700 (PDT)', 'Sun, 10 Aug 2014 03:4 4:56 +0200', 'Sun, 10 Aug 2014 01:55:24 +0000 (UTC)', 'Sun, 10 Aug 2014 02:01:06 +0000 (UTC)', 'Sat, 9 Aug 2014 19:41:08 -0700 (PDT)', 'Sat, 9 Aug 2014 22:51:29 -0400 (EDT)', 'Sun, 10 Aug 2014 07:34:44 +0200', 'Tue, 5 Aug 2014 01:55:24 +000 0 (UTC)'] >>> min(date) 'Fri, 8 Aug 2014 20:48:44 -0700 (PDT)' The result is wrong,the min date should be 'Tue, 5 Aug 2014 01:55:24 +000 0 (UTC)' ,how can i get it ? From breamoreboy at yahoo.co.uk Sun Aug 10 06:42:53 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 10 Aug 2014 11:42:53 +0100 Subject: get the min date from a list In-Reply-To: <53E71BCB.7060307@gmail.com> References: <53E71BCB.7060307@gmail.com> Message-ID: On 10/08/2014 08:14, luofeiyu wrote: > >>> date > ['Sat, 09 Aug 2014 07:36:46 -0700', 'Fri, 8 Aug 2014 22:25:40 -0400', > 'Sat, 9 Au > g 2014 12:46:43 +1000', 'Sat, 9 Aug 2014 12:50:52 +1000', 'Sat, 9 Aug > 2014 02:51 > :01 +0000 (UTC)', 'Sat, 9 Aug 2014 13:03:24 +1000', 'Sat, 09 Aug 2014 > 13:06:28 + > 1000', 'Fri, 8 Aug 2014 20:48:44 -0700 (PDT)', 'Fri, 8 Aug 2014 23:52:09 > -0700 ( > PDT)', 'Sat, 09 Aug 2014 09:15:50 +0200', 'Sat, 9 Aug 2014 01:49:54 > -0600', 'Sat > , 9 Aug 2014 01:57:18 -0600', 'Sat, 9 Aug 2014 17:54:23 +0800 (CST)', > 'Sat, 9 Au > g 2014 12:49:08 +0200', 'Sat, 9 Aug 2014 07:31:09 -0400', 'Sat, 9 Aug > 2014 07:34 > :16 -0400', 'Sat, 09 Aug 2014 11:39:16 +0000', 'Sat, 9 Aug 2014 07:40:41 > -0400', > 'Sat, 9 Aug 2014 11:46:54 +0000', 'Sat, 09 Aug 2014 13:48:17 +0200', > 'Sat, 09 A > ug 2014 21:53:11 +1000', 'Sat, 09 Aug 2014 14:13:13 +0200', 'Sat, 09 Aug > 2014 08 > :16:08 -0400', 'Sat, 09 Aug 2014 22:17:25 +1000', 'Sat, 09 Aug 2014 > 14:33:54 +02 > 00', 'Sat, 9 Aug 2014 14:46:01 +0200', 'Sat, 09 Aug 2014 10:34:58 > -0300', 'Sat, > 09 Aug 2014 11:34:22 -0400', 'Sat, 09 Aug 2014 12:16:56 -0400', 'Sat, 09 > Aug 201 > 4 12:26:38 -0400', 'Sat, 09 Aug 2014 13:29:59 -0400', 'Sat, 09 Aug 2014 > 13:43:33 > -0400', 'Sat, 9 Aug 2014 11:30:35 -0300', 'Sat, 09 Aug 2014 20:14:20 > +0200', 'S > un, 10 Aug 2014 08:18:34 +1000', 'Sat, 9 Aug 2014 18:23:08 -0400 (EDT)', > 'Sat, 0 > 9 Aug 2014 18:30:17 -0400', 'Sat, 09 Aug 2014 18:31:38 -0400', 'Sun, 10 > Aug 2014 > 09:43:44 +1000', 'Sat, 9 Aug 2014 18:27:15 -0700 (PDT)', 'Sun, 10 Aug > 2014 03:4 > 4:56 +0200', 'Sun, 10 Aug 2014 01:55:24 +0000 (UTC)', 'Sun, 10 Aug 2014 > 02:01:06 > +0000 (UTC)', 'Sat, 9 Aug 2014 19:41:08 -0700 (PDT)', 'Sat, 9 Aug 2014 > 22:51:29 > -0400 (EDT)', 'Sun, 10 Aug 2014 07:34:44 +0200', 'Tue, 5 Aug 2014 > 01:55:24 +000 > 0 (UTC)'] > >>> min(date) > 'Fri, 8 Aug 2014 20:48:44 -0700 (PDT)' > > The result is wrong,the min date should be 'Tue, 5 Aug 2014 01:55:24 +000 > 0 (UTC)' ,how can i get it ? The result is probably correct (I haven't checked) as you're comparing strings. I'll leave you to read the docs to find out how to convert the strings to datetimes and compare them. Start here https://docs.python.org/3/ as that way you'll get used to finding your way around them. -- 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 Sun Aug 10 07:02:49 2014 From: davea at davea.name (Dave Angel) Date: Sun, 10 Aug 2014 07:02:49 -0400 (EDT) Subject: get the min date from a list References: <53E71BCB.7060307@gmail.com> Message-ID: luofeiyu Wrote in message: > >>> date > ['Sat, 09 Aug 2014 07:36:46 -0700', 'Fri, 8 Aug 2014 22:25:40 -0400', > 'Sat, 9 Au > g 2014 12:46:43 +1000', 'Sat, 9 Aug 2014 12:50:52 +1000', 'Sat, 9 Aug > ......... > 2014 03:4 > 4:56 +0200', 'Sun, 10 Aug 2014 01:55:24 +0000 (UTC)', 'Sun, 10 Aug 2014 > 02:01:06 > +0000 (UTC)', 'Sat, 9 Aug 2014 19:41:08 -0700 (PDT)', 'Sat, 9 Aug 2014 > 22:51:29 > -0400 (EDT)', 'Sun, 10 Aug 2014 07:34:44 +0200', 'Tue, 5 Aug 2014 > 01:55:24 +000 > 0 (UTC)'] > >>> min(date) > 'Fri, 8 Aug 2014 20:48:44 -0700 (PDT)' > > The result is wrong,the min date should be 'Tue, 5 Aug 2014 01:55:24 +000 > 0 (UTC)' ,how can i get it ? > You neglected to specify your Python version, but I'll assume at least 2.5. The min function did exactly as it's documented to do, found the minimum string, by alphabetical ordering. Since 'F' is less than 'T' it didn't need to look at the rest. If you had been sorting a list of datetime objects, it would have found the least of those. Your simplest answer is probably to write a function that converts a string like you have into a datetime object, say call it converter (). Then after testing it, you call min (dates, key = converter) Note I did NOT use parens on converter. I also used the name dates for the list, since it's a collection of dates. But that assumes you rename it in your code that gathered them. -- DaveA From jeanpierreda at gmail.com Sun Aug 10 08:43:04 2014 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sun, 10 Aug 2014 05:43:04 -0700 Subject: Template language for random string generation In-Reply-To: <14d94692-2257-4dfb-a82f-f1674a839233@googlegroups.com> References: <14d94692-2257-4dfb-a82f-f1674a839233@googlegroups.com> Message-ID: On Fri, Aug 8, 2014 at 2:01 AM, Paul Wolf wrote: > This is a proposal with a working implementation for a random string generation template syntax for Python. `strgen` is a module for generating random strings in Python using a regex-like template language. Example: > > >>> from strgen import StringGenerator as SG > >>> SG("[\l\d]{8:15}&[\d]&[\p]").render() > u'F0vghTjKalf4^mGLk' Why aren't you using regular expressions? I am all for conciseness, but using an existing format is so helpful... Unfortunately, the equivalent regexp probably looks like r'(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z])[a-zA-Z0-9]{8:15}' (I've been working on this kind of thing with regexps, but it's still incomplete.) > * Uses SystemRandom class (if available, or falls back to Random) This sounds cryptographically weak. Isn't the normal thing to do to use a cryptographic hash function to generate a pseudorandom sequence? Someone should write a cryptographically secure pseudorandom number generator library for Python. :( (I think OpenSSL comes with one, but then you can't choose the seed.) -- Devin From roy at panix.com Sun Aug 10 08:46:53 2014 From: roy at panix.com (Roy Smith) Date: Sun, 10 Aug 2014 08:46:53 -0400 Subject: get the min date from a list References: <53E71BCB.7060307@gmail.com> Message-ID: In article , Dave Angel wrote: > Your simplest answer is probably to write a function that converts > a string like you have into a datetime object, say call it > converter (). Then after testing it, you call > > min (dates, key = converter) Wow, after all these years, I didn't know min() took a key argument. Of course, it makes sense, but I just never noticed that before. Thanks! And for the OP, for the converter function, I would suggest dateutil.parse.parser(), from the python-dateutil module (https://labix.org/python-dateutil). From rustompmody at gmail.com Sun Aug 10 12:28:01 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 10 Aug 2014 09:28:01 -0700 (PDT) Subject: how to get the ordinal number in list In-Reply-To: References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> Message-ID: On Saturday, August 9, 2014 9:04:22 PM UTC+5:30, Roy Smith wrote: > Rustom Mody wrote: > > [To the OP] > > Yeah I am in the minority at least out here in considering > > comprehensions simpler than loops. Take your pick > When comprehensions first came out, I stubbornly refused to get my head > around them. Now, I'm totally addicted. To the extent that I consider > dict comprehensions to the THE killer feature of 2.7 :-) Yeah I remember seeing a stunning example from Peter Otten a few months(?) ago... first I heard of them. If someone can track that example down... I'll be mighty pleased. > But, putting on my instructor's hat, I think it's important to answer > questions at a level that can be understood by the student. Painting > with a broad brush, there's three or four kinds of people asking > questions on this list: > 1) People who are totally new to programming, and are learning Python as > their first language. These are the people who are still struggling to > understand fundamental concepts. They haven't figured out yet that the > first step to solving a problem is to decide what algorithms you're > going to use, and only then can you start translating that into code. > They need to be led in small steps towards basic knowledge. > 2) People who are (at least somewhat) experienced programmers, and are > learning Python as a second language. Their experiential background is > limited to one way of doing things (i.e. the Java way, or the PHP way, > or whatever language way they learned first). They mostly should be > shown how translate the things they already know into familiar feeling > constructs. You already know how to write a loop, this is how we do it > in Python. You already know how build a data structure that maps keys > to values, this is how we do it in Python. Only after they've become > comfortable with that, should they start exploring the really cool > features of Python. > 3) People who already know many languages, and are learning Python as > their n-th. These folks have seen multiple ways of doing things, and > can understand concepts at a higher level. Oh, Python dicts are more > like C++ STL maps than PHP arrays. Oh, variables have function scope > and don't have to be explicitly declared. Oh, RAII is spelled "with" in > this language. Oh, functions are first-class objects, but code blocks > are not. > 4) People who are already proficient Python programmers and are looking > to explore deeper topics. > I think suggesting comprehensions in an answer should be reserved for > people at levels 3 and 4. Maybe level 2-1/2. Certainly not level 1. All this... (and in particular) > They haven't figured out yet that the > first step to solving a problem is to decide what algorithms you're > going to use, and only then can you start translating that into code. > They need to be led in small steps towards basic knowledge. makes perfect sense... under one assumption: viz. The 'first steps' to becoming a programmer are necessarily imperative steps. So much so that programming is usually *defined* as imperative programming. This usually goes thus: - CS is defined as the science of algorithms (or algorithmics) - Programming (in the layman sense: python, java, C etc) is just about converting these 'abstract algorithms' into executable code - And an algorithm? An algorithm is an effective method expressed as a finite list[1] of well-defined instructions[2] for calculating a function. quoting http://en.wikipedia.org/wiki/Algorithm In my view this is starting from the wrong end. I do not need to know which kind of adder the hardware is implementing to use +, which sorting algorithm to use sort, etc. IOW the 'calculating a function' is primary and the 'effective steps' is secondary and traditional programming pedagogy gets this order wrong. What do I need to know to use sort? Nothing? Not so. I should be able to distinguish a sorted list from an unsorted one. This is primary. Getting from one to the other -- the how -- is secondary. [This also BTW implies that in the python world the 'sorted' function is more fundamental than the sort (mutating) method. And their names are pedagogically the wrong way round. Of course this is for historical reasons. But for now let us wear instructor not historian hats shall we?] As a more demonstrative example of the above (abstract) talk, in the 90s I used to teach a first course in programming using a predecessor of haskell (gofer -- gofer stands for GOod For Equational Reasoning). By the end of the course students could - handle data structures like generic n-ary trees, graphs etc - write toy interpreters, compilers, semantic functions - combinatorial enumerators corresponding to various types of combinatorial functions like ?Cr ?Pr Catalan numbers All WITHOUT a single assignment statement [very easy to accomplish since the language has no assignment statement :-) ] and more important (and germane to this thread) NO PRINT statement. I believe this is more important than the NO ASSIGNMENT. Assignments can become a religious issue one way or other. However if beginning students start off writing print statements too easily, it becomes very hard to progress from toy egs to more reusable, modular stuff. So yes I may have been a bit remiss in missing pedagogic steps in showing: >>> def index_all(lst, val): return (i for i,v in enumerate(lst) if v == val) Perhaps a right in between step would be a point in the spectrum between mine and Steven's > def index_all(source, target): > results = [] > for i, obj in enumerate(source): > if obj == target: > results.append(i) > return results viz. def index_all(source, target): for i, obj in enumerate(source): if obj == target: yield i And now someone is going to say: "yield (generators/iterators etc) are advanced whereas lists (append etc) are easier" and the argument loop starts over! So before that comes let me preempt by saying that when I write the python def index_all(lst, val): return (i for i,v in enumerate(lst) if v == val) I am using python as 'assembly language' (so to speak) and using a pidgin Haskell-ish math language to think with in which it would look something like {i | (i,v) ? zip.lst.[0...], v = val } IOW as long as we think (and teach) that a comprehension:* squares = [x**2 for x in range(10)] is equivalent to squares = [] for x in range(10): squares.append(x**2) the comprehensions will seem advanced but ultimately an engineering trick. Instead if we treated the python: [x**2 for x in range(10)] as an executable version for the standard set-theory expression: {x? | x ? [0..10) } then it would - not seem difficult/advanced etc - it would be seen/felt to be more fundamental and not just an engineering trick * I have to say that this example comes from the official tutorial itself... Unfortunate... From steve+comp.lang.python at pearwood.info Sun Aug 10 12:31:01 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 11 Aug 2014 02:31:01 +1000 Subject: Template language for random string generation References: <14d94692-2257-4dfb-a82f-f1674a839233@googlegroups.com> Message-ID: <53e79e46$0$29967$c3e8da3$5496439d@news.astraweb.com> Devin Jeanpierre wrote: > On Fri, Aug 8, 2014 at 2:01 AM, Paul Wolf wrote: >> This is a proposal with a working implementation for a random string >> generation template syntax for Python. `strgen` is a module for >> generating random strings in Python using a regex-like template language. >> Example: >> >> >>> from strgen import StringGenerator as SG >> >>> SG("[\l\d]{8:15}&[\d]&[\p]").render() >> u'F0vghTjKalf4^mGLk' > > Why aren't you using regular expressions? I am all for conciseness, > but using an existing format is so helpful... You've just answered your own question: > Unfortunately, the equivalent regexp probably looks like > r'(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z])[a-zA-Z0-9]{8:15}' Apart from being needlessly verbose, regex syntax is not appropriate because it specifies too much, specifies too little, and specifies the wrong things. It specifies too much: regexes like ^ and $ are meaningless in this case. It specifies too little: there's no regex for the "shuffle operator". And it specifies the wrong things: regexes like (?= ...) as used in your example are for matching, not generating strings, and it isn't clear what "match any character but don't consume any of the string" means when generating strings. Personally, I think even the OP's specified language is too complex. For example, it supports literal text, but given the use-case (password generators) do we really want to support templates like "password[\d]"? I don't think so, and if somebody did, they can trivially say "password" + SG('[\d]').render(). Larry Wall (the creator of Perl) has stated that one of the mistakes with Perl's regular expression mini-language is that the Huffman coding is wrong. Common things should be short, uncommon things can afford to be longer. Since the most common thing for password generation is to specify character classes, they should be short, e.g. d rather than [\d] (one character versus four). The template given could potentially be simplified to: "(LD){8:15}&D&P" where the round brackets () are purely used for grouping. Character codes are specified by a single letter. (I use uppercase to avoid the problem that l & 1 look very similar. YMMV.) The model here is custom format codes from spreadsheets, which should be comfortable to anyone who is familiar with Excel or OpenOffice. If you insist on having the facility to including literal text in your templates, might I suggest: "'password'd" # Literal string "password", followed by a single digit. but personally I believe that for the use-case given, that's a mistake. Alternatively, date/time templates use two-character codes like %Y %m etc, which is better than > (I've been working on this kind of thing with regexps, but it's still > incomplete.) > >> * Uses SystemRandom class (if available, or falls back to Random) > > This sounds cryptographically weak. Isn't the normal thing to do to > use a cryptographic hash function to generate a pseudorandom sequence? I don't think that using a good, but not cryptographically-strong, random number generator to generate passwords is a serious vulnerability. What's your threat model? Attacks on passwords tend to be one of a very few: - dictionary attacks (including tables of common passwords and simple transformations of words, e.g. 'pas5w0d'); - brute force against short and weak passwords; - attacking the hash function used to store passwords (not the password itself), e.g. rainbow tables; - keyloggers or some other way of stealing the password (including phishing sites and the ever-popular "beat them with a lead pipe until they give up the password"); - other social attacks, e.g. guessing that the person's password is their date of birth in reverse. But unless the random number generator is *ridiculously* weak ("9, 9, 9, 9, 9, 9, ...") I can't see any way to realistically attack the password generator based on the weakness of the random number generator. Perhaps I'm missing something? > Someone should write a cryptographically secure pseudorandom number > generator library for Python. :( Here, let me google that for you :-) https://duckduckgo.com/html/?q=python+crypto -- Steven From paulwolf333 at gmail.com Sun Aug 10 12:34:52 2014 From: paulwolf333 at gmail.com (Paul Wolf) Date: Sun, 10 Aug 2014 09:34:52 -0700 (PDT) Subject: Template language for random string generation In-Reply-To: References: <14d94692-2257-4dfb-a82f-f1674a839233@googlegroups.com> Message-ID: On Sunday, 10 August 2014 13:43:04 UTC+1, Devin Jeanpierre wrote: > On Fri, Aug 8, 2014 at 2:01 AM, Paul Wolf wrote: > > > This is a proposal with a working implementation for a random string generation template syntax for Python. `strgen` is a module for generating random strings in Python using a regex-like template language. Example: > > > > > > >>> from strgen import StringGenerator as SG > > > >>> SG("[\l\d]{8:15}&[\d]&[\p]").render() > > > u'F0vghTjKalf4^mGLk' > > > > Why aren't you using regular expressions? I am all for conciseness, > > but using an existing format is so helpful... > > > > Unfortunately, the equivalent regexp probably looks like > > r'(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z])[a-zA-Z0-9]{8:15}' > > > > (I've been working on this kind of thing with regexps, but it's still > > incomplete.) > > > > > * Uses SystemRandom class (if available, or falls back to Random) > > > > This sounds cryptographically weak. Isn't the normal thing to do to > > use a cryptographic hash function to generate a pseudorandom sequence? > > > > Someone should write a cryptographically secure pseudorandom number > > generator library for Python. :( > > > > (I think OpenSSL comes with one, but then you can't choose the seed.) > > > > -- Devin > Why aren't you using regular expressions? I guess you answered your own question with your example: * No one will want to write that expression * The regex expression doesn't work anyway * The purpose of regex is just too different from the purpose of strgen The purpose of strgen is to make life easier for developers and provide benefits that get pushed downstream (to users of the software that gets produced with it). Adopting a syntax similar to regex is only necessary or useful to the extent it achieves that. I should also clarify that when I say the strgen template language is the converse of regular expressions, this is the case conceptually, not formally. Matching text strings is fundamentally different from producing randomized strings. For instance, a template language that validates the output would have to do frequency analysis. But that is getting too far off the purpose of strgen, although such a mechanism would certainly have its place. > This sounds cryptographically weak. Whether using SystemRandom is cryptographically weak is not something I'm taking up here. Someone already suggested allowing the class to accept a different random source provider. That's an excellent idea. I wanted to make sure strgen does whatever they would do anyway hand-coding using the Python Standard Library except vastly more flexible, easier to edit and shorter. strgen is two things: a proposed standard way of expressing a string generation specification that relies heavily on randomness and a wrapper around the standard library. I specifically did not want to try to write better cryptographic routines. From ian.g.kelly at gmail.com Sun Aug 10 12:38:16 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 10 Aug 2014 10:38:16 -0600 Subject: Template language for random string generation In-Reply-To: References: <14d94692-2257-4dfb-a82f-f1674a839233@googlegroups.com> Message-ID: On Aug 10, 2014 6:45 AM, "Devin Jeanpierre" wrote: > > * Uses SystemRandom class (if available, or falls back to Random) > > This sounds cryptographically weak. Isn't the normal thing to do to > use a cryptographic hash function to generate a pseudorandom sequence? You mean in the fallback case, right? I'm no crypto expert, but I've never heard of SystemRandom being contra-recommended for crypto, and even the Python docs recommend it. The output of even a cryptographically strong hash isn't going to have any more entropy than the input, so if the input is predictable then the output will be also. One approach I'm aware of, which is used by Django, is to hash the RNG state along with the time and a local secret In order to reseed the RNG unpredictably whenever randomness is required. That creates a configuration burden in order to establish the secret, though. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Sun Aug 10 12:47:48 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 10 Aug 2014 10:47:48 -0600 Subject: Template language for random string generation In-Reply-To: References: <14d94692-2257-4dfb-a82f-f1674a839233@googlegroups.com> Message-ID: On Sun, Aug 10, 2014 at 10:34 AM, Paul Wolf wrote: > For instance, a template language that validates the output would have to do frequency analysis. But that is getting too far off the purpose of strgen, although such a mechanism would certainly have its place. I don't think that would be necessary. The question being asked with validation is "can this string be generated from this template", not "is this string generated from this template with relatively high probability". From anamaria at dcc.ufrj.br Sun Aug 10 09:03:42 2014 From: anamaria at dcc.ufrj.br (Anamaria Martins Moreira) Date: Sun, 10 Aug 2014 10:03:42 -0300 Subject: Idle crashes when using accentuated letters in Mac OS X Message-ID: Hi! I am facing a problem with using accentuated characters in idle (2.7.6 or 2.7.8). When I type the accent, idle crashes. If I call python from a terminal, there is no such problem. I looked around and saw that there are a number of issues with utf-8-python-mac, but I could not find the solution. The one indicated on the Python doc "You need to create a file ~ /.MacOSX/environment.plist. See Apple?s Technical Document QA1067 for details." seems not to be recommended by Apple anymore. Does any mac users have an idea for me, please? Thanks, Anamaria -------------- next part -------------- An HTML attachment was scrubbed... URL: From elearn2014 at gmail.com Sun Aug 10 09:44:12 2014 From: elearn2014 at gmail.com (luofeiyu) Date: Sun, 10 Aug 2014 06:44:12 -0700 Subject: why i can't copy mail with imaplib? Message-ID: <53E7772C.40606@gmail.com> Help on method copy in module imaplib: copy(message_set, new_mailbox) method of imaplib.IMAP4_SSL instance Copy 'message_set' messages onto end of 'new_mailbox'. (typ, [data]) = .copy(message_set, new_mailbox) self is an instance in my code."[Gmail]/&kc2JgQ-]" is the important mailbox. self.con.select("inbox") self.con.copy(b"1","[Gmail]/&kc2JgQ-]") why i can not copy the first email into my important mailbox? From roy at panix.com Sun Aug 10 13:10:21 2014 From: roy at panix.com (Roy Smith) Date: Sun, 10 Aug 2014 13:10:21 -0400 Subject: how to get the ordinal number in list References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> Message-ID: In article , Rustom Mody wrote: > > They haven't figured out yet that the > > first step to solving a problem is to decide what algorithms you're > > going to use, and only then can you start translating that into code. > > They need to be led in small steps towards basic knowledge. > [...] > In my view this is starting from the wrong end. > I do not need to know which kind of adder the hardware is implementing to > use +, which sorting algorithm to use sort, etc. Well, no, but if the problem is, "Find the 5 largest numbers in a list", you might start solving the problem by thinking, "OK, first I'm going to sort the list into descending order, then I'm going to take the first five items from that"(*) Only then would you get down to "OK, how do I sort a list of numbers in this language", and "OK, how do I select the first five items from a list in this language". That's what I mean by first you come up with an algorithm, then you implement it in code. (*) Yes, I know, that's not the optimum way, but it's a reasonable first attempt. From steve+comp.lang.python at pearwood.info Sun Aug 10 13:17:11 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 11 Aug 2014 03:17:11 +1000 Subject: how to get the ordinal number in list References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> Message-ID: <53e7a918$0$30002$c3e8da3$5496439d@news.astraweb.com> Rustom Mody wrote: > On Saturday, August 9, 2014 9:04:22 PM UTC+5:30, Roy Smith wrote: [...] >> They haven't figured out yet that the >> first step to solving a problem is to decide what algorithms you're >> going to use, and only then can you start translating that into code. >> They need to be led in small steps towards basic knowledge. > > makes perfect sense... under one assumption: viz. > The 'first steps' to becoming a programmer are necessarily imperative > steps. So much so that programming is usually *defined* as imperative > programming. This usually goes thus: "Necessarily"? Well, that's possibly a bit strong, but I think it is reasonable to say that the first steps to becoming a programmer are *preferably* imperative, because the real world is imperative. If you want to make a coffee, you: - get a cup - put instant coffee in the cup - put sugar in the cup - boil water - pour boiling water into the cup - stir - add milk not: - call an abstract make_coffee() function. > - CS is defined as the science of algorithms (or algorithmics) Yes, but algorithms can be either concrete ("put the kettle on the stove and light the gas"), intermediate ("bring the water to the boil at 100?C"), or fully abstract ("f(Temperature(water)) = lambda: 100?C", or something like that). So CS can and does envelop both imperative and functional programming. They just don't typically teach functional programming to beginners. > - Programming (in the layman sense: python, java, C etc) is just about > converting these 'abstract algorithms' into executable code > - And an algorithm? An algorithm is an effective method expressed as a > finite list[1] of well-defined instructions[2] for calculating a function. > quoting http://en.wikipedia.org/wiki/Algorithm > > In my view this is starting from the wrong end. > I do not need to know which kind of adder the hardware is implementing to > use +, which sorting algorithm to use sort, etc. Nobody says that you do. You're attacking a strawman. > IOW the 'calculating a function' is primary and the 'effective steps' > is secondary and traditional programming pedagogy gets this order wrong. "Calculating a function" is *incredibly* abstract, and quite hard to consider. If you think it isn't, then you're probably focused on a subset of problems that involve transformations which are trivially modelled by mathematical functions. > What do I need to know to use sort? Nothing? Not so. I should be able to > distinguish a sorted list from an unsorted one. This is primary. > Getting from one to the other -- the how -- is secondary. And how do you distinguish sorted list from an unsorted list, using functional styles? You're not allowed to just propose a magic "is_sorted()" function, any more than you're allowed to propose a magic "do whatever I want" function. (The whole point of CS is to learn how to program, not to just assume the program you want already exists.) Nor is it sufficient to define it this way: def is_sorted(alist): return alist == sorted(alist) since that assumes that sorted is correct. Consider this definition of sorted: def sorted(alist): return alist Now, the naturally intuitive way to determine whether something is sorted is imperative: you start at one end of the list and loop over pairs of items. If every item is >= to the previous item, the list is sorted. Now, of course we both know that we can turn that into a functional approach using reduce(), but if you can find one person in a hundred -- hell, even one person in a thousand -- who will intuitively come up with that approach in preference to the imperative style without being coached, I'll buy you a coffee or soft drink of your choice. Even Carl Gauss started off reasoning imperatively, and he was a natural mathematics genius. Learning programming is hard enough without trying to do it floating up in the stratosphere breathing vacuum. Abstractions are *hard*, and the functional approach is an abstraction. [...] > As a more demonstrative example of the above (abstract) talk, in the 90s > I used to teach a first course in programming using a predecessor of > haskell (gofer -- gofer stands for GOod For Equational Reasoning). Aimed at what age and experience of student? There's a big difference between aiming a course at mathematics post-grads, or at 12 year olds who are still a bit fuzzy about the whole "what's a function?" thing. What percentage of students passed? > By the end of the course students could > - handle data structures like generic n-ary trees, graphs etc > - write toy interpreters, compilers, semantic functions > - combinatorial enumerators corresponding to various types > of combinatorial functions like ?Cr ?Pr Catalan numbers > > All WITHOUT a single assignment statement > [very easy to accomplish since the language has no assignment statement > [:-) ] > > and more important (and germane to this thread) NO PRINT statement. Hmmm. With no print, how could they tell whether their program was correct? By writing to a file? But that's just a generalised print. Wait... I get it... you have a print, it's just a function, not a statement. Am I close? > Instead if we treated the python: > > [x**2 for x in range(10)] > > as an executable version for the standard set-theory expression: > > {x? | x ? [0..10) } Apart from a difference of notation, the way I learned list comprehensions was by learning the correspondence to "set builder notation", but then I have a maths degree and many years of practice at using that notation. The average beginner may never have seen set builder notation, or forgotten it if they have. -- Steven From rustompmody at gmail.com Sun Aug 10 13:34:24 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 10 Aug 2014 10:34:24 -0700 (PDT) Subject: how to get the ordinal number in list In-Reply-To: References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> Message-ID: <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> On Sunday, August 10, 2014 10:40:21 PM UTC+5:30, Roy Smith wrote: > Rustom Mody wrote: > > > They haven't figured out yet that the > > > first step to solving a problem is to decide what algorithms you're > > > going to use, and only then can you start translating that into code. > > > They need to be led in small steps towards basic knowledge. > > [...] > > In my view this is starting from the wrong end. > > I do not need to know which kind of adder the hardware is implementing to > > use +, which sorting algorithm to use sort, etc. > Well, no, but if the problem is, "Find the 5 largest numbers in a list", > you might start solving the problem by thinking, "OK, first I'm going to > sort the list into descending order, then I'm going to take the first > five items from that"(*) Only then would you get down to "OK, how do I > sort a list of numbers in this language", and "OK, how do I select the > first five items from a list in this language". That's what I mean by > first you come up with an algorithm, then you implement it in code. >>> l= [6,2,9,12,1,4] >>> sorted(l,reverse=True)[:5] [12, 9, 6, 4, 2] No need to know how sorted works nor [:5] Now you (or Steven) can call it abstract. And yet its 1. Actual running code in the interpreter 2. Its as close as one can get to a literal translation of your "Find the 5 largest numbers in a list" Yeah the reverse=True is a fly in the ointment. I can do >>> sorted(l)[-5:] [2, 4, 6, 9, 12] But that's a bit arcane In any case coming back to the point All the above are clearer than loops+assignments and can be taught before them From rustompmody at gmail.com Sun Aug 10 13:45:03 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 10 Aug 2014 10:45:03 -0700 (PDT) Subject: how to get the ordinal number in list In-Reply-To: References: Message-ID: <2a9467ba-44e1-47b0-8adc-a0a3833bb209@googlegroups.com> On Saturday, August 9, 2014 7:53:22 AM UTC+5:30, luofeiyu wrote: > >>> x=["x1","x3","x7","x5"] > >>> y="x3" > how can i get the ordinal number by some codes? > for id ,value in enumerate(x): > if y==value : print(id) > Is more simple way to do that? I feel a bit discourteous going on a tangent and ignoring the OP... To the OP: The problem with your code is not that its not simple but that it uses a print statement To expunge the print statement you must pay a small price: Wrap it in a function: def search(x,y): for id ,value in enumerate(x): if y==value : print(id) >>> search(["x1","x2","x3"], "x2") 1 >>> # Change print to return >>> def search(x,y): ... for id ,value in enumerate(x): ... if y==value : return id ... >>> search(["x1","x2","x3"], "x2") 1 >>> # Works the same (SEEMINGLY) ... # Now change the return to an yield ... >>> def search(x,y): ... for id ,value in enumerate(x): ... if y==value : yield id ... >>> search(["x1","x2","x3", "x2", "x5", "x2"], "x2") >>> # Hmm wazzat?! ... list(search(["x1","x2","x3", "x2", "x5", "x2"], "x2")) [1, 3, 5] From rustompmody at gmail.com Sun Aug 10 14:00:33 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 10 Aug 2014 11:00:33 -0700 (PDT) Subject: how to get the ordinal number in list In-Reply-To: <2a9467ba-44e1-47b0-8adc-a0a3833bb209@googlegroups.com> References: <2a9467ba-44e1-47b0-8adc-a0a3833bb209@googlegroups.com> Message-ID: Pressed Send to early. On Sunday, August 10, 2014 11:15:03 PM UTC+5:30, Rustom Mody wrote: > >>> # Works the same (SEEMINGLY) > ... # Now change the return to an yield > ... > >>> def search(x,y): > ... for id ,value in enumerate(x): > ... if y==value : yield id > ... > >>> search(["x1","x2","x3", "x2", "x5", "x2"], "x2") > >>> # Hmm wazzat?! > ... list(search(["x1","x2","x3", "x2", "x5", "x2"], "x2")) > [1, 3, 5] Now you can of course use that to print if you choose >>> for x in search(["x1","x2","x3"], "x2"): ... print x 1 But you can also put some other possibly more complex and useful action there in place of the print if you choose. With the print version that's not an option. From roy at panix.com Sun Aug 10 14:14:23 2014 From: roy at panix.com (Roy Smith) Date: Sun, 10 Aug 2014 14:14:23 -0400 Subject: how to get the ordinal number in list References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> Message-ID: In article <154cc342-7f85-4d16-b636-a1a953913c98 at googlegroups.com>, Rustom Mody wrote: > >>> l= [6,2,9,12,1,4] > >>> sorted(l,reverse=True)[:5] > [12, 9, 6, 4, 2] > > No need to know how sorted works nor [:5] > > Now you (or Steven) can call it abstract. > > And yet its > 1. Actual running code in the interpreter > 2. Its as close as one can get to a literal translation of your > "Find the 5 largest numbers in a list" > [...] > All the above are clearer than loops+assignments and can be > taught before them I disagree. For a beginner, you want to be able to break things down into individual steps and examine the result at each point. If you do: > >>> l= [6,2,9,12,1,4] > >>> l2 = sorted(l,reverse=True) > >>> l2[:5] you have the advantage that you can stop after creating l2 and print it out. The student can see that it has indeed been sorted. With the chained operations, you have to build a mental image of an anonymous, temporary list, and then perform the slicing operation on that. Sure, it's the way you or I would write it in production code, but for a beginner, breaking it down into smaller pieces makes it easier to understand. From rustompmody at gmail.com Sun Aug 10 14:26:10 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 10 Aug 2014 11:26:10 -0700 (PDT) Subject: how to get the ordinal number in list In-Reply-To: References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> Message-ID: <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> On Sunday, August 10, 2014 11:44:23 PM UTC+5:30, Roy Smith wrote: > Rustom Mody wrote: > > >>> l= [6,2,9,12,1,4] > > >>> sorted(l,reverse=True)[:5] > > [12, 9, 6, 4, 2] > > No need to know how sorted works nor [:5] > > Now you (or Steven) can call it abstract. > > And yet its > > 1. Actual running code in the interpreter > > 2. Its as close as one can get to a literal translation of your > > "Find the 5 largest numbers in a list" > > [...] > > All the above are clearer than loops+assignments and can be > > taught before them > I disagree. For a beginner, you want to be able to break things down > into individual steps and examine the result at each point. If you do: > > >>> l= [6,2,9,12,1,4] > > >>> l2 = sorted(l,reverse=True) > > >>> l2[:5] > you have the advantage that you can stop after creating l2 and print it > out. The student can see that it has indeed been sorted. With the > chained operations, you have to build a mental image of an anonymous, > temporary list, and then perform the slicing operation on that. Sure, > it's the way you or I would write it in production code, but for a > beginner, breaking it down into smaller pieces makes it easier to > understand. Yeah Whats the disagreement?? You are writing straight-line code. I am recommending straight-line code -- another way of saying loops are bad. Or is it because you are using assignment? I call that 'nominal' assignment. Technically its called 'single-assignment' www.cs.princeton.edu/~appel/papers/ssafun.ps Its when we have variables that are assigned in multiple places that we start seeing mathematical abominations like x = x+1 From jeanpierreda at gmail.com Sun Aug 10 14:48:42 2014 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sun, 10 Aug 2014 11:48:42 -0700 Subject: Template language for random string generation In-Reply-To: References: <14d94692-2257-4dfb-a82f-f1674a839233@googlegroups.com> Message-ID: On Sun, Aug 10, 2014 at 9:34 AM, Paul Wolf wrote: > * No one will want to write that expression We've already established that one to be wrong. ;) > * The regex expression doesn't work anyway That's a cheap swipe. The regexp doesn't work because I used a colon instead of a comma, because I accidentally copied you. :( Speaking of which, is there a reason you've diverged from regex syntax in x{8: 15} vs x{8,15}? Don't mind my suggestion to use existing formats even when it's inconvenient. It's a knee jerk reaction/question, not a serious complaint. > I should also clarify that when I say the strgen template language is the converse of regular expressions, this is the case conceptually, not formally. Matching text strings is fundamentally different from producing randomized strings. Mmmm, I wouldn't be so quick to dismiss any insights from regexps here. It depends on your fundamentals. For example, automata-theoretic approaches do apply, and can let you guarantee that equivalent templates always generate the same outputs given the same inputs. (Meaning that the only thing that matters is what the template matches, not how it's spelled.) > Whether using SystemRandom is cryptographically weak is not something I'm taking up here. Someone already suggested allowing the class to accept a different random source provider. That's an excellent idea. I wanted to make sure strgen does whatever they would do anyway hand-coding using the Python Standard Library except vastly more flexible, easier to edit and shorter. strgen is two things: a proposed standard way of expressing a string generation specification that relies heavily on randomness and a wrapper around the standard library. I specifically did not want to try to write better cryptographic routines. The fallback is what worries me. Falling back from a secure thing to an insecure thing doesn't sound good. -- Devin From jeanpierreda at gmail.com Sun Aug 10 14:28:39 2014 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sun, 10 Aug 2014 11:28:39 -0700 Subject: Template language for random string generation In-Reply-To: <53e79e46$0$29967$c3e8da3$5496439d@news.astraweb.com> References: <14d94692-2257-4dfb-a82f-f1674a839233@googlegroups.com> <53e79e46$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Aug 10, 2014 at 9:31 AM, Steven D'Aprano wrote: >> (I've been working on this kind of thing with regexps, but it's still >> incomplete.) >> >>> * Uses SystemRandom class (if available, or falls back to Random) >> >> This sounds cryptographically weak. Isn't the normal thing to do to >> use a cryptographic hash function to generate a pseudorandom sequence? > > I don't think that using a good, but not cryptographically-strong, random > number generator to generate passwords is a serious vulnerability. What's > your threat model? I've always wanted a password generator that worked on the fly based off of a master password. If the passwords are generated randomly but not cryptographically securely so, then given sufficiently many passwords, the master password might be deduced. CSPRNGs guarantee otherwise. >> Someone should write a cryptographically secure pseudorandom number >> generator library for Python. :( > > Here, let me google that for you I should clarify that OpenSSL has one (which is what I assume you're alluding to), but it doesn't let you choose the seed, so it's useless for deterministic password generation. There are also lots of small libraries some person wrote at some time, but that sounds shady. ;) -- Devin From rosuav at gmail.com Sun Aug 10 15:03:59 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Aug 2014 05:03:59 +1000 Subject: how to get the ordinal number in list In-Reply-To: <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> Message-ID: On Mon, Aug 11, 2014 at 4:26 AM, Rustom Mody wrote: > > Its when we have variables that are assigned in multiple places that > we start seeing mathematical abominations like > x = x+1 That's an abomination to you because it breaks your mathematical model. It's fine to a computer, which has a sense of time. And it even can be strictly true. Consider: >>> x = 2.0**53 >>> x = x + 1 >>> x == x + 1 True x is clearly not infinity, yet it's equal to itself plus one. If you're going to try to pretend that maths and computers are exactly the same, you have a LOT of problems to deal with. In computing, assignment and reassignment aren't at all problematic, and neither is printing to the console, so please stop telling people off for using them. ChrisA From marko at pacujo.net Sun Aug 10 15:14:16 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 10 Aug 2014 22:14:16 +0300 Subject: how to get the ordinal number in list References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> Message-ID: <87tx5kf987.fsf@elektro.pacujo.net> Chris Angelico : > In computing, assignment and reassignment aren't at all problematic, > and neither is printing to the console, so please stop telling people > off for using them. Printing to the console is somewhat problematic: >>> with open("/dev/console", "w") as console: console.write("hello\n") ... Traceback (most recent call last): File "", line 1, in IOError: [Errno 13] Permission denied: '/dev/console' Marko From rosuav at gmail.com Sun Aug 10 15:20:45 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Aug 2014 05:20:45 +1000 Subject: how to get the ordinal number in list In-Reply-To: <87tx5kf987.fsf@elektro.pacujo.net> References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> <87tx5kf987.fsf@elektro.pacujo.net> Message-ID: On Mon, Aug 11, 2014 at 5:14 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> In computing, assignment and reassignment aren't at all problematic, >> and neither is printing to the console, so please stop telling people >> off for using them. > > Printing to the console is somewhat problematic: > > >>> with open("/dev/console", "w") as console: console.write("hello\n") > ... > Traceback (most recent call last): > File "", line 1, in > IOError: [Errno 13] Permission denied: '/dev/console' Har har :) I meant printing to the single most obvious destination, which is a combination of stdout and stderr (the latter for error tracebacks, by default). What he's saying is basically "print is EVIL, so do everything with the REPL, and pretend that the P in REPL doesn't stand for print". Apparently the idea that code should work from a .py file is foreign to him. ChrisA From rosuav at gmail.com Sun Aug 10 15:25:56 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Aug 2014 05:25:56 +1000 Subject: Template language for random string generation In-Reply-To: <53e79e46$0$29967$c3e8da3$5496439d@news.astraweb.com> References: <14d94692-2257-4dfb-a82f-f1674a839233@googlegroups.com> <53e79e46$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Aug 11, 2014 at 2:31 AM, Steven D'Aprano wrote: > Personally, I think even the OP's specified language is too complex. For > example, it supports literal text, but given the use-case (password > generators) do we really want to support templates like "password[\d]"? I > don't think so, and if somebody did, they can trivially say "password" + > SG('[\d]').render(). What if you're using this to generate IDs for something (think Youtube video references), and you want to have an alphabetic portion and a numeric portion separated by a hyphen? I think there is a use-case for interior literal text, because otherwise you'd have to either split the result or do two calls to the generator. > Here, let me google that for you :-) > > https://duckduckgo.com/html/?q=python+crypto Hehe. :) ChrisA From breamoreboy at yahoo.co.uk Sun Aug 10 16:32:14 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 10 Aug 2014 21:32:14 +0100 Subject: how to get the ordinal number in list In-Reply-To: <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> Message-ID: On 10/08/2014 19:26, Rustom Mody wrote: > > Its when we have variables that are assigned in multiple places that > we start seeing mathematical abominations like > x = x+1 > I'm not bothered about it being a mathematical or any other type of abomination. It works, practically beats purity, so if it ain't broke, please don't fix it, for some definition of fix. -- 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 Sun Aug 10 17:06:39 2014 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sun, 10 Aug 2014 23:06:39 +0200 Subject: Idle crashes when using accentuated letters in Mac OS X In-Reply-To: References: Message-ID: Am 10.08.14 15:03, schrieb Anamaria Martins Moreira > I am facing a problem with using accentuated characters in idle (2.7.6 > or 2.7.8). When I type the accent, idle crashes. If I call python from a > terminal, there is no such problem. Try updating your Tcl/Tk to the latest version, e.g. via ActiveTcl. I remember such a bug in the OSX version, which was fixed a long time ago. There is a number of bugs in the OSX Tk, a lot of them was recently fixed, so stay tuned and maybe update when 8.6.2 becomes available. Christian From roy at panix.com Sun Aug 10 18:01:08 2014 From: roy at panix.com (Roy Smith) Date: Sun, 10 Aug 2014 18:01:08 -0400 Subject: how to get the ordinal number in list References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> Message-ID: In article , Mark Lawrence wrote: > On 10/08/2014 19:26, Rustom Mody wrote: > > > > Its when we have variables that are assigned in multiple places that > > we start seeing mathematical abominations like > > x = x+1 > > > > I'm not bothered about it being a mathematical or any other type of > abomination. It works, practically beats purity, so if it ain't broke, > please don't fix it, for some definition of fix. I'm with Mark. This isn't math, it's programming. Sure, the intersection of the two is non-null, but they are different things. I'll often do things like: for line in input: line = line.strip() # do more stuff Sure, I could invent some other variable name to avoid re-using the same name, but does: for line in input: stripped_line = line.strip() # do more stuff really make this any easier to read or understand? I think not. From nad at acm.org Sun Aug 10 18:08:07 2014 From: nad at acm.org (Ned Deily) Date: Sun, 10 Aug 2014 15:08:07 -0700 Subject: Idle crashes when using accentuated letters in Mac OS X References: Message-ID: In article , Christian Gollwitzer wrote: > Am 10.08.14 15:03, schrieb Anamaria Martins Moreira > > I am facing a problem with using accentuated characters in idle (2.7.6 > > or 2.7.8). When I type the accent, idle crashes. If I call python from a > > terminal, there is no such problem. > > Try updating your Tcl/Tk to the latest version, e.g. via ActiveTcl. I > remember such a bug in the OSX version, which was fixed a long time ago. > There is a number of bugs in the OSX Tk, a lot of them was recently > fixed, so stay tuned and maybe update when 8.6.2 becomes available. You also need to be using a Python instance that will use the newer ActiveTcl. The crash is due to a bug in older versions of OS X Cocoa Tk; unfortunately, the versions of Tk 8.5 shipped by Apple with OS X from OS X 10.6 through at least current 10.9.x still have this bug. One way to avoid it is to use either one of the current python.org installers (Python 2.7.8 or 3.4.1) and the current ActiveTcl 8.5.15.0 from ActiveState (using 8.6.x will not help). There is more information here: https://www.python.org/download/mac/tcltk/ -- Ned Deily, nad at acm.org From rosuav at gmail.com Sun Aug 10 18:43:24 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Aug 2014 08:43:24 +1000 Subject: how to get the ordinal number in list In-Reply-To: References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> Message-ID: On Mon, Aug 11, 2014 at 8:01 AM, Roy Smith wrote: > I'm with Mark. This isn't math, it's programming. Sure, the > intersection of the two is non-null, but they are different things. > I'll often do things like: > > for line in input: > line = line.strip() > # do more stuff What does mathematics even have as a concept of looping? String manipulation? Input and output? ChrisA From gordon at panix.com Sun Aug 10 19:07:42 2014 From: gordon at panix.com (John Gordon) Date: Sun, 10 Aug 2014 23:07:42 +0000 (UTC) Subject: why i can't copy mail with imaplib? References: Message-ID: In luofeiyu writes: > self.con.select("inbox") > self.con.copy(b"1","[Gmail]/&kc2JgQ-]") > why i can not copy the first email into my important mailbox? What happens when you run the above code? Do you get an error? -- 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 elearn2014 at gmail.com Sun Aug 10 19:27:54 2014 From: elearn2014 at gmail.com (luofeiyu) Date: Sun, 10 Aug 2014 16:27:54 -0700 Subject: why i can't copy mail with imaplib? In-Reply-To: References: Message-ID: <53E7FFFA.2050902@gmail.com> >>> x.con.list() ('OK', [b'(\\HasNoChildren) "/" "INBOX"', b'(\\Noselect \\HasChildren) "/" "[Gma il]"', b'(\\HasNoChildren \\Junk) "/" "[Gmail]/&V4NXPpCuTvY-"', b'(\\HasNoChildr en \\Trash) "/" "[Gmail]/&XfJSIJZkkK5O9g-"', b'(\\HasNoChildren \\Flagged) "/" " [Gmail]/&XfJSoGYfaAc-"', b'(\\HasNoChildren \\Sent) "/" "[Gmail]/&XfJT0ZCuTvY-"' , b'(\\HasNoChildren \\All) "/" "[Gmail]/&YkBnCZCuTvY-"', b'(\\HasNoChildren \\D rafts) "/" "[Gmail]/&g0l6Pw-"', b'(\\HasNoChildren \\Important) "/" "[Gmail]/&kc 2JgQ-"']) >>> x.con.select("inbox") ('OK', [b'40']) >>> x.con.copy(b"1","[Gmail]/&kc2JgQ-]") ('NO', [b'[TRYCREATE] No folder [Gmail]/\xe9\x87\x8d\xe8\xa6\x81] (Failure)']) >>> x.con.copy(b"1","[Gmail]/Important") ('NO', [b'[TRYCREATE] No folder [Gmail]/Important (Failure)']) On 8/10/2014 4:07 PM, John Gordon wrote: > In luofeiyu writes: > >> self.con.select("inbox") >> self.con.copy(b"1","[Gmail]/&kc2JgQ-]") >> why i can not copy the first email into my important mailbox? > What happens when you run the above code? Do you get an error? > From ben+python at benfinney.id.au Sun Aug 10 19:32:56 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 11 Aug 2014 09:32:56 +1000 Subject: why i can't copy mail with imaplib? References: <53E7FFFA.2050902@gmail.com> Message-ID: <85r40n9azb.fsf@benfinney.id.au> luofeiyu writes: > >>> x.con.copy(b"1","[Gmail]/Important") > ('NO', [b'[TRYCREATE] No folder [Gmail]/Important (Failure)']) Your questions have mostly been unrelated to Python, and this is another example. You should search elsewhere for assistance with IMAP and GMail. -- \ ?The restriction of knowledge to an elite group destroys the | `\ spirit of society and leads to its intellectual | _o__) impoverishment.? ?Albert Einstein | Ben Finney From stuffstorehouse2014 at gmail.com Sun Aug 10 19:56:08 2014 From: stuffstorehouse2014 at gmail.com (ismeal shanshi) Date: Sun, 10 Aug 2014 16:56:08 -0700 (PDT) Subject: how to get the ordinal number in list In-Reply-To: References: Message-ID: Herion, Ketamine,Actavis promethazine codeine 16oz and 32oz available , Oxycontine Hydrocodone xanax and medicated marijuana US- free shipping and other related products for sell at competitive prices.We do world wide shipping to any clear address.Delivery is 100% safe due to our discreetness and experience.Try our quality and experience then have a story to tell another day. Email Address:stuffstorehouse2014 (AT) gmail.com CONTACT NUMBER: (407)-4852249 ***** Pleas text me only From steve+comp.lang.python at pearwood.info Sun Aug 10 22:04:40 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 11 Aug 2014 12:04:40 +1000 Subject: how to get the ordinal number in list References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> Message-ID: <53e824b9$0$30000$c3e8da3$5496439d@news.astraweb.com> Rustom Mody wrote: > Its when we have variables that are assigned in multiple places that > we start seeing mathematical abominations like > x = x+1 That's not a mathematical abomination. It's a perfectly reasonable mathematical equation, one with no solutions since the line f(x) = x and the line f(x) = x+1 are parallel. But what does this have to do with programming? Programming *is not* mathematics, and x = x+1 has a different meaning in programming than in mathematics. Perhaps it would help if we wrote it using mathematical notation? Using [x] for subscripts: x[n+1] = x[n] + 1 we have a perfectly good mathematical recursive definition. All it needs is an initial value x[0] and we're good to go. -- Steven From steve+comp.lang.python at pearwood.info Sun Aug 10 22:22:33 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 11 Aug 2014 12:22:33 +1000 Subject: Template language for random string generation References: <14d94692-2257-4dfb-a82f-f1674a839233@googlegroups.com> <53e79e46$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53e828e9$0$29966$c3e8da3$5496439d@news.astraweb.com> Devin Jeanpierre wrote: > On Sun, Aug 10, 2014 at 9:31 AM, Steven D'Aprano > wrote: >> I don't think that using a good, but not cryptographically-strong, random >> number generator to generate passwords is a serious vulnerability. What's >> your threat model? > > I've always wanted a password generator that worked on the fly based > off of a master password. If the passwords are generated randomly but > not cryptographically securely so, then given sufficiently many > passwords, the master password might be deduced. o_O So, what you're saying is that you're concerned that if an attacker has all your passwords, they might be able to generate new passwords? [...] >>> Someone should write a cryptographically secure pseudorandom number >>> generator library for Python. :( >> >> Here, let me google that for you > > I should clarify that OpenSSL has one (which is what I assume you're > alluding to), No. If you follow the link I provided, I'm sure you will find what you are after. > but it doesn't let you choose the seed, so it's useless > for deterministic password generation. There are also lots of small > libraries some person wrote at some time, but that sounds shady. ;) You mean the opposite to OpenSSL, which was handed down to Mankind from the Gods? The size of the library doesn't matter, what matters is how well it implements what crypto standards. -- Steven From rosuav at gmail.com Sun Aug 10 22:31:05 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Aug 2014 12:31:05 +1000 Subject: Template language for random string generation In-Reply-To: <53e828e9$0$29966$c3e8da3$5496439d@news.astraweb.com> References: <14d94692-2257-4dfb-a82f-f1674a839233@googlegroups.com> <53e79e46$0$29967$c3e8da3$5496439d@news.astraweb.com> <53e828e9$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Aug 11, 2014 at 12:22 PM, Steven D'Aprano wrote: > You mean the opposite to OpenSSL, which was handed down to Mankind from > the Gods? I thought Prometheus stole OpenSSL and gave it to mankind so a group of Minotaurs would stop teasing him about Heartbleed. ChrisA From steve+comp.lang.python at pearwood.info Sun Aug 10 23:00:32 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 11 Aug 2014 13:00:32 +1000 Subject: how to get the ordinal number in list References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> Message-ID: <53e831d1$0$30002$c3e8da3$5496439d@news.astraweb.com> Rustom Mody wrote: > On Sunday, August 10, 2014 10:40:21 PM UTC+5:30, Roy Smith wrote: >> Rustom Mody wrote: > >> > > They haven't figured out yet that the >> > > first step to solving a problem is to decide what algorithms you're >> > > going to use, and only then can you start translating that into code. >> > > They need to be led in small steps towards basic knowledge. >> > [...] >> > In my view this is starting from the wrong end. >> > I do not need to know which kind of adder the hardware is implementing >> > to use +, which sorting algorithm to use sort, etc. > >> Well, no, but if the problem is, "Find the 5 largest numbers in a list", >> you might start solving the problem by thinking, "OK, first I'm going to >> sort the list into descending order, then I'm going to take the first >> five items from that"(*) Only then would you get down to "OK, how do I >> sort a list of numbers in this language", and "OK, how do I select the >> first five items from a list in this language". That's what I mean by >> first you come up with an algorithm, then you implement it in code. > >>>> l= [6,2,9,12,1,4] >>>> sorted(l,reverse=True)[:5] > [12, 9, 6, 4, 2] > > No need to know how sorted works nor [:5] > > Now you (or Steven) can call it abstract. It *is* an abstraction. You are abstracting away the details of the real computer implementation into an abstraction of a pure mathematical function, and that's fine. As programmers, that's what we do. But abstractions leak, and someday someone is going to ask "Why does it take 45 minutes to find the five largest values of my list?", and if you persist in insisting that sorted() is a pure mathematical function you will have no clue on how to even begin solving this, except perhaps to deny that it matters. But because abstractions leak, and I know that the concrete implementation is more fundamental than the abstraction, I can answer the question: perhaps their system uses bubblesort instead of Timsort. Or perhaps their list has a hundred thousand billion items. Or, if we're talking about Python, perhaps the __lt__ method of the items is horribly inefficient. To those who insist that the abstraction is all that matters, these concrete factors are irrelevant, but in practice they can be critical. The real question is, as educators, should we teach the abstraction or a concrete implementation first? In actuality we do both. As a first year computer science student learning Pascal, I was taught to add numbers using + without caring about the details of the hardware adder, although I was taught to care about the abstractions "Integer" and "Real" leaking (i.e. the possibility of overflow). On the other hand, I was taught to write my own sort function, partly because Pascal doesn't have one, but mostly because *learning how to program* was the whole point of the class and the people teaching the course decided that sort algorithms was the right level of complexity for their intended audience. You did the same thing in your own course, the only difference being you accepted a different set of primitive functions. But ultimately you have to introduce *some* amount of concreteness, at some level, otherwise we're just engaged in mental masturbation: Q: "Write a function to calculate the nth Catalan number." A: "Assume that a function Catalan(n) exists and calculates the nth Catalan number. Then the solution is Catalan." > And yet its > 1. Actual running code in the interpreter > 2. Its as close as one can get to a literal translation of your > "Find the 5 largest numbers in a list" > > Yeah the reverse=True is a fly in the ointment. Why? It's just syntax. In the abstract, there is no difference between sorted_descending(alist) and sorted(alist, reverse=True), they're just different ways of spelling the same thing. -- Steven From rustompmody at gmail.com Sun Aug 10 23:35:24 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 10 Aug 2014 20:35:24 -0700 (PDT) Subject: how to get the ordinal number in list In-Reply-To: References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> Message-ID: <76ea87c0-9dc9-4d3c-8898-0b41a22d6fc3@googlegroups.com> On Monday, August 11, 2014 3:31:08 AM UTC+5:30, Roy Smith wrote: > Mark Lawrence wrote: > > On 10/08/2014 19:26, Rustom Mody wrote: > > > Its when we have variables that are assigned in multiple places that > > > we start seeing mathematical abominations like > > > x = x+1 > > I'm not bothered about it being a mathematical or any other type of > > abomination. It works, practically beats purity, so if it ain't broke, > > please don't fix it, for some definition of fix. > I'm with Mark. This isn't math, it's programming. Sure, the > intersection of the two is non-null, but they are different things. > I'll often do things like: > for line in input: > line = line.strip() > # do more stuff So would I > Sure, I could invent some other variable name to avoid re-using the same > name, but does: > for line in input: > stripped_line = line.strip() > # do more stuff > really make this any easier to read or understand? I think not. You are switching between software-engineer and teacher hat. As a software engineer you (and I and possibly most reasonable people) would do things like that. As a teacher when you introduce problematic concepts you have to answer questions -- possibly embarrassing -- about them. Just as parents need to talk of 'birds-and-bees' to their children sometime but also need good sense and judgement as to when, likewise teachers should deliver maturity-building easier stuff before maturity-needing harder ideas. Assignment is definitely in the latter category because we have to talk of time, environments and so on. When one explicates (and not handwaves) these pre-requisites -- as happens in denotational semantics or in any language implementation -- then assignment is seen to be as higher-order a concept as any other 2 level lambda expression. From rustompmody at gmail.com Mon Aug 11 00:29:12 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 10 Aug 2014 21:29:12 -0700 (PDT) Subject: how to get the ordinal number in list In-Reply-To: <53e831d1$0$30002$c3e8da3$5496439d@news.astraweb.com> References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <53e831d1$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <2768e86c-34cf-4478-ac02-2ea6a4eb9236@googlegroups.com> On Monday, August 11, 2014 8:30:32 AM UTC+5:30, Steven D'Aprano wrote: > You did the same thing in your own course, the only difference being you > accepted a different set of primitive functions. But ultimately you have to > introduce *some* amount of concreteness, at some level, otherwise we're > just engaged in mental masturbation: > Q: "Write a function to calculate the nth Catalan number." > A: "Assume that a function Catalan(n) exists and calculates the nth Catalan > number. Then the solution is Catalan." You're concocting your own definitions and critiquing/refuting them. Here is the Haskell definition [Ive modernized my '93 code]. It corresponds to the 4th interpretation from http://en.wikipedia.org/wiki/Catalan_number#Applications_in_combinatorics -- applications of a bin op to a 'full' binary tree All of 3 lines! data Tree a = I (Tree a) (Tree a) | L a deriving Show c [x]= [L x] c ls = [I x y | i<-[1..length ls -1], let (l,r) = splitAt i ls, x <- c l, y <- c r] Read 'L' as Leaf Node 'I' as Internal Node 'c' as the catalan enumerator splitAt splits a list at a position: *Main> splitAt 3 [3,4,5,6,7] ([3,4,5],[6,7]) And some example runs *Main> c [] [] *Main> c [1] [L 1] *Main> c [1,2] [I (L 1) (L 2)] *Main> c [1,2,3] [I (L 1) (I (L 2) (L 3)),I (I (L 1) (L 2)) (L 3)] *Main> c [1,2,3,4] [I (L 1) (I (L 2) (I (L 3) (L 4))),I (L 1) (I (I (L 2) (L 3)) (L 4)),I (I (L 1) (L 2)) (I (L 3) (L 4)),I (I (L 1) (I (L 2) (L 3))) (L 4),I (I (I (L 1) (L 2)) (L 3)) (L 4)] *Main> Opening up the last eg into separate lines: [I (L 1) (I (L 2) (I (L 3) (L 4))), I (L 1) (I (I (L 2) (L 3)) (L 4)), I (I (L 1) (L 2)) (I (L 3) (L 4)), I (I (L 1) (I (L 2) (L 3))) (L 4), I (I (I (L 1) (L 2)) (L 3)) (L 4)] From paulwolf333 at gmail.com Mon Aug 11 00:56:00 2014 From: paulwolf333 at gmail.com (Paul Wolf) Date: Sun, 10 Aug 2014 21:56:00 -0700 (PDT) Subject: Template language for random string generation In-Reply-To: References: <14d94692-2257-4dfb-a82f-f1674a839233@googlegroups.com> Message-ID: <47417cbb-5624-4cbd-96ce-6e2f064f527f@googlegroups.com> On Sunday, 10 August 2014 17:47:48 UTC+1, Ian wrote: > On Sun, Aug 10, 2014 at 10:34 AM, Paul Wolf wrote: > > > For instance, a template language that validates the output would have to do frequency analysis. But that is getting too far off the purpose of strgen, although such a mechanism would certainly have its place. > > > > I don't think that would be necessary. The question being asked with > > validation is "can this string be generated from this template", not > > "is this string generated from this template with relatively high > > probability". Sorry, I meant frequency incidence within a produced string. And I understood Devin's point to be: For any given strgen expression that produces a set of strings, is there always a regex expression that captures the exact same set. And therefore is it not theoretically the case (leaving aside verbosity) that one of the syntaxes is superfluous (strgen). I think that is an entirely valid and interesting question. I'd have said before that it is not the case, but now I'm not so sure. I would still be sure that the strgen syntax is more fit for purpose for generating strings than regex on the basis of easy-of-use. From paulwolf333 at gmail.com Mon Aug 11 01:06:39 2014 From: paulwolf333 at gmail.com (Paul Wolf) Date: Sun, 10 Aug 2014 22:06:39 -0700 (PDT) Subject: Template language for random string generation In-Reply-To: <53e79e46$0$29967$c3e8da3$5496439d@news.astraweb.com> References: <14d94692-2257-4dfb-a82f-f1674a839233@googlegroups.com> <53e79e46$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: <11d608c5-b615-4571-a146-b3506c44f24c@googlegroups.com> On Sunday, 10 August 2014 17:31:01 UTC+1, Steven D'Aprano wrote: > Devin Jeanpierre wrote: > > > > > On Fri, Aug 8, 2014 at 2:01 AM, Paul Wolf wrote: > > >> This is a proposal with a working implementation for a random string > > >> generation template syntax for Python. `strgen` is a module for > > >> generating random strings in Python using a regex-like template language. > > >> Example: > > >> > > >> >>> from strgen import StringGenerator as SG > > >> >>> SG("[\l\d]{8:15}&[\d]&[\p]").render() > > >> u'F0vghTjKalf4^mGLk' > > > > > > Why aren't you using regular expressions? I am all for conciseness, > > > but using an existing format is so helpful... > > > > You've just answered your own question: > > > > > Unfortunately, the equivalent regexp probably looks like > > > r'(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z])[a-zA-Z0-9]{8:15}' > > > > Apart from being needlessly verbose, regex syntax is not appropriate because > > it specifies too much, specifies too little, and specifies the wrong > > things. It specifies too much: regexes like ^ and $ are meaningless in this > > case. It specifies too little: there's no regex for the "shuffle operator". > > And it specifies the wrong things: regexes like (?= ...) as used in your > > example are for matching, not generating strings, and it isn't clear > > what "match any character but don't consume any of the string" means when > > generating strings. > > > > Personally, I think even the OP's specified language is too complex. For > > example, it supports literal text, but given the use-case (password > > generators) do we really want to support templates like "password[\d]"? I > > don't think so, and if somebody did, they can trivially say "password" + > > SG('[\d]').render(). > > > > Larry Wall (the creator of Perl) has stated that one of the mistakes with > > Perl's regular expression mini-language is that the Huffman coding is > > wrong. Common things should be short, uncommon things can afford to be > > longer. Since the most common thing for password generation is to specify > > character classes, they should be short, e.g. d rather than [\d] (one > > character versus four). > > > > The template given could potentially be simplified to: > > > > "(LD){8:15}&D&P" > > > > where the round brackets () are purely used for grouping. Character codes > > are specified by a single letter. (I use uppercase to avoid the problem > > that l & 1 look very similar. YMMV.) The model here is custom format codes > > from spreadsheets, which should be comfortable to anyone who is familiar > > with Excel or OpenOffice. If you insist on having the facility to including > > literal text in your templates, might I suggest: > > > > "'password'd" # Literal string "password", followed by a single digit. > > > > but personally I believe that for the use-case given, that's a mistake. > > > > Alternatively, date/time templates use two-character codes like %Y %m etc, > > which is better than > > > > > > > > > (I've been working on this kind of thing with regexps, but it's still > > > incomplete.) > > > > > >> * Uses SystemRandom class (if available, or falls back to Random) > > > > > > This sounds cryptographically weak. Isn't the normal thing to do to > > > use a cryptographic hash function to generate a pseudorandom sequence? > > > > I don't think that using a good, but not cryptographically-strong, random > > number generator to generate passwords is a serious vulnerability. What's > > your threat model? Attacks on passwords tend to be one of a very few: > > > > - dictionary attacks (including tables of common passwords and > > simple transformations of words, e.g. 'pas5w0d'); > > > > - brute force against short and weak passwords; > > > > - attacking the hash function used to store passwords (not the password > > itself), e.g. rainbow tables; > > > > - keyloggers or some other way of stealing the password (including > > phishing sites and the ever-popular "beat them with a lead pipe > > until they give up the password"); > > > > - other social attacks, e.g. guessing that the person's password is their > > date of birth in reverse. > > > > But unless the random number generator is *ridiculously* weak ("9, 9, 9, 9, > > 9, 9, ...") I can't see any way to realistically attack the password > > generator based on the weakness of the random number generator. Perhaps I'm > > missing something? > > > > > > > Someone should write a cryptographically secure pseudorandom number > > > generator library for Python. :( > > > > Here, let me google that for you :-) > > > > https://duckduckgo.com/html/?q=python+crypto > > > > > > > > -- > > Steven I should clarify that the use case of password generation is only one of the use cases out of several that strgen is intended to support. It is also for: Test data generation: [\l]{1:20}&[._]{0:1}@[\l]{15}.(com|net|org) email addresses that use word characters and might have a period or an underscore in the first part. Or ((john|robert|harry)|(mary|agnes|shelly)) (smith|jones|taylor) produce names with roughly equal distribution of female/male first names. I contemplated - but did not implement - a feature where you can give strgen named functions that generate the required string (using whatever selection process that implementation chooses): ($malefirstname|$femalefirstname) $lastname where def malefirstname(): # get a name from the database at random Voucher generation: [\d]{10} 10-digit voucher numbers. In none of the foregoing is security a concern, it should be noted. > Since the most common thing for password generation is to specify > character classes, they should be short, e.g. d rather than [\d] (one > character versus four). But you assume only standard character classes and not custom ones like "[aeiuy]", not to mention unicode ranges outside of the English language. > If you insist on having the facility to including literal text in your templates, I do :-), as per above. > might I suggest: "'password'd" # Literal string "password", followed by a single digit. As per above, I think the more verbose notation for character classes is necessary. Although your suggestion is not a bad one. I could have taken a route where you define the character classes with aliases and then construct a very lean template. That is effectively what the - unimplemented - function expressions do in the example above. The ability to produce weak passwords ('[abc]{3}') is something I chose not to take up in the strgen module because it should be (mostly) agnostic about what constitutes good security and to support a broader set of use cases as per above. From 13813962782 at 139.com Mon Aug 11 01:15:19 2014 From: 13813962782 at 139.com (13813962782) Date: Mon, 11 Aug 2014 13:15:19 +0800 (CST) Subject: What's the future of perfect Python? References: <2afe53e822333cc-00011.Richmail.00052294890130005718@139.com> Message-ID: <2afe53e84f50316-00009.Richmail.00058204692110809768@139.com> Hi Sir/Madam, Just like MANY people, I was one of guys who do very like Python. But there's one thing always puzzled me, could you kindly help give some words about it: "Java is belonging to Oracle, C++ is defined by ISO Python is designed by great Guido van Rossum then what is the future of Python( Guido van Rossum, GREAT man, but STILL just one person)? " Thanks a lot, Johnnny -------------- next part -------------- An HTML attachment was scrubbed... URL: From rustompmody at gmail.com Mon Aug 11 01:23:18 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 10 Aug 2014 22:23:18 -0700 (PDT) Subject: how to get the ordinal number in list In-Reply-To: References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> Message-ID: On Monday, August 11, 2014 12:33:59 AM UTC+5:30, Chris Angelico wrote: > On Mon, Aug 11, 2014 at 4:26 AM, Rustom Mody wrote: > > Its when we have variables that are assigned in multiple places that > > we start seeing mathematical abominations like > > x = x+1 > That's an abomination to you because it breaks your mathematical > model. It's fine to a computer, which has a sense of time. It does?!?! Completely missed the news flash Last I knew they were as dumb as a rock -- maybe a GHz rock A C programmer asked to swap variables x and y, typically writes something like t = x; x = y; y = t; Fine, since C cant do better. But then he assumes that that much sequentialization is inherent to the problem... Until he sees the python: x,y = y,x The same applies generally to all programmers brought up on imperative style. Yeah there are problems that need to address time -- OSes, network protocols, reactive systems like window managers etc But the vast majority of problems that a programmer is likely to solve dont need time. These are of the form: Given this situation, this is the desired outcome. Nothing wrong with giving a sequential solution to a not inherently sequential problem. What is wrong is then thinking that all *problems* are sequential rather than seeing that some over-specific sequential *solutions* to non-sequential problems are ok. A mindset exemplified by your hilarious statement: "computers have a sense of time" From rosuav at gmail.com Mon Aug 11 01:41:24 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Aug 2014 15:41:24 +1000 Subject: What's the future of perfect Python? In-Reply-To: <2afe53e84f50316-00009.Richmail.00058204692110809768@139.com> References: <2afe53e822333cc-00011.Richmail.00052294890130005718@139.com> <2afe53e84f50316-00009.Richmail.00058204692110809768@139.com> Message-ID: On Mon, Aug 11, 2014 at 3:15 PM, 13813962782 <13813962782 at 139.com> wrote: > Just like MANY people, I was one of guys who do very like Python. But > there's one thing always puzzled me, could you kindly help give some words > about it: > "Java is belonging to Oracle, C++ is defined by ISO; Python is designed by > great Guido van Rossum; then what is the future of Python( Guido van Rossum, > GREAT man, but STILL just one person)? " There are several things going on here. Firstly, Python isn't developed solely by Guido, by any means. If you poke around on python-dev and see who's talking, it's mainly not Guido, but other people. And if you look at the commit history in Mercurial, similar. There are lots of contributors. Guido's job is not to *write* Python, but to *guide* it. If someone wants to add a new operator to Python, s/he may well end up writing the code - but Guido decides whether or not it's accepted. (Or, as the case may be, delegates to someone else the authority and job of making that decision.) Effectively, it's not so much that "nothing is added to Python unless Guido does it" as it is "nothing can be added to Python that Guido is specifically against". Secondly, the state of a project that's commanded by a single person is far better than one that's governed by a committee. Ever heard the expression "designed by committee"? [1] It's not a compliment. PHP is a language that seems to grow features without a huge amount of guidance. It has not benefited from that status. Python, on the other hand, has a transparent procedure for raising potentially-controversial suggestions, which culminates in a BDFL pronouncement. (Usually something like this: discussion on the python-ideas mailing list, then someone writes a Python Enhancement Proposal or PEP, which then gets bikeshedded to kingdom come and back, and finally the PEP gets pronounced on - accepted or rejected.) One person cannot, by definition, be in disagreement with himself. (Conflicted, maybe, as Flynn Rider observed of his golden-haired companion, but not in disagreement.) A committee can be; and then what? Do you declare that no changes are made without 100% consensus? Do you do whatever a majority of the committee wants? And how do you decide who comprises this decision-making body? With organizations (Oracle, ISO, Microsoft, and everyone else who owns a language), there's either going to be ultimately one person in charge (in which case it's not materially different from Python with the python-dev community and Guido), or some means of resolving these kinds of conflicts; and either way, chances are you won't know how it's dealt with. I can surmise, for instance, that Microsoft will have someone who has the ultimate say as to what goes into the next version of C#; but I can't hazard a guess as to _who_ that might be. With the open source world, there's a general principle that whoever starts a project is its head, and that headship is transferred by explicit action as the "final duty" [2], or can be claimed for an inactive project by effectively forking it and becoming the head of a new project (if the old one really is dead, its users will generally be happy to follow you to the new project - especially if it has the same name). So there's a very good future. If something should happen to Guido, the Python Steering Union will no doubt find someone else to take over - which may result in a change of direction for the project, but I suspect not a dramatic one. And in the meantime, we have a well-defined hierarchy - the very best form of governance. ChrisA [1] https://en.wikipedia.org/wiki/Design_by_committee [2] "When you lose interest in a program, your last duty to it is to hand it off to a competent successor." - https://en.wikipedia.org/wiki/The_Cathedral_and_the_Bazaar From rosuav at gmail.com Mon Aug 11 01:46:25 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Aug 2014 15:46:25 +1000 Subject: how to get the ordinal number in list In-Reply-To: References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> Message-ID: On Mon, Aug 11, 2014 at 3:23 PM, Rustom Mody wrote: > A C programmer asked to swap variables x and y, typically writes something like > > t = x; x = y; y = t; > > Fine, since C cant do better. > But then he assumes that that much sequentialization is inherent to the problem... > Until he sees the python: > > x,y = y,x > > The same applies generally to all programmers brought up on imperative style. Uhh, that's still imperative. There is a chronological boundary here: prior to that statement's execution, x and y have certain values, and after it, they have the same values but the other way around. When you're manipulating algebraic statements, moving down the page doesn't correspond to any sort of time change, which is why "x = x + 1" has no solutions. Please explain to me how "x,y = y,x" is materially different from "x = x + 1" in that the latter is, in your words, an abomination, but you say the former doesn't have the same problem. ChrisA From sprin.dev at gmail.com Mon Aug 11 01:45:17 2014 From: sprin.dev at gmail.com (sprin.dev at gmail.com) Date: Sun, 10 Aug 2014 22:45:17 -0700 (PDT) Subject: Minimal Python Build in Docker Container Message-ID: <33e08e99-42da-4b41-a94a-7b6f16fc8fce@googlegroups.com> Hello, I wanted to share what I've learned about making a reasonably minimal Docker image containing CPython built from source. Motivation: Many popular distros are not able to provide packaged builds of the desired Python version. Operators of co-tenanted Python services have struggled since the dawn of time to manage the Matrix of Hell with Python apps - system Python version versus versions required by different applications versus shared lib versions, etc. We have made due with "almost good enough" tools like virtualenv, pyenv, and Software Collections. In spite of this, many operators just gave up and decided every Python service ought to live inside its own virtual machine. To me, it seems like we finally have a real solution: Compile Python from source with the version and deps you need inside a Standard Container on top of the distro of your choosing. Disclaimer: I have never been involved in the Python project or in the packaging of Python libs for any distro, so excuse me if this is naive. If you, like me, have decided the key to sanity is in containerized Python services, you might try pulling the official Docker Python image: python 2.7.7 a87a2288ce78 2 weeks ago 1.041 GB Hmm, Python 2.7.8 has been out for over a month with "regression and security fixes over 2.7.7". Also, over 1 GB? The "debian:wheezy" image with Python 2.7.3 installed from apt-get weighs in at 124 MB. And finally, this image is running on top of a pre-release version of the as-yet unreleased debian jessie. So we have 3 very good reasons from staying away from the official Python Docker image. Let's build our own. We chose Centos 7 as the standard base for both Docker hosts and guest containers. Here's what I did: FROM centos:centos7  RUN yum install -y tar gcc make  RUN mkdir /usr/src/python WORKDIR /usr/src/python RUN curl -Sl "https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tar.xz" \  | tar -xJ --strip-components=1 # You may want to verify the download with gpg: https://www.python.org/download  RUN ./configure \  && make -j$(nproc) \  && make install \  && make clean  # Clean up prior to flattening RUN yum remove -y tar gcc make \ && yum clean all \ && rm -rf /usr/src/python Beginning with the 244 MB Centos 7 base image, this yields a 369 MB image after flattening, with a compiled Python 2.7.8. While +125 MB to the base is not terrible, it seems like the image could still lose some weight. Any ideas? If you would like to check out the built image, it is at marina/python:2.7.8_r1 on the public registry. Of course I recommend building your own with whatever makes sense for your "Python base" for production use! From tjreedy at udel.edu Mon Aug 11 02:16:24 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 11 Aug 2014 02:16:24 -0400 Subject: What's the future of perfect Python? In-Reply-To: <2afe53e84f50316-00009.Richmail.00058204692110809768@139.com> References: <2afe53e822333cc-00011.Richmail.00052294890130005718@139.com> <2afe53e84f50316-00009.Richmail.00058204692110809768@139.com> Message-ID: On 8/11/2014 1:15 AM, 13813962782 wrote: > "Java is belonging to Oracle, C++ is defined by ISO; Python is designed > by great Guido van Rossum > ; Python is owned, as in copyright and trademark, by the Python Software Foundation, a US non-profit corporation, with a Board elected by the voting members. Python is defined by the Reference and Library manuals. It was originally designed by Guido, who subsequently gave it to the PSF. At least 95% of current design work is done by other people under the framework Guido established, with his occasional input to make sure Python 'stays on track'. -- Terry Jan Reedy From rustompmody at gmail.com Mon Aug 11 02:22:45 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 10 Aug 2014 23:22:45 -0700 (PDT) Subject: how to get the ordinal number in list In-Reply-To: References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> Message-ID: On Monday, August 11, 2014 11:16:25 AM UTC+5:30, Chris Angelico wrote: > On Mon, Aug 11, 2014 at 3:23 PM, Rustom Mody wrote: > > A C programmer asked to swap variables x and y, typically writes something like > > t = x; x = y; y = t; > > Fine, since C cant do better. > > But then he assumes that that much sequentialization is inherent to the problem... > > Until he sees the python: > > x,y = y,x > > The same applies generally to all programmers brought up on imperative style. > Uhh, that's still imperative. There is a chronological boundary here: > prior to that statement's execution, x and y have certain values, and > after it, they have the same values but the other way around. When > you're manipulating algebraic statements, moving down the page doesn't > correspond to any sort of time change, which is why "x = x + 1" has no > solutions. > Please explain to me how "x,y = y,x" is materially different from "x = > x + 1" in that the latter is, in your words, an abomination, but you > say the former doesn't have the same problem. I was giving an analogy for a mindset that - is sequencing hungup - is not aware of being hungup until a more abstract solution is presented. The two -- x=x+1 and the swap -- are not related. And yes the swap is imperative but less so than the C because it elides the fact that an implementation of x,y = y,x could be - t=x;x=y;y=t # the original - t=y;y=x=x=t # in the reverse order - push x; push y; pop x; pop y # use stack no temporary - xchng x y # hardware instruction in x86 and perhaps many other plausible ones. The terrible thing about an overspecific presentation is that it blinds one to alternatives And as for your wanting a fully non-imperative version: swap (x, y) = (y, x) -- the only option in Haskell, natural/easy in python, painfully laborious but still possible in C -- pass a struct, return a struct, unpack on return. You think that the '=' sign not standing for math equality is ok. How come? I aver that you (any competent programmer) have worked out/crystallized/created a switch in your brain. In 'programming' state: x=x+1 is not a problem In 'math' state : it is And you have become adroit at flipping from one to the other -- you do it all the time going from rhs to lhs!! I too have that switch as do most practised programmers. We are not talking about us, we are talking about noobs. So my reverse question to you is how do you inculcate this switch in a noob? From jeanpierreda at gmail.com Mon Aug 11 03:01:58 2014 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Mon, 11 Aug 2014 00:01:58 -0700 Subject: Template language for random string generation In-Reply-To: <53e828e9$0$29966$c3e8da3$5496439d@news.astraweb.com> References: <14d94692-2257-4dfb-a82f-f1674a839233@googlegroups.com> <53e79e46$0$29967$c3e8da3$5496439d@news.astraweb.com> <53e828e9$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Aug 10, 2014 at 7:22 PM, Steven D'Aprano wrote: > Devin Jeanpierre wrote: > >> On Sun, Aug 10, 2014 at 9:31 AM, Steven D'Aprano >> wrote: > >>> I don't think that using a good, but not cryptographically-strong, random >>> number generator to generate passwords is a serious vulnerability. What's >>> your threat model? >> >> I've always wanted a password generator that worked on the fly based >> off of a master password. If the passwords are generated randomly but >> not cryptographically securely so, then given sufficiently many >> passwords, the master password might be deduced. > > o_O > > So, what you're saying is that you're concerned that if an attacker has all > your passwords, they might be able to generate new passwords? No, I meant what I said. I was pretty specific. -- Devin From steve at pearwood.info Mon Aug 11 03:44:17 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 11 Aug 2014 07:44:17 GMT Subject: Is print thread safe? Message-ID: <53e87451$0$29890$c3e8da3$5496439d@news.astraweb.com> Specifically for Python 2.6 and 2.7, but answers for 3.x appreciated as well. Is print thread safe? That is, if I have two threads that each call print, say: print "spam spam spam" # thread 1 print "eggs eggs eggs" # thread 2 I don't care which line prints first, but I do care if the two lines are mixed in together, something like this: spam spaeggs eggs m seggspams Does print perform its own locking to prevent this? -- Steven From breamoreboy at yahoo.co.uk Mon Aug 11 03:58:08 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 11 Aug 2014 08:58:08 +0100 Subject: Template language for random string generation In-Reply-To: <11d608c5-b615-4571-a146-b3506c44f24c@googlegroups.com> References: <14d94692-2257-4dfb-a82f-f1674a839233@googlegroups.com> <53e79e46$0$29967$c3e8da3$5496439d@news.astraweb.com> <11d608c5-b615-4571-a146-b3506c44f24c@googlegroups.com> Message-ID: On 11/08/2014 06:06, Paul Wolf wrote: I'm pleased to see that you have answers. In return would you please read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing double line spacing and single line paragraphs, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From steve at pearwood.info Mon Aug 11 04:55:40 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 11 Aug 2014 08:55:40 GMT Subject: how to get the ordinal number in list References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> Message-ID: <53e8850b$0$29890$c3e8da3$5496439d@news.astraweb.com> On Sun, 10 Aug 2014 23:22:45 -0700, Rustom Mody wrote: > You think that the '=' sign not standing for math equality is ok. > > How come? For the same reason that in the following: [c.upper() for c in some_string if 'a' < c < 'x'] having the c symbol not stand for the speed of light is okay. Likewise, in the sentence "I went to the park today", the symbol I doesn't mean the element iodine. Symbols are context-dependent: the x in one equation is not necessarily the same x in another equation, and the symbol = in one context does not necessarily have the same meaning as in another context. -- Steven From steve at pearwood.info Mon Aug 11 05:04:21 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 11 Aug 2014 09:04:21 GMT Subject: What's the future of perfect Python? References: <2afe53e822333cc-00011.Richmail.00052294890130005718@139.com> Message-ID: <53e88715$0$29890$c3e8da3$5496439d@news.astraweb.com> On Mon, 11 Aug 2014 13:15:19 +0800, 13813962782 wrote: > Just like MANY people, I was one of guys who do very like Python. But > there's one thing always puzzled me, could you kindly help give some > words about it: > > "Java is belonging to Oracle, C++ is defined by ISO Python is designed > by great Guido van Rossum then what is the future of Python( Guido van > Rossum, GREAT man, but STILL just one person)? " Haven't you heard? Guido has retired. http://legacy.python.org/dev/peps/pep-0401/ -- Steven From feliphil at gmx.net Mon Aug 11 05:08:36 2014 From: feliphil at gmx.net (Wolfgang Keller) Date: Mon, 11 Aug 2014 11:08:36 +0200 Subject: Python and IDEs [was Re: Python 3 is killing Python] References: <87zjga4j4v.fsf@elektro.pacujo.net> <53c57bae$0$9505$c3e8da3$5496439d@news.astraweb.com> <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> <20140806143853.4ae3c37a34f8f9a482d3ce2e@gmx.net> Message-ID: <20140811110836.7cf2a4dad3f6d671cc0e73ef@gmx.net> > >> > Thankfully, all actually user-friendly operating systems (MacOS, > >> > TOS, RiscOS, probably AmigaOS, MacOS X) spare(d) their users the > >> > bottomless cesspit of "package management" and/or "installers". > >> > > >> > Because on such operating systems, each and every application is > >> > an entirely self-contained package that doesn't need any > >> > "packages" or "installers" to use it. > >> > >> You mean everyone has to reinvent the proverbial wheel AND worry > >> about dependency collisions? Yeah, that's a heavenly thought. > > > > You should get a clue in stead of just fantasizing up assumptions > > based on ignorance. > > I've worked with a number of operating systems, a number of dependency > management systems, and a number of absences of such systems. I stand > by my earlier statements in this thread, Then you seem to have a problem with elementary logical reasoning. Your above statement (about "re-inventing the wheel AND worrying about dependency collisions") is totally illogical nonsense. Just one issue: MacOS application have always been far more compact (both on disk and in RAM) than comparable Windows or Unix counterparts. "Despite" the fact that they where GUI applications since MacOS 1.0. No one has to "re-invent" any more wheels to develop a MacOS X application than he has to do for a Windows or Linux application. In fact, usually, there are less wheels to re-invent for MacOS X. Next: The self-contained nature of applications is obviously exactly what *eliminates* dependency collisions. Sincerely, Wolfgang From feliphil at gmx.net Mon Aug 11 05:08:43 2014 From: feliphil at gmx.net (Wolfgang Keller) Date: Mon, 11 Aug 2014 11:08:43 +0200 Subject: Python and IDEs [was Re: Python 3 is killing Python] References: <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> <20140806144758.f5817ee60d0e98ff30172a2a@gmx.net> <53e2f338$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20140811110843.a314bb1b78cda13d26844ab5@gmx.net> > > Linux was made by geeks who didn't have a clue of ergonomics for > > screenworkers and didn't care to get one. > > I can only repeat what you said earlier: > > "You should get a clue in stead [sic] of just fantasizing up > assumptions based on ignorance." > > I daresay that Linus Torvalds spends more time in front of a computer > screen than most 9 to 5 "screenworkers". He's a developer, not a usual screenworker. > By the way, you keep replying to people, and quoting them, but > deleting their name. Please leave the attribution in place, so we > know who you are replying to. That's what the "References:"-Header is there for. Sincerely, Wolfgang From rosuav at gmail.com Mon Aug 11 05:15:48 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Aug 2014 19:15:48 +1000 Subject: how to get the ordinal number in list In-Reply-To: <53e8850b$0$29890$c3e8da3$5496439d@news.astraweb.com> References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> <53e8850b$0$29890$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Aug 11, 2014 at 6:55 PM, Steven D'Aprano wrote: > On Sun, 10 Aug 2014 23:22:45 -0700, Rustom Mody wrote: > >> You think that the '=' sign not standing for math equality is ok. >> >> How come? > > For the same reason that in the following: > > [c.upper() for c in some_string if 'a' < c < 'x'] > > having the c symbol not stand for the speed of light is okay. Likewise, > in the sentence "I went to the park today", the symbol I doesn't mean the > element iodine. Symbols are context-dependent: the x in one equation is > not necessarily the same x in another equation, and the symbol = in one > context does not necessarily have the same meaning as in another context. Thanks, you said it better than I would have. That's exactly the sentiment I would have expressed, and while I hate to "Me too" a post, I'll do it here. +1. ChrisA From marko at pacujo.net Mon Aug 11 05:35:44 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 11 Aug 2014 12:35:44 +0300 Subject: how to get the ordinal number in list References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> Message-ID: <87ha1jweq7.fsf@elektro.pacujo.net> Rustom Mody : > You think that the '=' sign not standing for math equality is ok. > > How come? Python is a formal language with a well-defined syntax and reasonably well-understood semantics. That's all that matters. Any resemblance to the much more ad-hoc syntax of classical mathematics is almost coincidental. Instead of fighting the crystal-clear status of the = symbol in Python, you should choose a worthier crusade. For example, you could help mathematicians and physicists agree on the meaning of 6 3 ? ? f(x, y) dy dx 0 2 The mathematicians maintain the expression means x ranges from 0 to 6 and y from 2 to 3. The physicists consider that too confusing in practice and insist it is y that ranges from 0 to 6 and x from x to 3. Marko From alister.nospam.ware at ntlworld.com Mon Aug 11 05:37:38 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Mon, 11 Aug 2014 09:37:38 GMT Subject: Python and IDEs [was Re: Python 3 is killing Python] References: <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> <20140806144758.f5817ee60d0e98ff30172a2a@gmx.net> <53e2f338$0$29979$c3e8da3$5496439d@news.astraweb.com> <20140811110843.a314bb1b78cda13d26844ab5@gmx.net> Message-ID: On Mon, 11 Aug 2014 11:08:43 +0200, Wolfgang Keller wrote: >> By the way, you keep replying to people, and quoting them, but deleting >> their name. Please leave the attribution in place, so we know who you >> are replying to. > > That's what the "References:"-Header is there for. > > Sincerely, > > Wolfgang Which is not normally visible unless you go looking for it Also despite the problems it causes there are still an large number of posters that use Google groups & probably cant see those headers even if they wished. Common courtesy (or netiquet if you prefer) would be to follow the conventions of the group you are posting to. -- You definitely intend to start living sometime soon. From steve at pearwood.info Mon Aug 11 05:44:03 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 11 Aug 2014 09:44:03 GMT Subject: how to get the ordinal number in list References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> Message-ID: <53e89063$0$29890$c3e8da3$5496439d@news.astraweb.com> On Sun, 10 Aug 2014 22:23:18 -0700, Rustom Mody wrote: > A C programmer asked to swap variables x and y, typically writes > something like > > t = x; x = y; y = t; > > Fine, since C cant do better. > But then he assumes that that much sequentialization is inherent to the > problem... Until he sees the python: > > x,y = y,x Which is inherently sequential: the semantics of Python guarantee that the right-hand side will be evaluated before being bound to the names on the left-hand side. > The same applies generally to all programmers brought up on imperative > style. > > Yeah there are problems that need to address time -- OSes, network > protocols, reactive systems like window managers etc > > But the vast majority of problems that a programmer is likely to solve > dont need time. Incorrect. Most problems are time dependent in the sense that you have to do X before you do Y. "Print the file, then delete it" has a very different effect to "delete the file, then print it". Even functional programming has an implicit sense of time: f(g(x)) applies f *after* g, not the other way around. While there are some functions where it doesn't matter what order you call them, in general it does. There has been a huge amount of research into writing fully parallel code, where the order that code is executed is indeterminate. If we could take a general sequential program and parallelize it, we could speed up our programs hugely by throwing more cores or CPUs into the hardware. But in general we can't -- comparatively few tasks are easily, or at all parallelizable. One cannot make an omelet by cooking the eggs first and beating them second, or even at the same time. And even when you can parallelize a series of tasks, it's I think this is why both declarative and functional programming idioms will remain niche (although important niches). Most tasks are inherently imperative to at least some degree, and often a *great* degree. > What is wrong is then thinking that all *problems* are sequential rather > than seeing that some over-specific sequential *solutions* to > non-sequential problems are ok. > > A mindset exemplified by your hilarious statement: "computers have a > sense of time" Of course they do. Apart from a very few experimental asynchronous CPUs, computers are all based on CPUs with an internal clock signal which synchronizes distinct parts of the circuit with each other. -- Steven From rosuav at gmail.com Mon Aug 11 05:51:35 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Aug 2014 19:51:35 +1000 Subject: how to get the ordinal number in list In-Reply-To: <87ha1jweq7.fsf@elektro.pacujo.net> References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> <87ha1jweq7.fsf@elektro.pacujo.net> Message-ID: On Mon, Aug 11, 2014 at 7:35 PM, Marko Rauhamaa wrote: > Python is a formal language with a well-defined syntax and reasonably > well-understood semantics. That's all that matters. Any resemblance to > the much more ad-hoc syntax of classical mathematics is almost > coincidental. Well, it's a bit more than coincidence. It's the ELIZA effect: http://www.catb.org/jargon/html/E/ELIZA-effect.html Using notations that some people will be familiar with is better than constructing brand new notations from scratch, even if not everyone can gain that benefit. (Which is an argument in favour of Python's percent-formatting of strings; there are plenty of people out there who'll instantly understand that %d will plop in an integer and %s a string - even some non-programmers know that notation, as it's found in config files, translation data, etc, etc.) ChrisA From rosuav at gmail.com Mon Aug 11 05:53:45 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Aug 2014 19:53:45 +1000 Subject: how to get the ordinal number in list In-Reply-To: <53e89063$0$29890$c3e8da3$5496439d@news.astraweb.com> References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> <53e89063$0$29890$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Aug 11, 2014 at 7:44 PM, Steven D'Aprano wrote: > And even when you can > parallelize a series of tasks, it's ... easy for one task to get aborted part way while the rest of the tasks continue on, oblivious to the absence of the rest of that sentence? ChrisA From rosuav at gmail.com Mon Aug 11 06:07:46 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Aug 2014 20:07:46 +1000 Subject: how to get the ordinal number in list In-Reply-To: <53e89063$0$29890$c3e8da3$5496439d@news.astraweb.com> References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> <53e89063$0$29890$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Aug 11, 2014 at 7:44 PM, Steven D'Aprano wrote: > I think this is why both declarative and functional programming idioms > will remain niche (although important niches). Most tasks are inherently > imperative to at least some degree, and often a *great* degree. Maybe that's true as a whole, but there are certainly ways in which certain declarative or functional elements can be extremely useful to an otherwise-imperative program. Python's (list etc) comprehensions are broadly functional in style, as are most of the itertools oddments. There's not a lot that's declarative in Python, but (at least in Python 3) the presence of __eq__() in a class disables the default __hash__ implementation, which effectively makes __eq__ a declaration "I'm doing custom equality, so I'm unhashable unless I say otherwise". I've sometimes done some extremely declarative coding in places; my MUD client builds its menus by looking for specially-named functions and getting some metadata from them to work out what the menu item name should be. An approximate Python equivalent would be: @filemenu("E_xit") def exit(): prompt("Do you really want to exit?") where the presence of the function is what causes the menu item to exist. In this case, the 'filemenu' decorator is probably imperative code that adds the menu item to the File menu, but if you're reading through a source file that has a bunch of functions like that, you'd have to agree that that's a declarative style of coding. And it's a style that works well for this kind of thing. ChrisA From songofacandy at gmail.com Mon Aug 11 06:19:05 2014 From: songofacandy at gmail.com (INADA Naoki) Date: Mon, 11 Aug 2014 19:19:05 +0900 Subject: Is print thread safe? In-Reply-To: <53e87451$0$29890$c3e8da3$5496439d@news.astraweb.com> References: <53e87451$0$29890$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Python 3, print is thread safe. But Python 2 has broken scenario: print "spam", "spam", "spam" # thread 1 print "eggs", "eggs", "eggs" # thread 2 In this case, 2 lines are mixed. In your case, "spam spam spam" and "eggs eggs eggs" are not mixed. But newline is mixed like: spam spam spameggs eggs eggs eggs eggs eggsspam spam spam eggs eggs eggs spam spam spam On Mon, Aug 11, 2014 at 4:44 PM, Steven D'Aprano wrote: > Specifically for Python 2.6 and 2.7, but answers for 3.x appreciated as > well. > > Is print thread safe? That is, if I have two threads that each call > print, say: > > print "spam spam spam" # thread 1 > print "eggs eggs eggs" # thread 2 > > I don't care which line prints first, but I do care if the two lines are > mixed in together, something like this: > > spam spaeggs eggs m seggspams > > > Does print perform its own locking to prevent this? > > > > -- > Steven > -- > https://mail.python.org/mailman/listinfo/python-list -- INADA Naoki From rosuav at gmail.com Mon Aug 11 06:20:13 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Aug 2014 20:20:13 +1000 Subject: Python and IDEs [was Re: Python 3 is killing Python] In-Reply-To: References: <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> <20140806144758.f5817ee60d0e98ff30172a2a@gmx.net> <53e2f338$0$29979$c3e8da3$5496439d@news.astraweb.com> <20140811110843.a314bb1b78cda13d26844ab5@gmx.net> Message-ID: On Mon, Aug 11, 2014 at 7:37 PM, alister wrote: > On Mon, 11 Aug 2014 11:08:43 +0200, Wolfgang Keller wrote: > >>> By the way, you keep replying to people, and quoting them, but deleting >>> their name. Please leave the attribution in place, so we know who you >>> are replying to. >> >> That's what the "References:"-Header is there for. > > Which is not normally visible unless you go looking for it > Also despite the problems it causes there are still an large number of > posters that use Google groups & probably cant see those headers even if > they wished. Common courtesy (or netiquet if you prefer) would be to > follow the conventions of the group you are posting to. Additionally, the References header is good for at most one level in. Can you see, by looking at my post here, who Alister is quoting? Yes, easily, because his attribution line is part of the text that I've quoted. Can you see who Wolfgang is quoting? No, because there's no attribution line. It's completely impractical to dig through the References header (Alister's post has nineteen message IDs in References, and presumably mine will add a twentieth) to find out who quoted whom three levels ago. ChrisA From steve at pearwood.info Mon Aug 11 06:28:59 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 11 Aug 2014 10:28:59 GMT Subject: how to get the ordinal number in list References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <53e831d1$0$30002$c3e8da3$5496439d@news.astraweb.com> <2768e86c-34cf-4478-ac02-2ea6a4eb9236@googlegroups.com> Message-ID: <53e89aeb$0$29890$c3e8da3$5496439d@news.astraweb.com> On Sun, 10 Aug 2014 21:29:12 -0700, Rustom Mody wrote: > On Monday, August 11, 2014 8:30:32 AM UTC+5:30, Steven D'Aprano wrote: > >> You did the same thing in your own course, the only difference being >> you accepted a different set of primitive functions. But ultimately you >> have to introduce *some* amount of concreteness, at some level, >> otherwise we're just engaged in mental masturbation: > >> Q: "Write a function to calculate the nth Catalan number." A: "Assume >> that a function Catalan(n) exists and calculates the nth Catalan >> number. Then the solution is Catalan." > > > You're concocting your own definitions and critiquing/refuting them. No, but I think you are deliberately choosing to ignore my point for the sake of cheap shots. My point is that, at *some* level, you have to actually write code (well duh!) which must be targeted at some concrete environment. Different languages provide different levels of abstraction, but they all have a some concrete set of primitive operations which actually do *something*, and that something is concrete, not abstract. Every function, even in Haskell, has an implementation. Otherwise if you don't need an implementation, you can just declare "imagine a function that implements Foo" for any Foo, and you're done.[1] Computer science, if might be said, is the search for better and more productive abstractions which provide more useful implementations for concrete tasks. [1] A perfectly reasonable approach, sometimes, for some philosophical questions, including sometimes philosophical questions within the scope of computer science. E.g. if we had a supertask, or an oracle-machine, what class of problems could we solve? -- Steven From marko at pacujo.net Mon Aug 11 06:46:13 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 11 Aug 2014 13:46:13 +0300 Subject: how to get the ordinal number in list References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> <87ha1jweq7.fsf@elektro.pacujo.net> Message-ID: <87d2c7wbgq.fsf@elektro.pacujo.net> Chris Angelico : > On Mon, Aug 11, 2014 at 7:35 PM, Marko Rauhamaa wrote: >> Python is a formal language with a well-defined syntax and reasonably >> well-understood semantics. That's all that matters. Any resemblance >> to the much more ad-hoc syntax of classical mathematics is almost >> coincidental. > > Well, it's a bit more than coincidence. It's the ELIZA effect: > > http://www.catb.org/jargon/html/E/ELIZA-effect.html > > Using notations that some people will be familiar with is better than > constructing brand new notations from scratch, even if not everyone > can gain that benefit. The main thing is that the definitions must be clear. I must be able to look up the precise description quickly, and in fact, I always have the Python Library Reference in a browser tab or two because I have to review even familiar functionality over and over again. Less often, I also have to review the Python Language Reference. You don't have to like the = sign or the trailing comma of 1-tuples. What matters is that you know how to use them. The second in priority is that the language/module should be faithful to its own principles. An example is the so-called "file-like objects" in Python. A different one would be the principle that a new indentation level is always introduced by a colon. Yet another specialty of Python is the numerous "magic" access points that have been named __xyz__. You don't have to like the naming of __init__. It doesn't have to have a precedent in other programming languages. However, it is important that it follows a general, rigorous Python pattern. Marko From rosuav at gmail.com Mon Aug 11 07:06:36 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Aug 2014 21:06:36 +1000 Subject: how to get the ordinal number in list In-Reply-To: <87d2c7wbgq.fsf@elektro.pacujo.net> References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> <87ha1jweq7.fsf@elektro.pacujo.net> <87d2c7wbgq.fsf@elektro.pacujo.net> Message-ID: On Mon, Aug 11, 2014 at 8:46 PM, Marko Rauhamaa wrote: > The main thing is that the definitions must be clear. I must be able to > look up the precise description quickly, and in fact, I always have the > Python Library Reference in a browser tab or two because I have to > review even familiar functionality over and over again. Less often, I > also have to review the Python Language Reference. > > You don't have to like the = sign or the trailing comma of 1-tuples. > What matters is that you know how to use them. Fair enough. I'd say that there are two "main things", of nearly equal importance: one is clear definitions, as you describe, and the other is memorable definitions (so you don't have to keep going back to the reference for every little thing). The consistency you describe as your second priority is really part of memorability, because you can learn one principle and have it work for everything. Contrast the PHP standard library, where there's very little consistency in naming, so you're constantly going back to the docs - see examples here [1] - I can fully understand that switching from language to language will have me doing this sort of thing (often with very good justification - map() in Python takes func,iter,... but map() in Pike takes iter,func,...; this is because Python's map() takes multiple iterables, while Pike's takes exactly one iterable and will pass any other args through to the function unchanged - which is consistent with a lot of other Pike callback-calling functions), but within a single language, it's more reasonable to expect consistency. There are innumerable facets to the memorability of definitions, though, and consistency's just one of them. The ELIZA effect factors heavily in memorability; if you see "a + b" in code, you'll expect it to be, in some way, adding a and b. If you know what HTTP means from other places on the internet, you'll have some fairly strong expectations about the functionality of BasicHTTPServer. If you've worked with any of a huge bunch of languages, you'll not at all be surprised that "asdf" is a string containing those four letters. And that latter is true even though lots of languages have their variations - biggest one being that Python 3's "asdf" is a string of four Unicode codepoints, while C's "asdf" is a pointer to a buffer of four bytes (plus the 0, so five really); it's still a string containing four lowercase letters. And that's a Good Thing. ChrisA [1] http://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/#standard-library From steve+comp.lang.python at pearwood.info Mon Aug 11 07:30:10 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 11 Aug 2014 21:30:10 +1000 Subject: how to get the ordinal number in list References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> <53e89063$0$29890$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53e8a943$0$29982$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > On Mon, Aug 11, 2014 at 7:44 PM, Steven D'Aprano > wrote: >> And even when you can >> parallelize a series of tasks, it's > > ... easy for one task to get aborted part way while the rest of the > tasks continue on, oblivious to the absence of the rest of that > sentence? Exactly! -- Steven From rustompmody at gmail.com Mon Aug 11 07:49:34 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 11 Aug 2014 04:49:34 -0700 (PDT) Subject: how to get the ordinal number in list In-Reply-To: <53e89aeb$0$29890$c3e8da3$5496439d@news.astraweb.com> References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <53e831d1$0$30002$c3e8da3$5496439d@news.astraweb.com> <2768e86c-34cf-4478-ac02-2ea6a4eb9236@googlegroups.com> <53e89aeb$0$29890$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Monday, August 11, 2014 3:58:59 PM UTC+5:30, Steven D'Aprano wrote: > On Sun, 10 Aug 2014 21:29:12 -0700, Rustom Mody wrote: > > On Monday, August 11, 2014 8:30:32 AM UTC+5:30, Steven D'Aprano wrote: > >> You did the same thing in your own course, the only difference being > >> you accepted a different set of primitive functions. But ultimately you > >> have to introduce *some* amount of concreteness, at some level, > >> otherwise we're just engaged in mental masturbation: > >> Q: "Write a function to calculate the nth Catalan number." A: "Assume > >> that a function Catalan(n) exists and calculates the nth Catalan > >> number. Then the solution is Catalan." > > You're concocting your own definitions and critiquing/refuting them. > No, but I think you are deliberately choosing to ignore my point for the Because I dont understand what you are saying. [See below] > My point is that, at *some* level, you have to > actually write code (well duh!) which must be targeted at some concrete > environment. Different languages provide different levels of abstraction, > but they all have a some concrete set of primitive operations which > actually do *something*, and that something is concrete, not abstract. > Every function, even in Haskell, has an implementation. Otherwise if you > don't need an implementation, you can just declare "imagine a function > that implements Foo" for any Foo, and you're done.[1] I guess part of the problem is that evidently you and I use 'concrete' and 'abstract' in almost diametrically opposite ways. In my book, FP is easy and pleasant and smooth because (among other things) FP types are concrete, whereas OOP types are abstract. Here is an FP classic: http://www.nlda-tw.nl/janmartin/vakken/TFIT/Extra%20materiaal/Bird_Wadler.%20Introduction%20to%20Functional%20Programming.1ed.pdf In the section on 'abstract types' (pg 221 chap 8) he briefly explains what is an abstract type and indicates that the whole book only deals with concrete types. This was written in 1988. Across the last 25 years this view has only strengthened at least in the FP circles, viz. that concrete types are all thats needed for the most part whereas abstract types (ADTs) and other OOP fancies are a waste of time, a PITA and not worth the sweat of pursuing them. You are of course free to disagree with this viewpoint -- the majority of programmers do. But now you are turning the tables and saying that the FP types/constructs are more abstract than the conventional ones. I dont argue with this because I dont know how to, other than to say it does not seem to be the dominant view in either the conventional (OOP/imperative) communities or in the FP community. Here is a conversation from reddit: http://www.reddit.com/r/haskell/comments/xgq27/uday_reddy_sharpens_up_referential_transparency/ which should give a sense of the pov. Person 1 | By the way, somebody commented on the StackOverflow page that the | naive functional programmer seems to use syntactic reasoning while the | naive imperative programmer seems to use operational reasoning. Person 2 | Interesting. I have a theory that functional programmers use more | concrete (denotative, indicative, elemental) thought whereas | imperative programmers use more abstract (connotative, analogous) | thought. However, sequential and random thinking styles can also be | very different. On the Meyers-Briggs functional and imperative | programmers seem to differ on both axies of the four main personality | groups. Person 3 | Yup, that is also a quite insightful point. But we also need to keep | in mind the training aspect. Functional programming is taught in a | semi-rigorous way, using the knowledge of set theory and mathematics | that we all know. Imperative programming is taught in an intuitive | way, because there is no well-understood mathematics for it yet. In | fact, let us say that imperative programming is not really taught at | all. Whatever the imperative programmers learn, they learn through | experience. They write programs, see how they behave, and build up a | mental picture of how they work and how to reason about them. It is an | art rather than a science. From robert.kern at gmail.com Mon Aug 11 07:56:59 2014 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 11 Aug 2014 12:56:59 +0100 Subject: how to get the ordinal number in list In-Reply-To: <53e824b9$0$30000$c3e8da3$5496439d@news.astraweb.com> References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> <53e824b9$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2014-08-11 03:04, Steven D'Aprano wrote: > Rustom Mody wrote: > >> Its when we have variables that are assigned in multiple places that >> we start seeing mathematical abominations like >> x = x+1 > > That's not a mathematical abomination. It's a perfectly reasonable > mathematical equation, one with no solutions since the line f(x) = x and > the line f(x) = x+1 are parallel. > > But what does this have to do with programming? Programming *is not* > mathematics, and x = x+1 has a different meaning in programming than in > mathematics. Perhaps it would help if we wrote it using mathematical > notation? Using [x] for subscripts: > > x[n+1] = x[n] + 1 > > we have a perfectly good mathematical recursive definition. All it needs is > an initial value x[0] and we're good to go. Or a different operator for assignment (to distinguish it more clearly from equality, which it isn't). x <- x + 1 x := x + 1 -- 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 roy at panix.com Mon Aug 11 07:55:29 2014 From: roy at panix.com (Roy Smith) Date: Mon, 11 Aug 2014 07:55:29 -0400 Subject: how to get the ordinal number in list References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> Message-ID: In article , Rustom Mody wrote: > A C programmer asked to swap variables x and y, typically writes something > like > > t = x; x = y; y = t; > > Fine, since C cant do better. Sure C can do better. x = x ^ y y = y ^ x x = x ^ y Any self-respecting C hacker would write it this way :-) From rustompmody at gmail.com Mon Aug 11 08:11:40 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 11 Aug 2014 05:11:40 -0700 (PDT) Subject: how to get the ordinal number in list In-Reply-To: References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> <53e824b9$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55a85155-0c7d-4100-94e8-b24d36885289@googlegroups.com> Having it both ways aren't you? On the one hand you say On Monday, August 11, 2014 3:21:35 PM UTC+5:30, Chris Angelico wrote: > On Mon, Aug 11, 2014 at 7:35 PM, Marko Rauhamaa wrote: > > Python is a formal language with a well-defined syntax and reasonably > > well-understood semantics. That's all that matters. Any resemblance to > > the much more ad-hoc syntax of classical mathematics is almost > > coincidental. > Well, it's a bit more than coincidence. It's the ELIZA effect: > http://www.catb.org/jargon/html/E/ELIZA-effect.html Which describes the Eliza effect as: The tendency of humans to attach associations to terms from prior experience. Then you continue: > Using notations that some people will be familiar with is better than > constructing brand new notations from scratch, even if not everyone > can gain that benefit. (Which is an argument in favour of Python's > percent-formatting of strings; there are plenty of people out there > who'll instantly understand that %d will plop in an integer and %s a > string - even some non-programmers know that notation, as it's found > in config files, translation data, etc, etc.) So evidently using notations in the ways they are conventionally used is a good thing. But then when it comes to Steven supporting the violation 500 years* of math conventional usage of '=': On Monday, August 11, 2014 2:45:48 PM UTC+5:30, Chris Angelico wrote: > On Mon, Aug 11, 2014 at 6:55 PM, Steven D'Aprano wrote: > > On Sun, 10 Aug 2014 23:22:45 -0700, Rustom Mody wrote: > >> You think that the '=' sign not standing for math equality is ok. > >> How come? > > For the same reason that in the following: > > [c.upper() for c in some_string if 'a' < c < 'x'] > > having the c symbol not stand for the speed of light is okay. Likewise, > > in the sentence "I went to the park today", the symbol I doesn't mean the > > element iodine. Symbols are context-dependent: the x in one equation is > > not necessarily the same x in another equation, and the symbol = in one > > context does not necessarily have the same meaning as in another context. you are strongly approving. You really need to decide which side you are on! eg Marko disagrees but is fairly consistent: "Whether I like it or not, whether its conventional or not... Quite irrelevant. Its formally defined. I follow the definition. [Browser tabs stay open in case I slip]" But you seem to be hopping between: Its easy, its natural and thats why its so and Its the way it is... Take it or leave it * Robert Recorde invented the '=' and introduced algebra to England in 1557 http://en.wikipedia.org/wiki/Robert_Recorde#Publications From python.list at tim.thechases.com Mon Aug 11 08:30:04 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 11 Aug 2014 07:30:04 -0500 Subject: how to get the ordinal number in list In-Reply-To: References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> Message-ID: <20140811073004.6138f75d@bigbox.christie.dr> On 2014-08-11 07:55, Roy Smith wrote: > > A C programmer asked to swap variables x and y, typically writes > > something like > > > > t = x; x = y; y = t; > > > > Fine, since C cant do better. > > Sure C can do better. > > x = x ^ y > y = y ^ x > x = x ^ y > > Any self-respecting C hacker would write it this way :-) Pish, such redundancy...everyone knows a C programmer would write that as x ^= y y ^= x x ^= y :-) -tkc From alister.nospam.ware at ntlworld.com Mon Aug 11 08:30:13 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Mon, 11 Aug 2014 12:30:13 GMT Subject: how to get the ordinal number in list References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> <53e824b9$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, 11 Aug 2014 12:56:59 +0100, Robert Kern wrote: > On 2014-08-11 03:04, Steven D'Aprano wrote: >> Rustom Mody wrote: >> >>> Its when we have variables that are assigned in multiple places that >>> we start seeing mathematical abominations like x = x+1 >> >> That's not a mathematical abomination. It's a perfectly reasonable >> mathematical equation, one with no solutions since the line f(x) = x >> and the line f(x) = x+1 are parallel. >> >> But what does this have to do with programming? Programming *is not* >> mathematics, and x = x+1 has a different meaning in programming than in >> mathematics. Perhaps it would help if we wrote it using mathematical >> notation? Using [x] for subscripts: >> >> x[n+1] = x[n] + 1 >> >> we have a perfectly good mathematical recursive definition. All it >> needs is an initial value x[0] and we're good to go. > > Or a different operator for assignment (to distinguish it more clearly > from equality, which it isn't). > > x <- x + 1 x := x + 1 It already is a different operator from equality which is == perhaps it would have been better if the behaviour of these two operators were reversed (= for equality & == for assignment) but i suspect that Idea if even considered was quickly discarded as it would cause major confusion to programmers who work with multiple languages -- Meskimen's Law: There's never time to do it right, but there's always time to do it over. From marko at pacujo.net Mon Aug 11 08:41:00 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 11 Aug 2014 15:41:00 +0300 Subject: how to get the ordinal number in list References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> <53e824b9$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87tx5jurkz.fsf@elektro.pacujo.net> alister : > It already is a different operator from equality which is == > > perhaps it would have been better if the behaviour of these two > operators were reversed (= for equality & == for assignment) but i > suspect that Idea if even considered was quickly discarded as it would > cause major confusion to programmers who work with multiple languages Blame it on FORTRAN: X = X + 1 IF (X .EQ. 100) GOTO 999 BASIC took a no-nonsense approach: 5 LET S = 0 10 MAT INPUT V 20 LET N = NUM 30 IF N = 0 THEN 99 40 FOR I = 1 TO N 45 LET S = S + V(I) 50 NEXT I 60 PRINT S/N 70 GO TO 5 99 END () Marko From marko at pacujo.net Mon Aug 11 08:41:33 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 11 Aug 2014 15:41:33 +0300 Subject: how to get the ordinal number in list References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> Message-ID: <87ppg7urk2.fsf@elektro.pacujo.net> Tim Chase : > Pish, such redundancy...everyone knows a C programmer would write > that as > > x ^= y > y ^= x > x ^= y Aren't you forgetting something? Marko From rosuav at gmail.com Mon Aug 11 08:45:37 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Aug 2014 22:45:37 +1000 Subject: how to get the ordinal number in list In-Reply-To: <55a85155-0c7d-4100-94e8-b24d36885289@googlegroups.com> References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> <53e824b9$0$30000$c3e8da3$5496439d@news.astraweb.com> <55a85155-0c7d-4100-94e8-b24d36885289@googlegroups.com> Message-ID: On Mon, Aug 11, 2014 at 10:11 PM, Rustom Mody wrote: > So evidently using notations in the ways they are conventionally used > is a good thing. > > But then when it comes to Steven supporting the violation 500 years* of > math conventional usage of '=': Yep. It's not a violation; it's a modification. Since algebra has no concept of chronology and programming does, some notation must be found which captures this concept. Try explaining complex numbers to someone who has only ever used real numbers, and explain why you violate however-many centuries of conventional usage wherein letters are used for variables, but now you pick one of them and make it a constant. It's an abomination! This "complex" stuff is so utterly wrong compared to "real mathematics", and how dare you even support using symbols the same way in both of them! The double horizontal line is associated with equality. Assignment states that the LHS after this point is equal to the RHS before this point, which is a chronologically modified form of enforced equality. It makes good sense to use the double horizontal line for equality. ChrisA From rosuav at gmail.com Mon Aug 11 08:53:39 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Aug 2014 22:53:39 +1000 Subject: how to get the ordinal number in list In-Reply-To: <87ppg7urk2.fsf@elektro.pacujo.net> References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> <87ppg7urk2.fsf@elektro.pacujo.net> Message-ID: On Mon, Aug 11, 2014 at 10:41 PM, Marko Rauhamaa wrote: > Tim Chase : > >> Pish, such redundancy...everyone knows a C programmer would write >> that as >> >> x ^= y >> y ^= x >> x ^= y > > Aren't you forgetting something? I don't think he is. Those are augmented assignments, just as Python has (although with slightly different semantics in some places). The semicolons can be omitted in some C REPLs, although they are of course mandatory in regular code. ChrisA From breamoreboy at yahoo.co.uk Mon Aug 11 09:45:40 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 11 Aug 2014 14:45:40 +0100 Subject: Python and IDEs [was Re: Python 3 is killing Python] In-Reply-To: <20140811110843.a314bb1b78cda13d26844ab5@gmx.net> References: <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> <20140806144758.f5817ee60d0e98ff30172a2a@gmx.net> <53e2f338$0$29979$c3e8da3$5496439d@news.astraweb.com> <20140811110843.a314bb1b78cda13d26844ab5@gmx.net> Message-ID: On 11/08/2014 10:08, Wolfgang Keller wrote: > >> By the way, you keep replying to people, and quoting them, but >> deleting their name. Please leave the attribution in place, so we >> know who you are replying to. > > That's what the "References:"-Header is there for. > > Sincerely, > > Wolfgang > The references header is conspicious by its absence. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Mon Aug 11 09:48:30 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 11 Aug 2014 14:48:30 +0100 Subject: What's the future of perfect Python? In-Reply-To: <53e88715$0$29890$c3e8da3$5496439d@news.astraweb.com> References: <2afe53e822333cc-00011.Richmail.00052294890130005718@139.com> <53e88715$0$29890$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11/08/2014 10:04, Steven D'Aprano wrote: > On Mon, 11 Aug 2014 13:15:19 +0800, 13813962782 wrote: > >> Just like MANY people, I was one of guys who do very like Python. But >> there's one thing always puzzled me, could you kindly help give some >> words about it: >> >> "Java is belonging to Oracle, C++ is defined by ISO Python is designed >> by great Guido van Rossum then what is the future of Python( Guido van >> Rossum, GREAT man, but STILL just one person)? " > > Haven't you heard? Guido has retired. > > http://legacy.python.org/dev/peps/pep-0401/ > The miserable blighters didn't send a card around for me to sign either. Cheapskates or what? -- 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 Aug 11 09:57:38 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 11 Aug 2014 14:57:38 +0100 Subject: how to get the ordinal number in list In-Reply-To: <20140811073004.6138f75d@bigbox.christie.dr> References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> <20140811073004.6138f75d@bigbox.christie.dr> Message-ID: On 11/08/2014 13:30, Tim Chase wrote: > On 2014-08-11 07:55, Roy Smith wrote: >>> A C programmer asked to swap variables x and y, typically writes >>> something like >>> >>> t = x; x = y; y = t; >>> >>> Fine, since C cant do better. >> >> Sure C can do better. >> >> x = x ^ y >> y = y ^ x >> x = x ^ y >> >> Any self-respecting C hacker would write it this way :-) > > Pish, such redundancy...everyone knows a C programmer would write > that as > > x ^= y > y ^= x > x ^= y > > :-) > > -tkc > That says the LHS is assigned the RHS rotated by some angle, which I'll assume to be 90 degrees clockwise, yes? Well I don't suppose it really matters for x as it'll still be x when it gets assigned to y, but what would you call the shift on y that gets assigned to x? -- 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 Aug 11 10:01:56 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 11 Aug 2014 15:01:56 +0100 Subject: how to get the ordinal number in list In-Reply-To: <55a85155-0c7d-4100-94e8-b24d36885289@googlegroups.com> References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> <53e824b9$0$30000$c3e8da3$5496439d@news.astraweb.com> <55a85155-0c7d-4100-94e8-b24d36885289@googlegroups.com> Message-ID: On 11/08/2014 13:11, Rustom Mody wrote: > > But then when it comes to Steven supporting the violation 500 years* of > math conventional usage of '=': > I have no interest in the maths convention (see, you don't even know the original, correct English, math indeed). Of far more importance in the real world is the Irish navvy convention. Are there any such people lurking here who can give us the required insight? -- 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 Mon Aug 11 10:02:42 2014 From: torriem at gmail.com (Michael Torrie) Date: Mon, 11 Aug 2014 08:02:42 -0600 Subject: attendance system in pybluez In-Reply-To: <53E6E1EB.20109@gmail.com> References: <53e60ba8$0$29968$c3e8da3$5496439d@news.astraweb.com> <53E6E1EB.20109@gmail.com> Message-ID: <53E8CD02.2020906@gmail.com> On 08/09/2014 09:07 PM, luofeiyu wrote: > in the http://homepages.ius.edu/rwisman/C490/html/PythonandBluetooth.htm > > *Discovery* That only works for phones if the phones are manually switched to discoverable mode, which is off by default for security reasons. By default they are not going to show up on your discovery scans. From robin at reportlab.com Mon Aug 11 10:32:47 2014 From: robin at reportlab.com (Robin Becker) Date: Mon, 11 Aug 2014 15:32:47 +0100 Subject: how to get the ordinal number in list In-Reply-To: References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> <53e824b9$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53E8D40F.8000007@chamonix.reportlab.co.uk> On 11/08/2014 13:30, alister wrote: > It already is a different operator from equality which is == > > perhaps it would have been better if the behaviour of these two operators > were reversed (= for equality & == for assignment) but i suspect that > Idea if even considered was quickly discarded as it would cause major > confusion to programmers who work with multiple languages Of course Python can be even more confusing so that for example >>> class NeverEqual(int): ... def __new__(cls,v): ... self = int.__new__(cls,v) ... return self ... def __eq__(self,other): ... return False ... >>> a=NeverEqual(1) >>> a 1 >>> a==1 False >>> a==a False >>> not (a != a) True >>> a!=a False >>> so I think that assignment doesn't always make things equal even chronologically. -- Robin Becker From breamoreboy at yahoo.co.uk Mon Aug 11 10:56:43 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 11 Aug 2014 15:56:43 +0100 Subject: Nuitka Release 0.5.4 Message-ID: To me rather more interesting than discussing the relative merits of '=' compared to '==', '<=' or ':='. See here http://nuitka.net/posts/nuitka-release-054.html -- 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 Aug 11 12:07:03 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 12 Aug 2014 02:07:03 +1000 Subject: Is print thread safe? References: <53e87451$0$29890$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53e8ea27$0$29981$c3e8da3$5496439d@news.astraweb.com> INADA Naoki wrote: > On Python 3, print is thread safe. > > But Python 2 has broken scenario: Is this documented somewhere? -- Steven From invalid at invalid.invalid Mon Aug 11 14:39:28 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 11 Aug 2014 18:39:28 +0000 (UTC) Subject: Python and IDEs [was Re: Python 3 is killing Python] References: <87zjga4j4v.fsf@elektro.pacujo.net> <53c57bae$0$9505$c3e8da3$5496439d@news.astraweb.com> <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> <20140806144717.8847deb8b0bea888b89d814b@gmx.net> Message-ID: On 2014-08-06, Wolfgang Keller wrote: >> > Because on such operating systems, each and every application is an >> > entirely self-contained package that doesn't need any "packages" or >> > "installers" to use it. > >> For people who have never used such a system it's probably difficult >> to see the advantages. > > That's the whole point. > > The problem is that the ones who "decide" (well, they pretend to, but > actually can't, because they don't know the alternatives) are always > people who are "not even clueless". Ha! I love it. I presume that's an allusion to that-other-Wolfgang's apocryphal "not even wrong" comment. :) -- Grant Edwards grant.b.edwards Yow! I want to mail a at bronzed artichoke to gmail.com Nicaragua! From invalid at invalid.invalid Mon Aug 11 14:42:22 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 11 Aug 2014 18:42:22 +0000 (UTC) Subject: Python and IDEs [was Re: Python 3 is killing Python] References: <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> <20140806144758.f5817ee60d0e98ff30172a2a@gmx.net> <53e2f338$0$29979$c3e8da3$5496439d@news.astraweb.com> <20140811110843.a314bb1b78cda13d26844ab5@gmx.net> Message-ID: On 2014-08-11, Wolfgang Keller wrote: > [somebody, but we don't know who, wrote]... >> By the way, you keep replying to people, and quoting them, but >> deleting their name. Please leave the attribution in place, so we >> know who you are replying to. > > That's what the "References:"-Header is there for. Your over-confidence in Usenet, mailing list archives, news-to-mail gateways, and various client applications is showing... -- Grant Edwards grant.b.edwards Yow! Can I have an IMPULSE at ITEM instead? gmail.com From invalid at invalid.invalid Mon Aug 11 14:53:57 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 11 Aug 2014 18:53:57 +0000 (UTC) Subject: Linux distros w/o Python in "base" installation Message-ID: I just installed Arch Linux for the first time, and was surprosed to find that Python isn't installed as part of a "base" system. It's also not included in the 'base-devel' package group. It's trivial to install, but I'd still pretty surprised it's not there by default. I guess I've spent too much time with Gentoo, Debian, and RedHat derivitives which require Python be installed. I've probably used at least a dozen Linux distros over the years, and this is the first time I've noticed that Python wasn't installed by default. Just for the sake of curiosity, are there any other significant desktop/server Linux distros that don't come "out of the box" with Python? -- Grant Edwards grant.b.edwards Yow! If I am elected no one at will ever have to do their gmail.com laundry again! From clp2 at rebertia.com Mon Aug 11 15:02:07 2014 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 11 Aug 2014 12:02:07 -0700 Subject: Linux distros w/o Python in "base" installation In-Reply-To: References: Message-ID: On Mon, Aug 11, 2014 at 11:53 AM, Grant Edwards wrote: > I just installed Arch Linux for the first time, and was surprosed to > find that Python isn't installed as part of a "base" system. It's > also not included in the 'base-devel' package group. It's trivial to > install, but I'd still pretty surprised it's not there by default. I > guess I've spent too much time with Gentoo, Debian, and RedHat > derivitives which require Python be installed. > > I've probably used at least a dozen Linux distros over the years, and > this is the first time I've noticed that Python wasn't installed by > default. > > Just for the sake of curiosity, are there any other significant > desktop/server Linux distros that don't come "out of the box" with > Python? It would seem that such distros are opting to not be LSB-compliant?: http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Languages/LSB-Languages/pylocation.html Cheers, Chris From invalid at invalid.invalid Mon Aug 11 16:13:18 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 11 Aug 2014 20:13:18 +0000 (UTC) Subject: Linux distros w/o Python in "base" installation References: Message-ID: On 2014-08-11, Chris Rebert wrote: > On Mon, Aug 11, 2014 at 11:53 AM, Grant Edwards wrote: >> I just installed Arch Linux for the first time, and was surprosed to >> find that Python isn't installed as part of a "base" system. It's >> also not included in the 'base-devel' package group. It's trivial to >> install, but I'd still pretty surprised it's not there by default. I >> guess I've spent too much time with Gentoo, Debian, and RedHat >> derivitives which require Python be installed. >> >> I've probably used at least a dozen Linux distros over the years, and >> this is the first time I've noticed that Python wasn't installed by >> default. >> >> Just for the sake of curiosity, are there any other significant >> desktop/server Linux distros that don't come "out of the box" with >> Python? > > It would seem that such distros are opting to not be LSB-compliant?: > http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Languages/LSB-Languages/pylocation.html Apparently. Perhaps theres an "enable LSB compliance" option somewhere in the Arch install docs, but I didn't see it... -- Grant Edwards grant.b.edwards Yow! Somewhere in Tenafly, at New Jersey, a chiropractor gmail.com is viewing "Leave it to Beaver"! From thequietcenter at gmail.com Mon Aug 11 16:26:11 2014 From: thequietcenter at gmail.com (thequietcenter at gmail.com) Date: Mon, 11 Aug 2014 13:26:11 -0700 (PDT) Subject: Python Object Systems Message-ID: <2d41828e-19ac-4e46-a487-8700c22d9b92@googlegroups.com> (Cross-posted from http://www.reddit.com/r/Python/comments/2d9f7i/survey_of_python_object_systems/) Hello, has anyone created a survey of Python Object Systems? The two I am aware of are: - elk https://github.com/frasertweedale/elk - Traits http://code.enthought.com/projects/traits/ From skip at pobox.com Mon Aug 11 16:37:29 2014 From: skip at pobox.com (Skip Montanaro) Date: Mon, 11 Aug 2014 15:37:29 -0500 Subject: Python Object Systems In-Reply-To: <2d41828e-19ac-4e46-a487-8700c22d9b92@googlegroups.com> References: <2d41828e-19ac-4e46-a487-8700c22d9b92@googlegroups.com> Message-ID: On Mon, Aug 11, 2014 at 3:26 PM, wrote: > has anyone created a survey of Python Object Systems? For the uninitiated, can you back up a step and define what you mean by an "object system"? The term seems kind of broad for Google ( number of hits for CLOS, etc), and Wikipedia just directs to a page on object-oriented programming. Thx, Skip From thequietcenter at gmail.com Mon Aug 11 17:02:37 2014 From: thequietcenter at gmail.com (thequietcenter at gmail.com) Date: Mon, 11 Aug 2014 14:02:37 -0700 (PDT) Subject: Python Object Systems In-Reply-To: References: <2d41828e-19ac-4e46-a487-8700c22d9b92@googlegroups.com> Message-ID: <66c2838c-0658-4fcf-a27f-bb80a9c141e3@googlegroups.com> On Monday, August 11, 2014 4:37:29 PM UTC-4, Skip Montanaro wrote: > On Mon, Aug 11, 2014 at 3:26 PM, wrote: > > > has anyone created a survey of Python Object Systems? > > > > For the uninitiated, can you back up a step and define what you mean > > by an "object system"? I mean a system by which one creates and manages Python objects. For instance, Python ships with an object system as documented here: https://docs.python.org/2/tutorial/classes.html However, some developers have found the need to add features to the standard Python object system (e.g. delegation, typing, etc), thus offering a new object system. So far, the following object systems have been found: * elk https://github.com/frasertweedale/elk * Traits http://code.enthought.com/projects/traits/ * yuppy https://github.com/kuujo/yuppy -- Terrence From marko at pacujo.net Mon Aug 11 17:09:35 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 12 Aug 2014 00:09:35 +0300 Subject: Python Object Systems References: <2d41828e-19ac-4e46-a487-8700c22d9b92@googlegroups.com> Message-ID: <871tsmg2cw.fsf@elektro.pacujo.net> Skip Montanaro : > On Mon, Aug 11, 2014 at 3:26 PM, wrote: >> has anyone created a survey of Python Object Systems? > > For the uninitiated, can you back up a step and define what you mean > by an "object system"? Elk and Traits implement a C++-style object model on top of Python. The systems enforce member access, type constraints etc and result in ugly code that barely looks like Python. Marko From thequietcenter at gmail.com Mon Aug 11 17:26:03 2014 From: thequietcenter at gmail.com (thequietcenter at gmail.com) Date: Mon, 11 Aug 2014 14:26:03 -0700 (PDT) Subject: Python Object Systems In-Reply-To: <871tsmg2cw.fsf@elektro.pacujo.net> References: <2d41828e-19ac-4e46-a487-8700c22d9b92@googlegroups.com> <871tsmg2cw.fsf@elektro.pacujo.net> Message-ID: <1b08b207-1eef-4da2-9b81-ca997079d293@googlegroups.com> On Monday, August 11, 2014 5:09:35 PM UTC-4, Marko Rauhamaa wrote: > > Elk and Traits implement a C++-style object model on top of Python. The > > systems enforce member access, type constraints etc and result in ugly > > code that barely looks like Python. I personally get tired of manually assigning attributes in a __init__() method. So at the bare minimum something like Atom will do if nothing else: https://github.com/nucleic/atom And I imagine yuppy would make you upchuck as well: https://github.com/kuujo/yuppy From nad at acm.org Mon Aug 11 17:36:46 2014 From: nad at acm.org (Ned Deily) Date: Mon, 11 Aug 2014 14:36:46 -0700 Subject: Linux distros w/o Python in "base" installation References: Message-ID: In article , Grant Edwards wrote: > Apparently. Perhaps theres an "enable LSB compliance" option > somewhere in the Arch install docs, but I didn't see it... Also beware that, unlike most other distributions and contrary to recommended practice, Arch has chosen to make Python 3 its default, that is, when everything is installed, `python` invokes `python3`, rather than `python2`. So you may need to change shebang lines in scripts, etc. https://wiki.archlinux.org/index.php/python -- Ned Deily, nad at acm.org From breamoreboy at yahoo.co.uk Mon Aug 11 17:51:09 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 11 Aug 2014 22:51:09 +0100 Subject: Python Object Systems In-Reply-To: <1b08b207-1eef-4da2-9b81-ca997079d293@googlegroups.com> References: <2d41828e-19ac-4e46-a487-8700c22d9b92@googlegroups.com> <871tsmg2cw.fsf@elektro.pacujo.net> <1b08b207-1eef-4da2-9b81-ca997079d293@googlegroups.com> Message-ID: On 11/08/2014 22:26, thequietcenter at gmail.com wrote: > On Monday, August 11, 2014 5:09:35 PM UTC-4, Marko Rauhamaa wrote: > >> >> Elk and Traits implement a C++-style object model on top of Python. The >> >> systems enforce member access, type constraints etc and result in ugly >> >> code that barely looks like Python. > > I personally get tired of manually assigning attributes in a __init__() method. So at the bare minimum something like Atom will do if nothing else: > > https://github.com/nucleic/atom > > And I imagine yuppy would make you upchuck as well: > https://github.com/kuujo/yuppy > Would you please read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the double line spacing and single line paragraphs above, thanks. -- 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 Aug 11 17:51:01 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 12 Aug 2014 00:51:01 +0300 Subject: Python Object Systems References: <2d41828e-19ac-4e46-a487-8700c22d9b92@googlegroups.com> <871tsmg2cw.fsf@elektro.pacujo.net> <1b08b207-1eef-4da2-9b81-ca997079d293@googlegroups.com> Message-ID: <87sil2elve.fsf@elektro.pacujo.net> thequietcenter at gmail.com: > I personally get tired of manually assigning attributes in a > __init__() method. It's not all that bad. Just do it. Marko From tjreedy at udel.edu Mon Aug 11 18:01:25 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 11 Aug 2014 18:01:25 -0400 Subject: how to get the ordinal number in list In-Reply-To: <53E8D40F.8000007@chamonix.reportlab.co.uk> References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> <53e824b9$0$30000$c3e8da3$5496439d@news.astraweb.com> <53E8D40F.8000007@chamonix.reportlab.co.uk> Message-ID: > On 11/08/2014 13:30, alister wrote: >> It already is a different operator from equality which is == Mathematicians use '=' for name binding all the time, with and without 'let': Let u = x + y, v = x - y. Then ... . However, name binding itself is a mental operation, not a mathematical one. Mathematicians sometimes differentiate conditionally true expressions from necessarily true expressions (tautologies, 'identically true') by using triple bars for the latter. In algebra, (a+b)(a-b) a*a-b*b. I think the sense of the extra bar is 'really equal, not just contingently equal). Mathematicians sometimes use ':=' for definitions and sometimes decorate '=' in various other ways. Unicode has most of them. So mathematicians do not always use plain '=' for various ideas of sameness. >> perhaps it would have been better if the behaviour of these two operators >> were reversed (= for equality & == for assignment) but i suspect that >> Idea if even considered was quickly discarded as it would cause major >> confusion to programmers who work with multiple languages. Given that assignment occurs more often than equality testing, it makes sense to use the shorter coding for assignment. This principle operates in natural language (English at least) and in various codings from Morse to Huffman. -- Terry Jan Reedy From invalid at invalid.invalid Mon Aug 11 18:08:21 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 11 Aug 2014 22:08:21 +0000 (UTC) Subject: Keep one GUI always on TOP while python code is running References: Message-ID: On 2014-08-07, Jaydeep Patil wrote: > I have one query. I have did some programming which copies and paste > data using system clipboard. I need to keep one GUI always on top > till my python code is running. If you mean keep it on top while it is running, the answer is probably yes, but how to do it depends on the OS, windowing syste, and tookit in use. However, doing so is pure evil and will cause users to wish bad things upon you and all your family and descendants. If you want to make some particular dialog the only one from your app that can be used, that's fine, but don't try to override the user's desire to put other applications on top of yours or to even control the ordering of windows within your app. Thinking your app is so important that it can take over the entire desktop and needs to control what window is on top is just plain bad [not that it's unusual for windows apps]. -- Grant Edwards grant.b.edwards Yow! !! I am having fun!!! at gmail.com From invalid at invalid.invalid Mon Aug 11 18:14:12 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 11 Aug 2014 22:14:12 +0000 (UTC) Subject: Keep one GUI always on TOP while python code is running References: <32f85c79-17a1-4d2f-a926-43812b8083ed@googlegroups.com> <85fvh7icj4.fsf@rudin.co.uk> <53e4d7a0$0$24963$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2014-08-08, Chris Angelico wrote: > On Fri, Aug 8, 2014 at 11:58 PM, Steven D'Aprano > Why should that disable access to everything else? Most full screen > games let you alt-tab away from them (preferably auto-pausing the > game). If a game goes system modal on me, I would not be happy. > >> * my application is SOOOOO SPECIAL that it deserves to take over the >> entire GUI Just Because I Can. > > And that one is definitely not a reason, as I'm sure you agree :) But, AFAICT, that's the only reason behind the behavior for a lot of Windows apps. Authors of X apps don't seem to suffer from such delusions of grandeur (or maybe it's just too hard under under X). My opinion is that people with valid reasons to use a system-modal window don't need to ask how. IOW asking how to do it is pimae-facie evidence that you should not be doing it. -- Grant Edwards grant.b.edwards Yow! PIZZA!! at gmail.com From cs at zip.com.au Mon Aug 11 17:53:11 2014 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 12 Aug 2014 07:53:11 +1000 Subject: Is print thread safe? In-Reply-To: <53e8ea27$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <53e8ea27$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20140811215311.GA35466@cskk.homeip.net> On 12Aug2014 02:07, Steven D'Aprano wrote: >INADA Naoki wrote: > >> On Python 3, print is thread safe. >> But Python 2 has broken scenario: > >Is this documented somewhere? In python/2.7.6/reference/simple_stmts.html#index-22, "print" is described in terms of a "write" for each object, and a "write" for the separators. There is no mention of locking. On that basis, I would find the interleaving described normal and expected. And certainly not "broken". Just use a lock! And rebind "print"! Or use the logging system! Cheers, Cameron Simpson Wow! Yet another place that I've been quoted... - Andy Beals From breamoreboy at yahoo.co.uk Mon Aug 11 18:54:20 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 11 Aug 2014 23:54:20 +0100 Subject: converting ISO8601 date and time string representations to datetime In-Reply-To: References: Message-ID: On 31/07/2014 10:11, Wolfgang Maier wrote: > Hi, > I'm trying to convert ISO8601-compliant strings representing dates or > dates and times into datetime.datetime objects. > I tried using the strptime method, but the problem here is that I can > only specify one format argument, which can be used to parse either a > full date/time string or just a date string, but not both. > > While I could just try parsing with one format, then catch the > ValueError in case it fails and try another format, it feels like there > should be a more elegant way to do this. > > I do know about the dateutil package, but I'd prefer to stick to the > stdlib for this. > > Any suggestions ? > > Wolfgang > If you're not sorted via stdlib how about http://crsmithdev.com/arrow/ ? Haven't tried it myself as I've only just come across it. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From invalid at invalid.invalid Mon Aug 11 18:58:52 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 11 Aug 2014 22:58:52 +0000 (UTC) Subject: how to write file into my android phone? References: <53E660BF.7080401@gmail.com> <53e73de8$0$24963$c3e8da3$5496439d@news.astraweb.com> <871tsohdlp.fsf@elektro.pacujo.net> Message-ID: On 2014-08-10, Marko Rauhamaa wrote: > Christian Gollwitzer : > >> Am 10.08.14 11:39, schrieb Steven D'Aprano: >>> Android phones don't mount as storage devices? >>> Oh well, that's Android crossed off my list. >> >> Not any longer. They used to, but the support for mass storage was >> dropped in favour of MTP > > I don't see anything inherently wrong with an open protocol like MTP. > >> to allow concurrent access from both the computer and the phone. > > I don't know MTP at all, but > > MTP allows no parallelism; unlike USB mass storage, MTP has been > built to only allow a single operation at a time (for example, read, > write or delete operation), while no other operation can be executed > until the previous operation is complete. > That's the within MTP protocol itself, and that's not the "prallel access" problem which MTP was intended to address. What MTP allows is parallel access between the MTP protocol server in the phone and the rest of the phone (OS and apps). In order to mount a partition as a USB mass storage device, it has to first be unmounted by the Android system. That's OK for an SD card that doesn't contain anything important required by the Android system, but it means that you can't mount the "system" partition without shutting down the phone completely. For phones that don't have an SD card, there is nothing _but_ the system partition, and to mount it as a USB storage device you would have to completely shut down the phone. People don't like that. They want to keep the phone on while their doing with their MP3 files and JPEG files and whatnot. The only practical way to do that is to define a file transfer protocol that doesn't require the entire parition be unmounted by the phone. Hence MTP. It's something Microsoft came up with, so it of course has their usual level of "broken-as-designed" about it, but in general it works fairly well. For Linux systems there's a user-space MTP filesystem implementation that has always worked fine for me. So in practice, it works just like as somewhat slow USB mass storage device. -- Grant Edwards grant.b.edwards Yow! Now I understand the at meaning of "THE MOD SQUAD"! gmail.com From breamoreboy at yahoo.co.uk Mon Aug 11 18:57:08 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 11 Aug 2014 23:57:08 +0100 Subject: converting ISO8601 date and time string representations to datetime In-Reply-To: References: <53DB3931.8070406@biologie.uni-freiburg.de> <8738df7gav.fsf@gmail.com> Message-ID: On 06/08/2014 20:05, Skip Montanaro wrote: > On Wed, Aug 6, 2014 at 1:31 PM, Joel Goldstick wrote: >> Among other features it lists this: Gaps in functionality: ISO-8601 >> parsing, timespans, humanization > > What is "humanization"? > > Skip > Presumably as in https://pypi.python.org/pypi/humanize The page states "This modest package contains various common humanization utilities, like turning a number into a fuzzy human readable duration ('3 minutes ago') or into a human readable size or throughput. It works with python 2.7 and 3.3 and is localized to Russian, French, and Korean." -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From mcfletch at vrplumber.com Mon Aug 11 18:56:11 2014 From: mcfletch at vrplumber.com (Mike C. Fletcher) Date: Mon, 11 Aug 2014 18:56:11 -0400 Subject: Python Object Systems In-Reply-To: <2d41828e-19ac-4e46-a487-8700c22d9b92@googlegroups.com> References: <2d41828e-19ac-4e46-a487-8700c22d9b92@googlegroups.com> Message-ID: <53E94A0B.9050700@vrplumber.com> On 14-08-11 04:26 PM, thequietcenter at gmail.com wrote: ... > Hello, has anyone created a survey of Python Object Systems? The two I am aware of are: > > - elk https://github.com/frasertweedale/elk > - Traits http://code.enthought.com/projects/traits/ Here's the ones from my talk at Pycon 2005 (http://www.vrplumber.com/programming/descriptors-pycon2005.pdf): OpenGLContext/PyVRML97 http://bazaar.launchpad.net/~mcfletch/pyvrml97/trunk/files Observable, auto-coercing data properties w/ Numeric/numpy array support, defaults BasicProperty (now largely abandoned): http://bazaar.launchpad.net/~mcfletch/basicproperty/trunk/files Again, observable auto-coercing typed properties, defaults, introspection Zope2 FieldProperty, DublinCore, Validation, Observability PEAK Defaults, delegation, implicit feature loading Traits Delegation, typing, validation, defaults, Observability, introspection PyObjc, ctypes, JythonC, IronPython Function-like things with lots of metadata There's also a listing of the other tasks for which descriptors/object systems were expected to show up at the time, if you look for Python + that key-word you'll likely find a few dozen more "object systems" out there. You'll also likely find about a thousand metaclasses these days. HTH, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From rosuav at gmail.com Mon Aug 11 19:27:15 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Aug 2014 09:27:15 +1000 Subject: how to get the ordinal number in list In-Reply-To: <53E8D40F.8000007@chamonix.reportlab.co.uk> References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> <53e824b9$0$30000$c3e8da3$5496439d@news.astraweb.com> <53E8D40F.8000007@chamonix.reportlab.co.uk> Message-ID: On Tue, Aug 12, 2014 at 12:32 AM, Robin Becker wrote: > Of course Python can be even more confusing so that for example > >>>> class NeverEqual(int): > ... def __new__(cls,v): > ... self = int.__new__(cls,v) > ... return self > ... def __eq__(self,other): > ... return False > ... >>>> a=NeverEqual(1) >>>> a > 1 >>>> a==1 > False >>>> a==a > False >>>> not (a != a) > True >>>> a!=a > False >>>> > > so I think that assignment doesn't always make things equal even > chronologically. Sure, but at this point you're fiddling with the definition of equality, and Python has never stopped you from shooting yourself in the foot :) There are less contrived examples, too, like those involving floating-point round-off, which basically prove that Python's equality comparison is not the same as mathematical equality; but that doesn't stop people from comprehending that "1 + 3 == 2 + 2" in Python based on their knowledge of mathematics. ChrisA From rosuav at gmail.com Mon Aug 11 19:35:56 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Aug 2014 09:35:56 +1000 Subject: Linux distros w/o Python in "base" installation In-Reply-To: References: Message-ID: On Tue, Aug 12, 2014 at 7:36 AM, Ned Deily wrote: > In article , > Grant Edwards wrote: >> Apparently. Perhaps theres an "enable LSB compliance" option >> somewhere in the Arch install docs, but I didn't see it... > > Also beware that, unlike most other distributions and contrary to > recommended practice, Arch has chosen to make Python 3 its default, that > is, when everything is installed, `python` invokes `python3`, rather > than `python2`. So you may need to change shebang lines in scripts, etc. > > https://wiki.archlinux.org/index.php/python Well, it only *became* contrary to recommended practice in response to Arch doing it and everyone seeing the issues it caused :) Personally, I'm glad they did. Lets those of us who follow "slower" distros (I'm running Debian) get the benefit of someone else's hindsight. ChrisA From steve+comp.lang.python at pearwood.info Mon Aug 11 19:56:42 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 12 Aug 2014 09:56:42 +1000 Subject: Is print thread safe? References: <53e8ea27$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53e9583b$0$29973$c3e8da3$5496439d@news.astraweb.com> Cameron Simpson wrote: > On 12Aug2014 02:07, Steven D'Aprano > wrote: >>INADA Naoki wrote: >> >>> On Python 3, print is thread safe. >>> But Python 2 has broken scenario: >> >>Is this documented somewhere? > > In python/2.7.6/reference/simple_stmts.html#index-22, "print" is described > in terms of a "write" for each object, and a "write" for the separators. > There is no mention of locking. Ah, thanks! > On that basis, I would find the interleaving described normal and > expected. And certainly not "broken". I personally didn't describe it as "broken", but it is, despite the documentation. I just ran a couple of trials where I collected the output of sys.stdout while 50 threads blasted "Spam ABCD EFGH" (plus the implicit newline) to stdout as fast as possible using print. The result was that out of 248165 lines[1], 595 were mangled. Many of the mangled lines were the expected simple run-ons: Spam ABCD EFGHSpam ABCD EFGH\n\n which makes sense given the documentation, but there were lots of anomalies. Mysterious spaces appearing in the strings: Spam ABCD EFGH Spam ABCD EFGH\n\n Spam ABCD EFGH Spam ABCD EFGH\n Spam ABCD EFGH\n occasional collisions mid-string: Spam ABSpam ABCD EFGH\nCD EFGH\n letters disappearing: Spam AB\nD EFGH\n and at least one utterly perplexing (to me) block of ASCII NULs appearing in the middle of the output: \x00\x00\x00...\x00\x00\n This is with Python 2.7.2 on Linux. > Just use a lock! And rebind "print"! Or use the logging system! Personally, I believe that print ought to do its own locking. And print is a statement, although in this case there's no need to support anything older than 2.6, so something like this ought to work: from __future__ import print_function _print = print _rlock = threading.RLock() def print(*args, **kwargs): with _rlock: _print(*args, **kwargs) Sadly, using print as a function alone isn't enough to fix this problem, but in my quick tests, using locking as above does fix it, and with no appreciable slowdown. [1] Even the number of lines of output demonstrates a bug. I had fifty threads printing 5000 times each, which makes 250000 lines, not 248165. -- Steven From rosuav at gmail.com Mon Aug 11 20:14:29 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Aug 2014 10:14:29 +1000 Subject: Is print thread safe? In-Reply-To: <53e9583b$0$29973$c3e8da3$5496439d@news.astraweb.com> References: <53e8ea27$0$29981$c3e8da3$5496439d@news.astraweb.com> <53e9583b$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Aug 12, 2014 at 9:56 AM, Steven D'Aprano wrote: > from __future__ import print_function > > _print = print > _rlock = threading.RLock() > def print(*args, **kwargs): > with _rlock: > _print(*args, **kwargs) You're conflating print and stdout here. Do you know which one is the cause of your problems? Alternatively, can you be certain that you never use either without the other? ChrisA From steve+comp.lang.python at pearwood.info Mon Aug 11 20:11:01 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 12 Aug 2014 10:11:01 +1000 Subject: Python and IDEs [was Re: Python 3 is killing Python] References: <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> <20140806144758.f5817ee60d0e98ff30172a2a@gmx.net> <53e2f338$0$29979$c3e8da3$5496439d@news.astraweb.com> <20140811110843.a314bb1b78cda13d26844ab5@gmx.net> Message-ID: <53e95b96$0$30002$c3e8da3$5496439d@news.astraweb.com> Wolfgang Keller wrote: >> By the way, you keep replying to people, and quoting them, but >> deleting their name. Please leave the attribution in place, so we >> know who you are replying to. > > That's what the "References:"-Header is there for. The References header is for the benefit of news and mail clients, not human readers. Giving attribution in the body of your text is for the benefit of people reading your reply, and I maintain that people are far more important than your news or mail client. It is rude to deliberately refuse to give attributes: - you're saying that the person you are replying to doesn't deserve to have their identity acknowledged even in passing; - you're saying that you expect all of your readers to spend significant time and effort to follow the machine references in the headers if they want to understand who you are talking to, just to save you the one-off cost of turning on the phrase used when replying, which every mail and news client I know of supports (including Sylpheed); - you are saying that anyone reading this forum via unthreaded web archives don't matter; - and anyone who (for one reason or another) is missing some of the referenced posts, possibly because they have expired, or were never delivered in the first place. So please stop being rude, and follow the convention of both email and usenet (as well as broader society) to give attribution to those you quote. -- Steven From python.list at tim.thechases.com Mon Aug 11 20:27:25 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 11 Aug 2014 19:27:25 -0500 Subject: Quoting and attribution (was: Python and IDEs [was Re: Python 3 is killing Python]) In-Reply-To: <53e95b96$0$30002$c3e8da3$5496439d@news.astraweb.com> References: <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> <20140806144758.f5817ee60d0e98ff30172a2a@gmx.net> <53e2f338$0$29979$c3e8da3$5496439d@news.astraweb.com> <20140811110843.a314bb1b78cda13d26844ab5@gmx.net> <53e95b96$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20140811192725.314aa946@bigbox.christie.dr> On 2014-08-12 10:11, Steven D'Aprano wrote: > It is rude to deliberately refuse to give attributes While I find this true for first-level attribution, I feel far less obligation to attribute additional levels (and the verbosity they entail). If the reader is really that interested in who said what, then they can go back to previous posts to disinter that information. I find that On 2013-12-14 Ian Paul Freely wrote: > On 2014-12-11 Xavier Onasis wrote: >> On 2014-12-10 Pat McCann wrote: >>> On 2014-12-09 Mike Easter wrote: >>>> Lunch for Mary's birthday? >>> >>> How's Wednesday? >> >> Wed is good, what time? > > Earlier is better for me. 11:30? How about at that little Greek place on 4th Street? could just credit Ian and snip out the other attributions for the sake of quoting just the parts that I find matter. On 2013-12-14 Ian Paul Freely wrote: >>>> Lunch for Mary's birthday? >>> >>> How's Wednesday? >> >> Wed is good, what time? > > Earlier is better for me. 11:30? How about at that little Greek place on 4th Street? If I really care about who was associated with more historical comments, I'll pull up my message history and read the details. -tkc From steve at pearwood.info Mon Aug 11 22:07:07 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 12 Aug 2014 02:07:07 GMT Subject: Quoting and attribution (was: Python and IDEs [was Re: Python 3 is killing Python]) References: <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> <20140806144758.f5817ee60d0e98ff30172a2a@gmx.net> <53e2f338$0$29979$c3e8da3$5496439d@news.astraweb.com> <20140811110843.a314bb1b78cda13d26844ab5@gmx.net> <53e95b96$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53e976cb$0$29890$c3e8da3$5496439d@news.astraweb.com> On Mon, 11 Aug 2014 19:27:25 -0500, Tim Chase wrote: > On 2014-08-12 10:11, Steven D'Aprano wrote: >> It is rude to deliberately refuse to give attributes > > While I find this true for first-level attribution, I feel far less > obligation to attribute additional levels (and the verbosity they > entail). If the reader is really that interested in who said what, then > they can go back to previous posts to disinter that information. I cannot disagree with that. I consider that the first-level attribution MUST be given, second-level SHOULD be given, and third- and subsequent levels MAY be given, where MUST/SHOULD/MAY have their conventional meanings from RFC 2119. https://www.ietf.org/rfc/rfc2119.txt With one proviso: if you respond *directly* to something quoted at the Nth-level, for any N, (as opposed to merely leaving it in to establish context), then you MUST given an attribution. Even if that attribution is just "Sorry, I don't know who said this", you ought to make an honest effort to give credit to those you quote directly. -- Steven From rosuav at gmail.com Mon Aug 11 22:13:14 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Aug 2014 12:13:14 +1000 Subject: Quoting and attribution (was: Python and IDEs [was Re: Python 3 is killing Python]) In-Reply-To: <53e976cb$0$29890$c3e8da3$5496439d@news.astraweb.com> References: <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> <20140806144758.f5817ee60d0e98ff30172a2a@gmx.net> <53e2f338$0$29979$c3e8da3$5496439d@news.astraweb.com> <20140811110843.a314bb1b78cda13d26844ab5@gmx.net> <53e95b96$0$30002$c3e8da3$5496439d@news.astraweb.com> <53e976cb$0$29890$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Aug 12, 2014 at 12:07 PM, Steven D'Aprano wrote: > I cannot disagree with that. I consider that the first-level attribution > MUST be given, second-level SHOULD be given, and third- and subsequent > levels MAY be given, where MUST/SHOULD/MAY have their conventional > meanings from RFC 2119. > > https://www.ietf.org/rfc/rfc2119.txt That's fair. It's also very easy to give first-level attribution (just set your client up properly and that's that), while giving second-level means carefully retaining it from upstream. If it's easy (if you're quoting the beginning of the quote), then it's still of value, but it's not as important as first-level. ChrisA From python.list at tim.thechases.com Mon Aug 11 22:23:10 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 11 Aug 2014 21:23:10 -0500 Subject: Quoting and attribution (was: Python and IDEs [was Re: Python 3 is killing Python]) In-Reply-To: <53e976cb$0$29890$c3e8da3$5496439d@news.astraweb.com> References: <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> <20140806144758.f5817ee60d0e98ff30172a2a@gmx.net> <53e2f338$0$29979$c3e8da3$5496439d@news.astraweb.com> <20140811110843.a314bb1b78cda13d26844ab5@gmx.net> <53e95b96$0$30002$c3e8da3$5496439d@news.astraweb.com> <53e976cb$0$29890$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20140811212310.15067e13@bigbox.christie.dr> On 2014-08-12 02:07, Steven D'Aprano wrote: > >> It is rude to deliberately refuse to give attributes > > > > While I find this true for first-level attribution, I feel far > > less obligation to attribute additional levels (and the verbosity > > they entail). > > I cannot disagree with that. I consider that the first-level > attribution MUST be given, second-level SHOULD be given, and third- > and subsequent levels MAY be given > > With one proviso: if you respond *directly* to something quoted at > the Nth-level, for any N, (as opposed to merely leaving it in to > establish context), then you MUST given an attribution. For these case, I tend to do it interlinearly with my response, e.g. "while you have some good points, I still lean towards Terry's recommendation to frobniculate the hammerjammer" rather than have a long list of attributions at the top of the email. -tkc From invalid at invalid.invalid Mon Aug 11 22:33:20 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 12 Aug 2014 02:33:20 +0000 (UTC) Subject: Linux distros w/o Python in "base" installation References: Message-ID: On 2014-08-11, Chris Angelico wrote: > On Tue, Aug 12, 2014 at 7:36 AM, Ned Deily wrote: >> In article , >> Grant Edwards wrote: >>> Apparently. Perhaps theres an "enable LSB compliance" option >>> somewhere in the Arch install docs, but I didn't see it... >> >> Also beware that, unlike most other distributions and contrary to >> recommended practice, Arch has chosen to make Python 3 its default, >> that is, when everything is installed, `python` invokes `python3`, >> rather than `python2`. So you may need to change shebang lines in >> scripts, etc. >> >> https://wiki.archlinux.org/index.php/python I noticed that when I told it to install "python" it wanted to install 3.4 before I told it "no". > Well, it only *became* contrary to recommended practice in response > to Arch doing it and everyone seeing the issues it caused :) > Personally, I'm glad they did. Lets those of us who follow "slower" > distros (I'm running Debian) get the benefit of someone else's > hindsight. At the moment, I only have python2 installed and have manually set up symlinks so that typing "python" does what the rest of the world (including me) expects. -- Grant From rustompmody at gmail.com Tue Aug 12 00:36:25 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 11 Aug 2014 21:36:25 -0700 (PDT) Subject: Linux distros w/o Python in "base" installation In-Reply-To: References: Message-ID: <8ee71e7d-e731-4cdc-9993-6ac8630478f4@googlegroups.com> On Tuesday, August 12, 2014 12:23:57 AM UTC+5:30, Grant Edwards wrote: > I just installed Arch Linux for the first time, and was surprosed to > find that Python isn't installed as part of a "base" system. It's > also not included in the 'base-devel' package group. It's trivial to > install, but I'd still pretty surprised it's not there by default. I > guess I've spent too much time with Gentoo, Debian, and RedHat > derivitives which require Python be installed. > I've probably used at least a dozen Linux distros over the years, and > this is the first time I've noticed that Python wasn't installed by > default. > Just for the sake of curiosity, are there any other significant > desktop/server Linux distros that don't come "out of the box" with > Python? I see on my system (debian Jessie aka 'testing') these packages installed: lsb, lsb-{base,core,cxx,desktop,graphics,languages, multimedia,printing,release,security} Dont remember the details but I think I had to install one/some maybe (just lsb?) and that installed all the others. From marko at pacujo.net Tue Aug 12 01:01:39 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 12 Aug 2014 08:01:39 +0300 Subject: Is print thread safe? References: <53e8ea27$0$29981$c3e8da3$5496439d@news.astraweb.com> <53e9583b$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87k36ee1xo.fsf@elektro.pacujo.net> Steven D'Aprano : > Personally, I believe that print ought to do its own locking. And > print is a statement, although in this case there's no need to support > anything older than 2.6, so something like this ought to work: > > > from __future__ import print_function > > _print = print > _rlock = threading.RLock() > def print(*args, **kwargs): > with _rlock: > _print(*args, **kwargs) Could this cause a deadlock if print were used in signal handlers? Marko From cs at zip.com.au Tue Aug 12 02:15:20 2014 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 12 Aug 2014 16:15:20 +1000 Subject: Is print thread safe? In-Reply-To: <87k36ee1xo.fsf@elektro.pacujo.net> References: <87k36ee1xo.fsf@elektro.pacujo.net> Message-ID: <20140812061520.GA63773@cskk.homeip.net> On 12Aug2014 08:01, Marko Rauhamaa wrote: >Steven D'Aprano : >> Personally, I believe that print ought to do its own locking. And >> print is a statement, although in this case there's no need to support >> anything older than 2.6, so something like this ought to work: >> >> from __future__ import print_function >> >> _print = print >> _rlock = threading.RLock() >> def print(*args, **kwargs): >> with _rlock: >> _print(*args, **kwargs) > >Could this cause a deadlock if print were used in signal handlers? At the C level one tries to do as little as possible in q signal handler. Typically setting a flag or putting something on a queue for later work. In Python that may be a much smaller issue, since I imagine the handler runs in the ordinary course of interpretation, outside the C-level handler context. I personally wouldn't care if this might deadlock in a handler (lots of things might; avoid as many things as possible). Also, the code above uses an RLock; less prone to deadlock than a plain mutex Lock. Cheers, Cameron Simpson A host is a host from coast to coast & no one will talk to a host that's close Unless the host (that isn't close) is busy, hung or dead - David Lesher, wb8foz at skybridge.scl.cwru.edu From cs at zip.com.au Tue Aug 12 00:31:04 2014 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 12 Aug 2014 14:31:04 +1000 Subject: Is print thread safe? In-Reply-To: <53e9583b$0$29973$c3e8da3$5496439d@news.astraweb.com> References: <53e9583b$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20140812043104.GA21661@cskk.homeip.net> On 12Aug2014 09:56, Steven D'Aprano wrote: >Cameron Simpson wrote: >> On 12Aug2014 02:07, Steven D'Aprano wrote: >>>Is this documented somewhere? >> >> In python/2.7.6/reference/simple_stmts.html#index-22, "print" is described >> in terms of a "write" for each object, and a "write" for the separators. >> There is no mention of locking. > >Ah, thanks! > >> On that basis, I would find the interleaving described normal and >> expected. And certainly not "broken". > >I personally didn't describe it as "broken", Yes, sorry. >but it is, despite the >documentation. I just ran a couple of trials where I collected the output >of sys.stdout while 50 threads blasted "Spam ABCD EFGH" (plus the implicit >newline) to stdout as fast as possible using print. The result was that out >of 248165 lines[1], 595 were mangled. Many of the mangled lines were the >expected simple run-ons: > > Spam ABCD EFGHSpam ABCD EFGH\n\n > >which makes sense given the documentation, but there were lots of anomalies. > >Mysterious spaces appearing in the strings: > > Spam ABCD EFGH Spam ABCD EFGH\n\n > Spam ABCD EFGH Spam ABCD EFGH\n Spam ABCD EFGH\n > >occasional collisions mid-string: > > Spam ABSpam ABCD EFGH\nCD EFGH\n > >letters disappearing: > > Spam AB\nD EFGH\n > >and at least one utterly perplexing (to me) block of ASCII NULs appearing in >the middle of the output: > > \x00\x00\x00...\x00\x00\n > >This is with Python 2.7.2 on Linux. Sounds like print is not thread safe. Which it does not promise to be. But I would normally expect most file.write methods to be thread safe. Naively. >> Just use a lock! And rebind "print"! Or use the logging system! > >Personally, I believe that print ought to do its own locking. I don't, but I kind of believe "file"s should have thread safe write calls. Again, not guarrenteed AFAIR. >And print is a >statement, although in this case there's no need to support anything older >than 2.6, so something like this ought to work: > >from __future__ import print_function > >_print = print >_rlock = threading.RLock() >def print(*args, **kwargs): > with _rlock: > _print(*args, **kwargs) > >Sadly, using print as a function alone isn't enough to fix this problem, but >in my quick tests, using locking as above does fix it, and with no >appreciable slowdown. I would expect file.write to be fast enough that the lock would usually be free. With no evidence, just personal expectation. Taking a free lock should be almost instant. >[1] Even the number of lines of output demonstrates a bug. I had fifty >threads printing 5000 times each, which makes 250000 lines, not 248165. Sounds like the file internals are unsafe. Ugh. Cheers, Cameron Simpson If it ain't broken, keep playing with it. From nispray at gmail.com Tue Aug 12 03:04:33 2014 From: nispray at gmail.com (Wesley) Date: Tue, 12 Aug 2014 00:04:33 -0700 (PDT) Subject: Captcha identify Message-ID: <8c2e4bc2-4f46-4a68-83ed-469fe171de3a@googlegroups.com> Hi guys, These days I got a small task to identify Captcha characters. I googled a lot and find some way to do verification code identify. However, most are for general captcha. And, for simple captcha, I can use Pytesser. However, what about those advanced pictures. I mean: 1.including number and alpha 2.letters might be rotated 3.letters might be deformed I don't know why I cannot insert picture attachment here... But I think you guys can think out what the captcha looks like:-) So, any suggestions? Thanks. Wesley From nad at acm.org Tue Aug 12 03:18:34 2014 From: nad at acm.org (Ned Deily) Date: Tue, 12 Aug 2014 00:18:34 -0700 Subject: Linux distros w/o Python in "base" installation References: Message-ID: In article , Chris Angelico wrote: > Well, it only *became* contrary to recommended practice in response to > Arch doing it and everyone seeing the issues it caused :) Personally, > I'm glad they did. Lets those of us who follow "slower" distros (I'm > running Debian) get the benefit of someone else's hindsight. Well, many people thought that the problems caused by changing "python" to mean "python3" at this stage in its lifecycle were so obvious that there was no need to formalize them in a PEP. Arch proved us wrong, hence PEP 394. http://legacy.python.org/dev/peps/pep-0394/ -- Ned Deily, nad at acm.org From wxjmfauth at gmail.com Tue Aug 12 03:21:28 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Tue, 12 Aug 2014 00:21:28 -0700 (PDT) Subject: how to get the ordinal number in list In-Reply-To: References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> <53e824b9$0$30000$c3e8da3$5496439d@news.astraweb.com> <53E8D40F.8000007@chamonix.reportlab.co.uk> Message-ID: <9e179f4a-e56b-4100-9f8b-3d4e99cdc1ca@googlegroups.com> Math: Try to formalize with mathematics the Flexible String Representation. You should quickly realize, it is a logical mathematical absurdity. Unbelievable. jmf From rustompmody at gmail.com Tue Aug 12 03:33:11 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 12 Aug 2014 00:33:11 -0700 (PDT) Subject: Python in financial services Message-ID: Ive been asked to formulate a python course for financial services folk. If I actually knew about the subject, I'd have fatter pockets! Anyway heres some thoughts. What I am missing out? [Apart from basic python -- contents typically needs tailoring to the audience] the following: - Libraries -- Decimal? - scripts -- philosophy and infrastructure eg argparse, os.path - Pandas - Numpy Scipy (which? how much?) - ipython + matplotlib + ?? - Database interfacing - Excel interfacing (couple of libraries.. which?) - C(C++?) interfacing paradigms -- ranging from ctypes, cython to classic lo-level From dpalao.python at gmail.com Tue Aug 12 03:59:55 2014 From: dpalao.python at gmail.com (David Palao) Date: Tue, 12 Aug 2014 09:59:55 +0200 Subject: Linux distros w/o Python in "base" installation In-Reply-To: References: Message-ID: 2014-08-11 23:36 GMT+02:00 Ned Deily : > In article , > Grant Edwards wrote: >> Apparently. Perhaps theres an "enable LSB compliance" option >> somewhere in the Arch install docs, but I didn't see it... > > Also beware that, unlike most other distributions and contrary to > recommended practice, Arch has chosen to make Python 3 its default, that > is, when everything is installed, `python` invokes `python3`, rather > than `python2`. So you may need to change shebang lines in scripts, etc. > > https://wiki.archlinux.org/index.php/python > > -- > Ned Deily, > nad at acm.org > > -- > https://mail.python.org/mailman/listinfo/python-list Also Gentoo uses Python3 by default for some months now. The positive side effect for me has been that I started seriously to switch to python3. Best From fabien.maussion at gmail.com Tue Aug 12 05:53:31 2014 From: fabien.maussion at gmail.com (Fabien) Date: Tue, 12 Aug 2014 11:53:31 +0200 Subject: Linux distros w/o Python in "base" installation References: Message-ID: On 12.08.2014 09:59, David Palao wrote: > Also Gentoo uses Python3 by default for some months now. The positive > side effect for me has been that I started seriously to switch to > python3. it's a matter of months for debian/ubuntu to rely only on python3 code too, while still respecting PEP 394: https://wiki.ubuntu.com/Python/3 From kwpolska at gmail.com Tue Aug 12 06:00:27 2014 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Tue, 12 Aug 2014 12:00:27 +0200 Subject: Linux distros w/o Python in "base" installation In-Reply-To: References: Message-ID: On Mon, Aug 11, 2014 at 8:53 PM, Grant Edwards wrote: > I just installed Arch Linux for the first time, and was surprosed to > find that Python isn't installed as part of a "base" system. It's > also not included in the 'base-devel' package group. It's trivial to > install, but I'd still pretty surprised it's not there by default. I > guess I've spent too much time with Gentoo, Debian, and RedHat > derivitives which require Python be installed. > > I've probably used at least a dozen Linux distros over the years, and > this is the first time I've noticed that Python wasn't installed by > default. Arch has a different idea of ?base system?. The base group contains the most crucial packages needed to run an Arch Linux system, and that is all. And you do not need Python to do so. Nevertheless, most people will likely install Python by themselves, or with a package that depends on Python. On Mon, Aug 11, 2014 at 9:02 PM, Chris Rebert wrote: > It would seem that such distros are opting to not be LSB-compliant?: > http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Languages/LSB-Languages/pylocation.html Arch does not really care about LSB, AFAIK. -- Chris ?Kwpolska? Warrick PGP: 5EAAEA16 stop html mail | always bottom-post | only UTF-8 makes sense From alister.nospam.ware at ntlworld.com Tue Aug 12 06:40:33 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Tue, 12 Aug 2014 10:40:33 GMT Subject: how to get the ordinal number in list References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> <53e824b9$0$30000$c3e8da3$5496439d@news.astraweb.com> <53E8D40F.8000007@chamonix.reportlab.co.uk> <9e179f4a-e56b-4100-9f8b-3d4e99cdc1ca@googlegroups.com> Message-ID: On Tue, 12 Aug 2014 00:21:28 -0700, wxjmfauth wrote: > Math: > > Try to formalize with mathematics the Flexible String Representation. > You should quickly realize, it is a logical mathematical absurdity. > Unbelievable. > > jmf Mathematicians work with numbers (Algebra is a abstraction of numerical concepts) strings are concerned with characters (Arabic numerals are just characters commonly used to represent numbers ) therefore even trying to rationalise any string representation with mathematics is a logical absurdity in itself. -- Someone on IRC was very sad about the uptime of his machine wrapping from 497 days to 0. -- linux-kernel From as at sci.fi Tue Aug 12 09:31:23 2014 From: as at sci.fi (Anssi Saari) Date: Tue, 12 Aug 2014 16:31:23 +0300 Subject: how to write file into my android phone? References: <53E660BF.7080401@gmail.com> Message-ID: Chris ?Kwpolska? Warrick writes: >> 2) the phone isn't necessarily visible on a pc as a drive at all. >> For example the Samsung gs4. > > This is actually true for ALL android devices, starting with Android 3.0. There was just a guy on comp.mobile.android saying his Android 4.2 phone (BLU Dash or something like that, extremely Chinese) presents its external SD card as a USB Mass Storage drive to a PC when connected over USB. Exactly the thing Google hates and fears and has tried to kill off... But it's not like Google can force anything on phones running AOSP Android without Google services and that's China and a few other large emerging markets. So it's just our small market here in the western countries where Google has some control... From rosuav at gmail.com Tue Aug 12 09:39:42 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Aug 2014 23:39:42 +1000 Subject: how to get the ordinal number in list In-Reply-To: References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> <53e824b9$0$30000$c3e8da3$5496439d@news.astraweb.com> <53E8D40F.8000007@chamonix.reportlab.co.uk> <9e179f4a-e56b-4100-9f8b-3d4e99cdc1ca@googlegroups.com> Message-ID: On Tue, Aug 12, 2014 at 8:40 PM, alister wrote: > On Tue, 12 Aug 2014 00:21:28 -0700, wxjmfauth wrote: > [ chomp ] > > Mathematicians work with numbers (Algebra is a abstraction of numerical > concepts) strings are concerned with characters (Arabic numerals are just > characters commonly used to represent numbers ) > therefore even trying to rationalise any string representation with > mathematics is a logical absurdity in itself. Don't bother responding to jmf; he doesn't listen. Also, his posts don't survive the jump to python-list, so we see them only when someone quotes him like that... as far as I'm concerned, his posts are now on par with those trying to sell us solution manuals or herbal remedies. ChrisA From rosuav at gmail.com Tue Aug 12 09:53:03 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Aug 2014 23:53:03 +1000 Subject: Is print thread safe? In-Reply-To: <20140812043104.GA21661@cskk.homeip.net> References: <53e9583b$0$29973$c3e8da3$5496439d@news.astraweb.com> <20140812043104.GA21661@cskk.homeip.net> Message-ID: On Tue, Aug 12, 2014 at 2:31 PM, Cameron Simpson wrote: > I would expect file.write to be fast enough that the lock would usually be > free. Until the day when it becomes really REALLY slow, because your program's piped into 'less' and the user's paging through it. But even apart from that, writing to stdout can take a notable amount of time. Expecting the lock to usually be free will depend on the nature of the program - how much of it is spent in silent computation and how much in production of output. If that ratio is sufficiently skewed, then sure, the lock'll usually be free. ChrisA From denismfmcmahon at gmail.com Tue Aug 12 09:51:34 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Tue, 12 Aug 2014 13:51:34 +0000 (UTC) Subject: Captcha identify References: <8c2e4bc2-4f46-4a68-83ed-469fe171de3a@googlegroups.com> Message-ID: On Tue, 12 Aug 2014 00:04:33 -0700, Wesley wrote: > These days I got a small task to identify Captcha characters. Several of us code websites. Some of our websites may even use captcha. We use captcha to stop software posting spam to websites. What makes you think we have any inclination to help you defeat captchas? -- Denis McMahon, denismfmcmahon at gmail.com From invalid at invalid.invalid Tue Aug 12 10:12:33 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 12 Aug 2014 14:12:33 +0000 (UTC) Subject: Linux distros w/o Python in "base" installation References: Message-ID: On 2014-08-12, Chris ?Kwpolska? Warrick wrote: > On Mon, Aug 11, 2014 at 8:53 PM, Grant Edwards wrote: >> I just installed Arch Linux for the first time, and was surprosed to >> find that Python isn't installed as part of a "base" system. It's >> also not included in the 'base-devel' package group. It's trivial to >> install, but I'd still pretty surprised it's not there by default. I >> guess I've spent too much time with Gentoo, Debian, and RedHat >> derivitives which require Python be installed. >> >> I've probably used at least a dozen Linux distros over the years, and >> this is the first time I've noticed that Python wasn't installed by >> default. > > Arch has a different idea of ?base system?. The base group contains > the most crucial packages needed to run an Arch Linux system, and that > is all. That's true of Gentoo as well, but it includes Python. > And you do not need Python to do so. That's the part that surprised me. It's been a _long_ time since I've run a Linux distro that didn't require Python as a crucial system package. -- Grant Edwards grant.b.edwards Yow! Those people look at exactly like Donnie and gmail.com Marie Osmond!! From invalid at invalid.invalid Tue Aug 12 10:18:11 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 12 Aug 2014 14:18:11 +0000 (UTC) Subject: how to write file into my android phone? References: <53E660BF.7080401@gmail.com> <53e73de8$0$24963$c3e8da3$5496439d@news.astraweb.com> <871tsohdlp.fsf@elektro.pacujo.net> Message-ID: On 2014-08-11, Grant Edwards wrote: > What MTP allows is parallel access between the MTP protocol server in > the phone and the rest of the phone (OS and apps). In order to mount > a partition as a USB mass storage device, it has to first be unmounted > by the Android system. That's OK for an SD card that doesn't contain > anything important required by the Android system, but it means that > you can't mount the "system" partition without shutting down the phone > completely. Another important reason for not presenting the phone's built-in flash as a USB mass storage device is that it requires you to use a brain-dead broken-as-designed Microsoft filesystem left over from the days of 360K floppy disk drives -- otherwise Windows won't know what to do with it. It's _possible_ to build an Android phone tht runs an DOS file system (and IIRC people have done it) but it introduces all sorts of security, reliability, and performance problems. -- Grant Edwards grant.b.edwards Yow! I wonder if I ought at to tell them about my gmail.com PREVIOUS LIFE as a COMPLETE STRANGER? From nispray at gmail.com Tue Aug 12 10:57:31 2014 From: nispray at gmail.com (Wesley) Date: Tue, 12 Aug 2014 07:57:31 -0700 (PDT) Subject: Captcha identify In-Reply-To: References: <8c2e4bc2-4f46-4a68-83ed-469fe171de3a@googlegroups.com> Message-ID: <2320baf0-e097-4d67-97c1-dd37ca79fffb@googlegroups.com> Here is captcha link: https://drive.google.com/folderview?id=0B33_p7UnVqoyd09mT3V0aWFxRmc&usp=sharing ? 2014?8?12????UTC+8??8?59?11??Dennis Lee Bieber??? > On Tue, 12 Aug 2014 00:04:33 -0700 (PDT), Wesley > > declaimed the following: > > > > >Hi guys, > > > These days I got a small task to identify Captcha characters. > > > > In other words, you have a task to make a robot that can break the > > procedures put in place to prevent robots from posting to web sites... > > > > The whole purpose of the CAPTCHA scheme is that computer AI systems > > aren't advanced enough to process them, whereas a human mind can almost do > > it in the subconscious. > > > > > > (as for picture attachments? comp.lang.python is a text newsgroup -- > > binaries aren't wanted in it; c.l.p is also gatewayed to a mailing list; > > and that mailing list is gatewayed to gmane.comp.python.general where it is > > made available as a news group (after spam filtering). Google Groups links > > to c.l.p (and many of us wish it didn't) > > -- > > Wulfraed Dennis Lee Bieber AF6VN > > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ From rosuav at gmail.com Tue Aug 12 11:06:47 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Aug 2014 01:06:47 +1000 Subject: Captcha identify In-Reply-To: <2320baf0-e097-4d67-97c1-dd37ca79fffb@googlegroups.com> References: <8c2e4bc2-4f46-4a68-83ed-469fe171de3a@googlegroups.com> <2320baf0-e097-4d67-97c1-dd37ca79fffb@googlegroups.com> Message-ID: On Wed, Aug 13, 2014 at 12:57 AM, Wesley wrote: > Here is captcha link: > https://drive.google.com/folderview?id=0B33_p7UnVqoyd09mT3V0aWFxRmc&usp=sharing You seem to have misunderstood how grossly offensive your request is. I am now the third person to do you the courtesy of a response, but there are lots more who are simply deleting your post and moving on, or possibly marking you as a spammer, because that's about the only reason for wanting a program to solve CAPTCHAs. Let me spell it out for you: NO WE WILL NOT do this for you. And if you do it yourself, we will not be happy. Just don't. ChrisA From jhibschman at gmail.com Tue Aug 12 11:35:44 2014 From: jhibschman at gmail.com (Johann Hibschman) Date: Tue, 12 Aug 2014 11:35:44 -0400 Subject: Python in financial services References: Message-ID: Rustom Mody writes: > Ive been asked to formulate a python course for financial services > folk. > > If I actually knew about the subject, I'd have fatter pockets! > Anyway heres some thoughts. What I am missing out? Good luck! It's a pretty broad field, so everyone probably has different needs. > - Libraries -- Decimal? I've never seen decimal used, even though it makes sense for accounting-style finance. I've mostly been looking at forecasts, trading, and risk, where floats are fine. So maybe mention that it exists, so people know where to look if they need it, but don't stress it. > - scripts -- philosophy and infrastructure eg argparse, os.path Basic argparse is very handy, but, again, I wouldn't spend too much time on it. > - Pandas > - Numpy Scipy (which? how much?) For me, pandas is huge, numpy is a nice fundamental substrate, while only bits and pieces of scipy are used (mostly optimization). statsmodels may also be worth a mention, as the answer to "how do I do a regression". > - ipython + matplotlib + ?? Ipython notebook + matplotlib is great. At least show that it exists. pandas plots may be enough, though. > - Database interfacing Definitely mention. > - Excel interfacing (couple of libraries.. which?) Meh, maybe. At least give a strategy. It always seems like a fool's errand, though: I end up just dumping data to CSV and using that. > - C(C++?) interfacing paradigms -- ranging from ctypes, cython to > classic lo-level Probably not, but it depends on the audience. The overview, like "ctypes will link to C-like libraries, cython lets you write python-like code that runs fast, and there's SWIG and Boost.Python if you want to write your own modules" is about all you need. Hope that helps, Johann From denismfmcmahon at gmail.com Tue Aug 12 11:38:47 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Tue, 12 Aug 2014 15:38:47 +0000 (UTC) Subject: Captcha identify References: <8c2e4bc2-4f46-4a68-83ed-469fe171de3a@googlegroups.com> <2320baf0-e097-4d67-97c1-dd37ca79fffb@googlegroups.com> Message-ID: On Wed, 13 Aug 2014 01:06:47 +1000, Chris Angelico wrote: > Let me spell it out for you: NO WE WILL NOT do this for you. And if you > do it yourself, we will not be happy. Just don't. Chris, I suspect he's a codemonkey in a chinese or similar asian spamhaus. We should probably be thankful that he's so dumb. -- Denis McMahon, denismfmcmahon at gmail.com From ian.g.kelly at gmail.com Tue Aug 12 11:49:11 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 12 Aug 2014 09:49:11 -0600 Subject: Linux distros w/o Python in "base" installation In-Reply-To: References: Message-ID: On Tue, Aug 12, 2014 at 8:12 AM, Grant Edwards wrote: > On 2014-08-12, Chris ?Kwpolska? Warrick wrote: >> On Mon, Aug 11, 2014 at 8:53 PM, Grant Edwards wrote: >>> I just installed Arch Linux for the first time, and was surprosed to >>> find that Python isn't installed as part of a "base" system. It's >>> also not included in the 'base-devel' package group. It's trivial to >>> install, but I'd still pretty surprised it's not there by default. I >>> guess I've spent too much time with Gentoo, Debian, and RedHat >>> derivitives which require Python be installed. >>> >>> I've probably used at least a dozen Linux distros over the years, and >>> this is the first time I've noticed that Python wasn't installed by >>> default. >> >> Arch has a different idea of ?base system?. The base group contains >> the most crucial packages needed to run an Arch Linux system, and that >> is all. > > That's true of Gentoo as well, but it includes Python. Because Portage is written in Python. Otherwise Gentoo would probably omit it from the base system as well. From rosuav at gmail.com Tue Aug 12 11:54:04 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Aug 2014 01:54:04 +1000 Subject: Captcha identify In-Reply-To: References: <8c2e4bc2-4f46-4a68-83ed-469fe171de3a@googlegroups.com> <2320baf0-e097-4d67-97c1-dd37ca79fffb@googlegroups.com> Message-ID: On Wed, Aug 13, 2014 at 1:38 AM, Denis McMahon wrote: > On Wed, 13 Aug 2014 01:06:47 +1000, Chris Angelico wrote: > >> Let me spell it out for you: NO WE WILL NOT do this for you. And if you >> do it yourself, we will not be happy. Just don't. > > Chris, I suspect he's a codemonkey in a chinese or similar asian spamhaus. > We should probably be thankful that he's so dumb. Yeah, that is the most likely scenario. If I'm courteous, I'll assume that he has no idea what the rest of the world thinks of this kind of thing. ChrisA From denismfmcmahon at gmail.com Tue Aug 12 11:50:16 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Tue, 12 Aug 2014 15:50:16 +0000 (UTC) Subject: Python in financial services References: Message-ID: On Tue, 12 Aug 2014 00:33:11 -0700, Rustom Mody wrote: > Ive been asked to formulate a python course for financial services folk. I wouldn't worry too much about c or c++ interfacing paradigms. -- Denis McMahon, denismfmcmahon at gmail.com From ram.rachum at gmail.com Tue Aug 12 13:02:11 2014 From: ram.rachum at gmail.com (cool-RR) Date: Tue, 12 Aug 2014 10:02:11 -0700 (PDT) Subject: Using asyncio workers in a `concurrent.futures` interface Message-ID: Hello everybody! I have a question. I have a Django app running on Heroku. I need to run about 100 worker threads there to do uploads/downloads simultaneously. A Heroku Dyno has only 512MB of memory, so I'm reluctant to run 100 worker threads. (I've had Dynos crash from lack of memory when using 6 threads before.) I heard that the asyncio module is mature and ready for usage, and I was happy because I kept hearing about it in the last year, and I saw Guido's lecture about it. If I understand correctly it would let me run multiple uploads and downloads efficiently in one thread, which would conserve more resources than using threads. (Please correct me if I'm wrong.) Now, I am a little clueless about the whole way it's built, using coroutines and tricky usage of `yield from`. I figured that since this is eventually a library for concurrency, i.e. doing many tasks at the same time, there will be an API in a style of "Here are 100 tasks for you to do concurrently, let me know when they're done." I looked at the asyncio documentation page and saw that it does mention futures and executors, which is my favorite interface for doing concurrency. I was happy and I skimmed the docs. But, I couldn't find a simple way to use these. I don't want to learn how to define coroutines and use `yield from` to switch between them. (I use `yield from` regularly and fully understand how it works, I just don't write my programs that way.) What I'm expecting is something like this: download_file = lambda url: requests.get(url).content urls = ['http://google.com/file1.jpg', 'http://google.com/file2.jpg', 'http://google.com/file3.jpg'] # etc. with AsyncIOExecutor() as asyncio_executor: files = asyncio_executor.map(download_file, urls) And that's it, no coroutines, no `yield from`. Since, if I understand correctly, asyncio requires a mainloop, it would make sense for the AsyncIOExecutor to have a thread of its own in which it could run its mainloop. Is this possible? Did someone implement this? Thanks for your help, Ram. From neilc at norwich.edu Tue Aug 12 13:40:48 2014 From: neilc at norwich.edu (Neil D. Cerutti) Date: Tue, 12 Aug 2014 13:40:48 -0400 Subject: how to get the ordinal number in list In-Reply-To: References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> Message-ID: On 8/10/2014 2:14 PM, Roy Smith wrote: > In article <154cc342-7f85-4d16-b636-a1a953913c98 at googlegroups.com>, > Rustom Mody wrote: > >>>>> l= [6,2,9,12,1,4] >>>>> sorted(l,reverse=True)[:5] >> [12, 9, 6, 4, 2] >> >> No need to know how sorted works nor [:5] >> >> Now you (or Steven) can call it abstract. >> >> And yet its >> 1. Actual running code in the interpreter >> 2. Its as close as one can get to a literal translation of your >> "Find the 5 largest numbers in a list" >> [...] >> All the above are clearer than loops+assignments and can be >> taught before them > > I disagree. For a beginner, you want to be able to break things down > into individual steps and examine the result at each point. If you do: > >>>>> l= [6,2,9,12,1,4] >>>>> l2 = sorted(l,reverse=True) > > you have the advantage that you can stop after creating l2 and print it > out. The student can see that it has indeed been sorted. With the > chained operations, you have to build a mental image of an anonymous, > temporary list, and then perform the slicing operation on that. Sure, > it's the way you or I would write it in production code, but for a > beginner, breaking it down into smaller pieces makes it easier to > understand. > >>>>> l2[:5] Yes, and that teaching technique is supported by research. Beginners are particularly poor, in relation to experts, at noticing the applicability of idea, and at combining ideas together. Breaking things into component parts has multiple benefits: 1. The applicability of individual ideas becomes obvious. It's one thing to know about [].sort, and another thing to know when it's appropriate to sort something. 2. The expert specifically shows how and why the ideas are combined. This helps build the connection for the beginner, whose knowledge is not stored as an expert stores it; i.e, in broad categories with multiple connections; but as disorganized data with very few connections. http://www.amazon.com/How-Learning-Works-Research-Based-Principles/dp/0470484101 I bought the book based on a recommendation from SciPy talk, and it's really great. As an autodidact, it'll help me teach *myself* better, too. -- Neil Cerutti From rustompmody at gmail.com Tue Aug 12 13:44:44 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 12 Aug 2014 10:44:44 -0700 (PDT) Subject: Python in financial services In-Reply-To: References: Message-ID: <185c01ce-aff4-4f1f-8b32-11385649b9f0@googlegroups.com> On Tuesday, August 12, 2014 9:05:44 PM UTC+5:30, Johann Hibschman wrote: > Rustom Mody writes: > > - Pandas > > - Numpy Scipy (which? how much?) > For me, pandas is huge, numpy is a nice fundamental substrate, while > only bits and pieces of scipy are used (mostly optimization). > statsmodels may also be worth a mention, as the answer to "how do I do a > regression". statsmodels seems like something useful -- thanks for the pointer From rustompmody at gmail.com Tue Aug 12 13:48:14 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 12 Aug 2014 10:48:14 -0700 (PDT) Subject: Python in financial services In-Reply-To: References: Message-ID: <1c9a0c56-d898-4872-9df3-814816caf45f@googlegroups.com> On Tuesday, August 12, 2014 9:20:16 PM UTC+5:30, Denis McMahon wrote: > On Tue, 12 Aug 2014 00:33:11 -0700, Rustom Mody wrote: > > Ive been asked to formulate a python course for financial services folk. > I wouldn't worry too much about c or c++ interfacing paradigms. And I dont like teaching that stuff either :-) [especially on windows!] However those folks have thousands of lines of C/C++ which they are porting to python. So... Thanks anyway From rustompmody at gmail.com Tue Aug 12 14:20:54 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 12 Aug 2014 11:20:54 -0700 (PDT) Subject: how to get the ordinal number in list In-Reply-To: References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> Message-ID: <70c65ab0-0a9d-4705-a8a3-43b9ee0600a0@googlegroups.com> On Tuesday, August 12, 2014 11:10:48 PM UTC+5:30, Neil D. Cerutti wrote: > On 8/10/2014 2:14 PM, Roy Smith wrote: > > Rustom Mody wrote: > >>>>> l= [6,2,9,12,1,4] > >>>>> sorted(l,reverse=True)[:5] > >> [12, 9, 6, 4, 2] > >> No need to know how sorted works nor [:5] > >> Now you (or Steven) can call it abstract. > >> And yet its > >> 1. Actual running code in the interpreter > >> 2. Its as close as one can get to a literal translation of your > >> "Find the 5 largest numbers in a list" > >> [...] > >> All the above are clearer than loops+assignments and can be > >> taught before them > > I disagree. For a beginner, you want to be able to break things down > > into individual steps and examine the result at each point. If you do: > >>>>> l= [6,2,9,12,1,4] > >>>>> l2 = sorted(l,reverse=True) > > you have the advantage that you can stop after creating l2 and print it > > out. The student can see that it has indeed been sorted. With the > > chained operations, you have to build a mental image of an anonymous, > > temporary list, and then perform the slicing operation on that. Sure, > > it's the way you or I would write it in production code, but for a > > beginner, breaking it down into smaller pieces makes it easier to > > understand. > >>>>> l2[:5] > Yes, and that teaching technique is supported by research. Yes and I as said to Roy I dont see any disagreement at least on this account. > Beginners are particularly poor, in relation to experts, at noticing the > applicability of idea, and at combining ideas together. Breaking things > into component parts has multiple benefits: > 1. The applicability of individual ideas becomes obvious. It's one thing > to know about [].sort, and another thing to know when it's appropriate > to sort something. > 2. The expert specifically shows how and why the ideas are combined. > This helps build the connection for the beginner, whose knowledge is not > stored as an expert stores it; i.e, in broad categories with multiple > connections; but as disorganized data with very few connections. Nice! And how do we lead the beginners towards expertise? In a way functional programming is to programming creativity what lego is to children's spatial creativity. Specifically there are a bunch of pieces that need to fit: 1. Functional Programming: Nothing more than composing functions [Maybe a bit simplistic but not unrealistic a defn] 2. Trying this out at the interpreter 3. Introspectable objects Some things follow from this: For the lego-game of playing with functions at the REPL to work and be pleasant and rewarding: 1. functions should be non side-effecting; else same trials giving different answers adds more confusion than understanding 2. They should be non-printing else: def foo(x): return x+1 def bar(x): print x+1 look similar when trivially tried but compositionally are utterly different In effect a printing function breaks the lego bricks [The P in the REPL is DRY enough that it does not usually need to be repeated all over] 3. Abstractions (class instances) should be avoided in favor of concrete data (lists, dicts, scalars) because they add undue mess at little comprehension advantage. eg take the example of a regex match. It returns some object and then we have to scratch our heads wondering whats in the magic box. If instead of match, we use findall, the data is manifest and obvious. > http://www.amazon.com/How-Learning-Works-Research-Based-Principles/dp/0470484101 > I bought the book based on a recommendation from SciPy talk, and it's > really great. As an autodidact, it'll help me teach *myself* better, too. Looks interesting. Will take a look. From marko at pacujo.net Tue Aug 12 14:31:02 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 12 Aug 2014 21:31:02 +0300 Subject: Using asyncio workers in a `concurrent.futures` interface References: Message-ID: <87egwlef15.fsf@elektro.pacujo.net> cool-RR : > If I understand correctly [asyncio] would let me run multiple uploads > and downloads efficiently in one thread, which would conserve more > resources than using threads. Asyncio does make it convenient to multiplex event on one or more threads. Threads have their uses (exploiting multiple CPUs), only you shouldn't associate threads with every state machine, IMO. Asyncio allows you to separate your state machines from your threads. For example, you might have 1,000 state machines (for 1,000 connections) but only 8 threads for 4 CPUs. > Now, I am a little clueless about the whole way it's built, using > coroutines and tricky usage of `yield from`. Asyncio actively supports (at least) *two* multiplexing models: callbacks (aka listeners or handlers) and coroutines. Programming with callbacks involves storing the state explicitly in a state machine object. The callbacks are supposed to never block but return immediately. That model is a long-time favorite of many, including me. The coroutine model is highly analogous with the multithreading model in that you store the state implicitly in the code. Multithreading marks the state with blocking function calls. Coroutines mark the state with "yield from" statements. Otherwise, a multithreading implementation will have very much the shape of a coroutine implementation. The funky aspect of the coroutines is the way they "abuse" the "yield from" statement, whose original purpose is to pass a series of results from a generator to the caller by chaining lower-level generators. Coroutines employ a "trick:" the "yield from" statement does not pass any meaningful results. Instead, the statement is used to make the generator/coroutine pseudoblock and switch context within the same thread. There's one crucial advantage coroutines have over threads: you can multiplex events. If your thread is blocked on, say, reading a byte, you can't tell it to stop waiting and do something else instead. Coroutines can be made to wait on alternative stimuli. > I looked at the asyncio documentation page and saw that it does > mention futures and executors, which is my favorite interface for > doing concurrency. They are there. My favorite model is the Actor Model, where objects communicate with each other and the outside world through asynchornous stimuli of sorts. The thinking goes: something happened, so how do I react to it. The actor model just needs a class with the member "self.state", which contains the name of the internal state of the object. Then the objects callback methods receive the inputs send out messages and adjust the state. Both the actor model and the coroutines produce somewhat messy code that somewhat hard to get right. However, that's a reflection of how messy the reality is. Any attempts to pave it over will ultimately result in more trouble. > download_file = lambda url: requests.get(url).content > urls = ['http://google.com/file1.jpg', > 'http://google.com/file2.jpg', 'http://google.com/file3.jpg'] # > etc. > > with AsyncIOExecutor() as asyncio_executor: > files = asyncio_executor.map(download_file, urls) > > And that's it, no coroutines, no `yield from`. I'm not quite following you. However, one feature of the coroutines is that you must use "yield from" everywhere. You can't delegate it to a subroutine and forget about it. That's my main problem with coroutines. The simple function call syntax: y = f(x) is replaced with the weird: y = yield from f(x) > Since, if I understand correctly, asyncio requires a mainloop, it > would make sense for the AsyncIOExecutor to have a thread of its own > in which it could run its mainloop. > > Is this possible? Did someone implement this? Unfortunately, I have not. I have just implemented a toy example to satisfy my curiosity. All of my code uses callbacks and select.epoll() -- to great success. Here's my exploration in the classic dining philosophers problem: I have "fixed" the faulty protocol by having an assistant break the deadlock by occasionally nagging the philosophers to drop everything and get back to thinking. The main accomplishment of the exercise was that I convinced myself the coroutines can be used for serious things as coroutines can multiplex stimuli with asyncio.wait(..., return_when=asyncio.FIRST_COMPLETED). Marko From camilocelyg at gmail.com Tue Aug 12 14:36:17 2014 From: camilocelyg at gmail.com (c1223) Date: Tue, 12 Aug 2014 11:36:17 -0700 (PDT) Subject: Begginer in python trying to load a .dll Message-ID: <3dade0aa-55ca-4e52-af08-8104e9edf4c3@googlegroups.com> Hi, Im working in the development of a program based in python that allow us to contrl a spectometer. The spectometer has an .dll file. The idea is to work through this dll and operate the spectometer. The name of the .dll is AS5216.dll. I've trying with ctype, but it doesn't work. I'm begginer in python. All the comments are useful to me. From python at mrabarnett.plus.com Tue Aug 12 14:43:15 2014 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 12 Aug 2014 19:43:15 +0100 Subject: Using asyncio workers in a `concurrent.futures` interface In-Reply-To: References: Message-ID: <53EA6043.10504@mrabarnett.plus.com> On 2014-08-12 18:02, cool-RR wrote: > Hello everybody! I have a question. > > I have a Django app running on Heroku. I need to run about 100 worker > threads there to do uploads/downloads simultaneously. A Heroku Dyno > has only 512MB of memory, so I'm reluctant to run 100 worker threads. > (I've had Dynos crash from lack of memory when using 6 threads > before.) > > I heard that the asyncio module is mature and ready for usage, and I > was happy because I kept hearing about it in the last year, and I saw > Guido's lecture about it. If I understand correctly it would let me > run multiple uploads and downloads efficiently in one thread, which > would conserve more resources than using threads. (Please correct me > if I'm wrong.) > > Now, I am a little clueless about the whole way it's built, using > coroutines and tricky usage of `yield from`. I figured that since > this is eventually a library for concurrency, i.e. doing many tasks > at the same time, there will be an API in a style of "Here are 100 > tasks for you to do concurrently, let me know when they're done." > > I looked at the asyncio documentation page and saw that it does > mention futures and executors, which is my favorite interface for > doing concurrency. I was happy and I skimmed the docs. But, I > couldn't find a simple way to use these. I don't want to learn how to > define coroutines and use `yield from` to switch between them. (I use > `yield from` regularly and fully understand how it works, I just > don't write my programs that way.) > > What I'm expecting is something like this: > > download_file = lambda url: requests.get(url).content > urls = ['http://google.com/file1.jpg', 'http://google.com/file2.jpg', 'http://google.com/file3.jpg'] # etc. > > with AsyncIOExecutor() as asyncio_executor: > files = asyncio_executor.map(download_file, urls) > > And that's it, no coroutines, no `yield from`. Since, if I understand > correctly, asyncio requires a mainloop, it would make sense for the > AsyncIOExecutor to have a thread of its own in which it could run its > mainloop. > > Is this possible? Did someone implement this? > Do you really need to upload/download that many at the same time? I'd put them into a queue and have only a few of uploading/downloading at any time. From rosuav at gmail.com Tue Aug 12 14:44:40 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Aug 2014 04:44:40 +1000 Subject: Begginer in python trying to load a .dll In-Reply-To: <3dade0aa-55ca-4e52-af08-8104e9edf4c3@googlegroups.com> References: <3dade0aa-55ca-4e52-af08-8104e9edf4c3@googlegroups.com> Message-ID: On Wed, Aug 13, 2014 at 4:36 AM, c1223 wrote: > Im working in the development of a program based in python that allow us to contrl a spectometer. The spectometer has an .dll file. The idea is to work through this dll and operate the spectometer. > The name of the .dll is AS5216.dll. I've trying with ctype, but it doesn't work. > I'm begginer in python. > All the comments are useful to me. What have you tried, exactly? What does "it doesn't work" mean? Interfacing with a DLL is a potentially very hard and complex job (although it might turn out to be really easy - depends what the DLL's doing). We can't simply give you an answer right here, without knowing heaps about the DLL you're working with - where it came from, whether this is homework or a real-world problem, etc, etc, etc. ChrisA From skip at pobox.com Tue Aug 12 14:48:01 2014 From: skip at pobox.com (Skip Montanaro) Date: Tue, 12 Aug 2014 13:48:01 -0500 Subject: Begginer in python trying to load a .dll In-Reply-To: <3dade0aa-55ca-4e52-af08-8104e9edf4c3@googlegroups.com> References: <3dade0aa-55ca-4e52-af08-8104e9edf4c3@googlegroups.com> Message-ID: On Tue, Aug 12, 2014 at 1:36 PM, c1223 wrote: > I've trying with ctype, but it doesn't work. Can you post a small example of how you're trying to use cypes? I don't think a full example would be necessary, but knowing the API of one or two functions and how you're trying to call them from Python would be useful. Just as the off-chance your DLL was written in C++... I don't think you can interface with ctypes directly. I think you would have to write a little shim DLL which exposes a C-compatible API. Skip From alister.nospam.ware at ntlworld.com Tue Aug 12 14:45:19 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Tue, 12 Aug 2014 18:45:19 GMT Subject: how to get the ordinal number in list References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> <53e824b9$0$30000$c3e8da3$5496439d@news.astraweb.com> <53E8D40F.8000007@chamonix.reportlab.co.uk> <9e179f4a-e56b-4100-9f8b-3d4e99cdc1ca@googlegroups.com> Message-ID: <3htGv.167702$u21.75537@fx26.am4> On Tue, 12 Aug 2014 23:39:42 +1000, Chris Angelico wrote: > On Tue, Aug 12, 2014 at 8:40 PM, alister > wrote: >> On Tue, 12 Aug 2014 00:21:28 -0700, wxjmfauth wrote: >> [ chomp ] >> >> Mathematicians work with numbers (Algebra is a abstraction of numerical >> concepts) strings are concerned with characters (Arabic numerals are >> just characters commonly used to represent numbers ) >> therefore even trying to rationalise any string representation with >> mathematics is a logical absurdity in itself. > > Don't bother responding to jmf; he doesn't listen. Also, his posts don't > survive the jump to python-list, so we see them only when someone quotes > him like that... as far as I'm concerned, his posts are now on par with > those trying to sell us solution manuals or herbal remedies. > > ChrisA As you don't see them unless someone replies I will make sure I don't reply to any more of his posts. I would not want to inflict this nonsense on someone who would otherwise be spared. -- You will lose an important tape file. From breamoreboy at yahoo.co.uk Tue Aug 12 14:52:48 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 12 Aug 2014 19:52:48 +0100 Subject: Begginer in python trying to load a .dll In-Reply-To: <3dade0aa-55ca-4e52-af08-8104e9edf4c3@googlegroups.com> References: <3dade0aa-55ca-4e52-af08-8104e9edf4c3@googlegroups.com> Message-ID: On 12/08/2014 19:36, c1223 wrote: > Hi, > Im working in the development of a program based in python that allow us to contrl a spectometer. The spectometer has an .dll file. The idea is to work through this dll and operate the spectometer. > The name of the .dll is AS5216.dll. I've trying with ctype, but it doesn't work. > I'm begginer in python. > All the comments are useful to me. > Please help us to help you. Stating "it doesn't work" is of no use. Show us your code, what you expected to happen and what actually happened. If you get a traceback cut and paste all of it into your message. State what version of Python you have and your OS. Sure seeing dll we can surmise Windows but which one? For further advice on how to put your question(s) together see "The SSCCE - Short, Self Contained, Correct (Compilable), Example" at http://sscce.org/ -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From denismfmcmahon at gmail.com Tue Aug 12 14:54:12 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Tue, 12 Aug 2014 18:54:12 +0000 (UTC) Subject: Python in financial services References: <1c9a0c56-d898-4872-9df3-814816caf45f@googlegroups.com> Message-ID: On Tue, 12 Aug 2014 10:48:14 -0700, Rustom Mody wrote: > However those folks have thousands of lines of C/C++ which they are > porting to python. That begs the question: Why? Seriously, I'd like to know what benefits they expect to achieve by doing so. -- Denis McMahon, denismfmcmahon at gmail.com From ckaynor at zindagigames.com Tue Aug 12 14:55:14 2014 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Tue, 12 Aug 2014 11:55:14 -0700 Subject: Begginer in python trying to load a .dll In-Reply-To: References: <3dade0aa-55ca-4e52-af08-8104e9edf4c3@googlegroups.com> Message-ID: On Tue, Aug 12, 2014 at 11:48 AM, Skip Montanaro wrote: > Just as the off-chance your DLL was written in C++... I don't think > you can interface with ctypes directly. I think you would have to > write a little shim DLL which exposes a C-compatible API. > You should be able to use ctypes with a C++ library, you'd just need to know how your C++ compiler handles name mangling. Typically, changes are made to accommodate classes, namespaces, and function overloads. Of course, if you were to change to a different compiler (possibly including a different version) or made minor tweaks to the functions, you'd have to update all the Python code to use the new name mangling scheme. Hmm...On second thought, maybe just only using functions exports with "extern C" would be easier - or just using a C compiler. Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: From camilocelyg at gmail.com Tue Aug 12 14:56:37 2014 From: camilocelyg at gmail.com (c1234 py) Date: Tue, 12 Aug 2014 11:56:37 -0700 (PDT) Subject: Begginer in python trying to load a .dll In-Reply-To: <3dade0aa-55ca-4e52-af08-8104e9edf4c3@googlegroups.com> References: <3dade0aa-55ca-4e52-af08-8104e9edf4c3@googlegroups.com> Message-ID: On Tuesday, August 12, 2014 3:36:17 PM UTC-3, c1234 py wrote: > Hi, > > Im working in the development of a program based in python that allow us to contrl a spectometer. The spectometer has an .dll file. The idea is to work through this dll and operate the spectometer. > > The name of the .dll is AS5216.dll. I've trying with ctype, but it doesn't work. > > I'm begginer in python. > > All the comments are useful to me. I'm using this >>import ctypes hllDll=ctypes.WinDLL("C:\\AS5216.dll") hllApiProto = ctypes.WINFUNCTYPE (ctypes.c_int,ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p) hllApiParams = (1, "p1", 0), (1, "p2", 0), (1, "p3",0), (1, "p4",0), hllApi = hllApiProto (("HLLAPI", hllDll), hllApiParams) p1 = ctypes.c_int (1) p2 = ctypes.c_char_p (sessionVar) p3 = ctypes.c_int (1) p4 = ctypes.c_int (0) hllApi (ctypes.byref (p1), p2, ctypes.byref (p3), ctypes.byref (p4)) Thanks From rgaddi at technologyhighland.invalid Tue Aug 12 14:58:54 2014 From: rgaddi at technologyhighland.invalid (Rob Gaddi) Date: Tue, 12 Aug 2014 11:58:54 -0700 Subject: Begginer in python trying to load a .dll References: <3dade0aa-55ca-4e52-af08-8104e9edf4c3@googlegroups.com> Message-ID: <20140812115854.19cdccad@rg.highlandtechnology.com> On Tue, 12 Aug 2014 11:56:37 -0700 (PDT) c1234 py wrote: > On Tuesday, August 12, 2014 3:36:17 PM UTC-3, c1234 py wrote: > > Hi, > > > > Im working in the development of a program based in python that allow us to contrl a spectometer. The spectometer has an .dll file. The idea is to work through this dll and operate the spectometer. > > > > The name of the .dll is AS5216.dll. I've trying with ctype, but it doesn't work. > > > > I'm begginer in python. > > > > All the comments are useful to me. > > > I'm using this > > > >>import ctypes > hllDll=ctypes.WinDLL("C:\\AS5216.dll") > > > hllApiProto = ctypes.WINFUNCTYPE (ctypes.c_int,ctypes.c_void_p, > ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p) > hllApiParams = (1, "p1", 0), (1, "p2", 0), (1, "p3",0), (1, "p4",0), > > > hllApi = hllApiProto (("HLLAPI", hllDll), hllApiParams) > > p1 = ctypes.c_int (1) > p2 = ctypes.c_char_p (sessionVar) > p3 = ctypes.c_int (1) > p4 = ctypes.c_int (0) > hllApi (ctypes.byref (p1), p2, ctypes.byref (p3), ctypes.byref (p4)) > > Great. And that fails in what way, on which line, with what error message? -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From rosuav at gmail.com Tue Aug 12 15:09:13 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Aug 2014 05:09:13 +1000 Subject: Begginer in python trying to load a .dll In-Reply-To: <20140812115854.19cdccad@rg.highlandtechnology.com> References: <3dade0aa-55ca-4e52-af08-8104e9edf4c3@googlegroups.com> <20140812115854.19cdccad@rg.highlandtechnology.com> Message-ID: On Wed, Aug 13, 2014 at 4:58 AM, Rob Gaddi wrote: > Great. And that fails in what way, on which line, with what error message? And, is that the entire program? Because if it is, then I can see at least one problem, a NameError. ChrisA From rustompmody at gmail.com Tue Aug 12 15:05:45 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 12 Aug 2014 12:05:45 -0700 (PDT) Subject: Python in financial services In-Reply-To: References: <1c9a0c56-d898-4872-9df3-814816caf45f@googlegroups.com> Message-ID: <35550897-4ead-421b-acd6-ddd282643209@googlegroups.com> On Wednesday, August 13, 2014 12:24:12 AM UTC+5:30, Denis McMahon wrote: > On Tue, 12 Aug 2014 10:48:14 -0700, Rustom Mody wrote: > > However those folks have thousands of lines of C/C++ which they are > > porting to python. > That begs the question: Why? > Seriously, I'd like to know what benefits they expect to achieve by doing > so. Heh! I asked more or less that. Was told: "We want it!" I gather its to do with "agility" -- faster time to incorporate and integrate new logic into code etc. From camilocelyg at gmail.com Tue Aug 12 15:13:11 2014 From: camilocelyg at gmail.com (c1234 py) Date: Tue, 12 Aug 2014 12:13:11 -0700 (PDT) Subject: Begginer in python trying to load a .dll In-Reply-To: References: <3dade0aa-55ca-4e52-af08-8104e9edf4c3@googlegroups.com> <20140812115854.19cdccad@rg.highlandtechnology.com> Message-ID: On Tuesday, August 12, 2014 4:09:13 PM UTC-3, Chris Angelico wrote: > On Wed, Aug 13, 2014 at 4:58 AM, Rob Gaddi > > wrote: > > > Great. And that fails in what way, on which line, with what error message? > > > > And, is that the entire program? Because if it is, then I can see at > > least one problem, a NameError. > > > > ChrisA This appear in the terminal: >>> runfile('C://Python Scripts') File "C:\\sitecustomize.py", line 585, in runfile execfile(filename, namespace) File "C://Sin t?tulo 38.py", line 19, in hllApi = hllApiProto (("HLLAPI", hllDll), hllApiParams) AttributeError: function 'HLLAPI' not found >>> Traceback (most recent call last): File "", line 1, in From breamoreboy at yahoo.co.uk Tue Aug 12 15:16:17 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 12 Aug 2014 20:16:17 +0100 Subject: how to get the ordinal number in list In-Reply-To: <3htGv.167702$u21.75537@fx26.am4> References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> <53e824b9$0$30000$c3e8da3$5496439d@news.astraweb.com> <53E8D40F.8000007@chamonix.reportlab.co.uk> <9e179f4a-e56b-4100-9f8b-3d4e99cdc1ca@googlegroups.com> <3htGv.167702$u21.75537@fx26.am4> Message-ID: On 12/08/2014 19:45, alister wrote: > On Tue, 12 Aug 2014 23:39:42 +1000, Chris Angelico wrote: > >> On Tue, Aug 12, 2014 at 8:40 PM, alister >> wrote: >>> On Tue, 12 Aug 2014 00:21:28 -0700, wxjmfauth wrote: >>> [ chomp ] >>> >>> Mathematicians work with numbers (Algebra is a abstraction of numerical >>> concepts) strings are concerned with characters (Arabic numerals are >>> just characters commonly used to represent numbers ) >>> therefore even trying to rationalise any string representation with >>> mathematics is a logical absurdity in itself. >> >> Don't bother responding to jmf; he doesn't listen. Also, his posts don't >> survive the jump to python-list, so we see them only when someone quotes >> him like that... as far as I'm concerned, his posts are now on par with >> those trying to sell us solution manuals or herbal remedies. >> >> ChrisA > > As you don't see them unless someone replies I will make sure I don't > reply to any more of his posts. > > I would not want to inflict this nonsense on someone who would otherwise > be spared. > Thank you, as it saves me from once again losing it in public when his latest incarnation of complete dross appears. Two years he's been at it, I wonder how he manages to avoid "Sent to jail. Do not pass Go. Do not collect ?200" or where he gets his supply of "Get out of jail free" cards from? -- 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 Tue Aug 12 15:16:21 2014 From: auriocus at gmx.de (Christian Gollwitzer) Date: Tue, 12 Aug 2014 21:16:21 +0200 Subject: Begginer in python trying to load a .dll In-Reply-To: <3dade0aa-55ca-4e52-af08-8104e9edf4c3@googlegroups.com> References: <3dade0aa-55ca-4e52-af08-8104e9edf4c3@googlegroups.com> Message-ID: Am 12.08.14 20:36, schrieb c1223: > Hi, Im working in the development of a program based in python that > allow us to contrl a spectometer. The spectometer has an .dll file. > The idea is to work through this dll and operate the spectometer. The > name of the .dll is AS5216.dll. I've trying with ctype, but it > doesn't work. I'm begginer in python. All the comments are useful to > me. For sure this DLL will come with a header file for C. You could pass it through SWIG and see if it generates a useful Python module. You need a C compiler for that route, though. Christian From neilc at norwich.edu Tue Aug 12 15:29:35 2014 From: neilc at norwich.edu (Neil D. Cerutti) Date: Tue, 12 Aug 2014 15:29:35 -0400 Subject: how to get the ordinal number in list In-Reply-To: <70c65ab0-0a9d-4705-a8a3-43b9ee0600a0@googlegroups.com> References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <70c65ab0-0a9d-4705-a8a3-43b9ee0600a0@googlegroups.com> Message-ID: On 8/12/2014 2:20 PM, Rustom Mody wrote: > On Tuesday, August 12, 2014 11:10:48 PM UTC+5:30, Neil D. Cerutti wrote: >> Beginners are particularly poor, in relation to experts, at noticing the >> applicability of idea, and at combining ideas together. Breaking things >> into component parts has multiple benefits: > >> 1. The applicability of individual ideas becomes obvious. It's one thing >> to know about [].sort, and another thing to know when it's appropriate >> to sort something. > >> 2. The expert specifically shows how and why the ideas are combined. >> This helps build the connection for the beginner, whose knowledge is not >> stored as an expert stores it; i.e, in broad categories with multiple >> connections; but as disorganized data with very few connections. > > Nice! > > And how do we lead the beginners towards expertise? > In a way functional programming is to programming creativity > what lego is to children's spatial creativity. > > Specifically there are a bunch of pieces that need to fit: > > 1. Functional Programming: Nothing more than composing functions > [Maybe a bit simplistic but not unrealistic a defn] > 2. Trying this out at the interpreter > 3. Introspectable objects Functional programming could be particularly hard to teach since it is generally made up of numerous small units of work combined in a complex way. This is precisely the formula for something that beginners will find extremely challenging. When functional programming is dumbed down enough for a beginner to be able to grok it, the programming problems start to look really lame. It needn't be that way, of course, but it takes a good deal of creativity on the part of the instructor. If Factorial doesn't turn you on, you might be screwed. ;) > Some things follow from this: > > For the lego-game of playing with functions at the REPL to work and be > pleasant and rewarding: > > 1. functions should be non side-effecting; else same trials giving different > answers adds more confusion than understanding > 2. They should be non-printing else: > > def foo(x): return x+1 > def bar(x): print x+1 > > look similar when trivially tried but compositionally are utterly different > > In effect a printing function breaks the lego bricks That may be so, but printing stuff to the screen is very natural to people. I've downloaded Haskell a few times, but the knowledge that getting input and writing output requires something mysterious called gonads just frightens me. > [The P in the REPL is DRY enough that it does not usually need to be > repeated all over] A good REPL does help a lot, though. > 3. Abstractions (class instances) should be avoided in favor of > concrete data (lists, dicts, scalars) because they add undue mess at little > comprehension advantage. eg take the example of a regex match. It > returns some object and then we have to scratch our heads wondering > whats in the magic box. If instead of match, we use findall, the data > is manifest and obvious. I'm with you on regex: match objects suck. That and escaping. -- Neil Cerutti From camilocelyg at gmail.com Tue Aug 12 15:25:39 2014 From: camilocelyg at gmail.com (c1234 py) Date: Tue, 12 Aug 2014 12:25:39 -0700 (PDT) Subject: Begginer in python trying to load a .dll In-Reply-To: References: <3dade0aa-55ca-4e52-af08-8104e9edf4c3@googlegroups.com> Message-ID: El martes, 12 de agosto de 2014 16:16:21 UTC-3, Christian Gollwitzer escribi?: > Am 12.08.14 20:36, schrieb c1223: > > > Hi, Im working in the development of a program based in python that > > > allow us to contrl a spectometer. The spectometer has an .dll file. > > > The idea is to work through this dll and operate the spectometer. The > > > name of the .dll is AS5216.dll. I've trying with ctype, but it > > > doesn't work. I'm begginer in python. All the comments are useful to > > > me. > > > > For sure this DLL will come with a header file for C. You could pass it > > through SWIG and see if it generates a useful Python module. You need a > > C compiler for that route, though. > > > > Christian How can i pass it through a SWIG?, i don't know that and what it mean? From musicalhacksaw at yahoo.co.uk Tue Aug 12 16:00:30 2014 From: musicalhacksaw at yahoo.co.uk (Simon Evans) Date: Tue, 12 Aug 2014 13:00:30 -0700 (PDT) Subject: Suitable Python code to scrape specific details from web pages. Message-ID: Dear Programmers, I have been looking at the You tube 'Web Scraping Tutorials' of Chris Reeves. I have tried a few of his python programs in the Python27 command prompt, but altered them from accessing data using links say from the Dow Jones index, to accessing the details I would be interested in accessing from the 'Racing Post' on a daily basis. Anyhow, the code it returns is not in the example I am going to give, is not the information I am seeking, instead of returning the given odds on a horse, it only returns a [], which isn't much use. I would be glad if you could tell me where I am going wrong. Yours faithfully Simon Evans. -------------------------------------------------------------------------------- >>>import urllib >>>import re >>>htmlfile = urllib.urlopen("http://www.racingpost.com/horses2/cards/card.sd? race_id=600048r_date=2014-05-08#raceTabs=sc_") htmltext = htmlfile.read() regex = '1Lively Baron9/4F
' >>>pattern = re.compile(regex) >>>odds=re.findall(pattern,htmltext) >>>print odds [] >>> -------------------------------------------------------------------------------- >>>import urllib >>>import re >>>htmlfile = urllib.urlopen("http://www.racingpost.com/horses2/cards/card.sd? >>>race_id=600048r_date=2014-05-08#raceTabs=sc_") >>>htmltext = htmlfile.read() >>>regex = '' >>>pattern = re.compile(regex) >>>odds=re.findall(pattern,htmltext) >>>print odds [] >>> ------------------------------------------------------------------------------- From rgaddi at technologyhighland.invalid Tue Aug 12 16:11:47 2014 From: rgaddi at technologyhighland.invalid (Rob Gaddi) Date: Tue, 12 Aug 2014 13:11:47 -0700 Subject: Suitable Python code to scrape specific details from web pages. References: Message-ID: <20140812131147.5c99507c@rg.highlandtechnology.com> On Tue, 12 Aug 2014 13:00:30 -0700 (PDT) Simon Evans wrote: > Dear Programmers, > I have been looking at the You tube 'Web Scraping Tutorials' of Chris Reeves. I have tried a few of his python programs in the Python27 command prompt, but altered them from accessing data using links say from the Dow Jones index, to accessing the details I would be interested in accessing from the 'Racing Post' on a daily basis. Anyhow, the code it returns is not in the example I am going to give, is not the information I am seeking, instead of returning the given odds on a horse, it only returns a [], which isn't much use. > I would be glad if you could tell me where I am going wrong. > Yours faithfully > Simon Evans. > -------------------------------------------------------------------------------- > >>>import urllib > >>>import re > >>>htmlfile = urllib.urlopen("http://www.racingpost.com/horses2/cards/card.sd? > > race_id=600048r_date=2014-05-08#raceTabs=sc_") > htmltext = htmlfile.read() > regex = '1Lively > > Baron9/4F
' > >>>pattern = re.compile(regex) > >>>odds=re.findall(pattern,htmltext) > >>>print odds > [] > >>> > -------------------------------------------------------------------------------- > >>>import urllib > >>>import re > >>>htmlfile = urllib.urlopen("http://www.racingpost.com/horses2/cards/card.sd? > > >>>race_id=600048r_date=2014-05-08#raceTabs=sc_") > >>>htmltext = htmlfile.read() > >>>regex = '' > >>>pattern = re.compile(regex) > >>>odds=re.findall(pattern,htmltext) > >>>print odds > [] > >>> > ------------------------------------------------------------------------------- If you want web scraping, you want to use http://www.crummy.com/software/BeautifulSoup/ . End of story. -- 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 Tue Aug 12 16:17:26 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 12 Aug 2014 21:17:26 +0100 Subject: Begginer in python trying to load a .dll In-Reply-To: References: <3dade0aa-55ca-4e52-af08-8104e9edf4c3@googlegroups.com> Message-ID: On 12/08/2014 20:25, c1234 py wrote: > El martes, 12 de agosto de 2014 16:16:21 UTC-3, Christian Gollwitzer escribi?: >> Am 12.08.14 20:36, schrieb c1223: >> >>> Hi, Im working in the development of a program based in python that >> >>> allow us to contrl a spectometer. The spectometer has an .dll file. >> >>> The idea is to work through this dll and operate the spectometer. The >> >>> name of the .dll is AS5216.dll. I've trying with ctype, but it >> >>> doesn't work. I'm begginer in python. All the comments are useful to >> >>> me. >> >> >> >> For sure this DLL will come with a header file for C. You could pass it >> >> through SWIG and see if it generates a useful Python module. You need a >> >> C compiler for that route, though. >> >> >> >> Christian > > > How can i pass it through a SWIG?, i don't know that and what it mean? > Start here http://www.swig.org/ which you could easily have found for yourself, as I did by using a search engine. Also would you please access this list via https://mail.python.org/mailman/listinfo/python-list or read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing double line spacing and single line paragraphs, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From larry.martell at gmail.com Tue Aug 12 17:07:51 2014 From: larry.martell at gmail.com (Larry Martell) Date: Tue, 12 Aug 2014 17:07:51 -0400 Subject: Python in financial services In-Reply-To: References: Message-ID: On Tue, Aug 12, 2014 at 3:33 AM, Rustom Mody wrote: > Ive been asked to formulate a python course for financial services folk. > > If I actually knew about the subject, I'd have fatter pockets! > Anyway heres some thoughts. What I am missing out? > > [Apart from basic python -- contents typically needs tailoring to the audience] the following: > > - Libraries -- Decimal? > - scripts -- philosophy and infrastructure eg argparse, os.path > - Pandas > - Numpy Scipy (which? how much?) > - ipython + matplotlib + ?? > - Database interfacing > - Excel interfacing (couple of libraries.. which?) > - C(C++?) interfacing paradigms -- ranging from ctypes, cython to classic lo-level I'm not 100% sure what you're looking for. I work for a hedge fund and we make extensive use of python. Everything from soup to nuts: ETL, web scraping, database access (sybase, MySQL, and Oracle), log file archiving and reaping, wrappers for backups, startup and shutdown scripts for our C++ servers, GIUs (with wxpython), socket based communication with C++ servers, just about every problem that comes up. From roy at panix.com Tue Aug 12 17:28:15 2014 From: roy at panix.com (Roy Smith) Date: Tue, 12 Aug 2014 17:28:15 -0400 Subject: Suitable Python code to scrape specific details from web pages. References: Message-ID: In article , Simon Evans wrote: > Dear Programmers, > I have been looking at the You tube 'Web Scraping Tutorials' of Chris Reeves. > I have tried a few of his python programs in the Python27 command prompt, but > altered them from accessing data using links say from the Dow Jones index, to > accessing the details I would be interested in accessing from the 'Racing > Post' on a daily basis. Anyhow, the code it returns is not in the example I > am going to give, is not the information I am seeking, instead of returning > the given odds on a horse, it only returns a [], which isn't much use. > I would be glad if you could tell me where I am going wrong. Rather than comment on your specific code (but, thank you for posting it), I'll make a couple of more generic suggestions. First, if you're doing anything with fetching web pages, install the wonderful requests module (http://docs.python-requests.org/en/latest/). It's so much easier to work with than urllib. Second, if you're going to be parsing web pages, trying to use regexes is a losing game. You need something that knows how to parse HTML. The canonical answer is lxml (http://lxml.de/), but Beautiful Soup (http://www.crummy.com/software/BeautifulSoup/) is less intimidating to use. From ian.g.kelly at gmail.com Tue Aug 12 17:31:35 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 12 Aug 2014 15:31:35 -0600 Subject: Using asyncio workers in a `concurrent.futures` interface In-Reply-To: References: Message-ID: On Tue, Aug 12, 2014 at 11:02 AM, cool-RR wrote: > And that's it, no coroutines, no `yield from`. Since, if I understand correctly, asyncio requires a mainloop, it would make sense for the AsyncIOExecutor to have a thread of its own in which it could run its mainloop. I think that putting the event loop in a separate thread would be necessary if the intention is that the executor be invoked from outside. I'm not aware of this work having been done, but it sounds perfectly feasible. From tjreedy at udel.edu Tue Aug 12 18:01:12 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 12 Aug 2014 18:01:12 -0400 Subject: how to get the ordinal number in list In-Reply-To: References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> Message-ID: On 8/12/2014 1:40 PM, Neil D. Cerutti wrote: > I disagree. For a beginner, you want to be able to break things down > into individual steps and examine the result at each point. If you do: > >>>>> l= [6,2,9,12,1,4] >>>>> l2 = sorted(l,reverse=True) > > you have the advantage that you can stop after creating l2 and print it > out. The student can see that it has indeed been sorted. Or one can put the multiple steps in a file and step through with a debugger that shows local name values, like the Idle debugger. -- Terry Jan Reedy From musicalhacksaw at yahoo.co.uk Tue Aug 12 18:44:58 2014 From: musicalhacksaw at yahoo.co.uk (Simon Evans) Date: Tue, 12 Aug 2014 15:44:58 -0700 (PDT) Subject: Suitable Python code to scrape specific details from web pages. In-Reply-To: References: Message-ID: On Tuesday, August 12, 2014 9:00:30 PM UTC+1, Simon Evans wrote: > Dear Programmers, > > I have been looking at the You tube 'Web Scraping Tutorials' of Chris Reeves. I have tried a few of his python programs in the Python27 command prompt, but altered them from accessing data using links say from the Dow Jones index, to accessing the details I would be interested in accessing from the 'Racing Post' on a daily basis. Anyhow, the code it returns is not in the example I am going to give, is not the information I am seeking, instead of returning the given odds on a horse, it only returns a [], which isn't much use. > > I would be glad if you could tell me where I am going wrong. > > Yours faithfully > > Simon Evans. > > -------------------------------------------------------------------------------- > > >>>import urllib > > >>>import re > > >>>htmlfile = urllib.urlopen("http://www.racingpost.com/horses2/cards/card.sd? > > > > race_id=600048r_date=2014-05-08#raceTabs=sc_") > > htmltext = htmlfile.read() > > regex = '1Lively > > > > Baron9/4F
' > > >>>pattern = re.compile(regex) > > >>>odds=re.findall(pattern,htmltext) > > >>>print odds > > [] > > >>> > > -------------------------------------------------------------------------------- > > >>>import urllib > > >>>import re > > >>>htmlfile = urllib.urlopen("http://www.racingpost.com/horses2/cards/card.sd? > > > > >>>race_id=600048r_date=2014-05-08#raceTabs=sc_") > > >>>htmltext = htmlfile.read() > > >>>regex = '' > > >>>pattern = re.compile(regex) > > >>>odds=re.findall(pattern,htmltext) > > >>>print odds > > [] > > >>> > > ------------------------------------------------------------------------------- Dear Programmers, Thank you for your responses. I have installed 'Beautiful Soup' and I have the 'Getting Started in Beautiful Soup' book, but can't seem to make any progress with it, I am too thick to make much use of it. I was hoping I could scrape specified stuff off Web pages without using it. I have installed 'Requests' also, is there any code I can use that you can suggest that can access the sort of Web page values that I have referred to ? such as odds, names of runners, stuff like that off the 'inspect element' or 'source' htaml pages, on www.Racingpost.com. From steve+comp.lang.python at pearwood.info Tue Aug 12 20:04:12 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 13 Aug 2014 10:04:12 +1000 Subject: Suitable Python code to scrape specific details from web pages. References: Message-ID: <53eaab7d$0$29979$c3e8da3$5496439d@news.astraweb.com> Simon Evans wrote: > Dear Programmers, Thank you for your responses. I have installed > 'Beautiful Soup' and I have the 'Getting Started in Beautiful Soup' book, > but can't seem to make ?any progress with it, I am too thick to make much > use of it. I was hoping I could scrape specified stuff off Web pages > without using it. Yes, you can scrape stuff off web pages without programming. What you do is you open the web page in your browser, then open a notebook and, with a pencil or pen, copy the bits you read into the notebook. If you're very skilled, you can avoid the pencil and paper and type directly into a text editor on the computer. But other than that, every website is different, so there is no short-cut to web scraping. You need to customize the scraping code for each website you scrape, and that means programming. Do you know how to program? Are you interested in learning? If the answer is No and No, then I suggestion you pony up some money and pay somebody who already knows how to program to do the job for you. If the answer is No and Yes, then start at the beginning. Do some programming tutorials, learn to program the basics before moving on to something moderately difficult like web scraping. If the answer is that you already know how to program, but just don't know how to do web scraping, then stick with it and you'll get there. Web scraping is tricky, but possible, and if you work hard at it you'll succeed. Unless you're an experienced programmer with all the right skills, don't expect this to be something you do in a few minutes. Depending on your level of experience, you could expect to spend dozens of hours to learn how to scrape a single website. (Fortunately, the second website will probably be a little easier, and the third easier still. By the time you've done a dozen, you'll wonder what the fuss was about.) By studying how other scraping programs work, and studying how your racing pages store data, you should be able to put the two together and see how to get the data you want. There's plenty of information to help you learn how to web scrape, with or without BeautifulSoup: https://startpage.com/do/search/?q=beautifulsoup+web+scraping https://ixquick.com/do/search/?q=python+web+scraping+examples https://duckduckgo.com/html/?q=requests%20python%20web%20scraping%20example but no alternative to actually writing code. > I have installed 'Requests' also, is there any code I > can use that you can suggest that can access the sort of Web page values > that I have referred to ? ?such as odds, names of runners, stuff like that > off the 'inspect element' or 'source' htaml pages, on www.Racingpost.com. Specifically those pages? Doubtful. If you are really lucky (1) somebody else has already done the programming, (2) they've made their program available to others, and (3) you can find that program on the Internet. Use the search engine of your choice to search for it. -- Steven From roy at panix.com Tue Aug 12 20:30:39 2014 From: roy at panix.com (Roy Smith) Date: Tue, 12 Aug 2014 20:30:39 -0400 Subject: Suitable Python code to scrape specific details from web pages. References: <53eaab7d$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <53eaab7d$0$29979$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > By studying how other scraping programs work, and studying how your racing > pages store data, you should be able to put the two together and see how to > get the data you want. It's also worth mentioning, that some web sites *want* you to have their data, and make it easy to do so by exposing it via public APIs or other download methods. Wikipedia. Many government web sites. Twitter. Facebook. Reddit. Whenever you start thinking about web scraping, it's always worth spending a little time investigating if such an API exists. If it does, that's where you want to go. If not, well, there's always Beautiful Soup :-) From steve+comp.lang.python at pearwood.info Tue Aug 12 20:47:16 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 13 Aug 2014 10:47:16 +1000 Subject: how to get the ordinal number in list References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> <53e89063$0$29890$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53eab595$0$9505$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > On Mon, Aug 11, 2014 at 7:44 PM, Steven D'Aprano > wrote: >> I think this is why both declarative and functional programming idioms >> will remain niche (although important niches). Most tasks are inherently >> imperative to at least some degree, and often a *great* degree. > > Maybe that's true as a whole, but there are certainly ways in which > certain declarative or functional elements can be extremely useful to > an otherwise-imperative program. Oh yes! I think that using functional idioms is *very* valuable. List comps and similar are great, but more than that, the idea of writing idempotent functions with no side-effects (except IO) is (I believe) vital for good programming. Relying on argument passing rather communicating by global variables (or the OO equivalent, instance attributes) is likewise vital. It's not *quite* impossible to write good, reliable code without functional idioms, in the same sense that it is conceivable that somebody might write bug-free unstructured spaghetti code, but I think one of the failures of OO programming is the over-reliance on methods that communicate via side-effects. I don't insist that side-effects are completely verboten, as some functional programming purists do, but I do endeavour to ensure that any side-effects are limited, encapsulated, and introduce as little coupling as practical. (It is my belief that inappropriate coupling is the great evil in programming. Having too much coupling between parts of your code which ought to be independent is like Ebola for reliable code, contagious and deadly. I'm always looking for ways to reduce coupling between parts of my code, and functional idioms are good for that.) > Python's (list etc) comprehensions > are broadly functional in style, No surprise, since list comps were stolen from Haskell :-) [...] > I've sometimes done some extremely declarative coding in places; my > MUD client builds its menus by looking for specially-named functions > and getting some metadata from them to work out what the menu item > name should be. An approximate Python equivalent would be: > > @filemenu("E_xit") > def exit(): > prompt("Do you really want to exit?") > > where the presence of the function is what causes the menu item to > exist. In this case, the 'filemenu' decorator is probably imperative > code that adds the menu item to the File menu, but if you're reading > through a source file that has a bunch of functions like that, you'd > have to agree that that's a declarative style of coding. And it's a > style that works well for this kind of thing. I don't think I would agree that's declarative style. I think that's a form of imperative programming, where the syntax is: @ make menu def function: ... rather than: def function: ... make menu (function) but I wouldn't start a Holy War over it :-) There's a fair amount of overlap between the major programming paradigms, and hence disagreement as to what falls under which paradigm. For instance, FOLDOC has a good, simple distinction in its definition for "imperative": [quote] The Free On-line Dictionary of Computing (20 July 2014) [foldoc] imperative language imperative imperative programming Any programming language that specifies explicit manipulation of the state of the computer system, not to be confused with a procedural language, which specifies an explicit sequence of steps to perform. An example of an imperative (but non-procedural) language is a data manipulation language for a relational database management system. This specifies changes to the database but does not necessarily require anyone to specify a sequence of steps. Both contrast with declarative languages, which specify neither explicit state manipulation nor a sequence of steps. [end quote] You'll note that it suggests SQL would count as an imperative language, but Wikipedia's article on declarative languages gives SQL as a paragon of declarative languages! http://en.wikipedia.org/wiki/Declarative_programming In Python terms, we might consider "import" to be declarative, since it specifies what to do (load a name from a module) but not how to perform it. "import spam" might find spam anywhere, in any form (source code, byte code, machine code, in a zip file, somewhere on the disk, inside the Python executable itself), which to my mind suggests a declarative idiom. Or such things as test discovery, where unittest and doctest will automatically locate and run tests. (The tests themselves are typically written in a procedural paradigm.) Otherwise, Python doesn't really have a lot to offer in the declarative paradigm. -- Steven From ppearson at nowhere.invalid Tue Aug 12 20:50:55 2014 From: ppearson at nowhere.invalid (Peter Pearson) Date: 13 Aug 2014 00:50:55 GMT Subject: Suitable Python code to scrape specific details from web pages. References: Message-ID: On Tue, 12 Aug 2014 15:44:58 -0700 (PDT), Simon Evans wrote: [snip] > Dear Programmers, Thank you for your responses. I have installed > 'Beautiful Soup' and I have the 'Getting Started in Beautiful Soup' > book, but can't seem to make any progress with it, I am too thick to > make much use of it. I was hoping I could scrape specified stuff off > Web pages without using it. I've only used BeautifulSoup a little bit, and am no expert, but with it one can do wonderfully complex things with simple code. Perhaps you can find some examples online; this newsgroup sometimes has awesome demonstrations of BS prowess. At the risk of embarrassing myself in public, I'll show you some code I wrote that scrapes data from a web page containing a description of a drug. The drug's web page contains the desired data in tags that look like this: The following code finds all these tags and builds a dict by which you can lookup the "value" for any given "name". from BeautifulSoup import BeautifulSoup as BS ... def dump_drug_data(url): """Fetch data from one drug's URL and print selected fields in columns. """ contents = urllib2.urlopen(url=url).read() soup = BS(contents) inputs = soup.findAll("input") input_dict = dict((i.get("name"), i.get("value")) for i in inputs) print(" ".join(f.format(input_dict[n]) for f, n in ( ("{0:5s}", "form.widgets.absorption_halflife"), ("{0:5s}", "form.widgets.elimination_halflife"), ("{0:5s}", "form.widgets.minconcentration"), ("{0:5s}", "form.widgets.maxconcentration"), ("{0:13s}", "form.widgets.title"), ))) Try giving a more specific picture of your quest, and it's very likely that people smarter than me will give you good help. -- To email me, substitute nowhere->spamcop, invalid->net. From rosuav at gmail.com Tue Aug 12 21:31:59 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Aug 2014 11:31:59 +1000 Subject: how to get the ordinal number in list In-Reply-To: <53eab595$0$9505$c3e8da3$5496439d@news.astraweb.com> References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> <53e89063$0$29890$c3e8da3$5496439d@news.astraweb.com> <53eab595$0$9505$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Aug 13, 2014 at 10:47 AM, Steven D'Aprano wrote: > Chris Angelico wrote: > >> On Mon, Aug 11, 2014 at 7:44 PM, Steven D'Aprano >> wrote: >>> I think this is why both declarative and functional programming idioms >>> will remain niche (although important niches). Most tasks are inherently >>> imperative to at least some degree, and often a *great* degree. >> >> Maybe that's true as a whole, but there are certainly ways in which >> certain declarative or functional elements can be extremely useful to >> an otherwise-imperative program. > > Oh yes! I think that using functional idioms is *very* valuable. List comps > and similar are great, but more than that, the idea of writing idempotent > functions with no side-effects (except IO) is (I believe) vital for good > programming. Relying on argument passing rather communicating by global > variables (or the OO equivalent, instance attributes) is likewise vital. > ... > (It is my belief that inappropriate coupling is the great evil in > programming. Having too much coupling between parts of your code which > ought to be independent is like Ebola for reliable code, contagious and > deadly. I'm always looking for ways to reduce coupling between parts of my > code, and functional idioms are good for that.) There are times when coupling is unavoidable, but yes, it's usually detrimental to the code. Sometimes the alternatives are worse, but coupling is still bad. I have TODOs against certain pieces of code where I can't think of a clean way to decouple them... >> I've sometimes done some extremely declarative coding in places; my >> MUD client builds its menus by looking for specially-named functions >> and getting some metadata from them to work out what the menu item >> name should be. An approximate Python equivalent would be: >> >> @filemenu("E_xit") >> def exit(): >> prompt("Do you really want to exit?") >> >> where the presence of the function is what causes the menu item to >> exist. In this case, the 'filemenu' decorator is probably imperative >> code that adds the menu item to the File menu, but if you're reading >> through a source file that has a bunch of functions like that, you'd >> have to agree that that's a declarative style of coding. And it's a >> style that works well for this kind of thing. > > I don't think I would agree that's declarative style. I think that's a form > of imperative programming, where the syntax is: > > @ make menu > def function: ... > > rather than: > > def function: ... > make menu (function) > > but I wouldn't start a Holy War over it :-) In a sense, yes. That's partly because Python doesn't really have the concept that I'm using here. Here's the actual code (it's Pike): constant file_closewindow="E_xit"; int closewindow() { ... actual body of function isn't significant ... } The key here is the module-level constant which is "file_" followed by the name of a function. So a more direct translation into Python would be: file_closewindow="E_xit" def closewindow(): ... blah blah ... but since Python code tends to have uppercase constants, this would be frowned on. Also, it's hard in Python to "enumerate constants", as there's no such thing (Pike's constants are available at a slightly different level, which makes them easy to find). What might make it more declarative than imperative, even in Python, is that the *order* of items on the menu is alphabetical by function name, and thus has nothing to do with their position in the file. If the decorator actually added the items to the menu immediately, their positions would be based on order in the file; to do them alphabetically by function name, you basically need to collect them all up and create them all at the end. That's how the code works in Pike - a quick loop in the initialization code runs over the constants and adds the menu items, which means the constants are completely non-executable. It really is hard to draw the line. Ultimately, the CPU (at least, if it's of any architecture I've worked with) doesn't execute declarative or functional code, just as it doesn't execute callbacks or subthread multiplexing or anything like that. You need to have, somewhere, a bit of imperative code (usually a simple loop) that deals with the other types... which might be called an interpreter. In fact, *all* high level code is, in a sense, declarations to a lower level interpreter - consider the distinctions between various Python interpreters (even some that run inside your web browser), and how they all obey the same declarations, but implement them completely differently. > [ quoting FOLDOC ] > An example of an imperative (but non-procedural) language is a > data manipulation language for a relational database > management system. This specifies changes to the database > but does not necessarily require anyone to specify a sequence > of steps. > > Both contrast with declarative languages, which specify > neither explicit state manipulation nor a sequence of steps. > [end quote] > > You'll note that it suggests SQL would count as an imperative language, but > Wikipedia's article on declarative languages gives SQL as a paragon of > declarative languages! > > http://en.wikipedia.org/wiki/Declarative_programming Yeah, it's hard to draw the line. I like to look at SQL as a language that specifies an end result without specifying how to get there [1] and Python as a language that specifies exactly what to do. According to FOLDOC's definition, both of those are imperative languages, but the techniques for developing and debugging them vary significantly. Actually, that's probably the most useful way to distinguish, especially since it's easy to slide from one paradigm to another in the same language, even in the same program (your event handler is triggered by the magic of callbacks, but inside it, your code is strictly imperative). How do you go about debugging a piece of code? If you reorder things inside the code itself with the expectation that it'll have a clear and simple effect on the code's behaviour, that's imperative. If you tweak the external algorithms or change non-executable code in order to achieve what you want, that's declarative. > In Python terms, we might consider "import" to be declarative, since it > specifies what to do (load a name from a module) but not how to perform > it. "import spam" might find spam anywhere, in any form (source code, byte > code, machine code, in a zip file, somewhere on the disk, inside the Python > executable itself), which to my mind suggests a declarative idiom. Or such > things as test discovery, where unittest and doctest will automatically > locate and run tests. (The tests themselves are typically written in a > procedural paradigm.) Otherwise, Python doesn't really have a lot to offer > in the declarative paradigm. It's just as declarative as 'def' or 'class'. Technically, they're all executable statements; when the interpreter reaches one of them, it goes off and does what you asked it to do, and then continues on. But practically, they're usually used declaratively - "if I put this code in my file, I will have a function with this name". Most people will happily write Python functions with 'def' in the same way they'd write C functions, or PHP functions, or anything else, and the significance of def being executable is only seen when you have nested functions etc. Even order of execution is almost never a problem, except for class inheritance - and frankly, I've never seen anyone define a superclass lower in a file than its subclasses, in *any* language. When was the last time you needed to be aware that any of these three (import/def/class) was truly executable? ChrisA [1] There are exceptions - the CREATE INDEX command in various engines lets you do a lot more specification, and there are abominations in a popular low-end database that let you stipulate how a SELECT statement is to be processed, but the intent of SQL is to specify only the end result. From nispray at gmail.com Tue Aug 12 21:36:21 2014 From: nispray at gmail.com (Wesley) Date: Tue, 12 Aug 2014 18:36:21 -0700 (PDT) Subject: Captcha identify In-Reply-To: References: <8c2e4bc2-4f46-4a68-83ed-469fe171de3a@googlegroups.com> <2320baf0-e097-4d67-97c1-dd37ca79fffb@googlegroups.com> Message-ID: <376a239c-77e8-4e0e-9300-847dfa8a8547@googlegroups.com> If my questions make you guys not so happy, I am sorry and please just ignore. I just wanna a general suggestion here in the beginning. Why I need to write such program is just having such requirements, and has nothing to do with the coding work itself. Don't say something to prove you're so noble. From rosuav at gmail.com Tue Aug 12 21:46:48 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Aug 2014 11:46:48 +1000 Subject: Captcha identify In-Reply-To: <376a239c-77e8-4e0e-9300-847dfa8a8547@googlegroups.com> References: <8c2e4bc2-4f46-4a68-83ed-469fe171de3a@googlegroups.com> <2320baf0-e097-4d67-97c1-dd37ca79fffb@googlegroups.com> <376a239c-77e8-4e0e-9300-847dfa8a8547@googlegroups.com> Message-ID: On Wed, Aug 13, 2014 at 11:36 AM, Wesley wrote: > If my questions make you guys not so happy, I am sorry and please just ignore. > I just wanna a general suggestion here in the beginning. > Why I need to write such program is just having such requirements, and has nothing to do with the coding work itself. Don't say something to prove you're so noble. The general suggestion you're getting is: Do not do this. Many of us here use CAPTCHAs and spend time keeping one step ahead of those who try to break them with software. By writing something to solve CAPTCHAs, you would be stealing time from those people. Don't do it. Am I sufficiently clear? ChrisA From roy at panix.com Tue Aug 12 21:45:15 2014 From: roy at panix.com (Roy Smith) Date: Tue, 12 Aug 2014 21:45:15 -0400 Subject: how to get the ordinal number in list References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> <53e89063$0$29890$c3e8da3$5496439d@news.astraweb.com> <53eab595$0$9505$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Chris Angelico wrote: > I like to look at SQL as a language that specifies an end result > without specifying how to get there Well, sure, but sometimes the how to get there is a matter of 10x, or 100x, or 1000x in performance. I'm currently migrating a 3 TB database to a new 5 TB RAID array. Our initial guess is it's going to take two weeks to finish :-( From ben+python at benfinney.id.au Tue Aug 12 21:54:24 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 13 Aug 2014 11:54:24 +1000 Subject: Captcha identify References: <8c2e4bc2-4f46-4a68-83ed-469fe171de3a@googlegroups.com> <2320baf0-e097-4d67-97c1-dd37ca79fffb@googlegroups.com> <376a239c-77e8-4e0e-9300-847dfa8a8547@googlegroups.com> Message-ID: <85zjf96tnz.fsf@benfinney.id.au> Wesley writes: > If my questions make you guys not so happy, I am sorry and please just > ignore. You seek to dismiss the valid concerns by calling them ?not so happy?. You assert it is questions we object to, when we are clearly objecting to your intentions. Don't be disingenuous. The responses you get are because there are valid concerns about the motives you are pursuing. > Why I need to write such program is just having such requirements This is a circular statement, almost a tautology. If that is the best you can present in defense of harmful and deceitful actions, then there is no good reason for what you're doing. Stop, please. -- \ ?The World is not dangerous because of those who do harm but | `\ because of those who look at it without doing anything.? | _o__) ?Albert Einstein | Ben Finney From rosuav at gmail.com Tue Aug 12 22:06:40 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Aug 2014 12:06:40 +1000 Subject: how to get the ordinal number in list In-Reply-To: References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> <53e89063$0$29890$c3e8da3$5496439d@news.astraweb.com> <53eab595$0$9505$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Aug 13, 2014 at 11:45 AM, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> I like to look at SQL as a language that specifies an end result >> without specifying how to get there > > Well, sure, but sometimes the how to get there is a matter of 10x, or > 100x, or 1000x in performance. Of course it can! But generally, the "how to get there" is not stipulated in the SQL statement. If you say, for instance: select * from some_table where some_column='some_value'; then an index on some_column will make a huge difference to performance - without changing this statement at all. In contrast, taking advantage of an index in BTrieve requires recoding your program, as the index used is a part of the API call. (At least, this is true of the particular version of BTrieve that back-ended our accounting package in the 90s. I was able to turn an overnight job into a thirty-second job by rewriting it as an external program; the original is closed-source so I can't be sure, but I suspect most of that improvement is simply because I used an index.) SQL itself doesn't even have provision for indexes. The 'CREATE INDEX' command, found in many databases, is an extension. :) ChrisA From steve+comp.lang.python at pearwood.info Tue Aug 12 22:11:14 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 13 Aug 2014 12:11:14 +1000 Subject: how to get the ordinal number in list References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <53e831d1$0$30002$c3e8da3$5496439d@news.astraweb.com> <2768e86c-34cf-4478-ac02-2ea6a4eb9236@googlegroups.com> <53e89aeb$0$29890$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53eac942$0$29980$c3e8da3$5496439d@news.astraweb.com> Rustom Mody wrote: > I guess part of the problem is that evidently you and I use 'concrete' > and 'abstract' in almost diametrically opposite ways. [...] > But now you are turning the tables and saying that the FP types/constructs > are more abstract than the conventional ones. [...] > In my book, FP is easy and pleasant and smooth because (among other > things) FP types are concrete, whereas OOP types are abstract. I wrote about how your view of sorted() was an abstraction, not an Abstract Base Class. I thought that was clear enough: you ignore the concrete details of how one sorts (bubblesort, quicksort, timsort, ...) and everything but the result returned. I shouldn't think that is controversial. Let me repeat what I said at the time: You are abstracting away the details of the real computer implementation into an abstraction of a pure mathematical function... I am not talking about *abstract types* in the object-oriented sense. I then went on to say: But abstractions leak, and someday someone is going to ask "Why does it take 45 minutes to find the five largest values of my list?", and if you persist in insisting that sorted() is a pure mathematical function you will have no clue on how to even begin solving this [...] (I don't actually believe that *you personally* are incapable of thinking about the implementation of sorted(). It is a hypothetical situation.) For the record, Wikipedia defines abstract types as: In programming languages, an abstract type is a type in a nominative type system which cannot be instantiated directly. Abstract types are also known as existential types. and contrasts them with "concrete types" like Python's float, list, str. I am using "abstract" in the sense of an abstraction, as opposed to something concrete and real, not as a mechanism for specifying interfaces in Java or Python. Python's float is a leaky abstraction of mathematical Real numbers, and Python's softed() is a leaky abstraction of the concept of sorting a collection. Both are abstractions, because they are *intended* to gloss over real world details of Real numbers and sorting, but both leak because the implementation of the abstraction spoils the abstraction. http://www.joelonsoftware.com/articles/LeakyAbstractions.html -- Steven From rosuav at gmail.com Tue Aug 12 22:18:34 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Aug 2014 12:18:34 +1000 Subject: how to get the ordinal number in list In-Reply-To: <53eac942$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <53e831d1$0$30002$c3e8da3$5496439d@news.astraweb.com> <2768e86c-34cf-4478-ac02-2ea6a4eb9236@googlegroups.com> <53e89aeb$0$29890$c3e8da3$5496439d@news.astraweb.com> <53eac942$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Aug 13, 2014 at 12:11 PM, Steven D'Aprano wrote: > both leak > because the implementation of the abstraction spoils the abstraction. Can you name *any* nontrivial abstraction that doesn't leak? I can't. ChrisA From steve+comp.lang.python at pearwood.info Tue Aug 12 23:11:25 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 13 Aug 2014 13:11:25 +1000 Subject: how to get the ordinal number in list References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <53e831d1$0$30002$c3e8da3$5496439d@news.astraweb.com> <2768e86c-34cf-4478-ac02-2ea6a4eb9236@googlegroups.com> <53e89aeb$0$29890$c3e8da3$5496439d@news.astraweb.com> <53eac942$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53ead75e$0$29986$c3e8da3$5496439d@news.astraweb.com> Steven D'Aprano wrote: [...] > I am using "abstract" in the sense of an abstraction, as opposed to > something concrete and real, not as a mechanism for specifying interfaces > in Java or Python. Python's float is a leaky abstraction of mathematical > Real numbers, and Python's softed() is a leaky abstraction of the concept > of sorting a collection. Oh, I forgot to mention... "sorting a collection" is itself an abstraction (that is, a generalisation) of concrete examples of sorting, such as sorting a hand of cards, sorting an unruly crowd of school children into order of height, sorting out a messy cutlery drawer, or sorting the books in a library. Abstractions are good and necessary, being a programmer is about learning to invent and use abstractions, but both object-oriented and functional programming circles are prone to over-abstraction and that's why they're a an ill-fit for teaching beginners. To a beginner, functions and their return result is an abstraction (and quite a hard one for many people to learn). The natural tendency is to write functions like this: def frobnicate(value): print (value + spam + eggs) because they're thinking "how do I get the frobnicated value?" and the obvious interface between "I" (the beginner) and the computer is visual. They haven't learned the essential abstraction known as "returning a value" yet and so they use: - calculate the frobnicated value - print it instead of the generalisation: - calculate the frobnicated value - return[1] it to the caller[2] - which captures that return result somewhere[3] - and finally prints it or possibly this one: - calculate the frobnicated value - return it to the REPL - which prints it then throws it away [1] What does "return" in the context of functions even mean? Try explaining it to a beginner who doesn't understand functions. The best I can come up with is you just keep showing them examples until they draw the connection themselves. [2] Who? [3] Where? -- Steven From rustompmody at gmail.com Tue Aug 12 23:49:36 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 12 Aug 2014 20:49:36 -0700 (PDT) Subject: how to get the ordinal number in list In-Reply-To: References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <70c65ab0-0a9d-4705-a8a3-43b9ee0600a0@googlegroups.com> Message-ID: <0e4abe43-e864-4e19-b0f1-2c60c74ee3b6@googlegroups.com> On Wednesday, August 13, 2014 12:59:35 AM UTC+5:30, Neil D. Cerutti wrote: > > Some things follow from this: > > For the lego-game of playing with functions at the REPL to work and be > > pleasant and rewarding: > > 1. functions should be non side-effecting; else same trials giving different > > answers adds more confusion than understanding > > 2. They should be non-printing else: > > def foo(x): return x+1 > > def bar(x): print x+1 > > look similar when trivially tried but compositionally are utterly different > > In effect a printing function breaks the lego bricks > That may be so, but printing stuff to the screen is very natural to > people. I've downloaded Haskell a few times, but the knowledge that > getting input and writing output requires something mysterious called > gonads just frightens me. I thought they were quite common But yes... - Monads in Haskell - Pointers in C - Inheritance in Java/Python all suffer the same problem -- glorification of the failure-mode. When one uses pointers, especially non-trivial pointer arithmetic in C, one is essentially blasting a hole in the floor of the hi-level facade of C and working at machine level. Inheritance produces coupling whereas the whole intent of modularity is to avoid coupling. Likewise Monads are for imperative programming in Haskell. Maybe better to just use an imperative language? > Functional programming could be particularly hard to teach since it is > generally made up of numerous small units of work combined in a complex > way. This is precisely the formula for something that beginners will > find extremely challenging. > When functional programming is dumbed down enough for a beginner to be > able to grok it, the programming problems start to look really lame. It > needn't be that way, of course, but it takes a good deal of creativity > on the part of the instructor. If Factorial doesn't turn you on, you > might be screwed. ;) Did you see my example a bit earlier on Catalan numbers? I believe it explains them better -- certainly more succinctly -- than the math+verbiage you can find at: http://en.wikipedia.org/wiki/Catalan_number Yes it may be hard to grok but I think its the exact opposite of 'numerous small units' From marko at pacujo.net Wed Aug 13 01:03:01 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 13 Aug 2014 08:03:01 +0300 Subject: Using asyncio workers in a `concurrent.futures` interface References: Message-ID: <8738d1dlru.fsf@elektro.pacujo.net> Ian Kelly : > On Tue, Aug 12, 2014 at 11:02 AM, cool-RR wrote: >> And that's it, no coroutines, no `yield from`. Since, if I understand >> correctly, asyncio requires a mainloop, it would make sense for the >> AsyncIOExecutor to have a thread of its own in which it could run its >> mainloop. > > I think that putting the event loop in a separate thread would be > necessary if the intention is that the executor be invoked from > outside. I'm not aware of this work having been done, but it sounds > perfectly feasible. Multithreading will require normal locking to protect critical sections. Care must be taken to never yield while holding a threading lock. Marko From ian.g.kelly at gmail.com Wed Aug 13 02:03:42 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 13 Aug 2014 00:03:42 -0600 Subject: Using asyncio workers in a `concurrent.futures` interface In-Reply-To: <8738d1dlru.fsf@elektro.pacujo.net> References: <8738d1dlru.fsf@elektro.pacujo.net> Message-ID: On Tue, Aug 12, 2014 at 11:03 PM, Marko Rauhamaa wrote: > > Ian Kelly : > > > On Tue, Aug 12, 2014 at 11:02 AM, cool-RR wrote: > >> And that's it, no coroutines, no `yield from`. Since, if I understand > >> correctly, asyncio requires a mainloop, it would make sense for the > >> AsyncIOExecutor to have a thread of its own in which it could run its > >> mainloop. > > > > I think that putting the event loop in a separate thread would be > > necessary if the intention is that the executor be invoked from > > outside. I'm not aware of this work having been done, but it sounds > > perfectly feasible. > > Multithreading will require normal locking to protect critical sections. > Care must be taken to never yield while holding a threading lock. You can use event_loop.call_soon_threadsafe() to schedule tasks and callbacks on the event loop, and Queue objects to pass futures back to the caller. Apart from whatever synchronization those use internally, I don't think any locking would be needed. However, it would of course require that the "functions" passed in to the executor be coroutines in actuality. You just can't pass a blocking function into an asynchronous framework and expect it to magically not block. -------------- next part -------------- An HTML attachment was scrubbed... URL: From fpscafidi at gmail.com Tue Aug 12 19:57:14 2014 From: fpscafidi at gmail.com (Frank Scafidi) Date: Tue, 12 Aug 2014 19:57:14 -0400 Subject: newbee Message-ID: I just acquired a Raspberry Pi and want to program in Python. I was a PL/1 programmer back in the 60's & 70's and Python is similar. I am struggling with some very fundamental things that I am not finding in the documentation. Can someone help me with the basics like how do I save a program I've written, reload it in Python, list the program once it's loaded? How do I edit a program? Are these command line functions? Thanks Frank -------------- next part -------------- An HTML attachment was scrubbed... URL: From ed at pythoncharmers.com Tue Aug 12 23:28:03 2014 From: ed at pythoncharmers.com (Ed Schofield) Date: Wed, 13 Aug 2014 13:28:03 +1000 Subject: [Announce] Python-Future v0.13; cheatsheet for Python 2/3 compatible code Message-ID: <5E4F35CB-6A69-4DA6-99DD-7B0A85672BC6@pythoncharmers.com> Hi all, I am happy to announce an update to Python-Future for Python 2/3 compatibility and a new cheat-sheet for writing code compatible with both versions. Here?s the "What?s New" page for v0.13: http://python-future.org/whatsnew.html Here?s the Py2/3 compatibility cheat-sheet: http://python-future.org/compatible_idioms.html or as a PDF: http://python-future.org/compatible_idioms.pdf The cheat-sheet accompanies a talk I gave at PyCon AU 2014 last weekend called ?Writing Python 2/3 compatible code?. I will add a link to the video and slides from the cheat-sheet page when they are online. I would be happy to accept pull requests for additions or changes to the Py2/3 cheat-sheet. The source is here: https://github.com/PythonCharmers/python-future/blob/master/docs/notebooks/Writing%20Python%202-3%20compatible%20code.ipynb Best wishes, Ed -- Dr. Edward Schofield Python Charmers http://pythoncharmers.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From wxjmfauth at gmail.com Wed Aug 13 02:43:50 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Tue, 12 Aug 2014 23:43:50 -0700 (PDT) Subject: Python in financial services In-Reply-To: References: Message-ID: <6232be8e-0438-4936-b257-828f0bb3e1c2@googlegroups.com> Le mardi 12 ao?t 2014 09:33:11 UTC+2, Rustom Mody a ?crit : > Ive been asked to formulate a python course for financial services folk. > > > > If I actually knew about the subject, I'd have fatter pockets! > > Anyway heres some thoughts. What I am missing out? > > > > [Apart from basic python -- contents typically needs tailoring to the audience] the following: > > > > - Libraries -- Decimal? > > - scripts -- philosophy and infrastructure eg argparse, os.path > > - Pandas > > - Numpy Scipy (which? how much?) > > - ipython + matplotlib + ?? > > - Database interfacing > > - Excel interfacing (couple of libraries.. which?) > > - C(C++?) interfacing paradigms -- ranging from ctypes, cython to classic lo-level I recommend to toy intensively with the 'EURO SIGN' in strings manipulations. Py3: It may luckily work, Python may crash or fails (it raises unicode errors on valid string!). Py2: It is safer and solid. There is however a subtility. 3rd party tools may consider the Euro as byte or as unicode and/or are missinterpreting it, leading to a huge missmatch. Example: IDLE >>> print 'EURO' * 10 EURO EURO EURO EURO EURO EURO EURO EURO EURO EURO >>> print u'EURO' * 10 >>> # result: nothing! >>> This is not specific to the Euro. I let as an exercise to *understand* which chars are suffering from this issue. (Py2 and Py3) jmf PS Go, Ruby, C#, TeX (unicode engines): never meet a problem. From michele.simionato at gmail.com Wed Aug 13 04:32:04 2014 From: michele.simionato at gmail.com (Michele Simionato) Date: Wed, 13 Aug 2014 01:32:04 -0700 (PDT) Subject: Python Object Systems In-Reply-To: <2d41828e-19ac-4e46-a487-8700c22d9b92@googlegroups.com> References: <2d41828e-19ac-4e46-a487-8700c22d9b92@googlegroups.com> Message-ID: Years ago I wrote strait: https://pypi.python.org/pypi/strait I wonder who is using it and for what purpose, since surprisingly enough it has 50+ downloads per day. For me it was more of an experiment than a real project. From steve at pearwood.info Wed Aug 13 04:31:44 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 13 Aug 2014 08:31:44 GMT Subject: [Announce] Python-Future v0.13; cheatsheet for Python 2/3 compatible code References: Message-ID: <53eb2270$0$11123$c3e8da3@news.astraweb.com> On Wed, 13 Aug 2014 13:28:03 +1000, Ed Schofield wrote: > Hi all, > > I am happy to announce an update to Python-Future for Python 2/3 > compatibility and a new cheat-sheet for writing code compatible with > both versions. Nice! But are you aware that some of your Python 2 code only works in certain versions of Python 2? E.g. raising bare strings only works up to Python 2.5, in 2.6 and higher it is a syntax error. -- Steven From joel.goldstick at gmail.com Wed Aug 13 04:55:37 2014 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Wed, 13 Aug 2014 04:55:37 -0400 Subject: newbee In-Reply-To: References: Message-ID: On Tue, Aug 12, 2014 at 7:57 PM, Frank Scafidi wrote: > I just acquired a Raspberry Pi and want to program in Python. I was a PL/1 > programmer back in the 60's & 70's and Python is similar. I am struggling > with some very fundamental things that I am not finding in the > documentation. Can someone help me with the basics like how do I save a > program I've written, reload it in Python, list the program once it's > loaded? How do I edit a program? Are these command line functions? I've not worked with Rasberry Pi, but it has some kind of linux on it. So find a text editor (maybe vim is on it). Write your code with text editor and save. To run it type: python my_program.py See python.org website and read the tutorial > > Thanks > Frank > > > -- > https://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com From not at my.real.address.com Wed Aug 13 05:06:54 2014 From: not at my.real.address.com (GregS) Date: Wed, 13 Aug 2014 10:06:54 +0100 Subject: odd difference calling function from class or instance variable Message-ID: <201408131006549222-not@myrealaddresscom> Hello, This is my first post here so please gently inform me of any etiquette breaches. I'm seeing a behaviour I can't explain with Python 3.4.1 when I call a function via a reference stored in an object. When I assign the reference as a class variable, the reference has __self__ set, too, so I get an extra argument passed to the function. If I assign the reference as an instance variable, then __self__ is unset so no extra argument. Here's what I mean: >>> def print_args(*args): print(args) >>> class C: ref = None >>> C.ref = print_args # assign to class variable >>> i = C() >>> i.ref() # call via class variable - get a 'self' argument passed (<__main__.C object at 0x1071a05f8>,) >>> i.ref = print_args # assign to instance variable >>> i.ref() # call via instance variable: no arguments () If you look at i.ref.__self__ for the two cases, you'll see what's going on. I've tried RTFMing but can't find the reason for the two behaviours. Could someone provide an explanation for me, please? Thanks, Greg From rosuav at gmail.com Wed Aug 13 05:30:37 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Aug 2014 19:30:37 +1000 Subject: newbee In-Reply-To: References: Message-ID: On Wed, Aug 13, 2014 at 9:57 AM, Frank Scafidi wrote: > I just acquired a Raspberry Pi and want to program in Python. I was a PL/1 > programmer back in the 60's & 70's and Python is similar. I am struggling > with some very fundamental things that I am not finding in the > documentation. Can someone help me with the basics like how do I save a > program I've written, reload it in Python, list the program once it's > loaded? How do I edit a program? Are these command line functions? These sound like RPi questions, rather than Python questions. You may find knowledgeable people here on this list, but if not, I would advise hunting down an RPi mailing list or newsgroup and asking there. Most of us here use full computers, where questions like "how do I save a file?" are trivially easy... you may find, actually, that starting on a PC and then pushing the file to the RPi is the easiest way to work. ChrisA From __peter__ at web.de Wed Aug 13 05:40:18 2014 From: __peter__ at web.de (Peter Otten) Date: Wed, 13 Aug 2014 11:40:18 +0200 Subject: odd difference calling function from class or instance variable References: <201408131006549222-not@myrealaddresscom> Message-ID: GregS wrote: > Hello, > > This is my first post here so please gently inform me of any etiquette > breaches. > > I'm seeing a behaviour I can't explain with Python 3.4.1 when I call a > function via a reference stored in an object. > > When I assign the reference as a class variable, the reference has > __self__ set, too, so I get an extra argument passed to the function. > If I assign the reference as an instance variable, then __self__ is > unset so no extra argument. > > Here's what I mean: > >>>> def print_args(*args): > print(args) > >>>> class C: > ref = None > >>>> C.ref = print_args # assign to class variable >>>> i = C() >>>> i.ref() # call via class variable - get a 'self' argument passed > (<__main__.C object at 0x1071a05f8>,) >>>> i.ref = print_args # assign to instance variable >>>> i.ref() # call via instance variable: no arguments > () > > If you look at i.ref.__self__ for the two cases, you'll see what's > going on. I've tried RTFMing but can't find the reason for the two > behaviours. Could someone provide an explanation for me, please? When an attribute is found in the instance it is left as-is, so i.ref() is the same as print_ref() When the attribute is found in the class and itself has a __get__ attribute i.ref() is equivalent to print_ref.__get__(i, C)() which creates a bound method object (i. e. it is assumed that the function implements a method): >>> class C: pass ... >>> def f(self): pass ... >>> f.__get__(C(), C) > As you have seen a bound method implicitly passes the instance as the first arg to the function. The underlying mechanism is called "descriptor protocol" and is also used to implement properties. If you need to store a function in the class you can wrap it as a staticmethod: >>> def print_args(*args): print(args) ... >>> class C: ... ref = staticmethod(print_args) ... >>> C().ref() () From rosuav at gmail.com Wed Aug 13 05:45:05 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Aug 2014 19:45:05 +1000 Subject: odd difference calling function from class or instance variable In-Reply-To: <201408131006549222-not@myrealaddresscom> References: <201408131006549222-not@myrealaddresscom> Message-ID: On Wed, Aug 13, 2014 at 7:06 PM, GregS wrote: > If you look at i.ref.__self__ for the two cases, you'll see what's going on. > I've tried RTFMing but can't find the reason for the two behaviours. Could > someone provide an explanation for me, please? What you're seeing there is the magic of instance methods. I'll simplify it some by defining the method right there in the class, rather than doing the weird injection that you were doing: >>> class C: def meth(self): print("Hi! I'm a method.",self) >>> C().meth() Hi! I'm a method. <__main__.C object at 0x012BC6D0> >>> C.meth >>> C().meth > >>> _() Hi! I'm a method. <__main__.C object at 0x012AEDF0> When you look up something on the instance, if there's a regular function of that name on its class, you'll get back a piece of magic called a bound method. It's a curried function, if you know what that means (if you don't, just skip this sentence). When you then call that bound method, it ultimately goes back to the original function, with a pre-filled first argument (which comes from __self__). Basically, what this means is that a bound method can be treated like a function, and it automatically keeps track of its proper state; the unbound method *is* a function, so if you call that directly, you'll need to pass it an object as self. >>> C.meth(C()) Hi! I'm a method. <__main__.C object at 0x0169AA70> As a general rule, though, you won't be doing this kind of thing. Define functions inside a class body, and then call them on instances. Everything'll happily work, and all these little details are magic :) ChrisA From rosuav at gmail.com Wed Aug 13 05:51:38 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Aug 2014 19:51:38 +1000 Subject: Arbitrary dunder attributes (was Re: odd difference calling function from class or instance variable) Message-ID: On Wed, Aug 13, 2014 at 7:06 PM, GregS wrote: > When I assign the reference as a class variable, the reference has __self__ > set, too, so I get an extra argument passed to the function. If I assign > the reference as an instance variable, then __self__ is unset so no extra > argument. Spin-off from Greg's thread. The bound method object stores a reference to the original object (the thing that becomes the first argument to the target function) in __self__ (and the function in __func__). ISTM this ought to be _self (and _func), as it's intended to be private; is it really something that has language-level significance on par with __lt__ and so on? ChrisA From __peter__ at web.de Wed Aug 13 05:57:51 2014 From: __peter__ at web.de (Peter Otten) Date: Wed, 13 Aug 2014 11:57:51 +0200 Subject: newbee References: Message-ID: Frank Scafidi wrote: > I just acquired a Raspberry Pi and want to program in Python. I was a PL/1 > programmer back in the 60's & 70's and Python is similar. I am struggling > with some very fundamental things that I am not finding in the > documentation. Can someone help me with the basics like how do I save a > program I've written, reload it in Python, list the program once it's > loaded? How do I edit a program? Are these command line functions? You can use any text editor to write a python script. A simple editor which might be present ont the Pi is called "nano". It shows the hotkeys to store the text and quit the editor, and thus should be self-explanatory: $ nano helloworld.py Once you have written your simple script you can look at it with the "cat" command: $ cat helloworld.py #!/usr/bin/env python print "Hello world" Invoke it with: $ python helloworld.py Hello world You can also make your script "executable" which means that the first line controls which program is used to run it: $ chmod +x helloworld.py $ ./helloworld.py Hello world $ If the script is in a directory listed in the PATH environment variable you can omit the path (the "./" in the above example): $ mv helloworld.py ~/bin $ helloworld.py Hello world PS: I ran the above demo on a Linux system, but not on the Raspberry Pi, so if something doesn't work as shown above it's probably due to the difference between the two systems. From a.nandagoban at traxens.com Wed Aug 13 06:18:34 2014 From: a.nandagoban at traxens.com (Arulnambi Nandagoban) Date: Wed, 13 Aug 2014 12:18:34 +0200 Subject: logging question Message-ID: <001801cfb6df$f0f53e00$d2dfba00$@traxens.com> Hello, I posted a question about logger module to create a log file every day. I had a problem recently in logging. My pc restarts regularly. Whenever it restarts I lose all the log since it writes in the file once per day. Is there a way to log information in a file as soon as it available. My application is a tcp server. Before I did it without using logger module, I developed customized log module for the application. As soon as there is a connection I append it in the log file. By that way I didn't lose any log information. -- nambi -------------- next part -------------- An HTML attachment was scrubbed... URL: From not at my.real.address.com Wed Aug 13 06:20:30 2014 From: not at my.real.address.com (GregS) Date: Wed, 13 Aug 2014 11:20:30 +0100 Subject: odd difference calling function from class or instance variable References: <201408131006549222-not@myrealaddresscom> Message-ID: <2014081311203037705-not@myrealaddresscom> Thanks to both of you for your incredibly prompt replies. My homework for tonight is to digest the descriptor protocol... Peter, thanks for suggesting using staticmethod() to get the behaviour I was expecting. I've only used staticmethod as a decorator before now. Chris, I agree that it's not every day you assign functions to class attributes, but it does have its uses (I won't bore you with mine). Now that I know how it treads on the toes of Python's method magic, I can decide whether it's the best approach or not. Thanks again, Greg From rosuav at gmail.com Wed Aug 13 06:29:12 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Aug 2014 20:29:12 +1000 Subject: odd difference calling function from class or instance variable In-Reply-To: <2014081311203037705-not@myrealaddresscom> References: <201408131006549222-not@myrealaddresscom> <2014081311203037705-not@myrealaddresscom> Message-ID: On Wed, Aug 13, 2014 at 8:20 PM, GregS wrote: > Thanks to both of you for your incredibly prompt replies. My homework for > tonight is to digest the descriptor protocol... > > Peter, thanks for suggesting using staticmethod() to get the behaviour I was > expecting. I've only used staticmethod as a decorator before now. > > Chris, I agree that it's not every day you assign functions to class > attributes, but it does have its uses (I won't bore you with mine). Now > that I know how it treads on the toes of Python's method magic, I can decide > whether it's the best approach or not. You seem to know what you're doing, which is a good start :) I aimed my explanation a bit lower than your actual knowledge turns out to be, so go ahead and do what you know you need to do. You're not treading on Python's toes, here, but you're basically recreating some of what Python normally does under the covers, so you'll need to actually understand (instead of just treating as black-box magic) stuff like the descriptor protocol. ChrisA From feliphil at gmx.net Wed Aug 13 06:42:34 2014 From: feliphil at gmx.net (Wolfgang Keller) Date: Wed, 13 Aug 2014 12:42:34 +0200 Subject: Python and IDEs [was Re: Python 3 is killing Python] References: <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> <20140806144758.f5817ee60d0e98ff30172a2a@gmx.net> <53e2f338$0$29979$c3e8da3$5496439d@news.astraweb.com> <20140811110843.a314bb1b78cda13d26844ab5@gmx.net> <53e95b96$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20140813124234.28dcd9dda3eb9b114f4b51fb@gmx.net> > >> By the way, you keep replying to people, and quoting them, but > >> deleting their name. Please leave the attribution in place, so we > >> know who you are replying to. > > > > That's what the "References:"-Header is there for. > > The References header is for the benefit of news and mail clients, > not human readers. Any half-decent news client will happily display a thread tree for you. Based on that References:-Header. > It is rude to deliberately refuse to give attributes: > So please stop being rude, and follow the convention of both email and > usenet (as well as broader society) to give attribution to those you > quote. I've been using mail and news for over 20 years now, you definitely don't need to teach me anything. End of subthread. Good Bye, Wolfgang From duncan.booth at invalid.invalid Wed Aug 13 06:59:43 2014 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 13 Aug 2014 10:59:43 GMT Subject: newbee References: Message-ID: Peter Otten <__peter__ at web.de> wrote: > Frank Scafidi wrote: > >> I just acquired a Raspberry Pi and want to program in Python. I was a >> PL/1 programmer back in the 60's & 70's and Python is similar. I am >> struggling with some very fundamental things that I am not finding in >> the documentation. Can someone help me with the basics like how do I >> save a program I've written, reload it in Python, list the program >> once it's loaded? How do I edit a program? Are these command line >> functions? > > You can use any text editor to write a python script. A simple editor > which might be present ont the Pi is called "nano". It shows the > hotkeys to store the text and quit the editor, and thus should be > self-explanatory: > > $ nano helloworld.py > > Once you have written your simple script you can look at it with the > "cat" command: > > $ cat helloworld.py > #!/usr/bin/env python > print "Hello world" > > Invoke it with: > > $ python helloworld.py > Hello world > > You can also make your script "executable" which means that the first > line controls which program is used to run it: > > $ chmod +x helloworld.py > $ ./helloworld.py > Hello world > $ > > If the script is in a directory listed in the PATH environment > variable you can omit the path (the "./" in the above example): > > $ mv helloworld.py ~/bin > $ helloworld.py > Hello world > > PS: I ran the above demo on a Linux system, but not on the Raspberry > Pi, so if something doesn't work as shown above it's probably due to > the difference between the two systems. > All of the above should work just fine on a Pi. The only thing I thing you could have added is that you also have the option of using Idle to edit and run Python programs. If you are running Raspian on your Pi then you will find an icon to run Idle sitting on the initial desktop. There's an introduction to using Idle on the Raspberry Pi at http://www.raspberrypi.org/documentation/usage/python/ -- Duncan Booth From feliphil at gmx.net Wed Aug 13 07:46:45 2014 From: feliphil at gmx.net (Wolfgang Keller) Date: Wed, 13 Aug 2014 13:46:45 +0200 Subject: Python and IDEs [was Re: Python 3 is killing Python] References: <87zjga4j4v.fsf@elektro.pacujo.net> <53c57bae$0$9505$c3e8da3$5496439d@news.astraweb.com> <87iomy4ciy.fsf@elektro.pacujo.net> <53c5f6dc$0$9505$c3e8da3$5496439d@news.astraweb.com> <87egxl4zq8.fsf@elektro.pacujo.net> <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> <20140806144717.8847deb8b0bea888b89d814b@gmx.net> Message-ID: <20140813134645.7363574988e5474acdfa162d@gmx.net> > >> > Because on such operating systems, each and every application is > >> > an entirely self-contained package that doesn't need any > >> > "packages" or "installers" to use it. > > > >> For people who have never used such a system it's probably > >> difficult to see the advantages. > > > > That's the whole point. > > > > The problem is that the ones who "decide" (well, they pretend to, > > but actually can't, because they don't know the alternatives) are > > always people who are "not even clueless". > > Ha! I love it. I presume that's an allusion to that-other-Wolfgang's > apocryphal "not even wrong" comment. :) Exactly. And it's also an allusion to that statement that "knowledge means to know what you don't know". Sincerely, Wolfgang From alister.nospam.ware at ntlworld.com Wed Aug 13 07:55:17 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Wed, 13 Aug 2014 11:55:17 GMT Subject: newbee References: Message-ID: On Tue, 12 Aug 2014 19:57:14 -0400, Frank Scafidi wrote: > I just acquired a Raspberry Pi and want to program in Python. I was a > PL/1 programmer back in the 60's & 70's and Python is similar. I am > struggling with some very fundamental things that I am not finding in > the documentation. Can someone help me with the basics like how do I > save a program I've written, reload it in Python, list the program once > it's loaded? How do I edit a program? Are these command line functions? > > Thanks Frank
style="font-family:georgia,serif;font-size:small;color:#3366ff">I just > acquired a Raspberry Pi and want to program in Python. I was a PL/1 > programmer back in the 60's & 70's and Python is similar. I > am struggling with some very fundamental things that I am not finding in > the documentation. Can someone help me with the basics like how do I > save a program I've written, reload it in Python, list the program > once it's loaded? How do I edit a program? Are these command line > functions??
>
style="font-family:georgia,serif;font-size:small;color:#3366ff">
class="gmail_default" > style="font-family:georgia,serif;font-size:small;color:#3366ff">Thanks
class="gmail_default" > style="font-family:georgia,serif;font-size:small;color:#3366ff"> > Frank
style="font-family:georgia,serif;font-size:small;color:#3366ff">
I am not in the same league as many of the posters here when it comes to Python but fortunately i do have two Raspberry Pi's :-) if you are running the Pi connected to a TV/Monitor with the Gui enabled then you should have access to Idle as well as a number of text editors (Geany works well if installed) if you are using it from the commands line then as previously stated you need to use a text editor to write the code (Nano is part of the basic Raspian Distro and easier to use than VI/Vim) once you have created your code file type python at the command prompt remember if you are connecting to the Pi remotely Via SSH it is useful to have multiple connections open, one for the text editor & 1 to enable you to run the code or execute other Linux commands. If you have any more questions post them back &I hope I can help (Maybe I can become useful to this group as the R-Pi expert, hopefully more productively than some of the groups other 'Experts') -- Expect the worst, it's the least you can do. From ned at nedbatchelder.com Wed Aug 13 08:11:05 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Wed, 13 Aug 2014 08:11:05 -0400 Subject: Arbitrary dunder attributes (was Re: odd difference calling function from class or instance variable) In-Reply-To: References: Message-ID: On 8/13/14 5:51 AM, Chris Angelico wrote: > On Wed, Aug 13, 2014 at 7:06 PM, GregS wrote: >> When I assign the reference as a class variable, the reference has __self__ >> set, too, so I get an extra argument passed to the function. If I assign >> the reference as an instance variable, then __self__ is unset so no extra >> argument. > > Spin-off from Greg's thread. > > The bound method object stores a reference to the original object (the > thing that becomes the first argument to the target function) in > __self__ (and the function in __func__). ISTM this ought to be _self > (and _func), as it's intended to be private; is it really something > that has language-level significance on par with __lt__ and so on? > > ChrisA > As I see it, dunder names are those whose meaning is defined by the Python language (and/or implementation?), and whose use is typically behind-the-scenes. So "len" is defined by the language, but is meant to be front-and-center, so it has a nice name. __init__, __lt__, and __self__, have meanings and uses defined by Python itself, and so are reasonable as dunder names. This is a crude namespacing: Python can use any name it likes so long as its a dunder name, and I can use any name I like, so long as it isn't. Yes, the definition is fuzzy.... :) -- Ned Batchelder, http://nedbatchelder.com From mok-kong.shen at t-online.de Wed Aug 13 09:05:48 2014 From: mok-kong.shen at t-online.de (Mok-Kong Shen) Date: Wed, 13 Aug 2014 15:05:48 +0200 Subject: Log base 2 of large integers Message-ID: I like to compute log base 2 of a fairly large integer n but with math.log(n,2) I got: OverflowError: long int too large to convert to float. Is there any feasible work-around for that? Thanks in advance. M. K. Shen From steve+comp.lang.python at pearwood.info Wed Aug 13 09:12:16 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 13 Aug 2014 23:12:16 +1000 Subject: Arbitrary dunder attributes (was Re: odd difference calling function from class or instance variable) References: Message-ID: <53eb6431$0$29982$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > The bound method object stores a reference to the original object (the > thing that becomes the first argument to the target function) in > __self__ (and the function in __func__). ISTM this ought to be _self > (and _func), as it's intended to be private; Why do you say they are intended to be private? Is that documented somewhere, or do you mean that if you designed the system, *you* would have intended them to be private? :-) > is it really something > that has language-level significance on par with __lt__ and so on? To be honest, I didn't even know about __self__, but I understood __func__ to be public. And yes, it should be public: being able to introspect a method and find the function it came from is a good thing, and sometimes useful. -- Steven From mok-kong.shen at t-online.de Wed Aug 13 09:13:34 2014 From: mok-kong.shen at t-online.de (Mok-Kong Shen) Date: Wed, 13 Aug 2014 15:13:34 +0200 Subject: newbee In-Reply-To: References: Message-ID: Am 13.08.2014 13:55, schrieb alister: [snip] A related question: How could one write a Python program and have it run on a mobile phone in general (independent of a PC)? M. K. Shen From skip at pobox.com Wed Aug 13 09:16:40 2014 From: skip at pobox.com (Skip Montanaro) Date: Wed, 13 Aug 2014 08:16:40 -0500 Subject: Log base 2 of large integers In-Reply-To: References: Message-ID: On Wed, Aug 13, 2014 at 8:05 AM, Mok-Kong Shen wrote: > I like to compute log base 2 of a fairly large integer n but > with math.log(n,2) I got: > > OverflowError: long int too large to convert to float. > > Is there any feasible work-around for that? A bit of googling turned up this page: http://gnumbers.blogspot.com/2011/10/logarithm-of-large-number-it-is-not.html Might be worth studying for ideas. Skip From steve+comp.lang.python at pearwood.info Wed Aug 13 09:32:51 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 13 Aug 2014 23:32:51 +1000 Subject: Log base 2 of large integers References: Message-ID: <53eb6903$0$29982$c3e8da3$5496439d@news.astraweb.com> Mok-Kong Shen wrote: > > I like to compute log base 2 of a fairly large integer n but > with math.log(n,2) I got: > > OverflowError: long int too large to convert to float. > > Is there any feasible work-around for that? If you want the integer log2, that is, the floor of log2, the simplest way is calculate it like this: def log2(n): """Return the floor of log2(n).""" if n <= 0: raise ValueError i = -1 while n: n //= 2 i += 1 return i log2(511) => returns 8 log2(512) => returns 9 log2(513) => returns 9 Does that help? -- Steven From steve+comp.lang.python at pearwood.info Wed Aug 13 09:35:04 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 13 Aug 2014 23:35:04 +1000 Subject: Python and IDEs [was Re: Python 3 is killing Python] References: <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> <20140806144758.f5817ee60d0e98ff30172a2a@gmx.net> <53e2f338$0$29979$c3e8da3$5496439d@news.astraweb.com> <20140811110843.a314bb1b78cda13d26844ab5@gmx.net> <53e95b96$0$30002$c3e8da3$5496439d@news.astraweb.com> <20140813124234.28dcd9dda3eb9b114f4b51fb@gmx.net> Message-ID: <53eb6988$0$29982$c3e8da3$5496439d@news.astraweb.com> Wolfgang Keller wrote: > I've been using mail and news for over 20 years now, you definitely > don't need to teach me anything. Except common courtesy. You may have been rude for over 20 years, but I don't have to put up with it for a second longer. > Good Bye, Agreed. *plonk* -- Steven From mok-kong.shen at t-online.de Wed Aug 13 09:46:09 2014 From: mok-kong.shen at t-online.de (Mok-Kong Shen) Date: Wed, 13 Aug 2014 15:46:09 +0200 Subject: Log base 2 of large integers In-Reply-To: <53eb6903$0$29982$c3e8da3$5496439d@news.astraweb.com> References: <53eb6903$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 13.08.2014 15:32, schrieb Steven D'Aprano: > Mok-Kong Shen wrote: > >> >> I like to compute log base 2 of a fairly large integer n but >> with math.log(n,2) I got: >> >> OverflowError: long int too large to convert to float. >> >> Is there any feasible work-around for that? > > If you want the integer log2, that is, the floor of log2, the simplest way > is calculate it like this: > > def log2(n): > """Return the floor of log2(n).""" > if n <= 0: raise ValueError > i = -1 > while n: > n //= 2 > i += 1 > return i > > log2(511) > => returns 8 > log2(512) > => returns 9 > log2(513) > => returns 9 > > > Does that help? That is too inaccurate (e.g. for 513 above) for me, I would like to get accuracy around 0.01 and that for very large n. M. K. Shen From mok-kong.shen at t-online.de Wed Aug 13 09:50:24 2014 From: mok-kong.shen at t-online.de (Mok-Kong Shen) Date: Wed, 13 Aug 2014 15:50:24 +0200 Subject: Log base 2 of large integers In-Reply-To: References: Message-ID: Am 13.08.2014 15:16, schrieb Skip Montanaro: > http://gnumbers.blogspot.com/2011/10/logarithm-of-large-number-it-is-not.html > > Might be worth studying for ideas. Thanks. I think the idea may help. M. K. Shen From __peter__ at web.de Wed Aug 13 09:58:02 2014 From: __peter__ at web.de (Peter Otten) Date: Wed, 13 Aug 2014 15:58:02 +0200 Subject: Log base 2 of large integers References: Message-ID: Mok-Kong Shen wrote: > I like to compute log base 2 of a fairly large integer n but > with math.log(n,2) I got: > > OverflowError: long int too large to convert to float. > > Is there any feasible work-around for that? What version of Python are you using? Python 2.7 can handle "fairly large" integers: >>> float(x) Traceback (most recent call last): File "", line 1, in OverflowError: long int too large to convert to float >>> math.log(x, 2) 50462500.07504181 Or maybe our idea of "fairly large" differ; so how large is fairly large? From alister.nospam.ware at ntlworld.com Wed Aug 13 09:57:53 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Wed, 13 Aug 2014 13:57:53 GMT Subject: newbee References: Message-ID: On Wed, 13 Aug 2014 15:13:34 +0200, Mok-Kong Shen wrote: > Am 13.08.2014 13:55, schrieb alister: > [snip] > > A related question: How could one write a Python program and have it run > on a mobile phone in general (independent of a PC)? > > M. K. Shen you would need a python interpreter for that device, IIRC there is one available for android, I do not know about IOS -- It's not hard to admit errors that are [only] cosmetically wrong. -- J.K. Galbraith From a.h.jaffe at gmail.com Wed Aug 13 10:06:48 2014 From: a.h.jaffe at gmail.com (Andrew Jaffe) Date: Wed, 13 Aug 2014 15:06:48 +0100 Subject: Log base 2 of large integers In-Reply-To: References: <53eb6903$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53EB70F8.6020407@gmail.com> On 13/08/2014 14:46, Mok-Kong Shen wrote: > Am 13.08.2014 15:32, schrieb Steven D'Aprano: >> Mok-Kong Shen wrote: >> >>> >>> I like to compute log base 2 of a fairly large integer n but >>> with math.log(n,2) I got: >>> >>> OverflowError: long int too large to convert to float. >>> >>> Is there any feasible work-around for that? >> >> If you want the integer log2, that is, the floor of log2, the simplest >> way >> is calculate it like this: >> >> <<< removed... see below >>> >> >> Does that help? > > That is too inaccurate (e.g. for 513 above) for me, I would like > to get accuracy around 0.01 and that for very large n. > > M. K. Shen Well, we can use Steven d'A's idea as a starting point: import math def log2_floor(n): """Return the floor of log2(n).""" if n <= 0: raise ValueError i = -1 while n: n //= 2 i += 1 return i def log2(n): """ return log_2(n) by splitting the problem into the integer and fractional parts""" l2f = log2_floor(n) if n == 2**l2f: return l2f else: return l2f + math.log(n*2**-l2f, 2) Andrew From a.h.jaffe at gmail.com Wed Aug 13 10:06:48 2014 From: a.h.jaffe at gmail.com (Andrew Jaffe) Date: Wed, 13 Aug 2014 15:06:48 +0100 Subject: Log base 2 of large integers In-Reply-To: References: <53eb6903$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53EB70F8.6020407@gmail.com> On 13/08/2014 14:46, Mok-Kong Shen wrote: > Am 13.08.2014 15:32, schrieb Steven D'Aprano: >> Mok-Kong Shen wrote: >> >>> >>> I like to compute log base 2 of a fairly large integer n but >>> with math.log(n,2) I got: >>> >>> OverflowError: long int too large to convert to float. >>> >>> Is there any feasible work-around for that? >> >> If you want the integer log2, that is, the floor of log2, the simplest >> way >> is calculate it like this: >> >> <<< removed... see below >>> >> >> Does that help? > > That is too inaccurate (e.g. for 513 above) for me, I would like > to get accuracy around 0.01 and that for very large n. > > M. K. Shen Well, we can use Steven d'A's idea as a starting point: import math def log2_floor(n): """Return the floor of log2(n).""" if n <= 0: raise ValueError i = -1 while n: n //= 2 i += 1 return i def log2(n): """ return log_2(n) by splitting the problem into the integer and fractional parts""" l2f = log2_floor(n) if n == 2**l2f: return l2f else: return l2f + math.log(n*2**-l2f, 2) Andrew From rosuav at gmail.com Wed Aug 13 10:09:20 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Aug 2014 00:09:20 +1000 Subject: Arbitrary dunder attributes (was Re: odd difference calling function from class or instance variable) In-Reply-To: <53eb6431$0$29982$c3e8da3$5496439d@news.astraweb.com> References: <53eb6431$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Aug 13, 2014 at 11:12 PM, Steven D'Aprano wrote: > Chris Angelico wrote: > >> The bound method object stores a reference to the original object (the >> thing that becomes the first argument to the target function) in >> __self__ (and the function in __func__). ISTM this ought to be _self >> (and _func), as it's intended to be private; > > Why do you say they are intended to be private? Is that documented > somewhere, or do you mean that if you designed the system, *you* would have > intended them to be private? :-) Good point - the latter :) However, that applies only to the one leading underscore. Whether they're _self/_func or self/func, they could be regular attributes without being dunder ones. >> is it really something >> that has language-level significance on par with __lt__ and so on? > > To be honest, I didn't even know about __self__, but I understood __func__ > to be public. And yes, it should be public: being able to introspect a > method and find the function it came from is a good thing, and sometimes > useful. I stand corrected on the privacy issue. But introspection would be just as easy if it were called func instead. Picking up Ned's wording: On Wed, Aug 13, 2014 at 10:11 PM, Ned Batchelder wrote: > This is a crude namespacing: Python can use any name it likes so long as its > a dunder name, and I can use any name I like, so long as it isn't. This concept generally applies to Python doing stuff with my class. If I define a class that I want a built-in function, operator, or language feature, to work with, I define a dunder attribute (most often a method) to tie in with that - my class, Python's functionality. When Python defines the class, it's free to do whatever it likes with naming. There are public methods and attributes, named nice and simply because there's no possibility of collision. The bound method object is like this; it could easily have any number of simply-named attributes, and most of us wouldn't even be aware of them, much less concerned that we now can't use those names. We can't possibly collide, because this is a completely different class from anything I'm working with. Even namedtuple, where it *is* possible to have collisions, doesn't go dunder - it has single-underscore public members. That's a deliberate decision to use a namespace other than the normal one of simply-named members; and dunders weren't used. In the case of __self__ and __func__, what's the advantage of this tagging? ChrisA From davea at davea.name Wed Aug 13 10:10:04 2014 From: davea at davea.name (Dave Angel) Date: Wed, 13 Aug 2014 10:10:04 -0400 (EDT) Subject: Log base 2 of large integers References: Message-ID: Mok-Kong Shen Wrote in message: > > I like to compute log base 2 of a fairly large integer n but > with math.log(n,2) I got: > > OverflowError: long int too large to convert to float. > > Is there any feasible work-around for that? > > Thanks in advance. > > M. K. Shen > Easiest way to get the integer part is to convert to binary string, and take the length of that string. Call that m. Then construct a string consisting of a 1 followed by m zeroes. Convert that to a long, and divide your original number by it. Now take the log base 2 of the quotient. Add that to m and you have your answer, plus or minus 1. -- DaveA From __peter__ at web.de Wed Aug 13 10:17:47 2014 From: __peter__ at web.de (Peter Otten) Date: Wed, 13 Aug 2014 16:17:47 +0200 Subject: Log base 2 of large integers References: <53eb6903$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Mok-Kong Shen wrote: > >> >> I like to compute log base 2 of a fairly large integer n but >> with math.log(n,2) I got: >> >> OverflowError: long int too large to convert to float. >> >> Is there any feasible work-around for that? > > If you want the integer log2, that is, the floor of log2, the simplest way > is calculate it like this: > > def log2(n): > """Return the floor of log2(n).""" > if n <= 0: raise ValueError > i = -1 > while n: > n //= 2 > i += 1 > return i > > log2(511) > => returns 8 > log2(512) > => returns 9 > log2(513) > => returns 9 For base 2 there is also the bit_length() method: >>> 511 .bit_length() 9 >>> 512 .bit_length() 10 >>> 513 .bit_length() 10 From denismfmcmahon at gmail.com Wed Aug 13 10:53:41 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Wed, 13 Aug 2014 14:53:41 +0000 (UTC) Subject: Suitable Python code to scrape specific details from web pages. References: Message-ID: On Tue, 12 Aug 2014 13:00:30 -0700, Simon Evans wrote: > in accessing from the 'Racing Post' on a daily basis. Anyhow, the code Following is some starter code. You will have to look at the output, compare it to the web page, and work out how you want to process it further. Note that I use beautifulsoup and requests. The output is the html for each cell in the table with a line of "+" characters at the table row breaks. I suggest you look at the beautifulsoup documentation at http://www.crummy.com/software/BeautifulSoup/bs4/doc/ to work out how you may wish to select which table cells contain data you are interested in and how to extract it. #!/usr/bin/python """ Program to extract data from racingpost. """ from bs4 import BeautifulSoup import requests r = requests.get( "http://www.racingpost.com/horses2/cards/card.sd? race_id=607466&r_date=2014-08-13#raceTabs=sc_" ) if r.status_code == 200: soup = BeautifulSoup( r.content ) table = soup.find( "table", id="sc_horseCard" ) for row in table.find_all( "tr" ): for cell in row.find_all( "td" ): print cell print "+++++++++++++++++++++++++++++++++++++" else: print "HTTP Status", r.status_code -- Denis McMahon, denismfmcmahon at gmail.com From camilocelyg at gmail.com Wed Aug 13 11:25:25 2014 From: camilocelyg at gmail.com (c1234 py) Date: Wed, 13 Aug 2014 08:25:25 -0700 (PDT) Subject: Begginer in python trying to load a .dll In-Reply-To: References: <3dade0aa-55ca-4e52-af08-8104e9edf4c3@googlegroups.com> Message-ID: <0014387b-9168-4b7f-820e-d0cff91ad763@googlegroups.com> Thanks a lot. El martes, 12 de agosto de 2014 17:17:26 UTC-3, Mark Lawrence escribi?: > On 12/08/2014 20:25, c1234 py wrote: > > > El martes, 12 de agosto de 2014 16:16:21 UTC-3, Christian Gollwitzer escribi???: > > >> Am 12.08.14 20:36, schrieb c1223: > > >> > > >>> Hi, Im working in the development of a program based in python that > > >> > > >>> allow us to contrl a spectometer. The spectometer has an .dll file. > > >> > > >>> The idea is to work through this dll and operate the spectometer. The > > >> > > >>> name of the .dll is AS5216.dll. I've trying with ctype, but it > > >> > > >>> doesn't work. I'm begginer in python. All the comments are useful to > > >> > > >>> me. > > >> > > >> > > >> > > >> For sure this DLL will come with a header file for C. You could pass it > > >> > > >> through SWIG and see if it generates a useful Python module. You need a > > >> > > >> C compiler for that route, though. > > >> > > >> > > >> > > >> Christian > > > > > > > > > How can i pass it through a SWIG?, i don't know that and what it mean? > > > > > > > Start here http://www.swig.org/ which you could easily have found for > > yourself, as I did by using a search engine. > > > > Also would you please access this list via > > https://mail.python.org/mailman/listinfo/python-list or read and action > > this https://wiki.python.org/moin/GoogleGroupsPython to prevent us > > seeing double line spacing and single line paragraphs, thanks. > > > > -- > > 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 Aug 13 11:51:10 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 13 Aug 2014 16:51:10 +0100 Subject: Python and IDEs [was Re: Python 3 is killing Python] In-Reply-To: <20140813124234.28dcd9dda3eb9b114f4b51fb@gmx.net> References: <53c73ff0$0$29897$c3e8da3$5496439d@news.astraweb.com> <9ef930a0-5a41-4a20-a13a-003c9e8246fe@googlegroups.com> <53c9655a$0$9505$c3e8da3$5496439d@news.astraweb.com> <368c1e4f-9328-445b-9876-9f26560a50c2@googlegroups.com> <53ca1e27$0$9505$c3e8da3$5496439d@news.astraweb.com> <20140801131035.f672ac56af3aa4eda5d36dcd@gmx.net> <20140806144758.f5817ee60d0e98ff30172a2a@gmx.net> <53e2f338$0$29979$c3e8da3$5496439d@news.astraweb.com> <20140811110843.a314bb1b78cda13d26844ab5@gmx.net> <53e95b96$0$30002$c3e8da3$5496439d@news.astraweb.com> <20140813124234.28dcd9dda3eb9b114f4b51fb@gmx.net> Message-ID: On 13/08/2014 11:42, Wolfgang Keller wrote: >>>> By the way, you keep replying to people, and quoting them, but >>>> deleting their name. Please leave the attribution in place, so we >>>> know who you are replying to. >>> >>> That's what the "References:"-Header is there for. >> >> The References header is for the benefit of news and mail clients, >> not human readers. > > Any half-decent news client will happily display a thread tree for you. > Based on that References:-Header. > >> It is rude to deliberately refuse to give attributes: > >> So please stop being rude, and follow the convention of both email and >> usenet (as well as broader society) to give attribution to those you >> quote. > > I've been using mail and news for over 20 years now, you definitely > don't need to teach me anything. Very funny. It strikes me that your knowledge of using mail and news is akin to that of our resident unicode expert's knowledge of the FSR. > > End of subthread. > The subthread ends when people want it to end, not when you state that it has ended. It will not end until you stop being so downright rude in refusing to give attribution to those you quote. > Good Bye, Good riddance. Ditto Steven D'Aprano's *plonk* > > Wolfgang > -- 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 Aug 13 12:00:09 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 14 Aug 2014 02:00:09 +1000 Subject: Why does str not have a __radd__ method? Message-ID: <53eb8b8a$0$6574$c3e8da3$5496439d@news.astraweb.com> I just tried to override str.__radd__: class Special(str): def __radd__(self, other): print("I'm special!") return super().__radd__(self, other) My __radd__ method was called correctly by the + operator, but to my surprise, the super().__radd__ call failed with: Traceback (most recent call last): File "", line 1, in File "", line 4, in __radd__ AttributeError: 'super' object has no attribute '__radd__' Sure enough, in both Python 3.3 and 2.7: py> str.__radd__ Traceback (most recent call last): File "", line 1, in AttributeError: type object 'str' has no attribute '__radd__' This is especially astonishing, since int and float both have __radd__ methods, and yet numeric addition is commutative (x+y == y+x) whereas the same is not true for string concatenation. What is the rationale for str not having __radd__ method? -- Steven From taifulsust at gmail.com Wed Aug 13 12:11:29 2014 From: taifulsust at gmail.com (taifulsust at gmail.com) Date: Wed, 13 Aug 2014 09:11:29 -0700 (PDT) Subject: Need simple Python Script Message-ID: <0ec17bee-0ed6-4494-b4ab-2319880315af@googlegroups.com> Hello Guys I am new in Python programming.Currently reading the book " Learn Python the Heard Way".However i need a python script which will take an image file (any standard format) from my windows pc as input.Can anybody have any solution?I use command prompt and gedit to learn python. Thanks Leon From ppearson at nowhere.invalid Wed Aug 13 12:12:31 2014 From: ppearson at nowhere.invalid (Peter Pearson) Date: 13 Aug 2014 16:12:31 GMT Subject: Log base 2 of large integers References: Message-ID: On Wed, 13 Aug 2014 15:58:02 +0200, Peter Otten <__peter__ at web.de> wrote: > Mok-Kong Shen wrote: > >> I like to compute log base 2 of a fairly large integer n but >> with math.log(n,2) I got: >> >> OverflowError: long int too large to convert to float. [snip] > Or maybe our idea of "fairly large" differ; so how large is fairly large? MK Shen used to hang out on the sci.crypt newsgroup, so we're probably talking "cryptographically large" rather than "engineeringly large". -- To email me, substitute nowhere->spamcop, invalid->net. From rosuav at gmail.com Wed Aug 13 12:17:37 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Aug 2014 02:17:37 +1000 Subject: Need simple Python Script In-Reply-To: <0ec17bee-0ed6-4494-b4ab-2319880315af@googlegroups.com> References: <0ec17bee-0ed6-4494-b4ab-2319880315af@googlegroups.com> Message-ID: On Thu, Aug 14, 2014 at 2:11 AM, wrote: > I am new in Python programming.Currently reading the book " Learn Python the Heard Way".However i need a python script which will take an image file (any standard format) from my windows pc as input.Can anybody have any solution?I use command prompt and gedit to learn python. > If you finish studying the book, you'll have a better idea of how to go about doing things in Python, and also of how to find out more about what you can work with. For a start, you probably want a Python imaging library. You could type those three words into a search engine and see what comes back. In fact, that's probably a good start for any question you have. ChrisA From rosuav at gmail.com Wed Aug 13 12:18:57 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Aug 2014 02:18:57 +1000 Subject: Log base 2 of large integers In-Reply-To: References: Message-ID: On Thu, Aug 14, 2014 at 2:12 AM, Peter Pearson wrote: > MK Shen used to hang out on the sci.crypt newsgroup, so we're > probably talking "cryptographically large" rather than "engineeringly > large". So "fairly large" means somewhere between googolplex an Graham's Number, and after that they'd be called "very large"? ChrisA From marko at pacujo.net Wed Aug 13 12:15:31 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 13 Aug 2014 19:15:31 +0300 Subject: Log base 2 of large integers References: Message-ID: <87wqaccqn0.fsf@elektro.pacujo.net> Peter Pearson : > MK Shen used to hang out on the sci.crypt newsgroup, so we're probably > talking "cryptographically large" rather than "engineeringly large". I'm thinking we're talking about philosophically large. Those kinds of numbers are unwieldy from all angles, including cryptography. Marko From rgaddi at technologyhighland.invalid Wed Aug 13 12:28:07 2014 From: rgaddi at technologyhighland.invalid (Rob Gaddi) Date: Wed, 13 Aug 2014 09:28:07 -0700 Subject: Captcha identify References: <8c2e4bc2-4f46-4a68-83ed-469fe171de3a@googlegroups.com> <2320baf0-e097-4d67-97c1-dd37ca79fffb@googlegroups.com> <376a239c-77e8-4e0e-9300-847dfa8a8547@googlegroups.com> Message-ID: <20140813092807.7f66e8ad@rg.highlandtechnology.com> On Tue, 12 Aug 2014 18:36:21 -0700 (PDT) Wesley wrote: > If my questions make you guys not so happy, I am sorry and please just ignore. > I just wanna a general suggestion here in the beginning. > Why I need to write such program is just having such requirements, and has nothing to do with the coding work itself. Don't say something to prove you're so noble. > Hai guyz I am new to biochemistry and so I need lots of help with things.can you tell me how to make anthrax? I need it for stuff, so dont worry -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From wrw at mac.com Wed Aug 13 11:44:39 2014 From: wrw at mac.com (William Ray Wing) Date: Wed, 13 Aug 2014 11:44:39 -0400 Subject: newbee In-Reply-To: References: Message-ID: <019E02B9-D4ED-4E1D-96B2-2052DD570277@mac.com> On Aug 13, 2014, at 9:57 AM, alister wrote: > On Wed, 13 Aug 2014 15:13:34 +0200, Mok-Kong Shen wrote: > >> Am 13.08.2014 13:55, schrieb alister: >> [snip] >> >> A related question: How could one write a Python program and have it run >> on a mobile phone in general (independent of a PC)? >> >> M. K. Shen > > you would need a python interpreter for that device, IIRC there is one > available for android, I do not know about IOS > There are several for iOS, but because of Apple?s sandboxing they don?t have as much reach as you might want. -Bill From gordon at panix.com Wed Aug 13 13:08:28 2014 From: gordon at panix.com (John Gordon) Date: Wed, 13 Aug 2014 17:08:28 +0000 (UTC) Subject: Need simple Python Script References: <0ec17bee-0ed6-4494-b4ab-2319880315af@googlegroups.com> Message-ID: In <0ec17bee-0ed6-4494-b4ab-2319880315af at googlegroups.com> taifulsust at gmail.com writes: > I am new in Python programming.Currently reading the book " Learn Python > the Heard Way".However i need a python script which will take an image > file (any standard format) from my windows pc as input.Can anybody have > any solution? I use command prompt and gedit to learn python. What is the script supposed to *do* with the image file? -- 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 thequietcenter at gmail.com Wed Aug 13 13:13:16 2014 From: thequietcenter at gmail.com (thequietcenter at gmail.com) Date: Wed, 13 Aug 2014 10:13:16 -0700 (PDT) Subject: Python Object Systems In-Reply-To: References: <2d41828e-19ac-4e46-a487-8700c22d9b92@googlegroups.com> Message-ID: <0299640d-310c-41c6-a308-5552c202e0a8@googlegroups.com> On Wednesday, August 13, 2014 4:32:04 AM UTC-4, Michele Simionato wrote: > Years ago I wrote strait: https://pypi.python.org/pypi/strait What is the difference between traits and roles? From ethan at stoneleaf.us Wed Aug 13 13:27:08 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 13 Aug 2014 10:27:08 -0700 Subject: Why does str not have a __radd__ method? In-Reply-To: <53eb8b8a$0$6574$c3e8da3$5496439d@news.astraweb.com> References: <53eb8b8a$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53EB9FEC.7030809@stoneleaf.us> On 08/13/2014 09:00 AM, Steven D'Aprano wrote: > > What is the rationale for str not having __radd__ method? At a guess I would say because string only knows how to add itself to other strings, so __add__ is sufficient. -- ~Ethan~ From steve+comp.lang.python at pearwood.info Wed Aug 13 13:52:44 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 14 Aug 2014 03:52:44 +1000 Subject: Captcha identify References: <8c2e4bc2-4f46-4a68-83ed-469fe171de3a@googlegroups.com> <2320baf0-e097-4d67-97c1-dd37ca79fffb@googlegroups.com> <376a239c-77e8-4e0e-9300-847dfa8a8547@googlegroups.com> <20140813092807.7f66e8ad@rg.highlandtechnology.com> Message-ID: <53eba5ed$0$29967$c3e8da3$5496439d@news.astraweb.com> Rob Gaddi wrote: > On Tue, 12 Aug 2014 18:36:21 -0700 (PDT) > Wesley wrote: > >> If my questions make you guys not so happy, I am sorry and please just >> ignore. I just wanna a general suggestion here in the beginning. >> Why I need to write such program is just having such requirements, and >> has nothing to do with the coding work itself. Don't say something to >> prove you're so noble. >> > > Hai guyz I am new to biochemistry and so I need lots of help with > things.can you tell me how to make anthrax? > > I need it for stuff, so dont worry :-) You'll only use it for good, right? -- Steven From steve+comp.lang.python at pearwood.info Wed Aug 13 13:55:46 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 14 Aug 2014 03:55:46 +1000 Subject: Why does str not have a __radd__ method? References: <53eb8b8a$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53eba6a3$0$6574$c3e8da3$5496439d@news.astraweb.com> Ethan Furman wrote: > On 08/13/2014 09:00 AM, Steven D'Aprano wrote: >> >> What is the rationale for str not having __radd__ method? > > At a guess I would say because string only knows how to add itself to > other strings, so __add__ is sufficient. # Python 2.7 py> "Hello" + u"World" u'HelloWorld' py> unicode.__radd__ Traceback (most recent call last): File "", line 1, in AttributeError: type object 'unicode' has no attribute '__radd__' My brain hurts. -- Steven From ian.g.kelly at gmail.com Wed Aug 13 14:13:46 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 13 Aug 2014 12:13:46 -0600 Subject: Log base 2 of large integers In-Reply-To: References: Message-ID: On Wed, Aug 13, 2014 at 10:18 AM, Chris Angelico wrote: > On Thu, Aug 14, 2014 at 2:12 AM, Peter Pearson wrote: >> MK Shen used to hang out on the sci.crypt newsgroup, so we're >> probably talking "cryptographically large" rather than "engineeringly >> large". > > So "fairly large" means somewhere between googolplex an Graham's > Number, and after that they'd be called "very large"? I estimate that representing a googolplex as a 64-bit Python 3 int would require around 4.429 * 10**75 yottabytes of memory. So probably not that large. From rosuav at gmail.com Wed Aug 13 14:21:01 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Aug 2014 04:21:01 +1000 Subject: Captcha identify In-Reply-To: <53eba5ed$0$29967$c3e8da3$5496439d@news.astraweb.com> References: <8c2e4bc2-4f46-4a68-83ed-469fe171de3a@googlegroups.com> <2320baf0-e097-4d67-97c1-dd37ca79fffb@googlegroups.com> <376a239c-77e8-4e0e-9300-847dfa8a8547@googlegroups.com> <20140813092807.7f66e8ad@rg.highlandtechnology.com> <53eba5ed$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Aug 14, 2014 at 3:52 AM, Steven D'Aprano wrote: >> I need it for stuff, so dont worry > > :-) > > You'll only use it for good, right? He needs it for stuffing. Remind me to decline any invitation to turkey dinner that he sends. ChrisA From ethan at stoneleaf.us Wed Aug 13 14:22:50 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 13 Aug 2014 11:22:50 -0700 Subject: Why does str not have a __radd__ method? In-Reply-To: <53eba6a3$0$6574$c3e8da3$5496439d@news.astraweb.com> References: <53eb8b8a$0$6574$c3e8da3$5496439d@news.astraweb.com> <53eba6a3$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53EBACFA.5040303@stoneleaf.us> On 08/13/2014 10:55 AM, Steven D'Aprano wrote: > Ethan Furman wrote: > >> On 08/13/2014 09:00 AM, Steven D'Aprano wrote: >>> >>> What is the rationale for str not having __radd__ method? >> >> At a guess I would say because string only knows how to add itself to >> other strings, so __add__ is sufficient. > > # Python 2.7 > py> "Hello" + u"World" > u'HelloWorld' > py> unicode.__radd__ > Traceback (most recent call last): > File "", line 1, in > AttributeError: type object 'unicode' has no attribute '__radd__' Well, unicode is a string type, right? ;) And for the proof: >>> 'hello'.__add__(u'world') u'helloworld' >>> u'hello'.__add__('world') u'helloworld' > My brain hurts. An occupational hazard of unicode, surely. -- ~Ethan~ From jason.swails at gmail.com Wed Aug 13 14:36:55 2014 From: jason.swails at gmail.com (Jason Swails) Date: Wed, 13 Aug 2014 14:36:55 -0400 Subject: Why does str not have a __radd__ method? In-Reply-To: <53eba6a3$0$6574$c3e8da3$5496439d@news.astraweb.com> References: <53eb8b8a$0$6574$c3e8da3$5496439d@news.astraweb.com> <53eba6a3$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Aug 13, 2014 at 1:55 PM, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > Ethan Furman wrote: > > > On 08/13/2014 09:00 AM, Steven D'Aprano wrote: > >> > >> What is the rationale for str not having __radd__ method? > > > > At a guess I would say because string only knows how to add itself to > > other strings, so __add__ is sufficient. > > # Python 2.7 > py> "Hello" + u"World" > u'HelloWorld' > py> unicode.__radd__ > Traceback (most recent call last): > File "", line 1, in > AttributeError: type object 'unicode' has no attribute '__radd__' > This happens because the str.__add__ function calls string_concat under the hood (see Objects/stringobject.c) -- there's a unicode check on the other operand that results in the result of PyUnicode_Concat being returned instead of the concatenated str type. This doesn't require that unicode define __radd__. When the left-hand operand is Unicode, PyUnicode_Concat is called directly (which is why the exception message is different for u'this' + 1 and 'this' + 1): >>> 'this' + 1 Traceback (most recent call last): File "", line 1, in TypeError: cannot concatenate 'str' and 'int' objects >>> u'this' + 1 Traceback (most recent call last): File "", line 1, in TypeError: coercing to Unicode: need string or buffer, int found All the best, Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Wed Aug 13 15:15:14 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 13 Aug 2014 15:15:14 -0400 Subject: Arbitrary dunder attributes (was Re: odd difference calling function from class or instance variable) In-Reply-To: References: Message-ID: On 8/13/2014 5:51 AM, Chris Angelico wrote: > On Wed, Aug 13, 2014 at 7:06 PM, GregS wrote: >> When I assign the reference as a class variable, the reference has __self__ >> set, too, so I get an extra argument passed to the function. If I assign >> the reference as an instance variable, then __self__ is unset so no extra >> argument. > > Spin-off from Greg's thread. > > The bound method object stores a reference to the original object (the > thing that becomes the first argument to the target function) in > __self__ (and the function in __func__). ISTM this ought to be _self > (and _func), as it's intended to be private; is it really something > that has language-level significance on par with __lt__ and so on? In 3.0, the iterator protocol .next became .__next__ for consistency with other syntax dunder methods. In 2.x, bound python-coded functions had im_func and im_self (and im_class for the class im_func was attached to, which has no equivalent in 3.x). Bound C-coded functions, such as [].sort, had and still have __self__ instead of im_self (and no equivalent of im_func/__func__). I presume this difference goes back to the gulf between C-coded types and Python-coded old-style classes. With old-style classes gone, im_class went and it made sense to consistently use __self__ instead of sometimes im_self (and change im_func to __func__ alone with it). In 3.0, function attributes were also dunderized. This was needed once function namespaces were unfrozen and users allowed to add possibly conflicting function attributes. >>> dir(lambda:0) #2.7 ['__call__', '__class__', '__closure__', '__code__', '__defaults__', '__delattr__', '__dict__', '__doc__', '__format__', '__get__', '__getattribute__', '__globals__', '__hash__', '__init__', '__module__', '__name__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'func_closure', 'func_code', 'func_defaults', 'func_dict', 'func_doc', 'func_globals', 'func_name'] (In 2.7, many of the func attributes are duplicates: __code__ == func_code, etc, though this might not have always been true.) >>> dir(lambda:0) ['__annotations__', '__call__', '__class__', '__closure__', '__code__', '__defaults__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__get__', '__getattribute__', '__globals__', '__gt__', '__hash__', '__init__', '__kwdefaults__', '__le__', '__lt__', '__module__', '__name__', '__ne__', '__new__', '__qualname__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__'] The function specific attributes are documented in https://docs.python.org/3/reference/datamodel.html#the-standard-type-hierarchy The same was not done for 'internal types': code objects and co_, frame objects and f_, traceback objects and tb_. Their namespaces are still frozen. -- Terry Jan Reedy From esj at harvee.org Wed Aug 13 07:39:20 2014 From: esj at harvee.org (Eric S. Johansson) Date: Wed, 13 Aug 2014 07:39:20 -0400 Subject: Captcha identify In-Reply-To: References: <8c2e4bc2-4f46-4a68-83ed-469fe171de3a@googlegroups.com> <2320baf0-e097-4d67-97c1-dd37ca79fffb@googlegroups.com> <376a239c-77e8-4e0e-9300-847dfa8a8547@googlegroups.com> Message-ID: <53EB4E68.8050405@harvee.org> On 8/12/2014 9:46 PM, Chris Angelico wrote: > On Wed, Aug 13, 2014 at 11:36 AM, Wesley wrote: >> If my questions make you guys not so happy, I am sorry and please just ignore. >> I just wanna a general suggestion here in the beginning. >> Why I need to write such program is just having such requirements, and has nothing to do with the coding work itself. Don't say something to prove you're so noble. > The general suggestion you're getting is: Do not do this. Many of us > here use CAPTCHAs and spend time keeping one step ahead of those who > try to break them with software. By writing something to solve > CAPTCHAs, you would be stealing time from those people. Don't do it. > > Am I sufficiently clear? > you are clear but also missing a really good reason to break captchas. handicapped accessibility. Captchas are a huge barrier to access and in many cases push disabled users away from using a service with captchas. For me (very acute vision, crap hands) it take me 2-5 tries before I get an image I think I can read reliably, then it take 2-3 tries to type the letters in (slowly and with hand pain) correctly. My mom (80yr and going strong) sees a captcha and gives up on using the site unless I tell her what to type. one major tests for accessibility is "can I automate common user tasks including tasks with context based decisions". Captchas fail that test as do many authentication system user interactions and, if one is entirely truthful, entire applications. Automating captcha solving would be a boon for the disabled or aging user. try taking this moment as a challenge. build an authentication system+ui that works for the disabled/aged and you will have an authentication system that will work better for everybody. for example, use an equivalent of ssh-agent to supply credentials to sites needing them. I can automate ssh-agent and we can make the process+UI easy enough for my mom to use it or automate it for her too. eliminate captchas, 35+million disabled people would thank you as would many more millions of the not-yet-disabled like your future self. From rosuav at gmail.com Wed Aug 13 15:27:01 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Aug 2014 05:27:01 +1000 Subject: Captcha identify In-Reply-To: <53EB4E68.8050405@harvee.org> References: <8c2e4bc2-4f46-4a68-83ed-469fe171de3a@googlegroups.com> <2320baf0-e097-4d67-97c1-dd37ca79fffb@googlegroups.com> <376a239c-77e8-4e0e-9300-847dfa8a8547@googlegroups.com> <53EB4E68.8050405@harvee.org> Message-ID: On Wed, Aug 13, 2014 at 9:39 PM, Eric S. Johansson wrote: > you are clear but also missing a really good reason to break captchas. > handicapped accessibility. Captchas are a huge barrier to access and in > many cases push disabled users away from using a service with captchas. > For me (very acute vision, crap hands) it take me 2-5 tries before I get an > image I think I can read reliably, then it take 2-3 tries to type the > letters in (slowly and with hand pain) correctly. My mom (80yr and going > strong) sees a captcha and gives up on using the site unless I tell her what > to type. > > one major tests for accessibility is "can I automate common user tasks > including tasks with context based decisions". Captchas fail that test as > do many authentication system user interactions and, if one is entirely > truthful, entire applications. Automating captcha solving would be a boon > for the disabled or aging user. > > try taking this moment as a challenge. build an authentication system+ui > that works for the disabled/aged and you will have an authentication system > that will work better for everybody. for example, use an equivalent of > ssh-agent to supply credentials to sites needing them. I can automate > ssh-agent and we can make the process+UI easy enough for my mom to use it or > automate it for her too. > > eliminate captchas, 35+million disabled people would thank you as would many > more millions of the not-yet-disabled like your future self. I agree with you, and I don't use CAPTCHAs on any of my services, anywhere, and never have. (Partly because they *are* broken by people writing scripts, and/or by just grinding them with human solvers; but also because of the problems they cause for legit users, even those with perfect eyesight.) However, the accessibility argument is one for the removal of the captcha, *not* for its automated solving. I will not support a scripted captcha solver for any reason. If you move away from a site because you can't use it, so be it. If you get a chance, tell the owner that there are alternatives to barely-readable images; tricks involving page layouts are almost always safe, and there's infinite room to play around in them. There is no valid reason for automating something that's specifically to prevent automation. The admin needs to provide an alternative, instead. ChrisA From ckaynor at zindagigames.com Wed Aug 13 15:24:37 2014 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Wed, 13 Aug 2014 12:24:37 -0700 Subject: Captcha identify In-Reply-To: <53EB4E68.8050405@harvee.org> References: <8c2e4bc2-4f46-4a68-83ed-469fe171de3a@googlegroups.com> <2320baf0-e097-4d67-97c1-dd37ca79fffb@googlegroups.com> <376a239c-77e8-4e0e-9300-847dfa8a8547@googlegroups.com> <53EB4E68.8050405@harvee.org> Message-ID: On Wed, Aug 13, 2014 at 4:39 AM, Eric S. Johansson wrote: > eliminate captchas, 35+million disabled people would thank you as would > many more millions of the not-yet-disabled like your future self. And so would the spammers, which is who captchas are trying to block. For ease-of-use, most sites only require captchas to be entered once upon creating the account. Some might also require additional captcha entries when the account is suspected of spamming. This is ultimately a trade-off of blocking spammers and allowing accessibility. Many of the better captchas also include options for an audio cue in addition to the default visual one. Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Wed Aug 13 15:31:37 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 13 Aug 2014 15:31:37 -0400 Subject: newbee In-Reply-To: References: Message-ID: On 8/13/2014 7:55 AM, alister wrote: > > I am not in the same league as many of the posters here when it comes to > Python but fortunately i do have two Raspberry Pi's :-) Great! We really someone with hands-on experience. > if you are running the Pi connected to a TV/Monitor with the Gui enabled > then you should have access to Idle Have you verified that Idle *does* (not just *should*) run on RPi? (That would mean having tcl/tk running, with whatever *it* requires on linux.) I am working on Idle and the idea of people (especially hobbyists, students, and other amateurs) running it on microsystems would really please me. > If you have any more questions post them back &I hope I can help > (Maybe I can become useful to this group as the R-Pi expert, Answering questions, sometimes after experiment and research, is a great way to learn. -- Terry Jan Reedy From rosuav at gmail.com Wed Aug 13 15:43:53 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Aug 2014 05:43:53 +1000 Subject: Captcha identify In-Reply-To: References: <8c2e4bc2-4f46-4a68-83ed-469fe171de3a@googlegroups.com> <2320baf0-e097-4d67-97c1-dd37ca79fffb@googlegroups.com> <376a239c-77e8-4e0e-9300-847dfa8a8547@googlegroups.com> <53EB4E68.8050405@harvee.org> Message-ID: On Thu, Aug 14, 2014 at 5:24 AM, Chris Kaynor wrote: > On Wed, Aug 13, 2014 at 4:39 AM, Eric S. Johansson wrote: >> >> eliminate captchas, 35+million disabled people would thank you as would >> many more millions of the not-yet-disabled like your future self. > > > And so would the spammers, which is who captchas are trying to block. There are alternatives that are both easier for legit people and harder for spambots. Some rely on the fact that humans read things two dimensionally, and scripts look at the underlying structure; so, for instance, random field names and cunning CSS to match them up with their labels can result in a form that's completely messed up in the source, but looks perfect to a user. Or you can put extra fields down that you can't see if the form's laid out properly. Or you can combine those sorts of tricks with a very simple challenge-response, like "What is one plus one?" that requires some specific value to be in a specific field - and if that value occurs in the wrong field, you throw the form back to the user. For some reason, everyone's jumped on the "show some mangled text/numbers and ask the user to enter them" bandwagon, in the same way that everyone has gone for passwords that require lower/upper/digit/symbol and (in the most annoying cases) are actually length-limited to something stupid like 12 characters. Yes, maximum, not minimum. Grumble. ChrisA From joel.goldstick at gmail.com Wed Aug 13 15:44:00 2014 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Wed, 13 Aug 2014 15:44:00 -0400 Subject: Captcha identify In-Reply-To: References: <8c2e4bc2-4f46-4a68-83ed-469fe171de3a@googlegroups.com> <2320baf0-e097-4d67-97c1-dd37ca79fffb@googlegroups.com> <376a239c-77e8-4e0e-9300-847dfa8a8547@googlegroups.com> <53EB4E68.8050405@harvee.org> Message-ID: On Wed, Aug 13, 2014 at 3:24 PM, Chris Kaynor wrote: > On Wed, Aug 13, 2014 at 4:39 AM, Eric S. Johansson wrote: >> >> eliminate captchas, 35+million disabled people would thank you as would >> many more millions of the not-yet-disabled like your future self. > > > And so would the spammers, which is who captchas are trying to block. > > For ease-of-use, most sites only require captchas to be entered once upon > creating the account. Some might also require additional captcha entries > when the account is suspected of spamming. This is ultimately a trade-off of > blocking spammers and allowing accessibility. > > Many of the better captchas also include options for an audio cue in > addition to the default visual one. > > Chris > > -- > https://mail.python.org/mailman/listinfo/python-list > I wrote a sample form page with a simple math problem to solve -- 2 or 3 random small integers to add and put the result in a form field def produce_expression(): """ return a tuple: expression (str), answer (int) """ num_terms = random.randint(2,3) operands = [] while num_terms: n = random.randint(1,21) operands.append(n) num_terms -= 1 result = sum(operands) string_operands = map(str, operands) expression = " + ".join(string_operands) return expression, result Its not as annoying as captcha and I think it would work with audio browsers. Never tested -- Joel Goldstick http://joelgoldstick.com From skip at pobox.com Wed Aug 13 15:55:01 2014 From: skip at pobox.com (Skip Montanaro) Date: Wed, 13 Aug 2014 14:55:01 -0500 Subject: Captcha identify In-Reply-To: References: <8c2e4bc2-4f46-4a68-83ed-469fe171de3a@googlegroups.com> <2320baf0-e097-4d67-97c1-dd37ca79fffb@googlegroups.com> <376a239c-77e8-4e0e-9300-847dfa8a8547@googlegroups.com> <53EB4E68.8050405@harvee.org> Message-ID: On Wed, Aug 13, 2014 at 2:44 PM, Joel Goldstick wrote: > I wrote a sample form page with a simple math problem to solve -- 2 or > 3 random small integers to add ... I've also seen challenge systems where they present you with a small set of images and ask you to select one with a particular property (looks like a tennis racquet, shaped like a square, etc). While simple to solve for most humans -- assuming they can read the language -- they would be difficult to solve by automated means. You can also magnify them for visually impaired or speak what they are on rollover/hover, and don't require any typing. They can make cultural assumptions (not everyone will know what a tennis racquet looks like, for instance), so the images might have to be selected carefully. Skip From python.list at tim.thechases.com Wed Aug 13 16:01:28 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 13 Aug 2014 15:01:28 -0500 Subject: Captcha identify In-Reply-To: References: <8c2e4bc2-4f46-4a68-83ed-469fe171de3a@googlegroups.com> <2320baf0-e097-4d67-97c1-dd37ca79fffb@googlegroups.com> <376a239c-77e8-4e0e-9300-847dfa8a8547@googlegroups.com> <53EB4E68.8050405@harvee.org> Message-ID: <20140813150128.1cab8cc5@bigbox.christie.dr> On 2014-08-13 12:24, Chris Kaynor wrote: > Many of the better captchas also include options for an audio cue in > addition to the default visual one. Have you actually tried to use the audio cue? They're atrocious. I got more intelligible words out of my old 8-bit SoundBlaster or a de-tuned radio station. I'm all for just ditching them (and avoiding sites that employ them). -tkc From ian.g.kelly at gmail.com Wed Aug 13 16:16:02 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 13 Aug 2014 14:16:02 -0600 Subject: Captcha identify In-Reply-To: References: <8c2e4bc2-4f46-4a68-83ed-469fe171de3a@googlegroups.com> <2320baf0-e097-4d67-97c1-dd37ca79fffb@googlegroups.com> <376a239c-77e8-4e0e-9300-847dfa8a8547@googlegroups.com> <53EB4E68.8050405@harvee.org> Message-ID: On Wed, Aug 13, 2014 at 1:43 PM, Chris Angelico wrote: > There are alternatives that are both easier for legit people and > harder for spambots. Some rely on the fact that humans read things two > dimensionally, and scripts look at the underlying structure; so, for > instance, random field names and cunning CSS to match them up with > their labels can result in a form that's completely messed up in the > source, but looks perfect to a user. Or you can put extra fields down > that you can't see if the form's laid out properly. Chances are that if these tricks mess up a spambot, they will also mess up a screen reader. > Or you can combine > those sorts of tricks with a very simple challenge-response, like > "What is one plus one?" that requires some specific value to be in a > specific field - and if that value occurs in the wrong field, you > throw the form back to the user. If I ask my phone "What is one plus one", a very nice sounding voice will tell me that one plus one is two. It takes some cleverness to come up with a question that is likely to stump a machine but not deter a human, so the pool of such questions will necessarily be limited. Meanwhile, all the spambot has to do is flag the question for a human to answer and store the answer somewhere, and the question is now useless. > For some reason, everyone's jumped on the "show some mangled > text/numbers and ask the user to enter them" bandwagon, in the same > way that everyone has gone for passwords that require > lower/upper/digit/symbol and (in the most annoying cases) are actually > length-limited to something stupid like 12 characters. Yes, maximum, > not minimum. Grumble. I've seen some captcha systems that I couldn't solve after a dozen attempts, and I have no serious vision problems. It's a problem with no easy solution, and as computers get more powerful the intersection of {problems machines can't solve} and {problems humans can reliably solve} grows ever smaller. From esj at harvee.org Wed Aug 13 16:42:48 2014 From: esj at harvee.org (Eric S. Johansson) Date: Wed, 13 Aug 2014 16:42:48 -0400 Subject: Captcha identify In-Reply-To: References: <8c2e4bc2-4f46-4a68-83ed-469fe171de3a@googlegroups.com> <2320baf0-e097-4d67-97c1-dd37ca79fffb@googlegroups.com> <376a239c-77e8-4e0e-9300-847dfa8a8547@googlegroups.com> <53EB4E68.8050405@harvee.org> Message-ID: <53EBCDC8.1050904@harvee.org> On 8/13/2014 3:27 PM, Chris Angelico wrote: > I agree with you, and I don't use CAPTCHAs on any of my services, > anywhere, and never have. (Partly because they *are* broken by people > writing scripts, and/or by just grinding them with human solvers; but > also because of the problems they cause for legit users, even those > with perfect eyesight.) However, the accessibility argument is one for > the removal of the captcha, *not* for its automated solving. I will > not support a scripted captcha solver for any reason. If you move away > from a site because you can't use it, so be it. If you get a chance, > tell the owner that there are alternatives to barely-readable images; > tricks involving page layouts are almost always safe, and there's > infinite room to play around in them. your suggestion reminds me of the time I asked front range for help with accessibility because I had to use Goldmine on the job. Immediately after I asked for accessibility information, they told me they don't have any accessibility information because they don't have any disabled users. Yes, they really did your suggestion will probably generate a similar response. > > There is no valid reason for automating something that's specifically > to prevent automation. The admin needs to provide an alternative, > instead. There is only one valid reason based in the fact that we don't own or control many of the sites we depend on. Therefore, if I need to use a site be it government or commercial and it has a Captcha, I need to pay some form of cripple tax by either incurring pain or find/pay somebody to type for me. In this situation I thing it is perfectly acceptable to automate bypassing Captcha's. From tjreedy at udel.edu Wed Aug 13 17:01:32 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 13 Aug 2014 17:01:32 -0400 Subject: Need simple Python Script In-Reply-To: <0ec17bee-0ed6-4494-b4ab-2319880315af@googlegroups.com> References: <0ec17bee-0ed6-4494-b4ab-2319880315af@googlegroups.com> Message-ID: On 8/13/2014 12:11 PM, taifulsust at gmail.com wrote: > I am new in Python programming. > Currently reading the book " Learn Python the Heard Way". The title is '... Hard Way'. This is literally true. The author 'warns' beginners to not learn Python 3, which is easier to learn than Python 2, and works better in many ways. Even worse, he warns people not to use Idle (or any other IDE) and use a plain text editor like Notepad++ and a terminal to edit and run programs. This is definitely the Hard Way compared to edit and run with Idle. I know from experience, because I started the way he recommends (editor and command prompt) and put off learning to use Idle. What I fool I was. > However i need a python script which will take > an image file (any standard format) from my windows pc as input. Python will read any file as input: bytes are bytes. Open non-text files in binary mode. For example, pic = open('image.jpg', 'rb') # I believe this is the same in 2.x. However, this is not useful unless you know the file layout and enjoy parsing it at the byte level. Better to use a package that does that for you. For doing anything with images, you might use pillow, a friendly updated fork of PIL (Python Imaging Library), which works on 2.6-7 and 3.2-4. I just did C:\Programs\Python34>pip install pillow (I have been meaning to do this anyway) and a few seconds later it is installed and 'import PIL' works. For the docs, I had to go back to https://pypi.python.org/pypi/Pillow/2.5.2 to find the reference to http://pillow.readthedocs.org/en/latest/ In Idle I added 'pillow' to the help menu, linked to the url above, using the options dialog General tab, Additional Help Sources box. -- Terry Jan Reedy From ian.g.kelly at gmail.com Wed Aug 13 16:18:50 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 13 Aug 2014 14:18:50 -0600 Subject: Captcha identify In-Reply-To: <20140813150128.1cab8cc5@bigbox.christie.dr> References: <8c2e4bc2-4f46-4a68-83ed-469fe171de3a@googlegroups.com> <2320baf0-e097-4d67-97c1-dd37ca79fffb@googlegroups.com> <376a239c-77e8-4e0e-9300-847dfa8a8547@googlegroups.com> <53EB4E68.8050405@harvee.org> <20140813150128.1cab8cc5@bigbox.christie.dr> Message-ID: On Wed, Aug 13, 2014 at 2:01 PM, Tim Chase wrote: > On 2014-08-13 12:24, Chris Kaynor wrote: >> Many of the better captchas also include options for an audio cue in >> addition to the default visual one. > > Have you actually tried to use the audio cue? They're atrocious. I > got more intelligible words out of my old 8-bit SoundBlaster or a > de-tuned radio station. I'm all for just ditching them (and avoiding > sites that employ them). Just like the images, if they were easy to understand then they would be easily defeated by a spambot with a speech recognition module. I think the effort to make captcha systems more accessible is laudable, if perhaps misguided. From rosuav at gmail.com Wed Aug 13 19:13:32 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Aug 2014 09:13:32 +1000 Subject: Captcha identify In-Reply-To: References: <8c2e4bc2-4f46-4a68-83ed-469fe171de3a@googlegroups.com> <2320baf0-e097-4d67-97c1-dd37ca79fffb@googlegroups.com> <376a239c-77e8-4e0e-9300-847dfa8a8547@googlegroups.com> <53EB4E68.8050405@harvee.org> Message-ID: On Thu, Aug 14, 2014 at 6:16 AM, Ian Kelly wrote: > On Wed, Aug 13, 2014 at 1:43 PM, Chris Angelico wrote: >> There are alternatives that are both easier for legit people and >> harder for spambots. Some rely on the fact that humans read things two >> dimensionally, and scripts look at the underlying structure; so, for >> instance, random field names and cunning CSS to match them up with >> their labels can result in a form that's completely messed up in the >> source, but looks perfect to a user. Or you can put extra fields down >> that you can't see if the form's laid out properly. > > Chances are that if these tricks mess up a spambot, they will also > mess up a screen reader. They may, yes. I haven't seen a report on that. However, they're hardly going to be worse at messing up screen readers than classic captchas. >> Or you can combine >> those sorts of tricks with a very simple challenge-response, like >> "What is one plus one?" that requires some specific value to be in a >> specific field - and if that value occurs in the wrong field, you >> throw the form back to the user. > > If I ask my phone "What is one plus one", a very nice sounding voice > will tell me that one plus one is two. It takes some cleverness to > come up with a question that is likely to stump a machine but not > deter a human... The point isn't the question itself, the point is that you have to put the answer in exactly this field. The field is visually near the challenge, but only because of CSS, and its name is randomized in some way as to be unpredictable. If, as some spambots do, you blat the response into lots of fields in the expectation of catching the right one, then the form gets rejected (I don't know of anyone whose name or email address is "two", all lowercase, and if you have even a small pool of questions, you'll get past those weird cases by having the next question be "What colour is the sky?"). > I've seen some captcha systems that I couldn't solve after a dozen > attempts, and I have no serious vision problems. It's a problem with > no easy solution, and as computers get more powerful the intersection > of {problems machines can't solve} and {problems humans can reliably > solve} grows ever smaller. The issue isn't finding an intersection there. The issue is finding a form of test that a computer can administer. There's a really great test for humanness: be creative. You know that I'm a human, because I've made posts here on python-list that are just way too complex for a computer to synthesize. This sums up my feelings on the matter: http://xkcd.com/810/ (Warning, language.) ChrisA From elearn2014 at gmail.com Wed Aug 13 21:46:20 2014 From: elearn2014 at gmail.com (luofeiyu) Date: Thu, 14 Aug 2014 09:46:20 +0800 Subject: how to change the time string into number? Message-ID: <53EC14EC.2090503@gmail.com> s="Aug" how can i change it into 8 with some python time module? From rosuav at gmail.com Wed Aug 13 21:55:18 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Aug 2014 11:55:18 +1000 Subject: how to change the time string into number? In-Reply-To: <53EC14EC.2090503@gmail.com> References: <53EC14EC.2090503@gmail.com> Message-ID: On Thu, Aug 14, 2014 at 11:46 AM, luofeiyu wrote: > s="Aug" > > how can i change it into 8 with some python time module? Is this homework? If not, let me set you some homework. Step 1: Read the docs for some Python time module. Step 2: See if it lets you do what you want. Step 3: Return to step 1 with a different module, until your problem is solved. ChrisA From elearn2014 at gmail.com Wed Aug 13 22:01:43 2014 From: elearn2014 at gmail.com (luofeiyu) Date: Thu, 14 Aug 2014 10:01:43 +0800 Subject: what is the "/" mean in __init__(self, /, *args, **kwargs) ? Message-ID: <53EC1887.6060205@gmail.com> >>> help(int.__init__) Help on wrapper_descriptor: __init__(self, /, *args, **kwargs) Initialize self. See help(type(self)) for accurate signature. what is the "/" mean in __init__(self, /, *args, **kwargs) ? From ben+python at benfinney.id.au Wed Aug 13 22:01:59 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 14 Aug 2014 12:01:59 +1000 Subject: how to change the time string into number? References: <53EC14EC.2090503@gmail.com> Message-ID: <85mwb77rs8.fsf@benfinney.id.au> luofeiyu writes: > s="Aug" > > how can i change it into 8 with some python time module? What is your purpose here? If you want to parse a text value into a structured time object, don't do it piece by piece. Use the ?time.strptime? function. >>> import time >>> input_time_text = "14 Aug 2014" >>> input_time = time.strptime(input_text, "%d %b %Y") >>> input_time.tm_mon 8 -- \ ?I knew it was a shocking thing to say, but ? no-one has the | `\ right to spend their life without being offended.? ?Philip | _o__) Pullman, 2010-03-28 | Ben Finney From tim at thechases.com Wed Aug 13 22:01:11 2014 From: tim at thechases.com (Tim Chase) Date: Wed, 13 Aug 2014 21:01:11 -0500 Subject: how to change the time string into number? In-Reply-To: <53EC14EC.2090503@gmail.com> References: <53EC14EC.2090503@gmail.com> Message-ID: <20140813210111.197005cd@bigbox.christie.dr> On 2014-08-14 09:46, luofeiyu wrote: > s="Aug" > > how can i change it into 8 with some python time module? >>> import time >>> s = "Aug" >>> time.strptime(s, "%b").tm_mon 8 works for me. -tkc From orgnut at yahoo.com Wed Aug 13 22:00:43 2014 From: orgnut at yahoo.com (Larry Hudson) Date: Wed, 13 Aug 2014 19:00:43 -0700 Subject: newbee In-Reply-To: References: Message-ID: On 08/12/2014 04:57 PM, Frank Scafidi wrote: > I just acquired a Raspberry Pi and want to program in Python. I was a PL/1 programmer back in > the 60's & 70's and Python is similar. I am struggling with some very fundamental things that I > am not finding in the documentation. Can someone help me with the basics like how do I save a > program I've written, reload it in Python, list the program once it's loaded? How do I edit a > program? Are these command line functions? > > Thanks > Frank > You've already received a lot of suggestions, but I'll add one more... If you don't mind shelling out for some dead-tree documentation, there is a book in the "Sam's Teach Yourself in 24 Hours" series -- Python Programming for Raspberry Pi. It is a pretty good basic tutorial for Python in general, and specifically written for the RPi. You might check it out. (Current Amazon price -- $25.81) -=- Larry -=- From ben+python at benfinney.id.au Wed Aug 13 22:08:16 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 14 Aug 2014 12:08:16 +1000 Subject: what is the "/" mean in __init__(self, /, *args, **kwargs) ? References: <53EC1887.6060205@gmail.com> Message-ID: <85iolv7rhr.fsf@benfinney.id.au> luofeiyu writes: > >>> help(int.__init__) > Help on wrapper_descriptor: > > __init__(self, /, *args, **kwargs) > Initialize self. See help(type(self)) for accurate signature. > > what is the "/" mean in __init__(self, /, *args, **kwargs) ? I don't know, I haven't seen that before. It is confusing. At least it is acknowledged (?See [elsewhere] for accurate signature?) to be unhelpful. I suspect this is an artefact of the impedance mismatch between Python function signatures and the implementation of ?int? in C code. The ?/? may be a placeholder for something the C implementation requires but that Python's function signature expectation doesn't allow. Perhaps Python 3's keyword-only arguments may one day help functions like that get implemented with a more useful signature, but I'm not holding my breath for that. -- \ ?Religious faith is the one species of human ignorance that | `\ will not admit of even the *possibility* of correction.? ?Sam | _o__) Harris, _The End of Faith_, 2004 | Ben Finney From python.list at tim.thechases.com Wed Aug 13 22:12:12 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 13 Aug 2014 21:12:12 -0500 Subject: what is the "/" mean in __init__(self, /, *args, **kwargs) ? In-Reply-To: <53EC1887.6060205@gmail.com> References: <53EC1887.6060205@gmail.com> Message-ID: <20140813211212.0c0843b8@bigbox.christie.dr> On 2014-08-14 10:01, luofeiyu wrote: > >>> help(int.__init__) > Help on wrapper_descriptor: > > __init__(self, /, *args, **kwargs) > Initialize self. See help(type(self)) for accurate signature. > > what is the "/" mean in __init__(self, /, *args, **kwargs) ? Where are you seeing this? Python 2.7.3 (default, Mar 13 2014, 11:03:55) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> help(int.__init__) Help on wrapper_descriptor: __init__(...) x.__init__(...) initializes x; see help(type(x)) for signature >>> ^D 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. >>> help(int.__init__) Help on wrapper_descriptor: __init__(...) x.__init__(...) initializes x; see help(type(x)) for signature -tkc From python.list at tim.thechases.com Wed Aug 13 22:16:05 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 13 Aug 2014 21:16:05 -0500 Subject: how to change the time string into number? In-Reply-To: <20140813210111.197005cd@bigbox.christie.dr> References: <53EC14EC.2090503@gmail.com> <20140813210111.197005cd@bigbox.christie.dr> Message-ID: <20140813211605.1131e772@bigbox.christie.dr> On 2014-08-13 21:01, Tim Chase wrote: > On 2014-08-14 09:46, luofeiyu wrote: > > s="Aug" > > > > how can i change it into 8 with some python time module? > > >>> import time > >>> s = "Aug" > >>> time.strptime(s, "%b").tm_mon > 8 > > works for me. Or, if you want a more convoluted way: >>> import calendar as c >>> [i for i, m in enumerate(c.month_abbr) if m == "Aug"].pop() 8 -tkc From ethan at stoneleaf.us Wed Aug 13 22:20:06 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 13 Aug 2014 19:20:06 -0700 Subject: what is the "/" mean in __init__(self, /, *args, **kwargs) ? In-Reply-To: <53EC1887.6060205@gmail.com> References: <53EC1887.6060205@gmail.com> Message-ID: <53EC1CD6.4080203@stoneleaf.us> On 08/13/2014 07:01 PM, luofeiyu wrote: >>>> help(int.__init__) > Help on wrapper_descriptor: > > __init__(self, /, *args, **kwargs) > Initialize self. See help(type(self)) for accurate signature. > > what is the "/" mean in __init__(self, /, *args, **kwargs) ? The '/' means that all arguments before it must be positional only. This looks like an artifact of the new Argument Clinic for C code. For example, if this also worked at the Python level, you could say: def some_func(this, that, /, spam, eggs, *, foo, bar): pass Meaning that the first two parameters could not be specified by name, the next two could be either name or position, and the last two by name only. Oh, and the * is valid Python now (the / is not -- it's solely a documentation feature at this point). -- ~Ethan~ From drsalists at gmail.com Wed Aug 13 22:21:39 2014 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 13 Aug 2014 19:21:39 -0700 Subject: web2py and python3 Message-ID: I heard there was a presentation about web2py in my area tonight. Trying to decide if I wanted to attend, I googled about web2py and python3. I was amazed by what I found. I've never seen a group so opposed to python3. They make the old (and long-since lost) Solaris 2 wars seem tame. I don't think I'm going to be doing web2py anytime soon. :( But I was hoping it'd be a better alternative than Django for web development. From ethan at stoneleaf.us Wed Aug 13 22:22:03 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 13 Aug 2014 19:22:03 -0700 Subject: what is the "/" mean in __init__(self, /, *args, **kwargs) ? In-Reply-To: <20140813211212.0c0843b8@bigbox.christie.dr> References: <53EC1887.6060205@gmail.com> <20140813211212.0c0843b8@bigbox.christie.dr> Message-ID: <53EC1D4B.6070608@stoneleaf.us> On 08/13/2014 07:12 PM, Tim Chase wrote: > > Where are you seeing this? Probably in 3.4, or the tip (what will be 3.5). -- ~Ethan~ From elearn2014 at gmail.com Wed Aug 13 21:50:39 2014 From: elearn2014 at gmail.com (luofeiyu) Date: Thu, 14 Aug 2014 09:50:39 +0800 Subject: a python console in bluestacks Message-ID: <53EC15EF.3000601@gmail.com> I have installed bluestacks(an android phone emulator) on my pc,and SL4A on it.Now i can run python thish way : 1.edit an file ending with |.py|, save it in /sdcard/sl4a/scripts/yourname.py. 2.open sl4a ,and click the file to make it run. Is there a python console to type python command to run python directly such as in pc ? -------------- next part -------------- An HTML attachment was scrubbed... URL: From ybmess at nooos.fr.invalid Wed Aug 13 22:51:50 2014 From: ybmess at nooos.fr.invalid (YBM) Date: Thu, 14 Aug 2014 04:51:50 +0200 Subject: how to change the time string into number? In-Reply-To: References: <53EC14EC.2090503@gmail.com> <20140813210111.197005cd@bigbox.christie.dr> Message-ID: <53ec2453$0$2299$426a74cc@news.free.fr> Le 14/08/2014 04:16, Tim Chase a ?crit : > On 2014-08-13 21:01, Tim Chase wrote: >> On 2014-08-14 09:46, luofeiyu wrote: >>> s="Aug" >>> >>> how can i change it into 8 with some python time module? >> >> >>> import time >> >>> s = "Aug" >> >>> time.strptime(s, "%b").tm_mon >> 8 >> >> works for me. > > Or, if you want a more convoluted way: > > >>> import calendar as c > >>> [i for i, m in enumerate(c.month_abbr) if m == "Aug"].pop() > 8 it's a joke isn't it ? >>> import calendar as c >>> list(c.month_abbr).index('Aug') 8 BTW, why iterators does not have such an index method ? >>> iter(c.month_abbr).index('Aug') Traceback (most recent call last): File "", line 1, in AttributeError: 'iterator' object has no attribute 'index' From ian.g.kelly at gmail.com Wed Aug 13 23:07:27 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 13 Aug 2014 21:07:27 -0600 Subject: how to change the time string into number? In-Reply-To: <53ec2453$0$2299$426a74cc@news.free.fr> References: <53EC14EC.2090503@gmail.com> <20140813210111.197005cd@bigbox.christie.dr> <53ec2453$0$2299$426a74cc@news.free.fr> Message-ID: On Wed, Aug 13, 2014 at 8:51 PM, YBM wrote: > BTW, why iterators does not have such an index method ? Because iterators don't support indexing. In order to support such a thing, it would have to exhaust the iterator. >>> iter(range(5))[3] Traceback (most recent call last): File "", line 1, in TypeError: 'range_iterator' object is not subscriptable The only methods you can rely upon an arbitrary iterator to have are __iter__ and __next__. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Wed Aug 13 23:09:47 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Aug 2014 13:09:47 +1000 Subject: web2py and python3 In-Reply-To: References: Message-ID: On Thu, Aug 14, 2014 at 12:21 PM, Dan Stromberg wrote: > I don't think I'm going to be doing web2py anytime soon. :( But I > was hoping it'd be a better alternative than Django for web > development. I'm no expert on Python web frameworks, but the only one that I've used seems to be pretty decent: Flask. I'm happy with it. It's light-weight, it gets the job done, it doesn't much get in the way. If someone's going to hate Py3, ignore 'em and go somewhere else. ChrisA From roy at panix.com Wed Aug 13 23:14:58 2014 From: roy at panix.com (Roy Smith) Date: Wed, 13 Aug 2014 23:14:58 -0400 Subject: how to change the time string into number? References: <53EC14EC.2090503@gmail.com> <20140813210111.197005cd@bigbox.christie.dr> <53ec2453$0$2299$426a74cc@news.free.fr> Message-ID: In article <53ec2453$0$2299$426a74cc at news.free.fr>, YBM wrote: > Le 14/08/2014 04:16, Tim Chase a ?crit : > > On 2014-08-13 21:01, Tim Chase wrote: > >> On 2014-08-14 09:46, luofeiyu wrote: > >>> s="Aug" > >>> > >>> how can i change it into 8 with some python time module? > >> > >> >>> import time > >> >>> s = "Aug" > >> >>> time.strptime(s, "%b").tm_mon > >> 8 > >> > >> works for me. > > > > Or, if you want a more convoluted way: > > > > >>> import calendar as c > > >>> [i for i, m in enumerate(c.month_abbr) if m == "Aug"].pop() > > 8 > > it's a joke isn't it ? No, it's a song. If I could save time in a bottle The first thing that I'd like to do Is to make every month be an integer number And then I could count them with you. From ben+python at benfinney.id.au Wed Aug 13 23:48:29 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 14 Aug 2014 13:48:29 +1000 Subject: what is the "/" mean in __init__(self, /, *args, **kwargs) ? References: <53EC1887.6060205@gmail.com> <20140813211212.0c0843b8@bigbox.christie.dr> Message-ID: <85egwj7muq.fsf@benfinney.id.au> Tim Chase writes: > On 2014-08-14 10:01, luofeiyu wrote: > > >>> help(int.__init__) > > Help on wrapper_descriptor: > > > > __init__(self, /, *args, **kwargs) > > Initialize self. See help(type(self)) for accurate signature. > > > > what is the "/" mean in __init__(self, /, *args, **kwargs) ? > > Where are you seeing this? I see the same output as ?luofeiyu? reports. My Python is:: >>> sys.version '3.4.1 (default, Jul 26 2014, 13:46:45) \n[GCC 4.9.1]' -- \ ?Stop ? Drive sideways.? ?detour sign, Kyushu, Japan | `\ | _o__) | Ben Finney From tjreedy at udel.edu Thu Aug 14 00:03:16 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 14 Aug 2014 00:03:16 -0400 Subject: what is the "/" mean in __init__(self, /, *args, **kwargs) ? In-Reply-To: <53EC1CD6.4080203@stoneleaf.us> References: <53EC1887.6060205@gmail.com> <53EC1CD6.4080203@stoneleaf.us> Message-ID: On 8/13/2014 10:20 PM, Ethan Furman wrote: > On 08/13/2014 07:01 PM, luofeiyu wrote: >>>>> help(int.__init__) >> Help on wrapper_descriptor: >> >> __init__(self, /, *args, **kwargs) >> Initialize self. See help(type(self)) for accurate signature. >> >> what is the "/" mean in __init__(self, /, *args, **kwargs) ? > > The '/' means that all arguments before it must be positional only. In particular, int.__init__(self = ) will not work because 'self' is positional only. (I don't think int.__init__ actually does anything, but a subclass of int might call it.) > This looks like an artifact of the new Argument Clinic for C code. > > For example, if this also worked at the Python level, you could say: > > def some_func(this, that, /, spam, eggs, *, foo, bar): > pass > > Meaning that the first two parameters could not be specified by name, > the next two could be either name or position, and the last two by name > only. > > Oh, and the * is valid Python now (the / is not -- it's solely a > documentation feature at this point). I hope / will be valid Python in 3.5. -- Terry Jan Reedy From steve at pearwood.info Thu Aug 14 00:54:52 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 14 Aug 2014 04:54:52 GMT Subject: [OT] Awesome bug of the week Message-ID: <53ec411c$0$11123$c3e8da3@news.astraweb.com> Nothing to do with Python, but awesome: "OpenOffice won't print on Tuesdays". https://bugs.launchpad.net/ubuntu/+source/cupsys/+bug/255161/comments/28 -- Steven From steve at pearwood.info Thu Aug 14 01:02:02 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 14 Aug 2014 05:02:02 GMT Subject: Optional static typing Message-ID: <53ec42ca$0$11123$c3e8da3@news.astraweb.com> The BDFL Guido van Rossum is considering optional static typing (ish) for Python 3.5: https://mail.python.org/pipermail/python-ideas/2014-August/028618.html Does anyone here use function annotations? If so, what do you use them for? -- Steven From contact at xavierho.com Thu Aug 14 01:12:56 2014 From: contact at xavierho.com (Xavier Ho) Date: Thu, 14 Aug 2014 15:12:56 +1000 Subject: [OT] Awesome bug of the week In-Reply-To: <53ec411c$0$11123$c3e8da3@news.astraweb.com> References: <53ec411c$0$11123$c3e8da3@news.astraweb.com> Message-ID: Haha! On 14 August 2014 14:54, Steven D'Aprano wrote: > Nothing to do with Python, but awesome: "OpenOffice won't print on > Tuesdays". > > https://bugs.launchpad.net/ubuntu/+source/cupsys/+bug/255161/comments/28 > > > > -- > Steven > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From marko at pacujo.net Thu Aug 14 01:19:28 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 14 Aug 2014 08:19:28 +0300 Subject: how to change the time string into number? References: <53EC14EC.2090503@gmail.com> <20140813210111.197005cd@bigbox.christie.dr> Message-ID: <874mxfd4wv.fsf@elektro.pacujo.net> Tim Chase : > Or, if you want a more convoluted way: > > >>> import calendar as c > >>> [i for i, m in enumerate(c.month_abbr) if m == "Aug"].pop() > 8 Let's not forget the much simpler solutions: >>> def eight(x): return 8 ... >>> eight("Aug") 8 and: >>> 8 8 BTW, is this a bug: >>> import locale >>> locale.getlocale() ('de_DE', 'UTF-8') >>> import time >>> time.strptime("Dez", "%b").tm_mon Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3.2/_strptime.py", line 482, in _strptime_time tt = _strptime(data_string, format)[0] File "/usr/lib/python3.2/_strptime.py", line 337, in _strptime (data_string, format)) ValueError: time data 'Dez' does not match format '%b' >>> time.strftime("%b", time.localtime(time.time() + 120 * 86400)) 'Dec' >>> time.strftime("%x") '08/14/14' After all, "%b" is documented as "Locale?s abbreviated month name." Anyway, "%b" *should* depend on the locale, so str[pf]time may not be suitable to deal with email dates, for example. Marko From wuwei23 at gmail.com Thu Aug 14 02:09:36 2014 From: wuwei23 at gmail.com (alex23) Date: Thu, 14 Aug 2014 16:09:36 +1000 Subject: how to write file into my android phone? In-Reply-To: References: <53E660BF.7080401@gmail.com> Message-ID: On 10/08/2014 7:08 PM, Chris ?Kwpolska? Warrick wrote: >> 2) the phone isn't necessarily visible on a pc as a drive at all. >> For example the Samsung gs4. > > This is actually true for ALL android devices, starting with Android 3.0. This isn't true for my Samsung gs2 running Android 4.1.2. From kwpolska at gmail.com Thu Aug 14 02:21:08 2014 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Thu, 14 Aug 2014 08:21:08 +0200 Subject: how to write file into my android phone? In-Reply-To: References: <53E660BF.7080401@gmail.com> Message-ID: On Aug 14, 2014 8:11 AM, "alex23" wrote: > > On 10/08/2014 7:08 PM, Chris ?Kwpolska? Warrick wrote: >>> >>> 2) the phone isn't necessarily visible on a pc as a drive at all. >>> For example the Samsung gs4. >> >> >> This is actually true for ALL android devices, starting with Android 3.0. > > > This isn't true for my Samsung gs2 running Android 4.1.2. Apparently, Samsung modified the feature for this phone, which shipped with 2.3 Gingerbread, to prevent breaking user experience. Galaxy S3 shipped with 4.0 ICS and uses MTP. -- Chris ?Kwpolska? Warrick Sent from my SGS3. -------------- next part -------------- An HTML attachment was scrubbed... URL: From wxjmfauth at gmail.com Thu Aug 14 02:24:36 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 13 Aug 2014 23:24:36 -0700 (PDT) Subject: Why does str not have a __radd__ method? In-Reply-To: References: <53eb8b8a$0$6574$c3e8da3$5496439d@news.astraweb.com> <53eba6a3$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: <655739a7-d606-42c9-aa3d-2e59fcdddc29@googlegroups.com> Le mercredi 13 ao?t 2014 20:36:55 UTC+2, Jason Swails a ?crit?: > On Wed, Aug 13, 2014 at 1:55 PM, Steven D'Aprano wrote: > > > Ethan Furman wrote: > > > > > On 08/13/2014 09:00 AM, Steven D'Aprano wrote: > > >> > > > >> What is the rationale for str not having __radd__ method? > > > > > > > At a guess I would say because string only knows how to add itself to > > > other strings, so __add__ is sufficient. > > > > # Python 2.7 > > py> "Hello" + u"World" > > u'HelloWorld' > > py> unicode.__radd__ > > > Traceback (most recent call last): > > ? File "", line 1, in > > AttributeError: type object 'unicode' has no attribute '__radd__' > > > > This happens because the str.__add__ function calls string_concat under the hood (see Objects/stringobject.c) -- there's a unicode check on the other operand that results in the result of PyUnicode_Concat being returned instead of the concatenated str type. ?This doesn't require that unicode define __radd__. > > > > When the left-hand operand is Unicode, PyUnicode_Concat is called directly (which is why the exception message is different for u'this' + 1 and 'this' + 1): > > > > > >>> 'this' + 1 > Traceback (most recent call last): > > ? File "", line 1, in > TypeError: cannot concatenate 'str' and 'int' objects > > >>> u'this' + 1 > Traceback (most recent call last): > ? File "", line 1, in > > TypeError: coercing to Unicode: need string or buffer, int found > > > > > All the best, > Jason -------- This is more funny. >>> print u'a' + 'a' aa >>> print 'a' + u'a' aa >>> print u'a' + '?' Traceback (most recent call last): File "", line 1, in print u'a' + '?' UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 0: ordinal not in range(128) >>> Python? The single language, which tried (and still tries to make the ascii world compatible with the unicode world. In a somwhow symmetrical way, but a little bit differently, the situation in Python 3 is even worse. jmf PS See my comment about the Euro sign in a previous thread. From kwpolska at gmail.com Thu Aug 14 02:25:00 2014 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Thu, 14 Aug 2014 08:25:00 +0200 Subject: a python console in bluestacks In-Reply-To: <53EC15EF.3000601@gmail.com> References: <53EC15EF.3000601@gmail.com> Message-ID: On Aug 14, 2014 4:30 AM, "luofeiyu" wrote: > > I have installed bluestacks(an android phone emulator) on my pc,and SL4A on it.Now i can run python thish way : > 1.edit an file ending with .py, save it in /sdcard/sl4a/scripts/yourname.py. > 2.open sl4a ,and click the file to make it run. > > Is there a python console to type python command to run python directly such as in pc ? Why are you using an Android emulator to run Python, a PC-first software?! Just install the Windows version from http://python.org/ and use that. -- Chris ?Kwpolska? Warrick Sent from my SGS3. -------------- next part -------------- An HTML attachment was scrubbed... URL: From kwpolska at gmail.com Thu Aug 14 02:42:32 2014 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Thu, 14 Aug 2014 08:42:32 +0200 Subject: newbee In-Reply-To: References: Message-ID: On Aug 13, 2014 9:34 PM, "Terry Reedy" wrote: > Have you verified that Idle *does* (not just *should*) run on RPi? (That would mean having tcl/tk running, with whatever *it* requires on linux.) I am working on Idle and the idea of people (especially hobbyists, students, and other amateurs) running it on microsystems would really please me. I don't have a RPi, but I know it is just a glorified ARM computer with terrible specs. But it is enough to run LXDE or other lightweight graphical environments, which means tcl/tk is VERY likely to work. You could also look up packages for Raspbian or other RPi-friendly distros and see python-tk there, or various Python tutorials for the device: http://davidbriddock.blogspot.com/2013/04/learn-python-installing-tkinter.html -- Chris ?Kwpolska? Warrick Sent from my SGS3. -------------- next part -------------- An HTML attachment was scrubbed... URL: From elearn2014 at gmail.com Thu Aug 14 02:52:17 2014 From: elearn2014 at gmail.com (luofeiyu) Date: Thu, 14 Aug 2014 14:52:17 +0800 Subject: how to change the time string into number? In-Reply-To: <85mwb77rs8.fsf@benfinney.id.au> References: <53EC14EC.2090503@gmail.com> <85mwb77rs8.fsf@benfinney.id.au> Message-ID: <53EC5CA1.5090002@gmail.com> in the manual https://docs.python.org/3.4/library/time.html %z Time zone offset indicating a positive or negative time difference from UTC/GMT of the form +HHMM or -HHMM, where H represents decimal hour digits and M represents decimal minute digits [-23:59, +23:59]. %Z Time zone name (no characters if no time zone exists). t1='Sat, 09 Aug 2014 07:36:46 ' time.strptime(t1,"%a, %d %b %Y %H:%M:%S ") time.struct_time(tm_year=2014, tm_mon=8, tm_mday=9, tm_hour=7, tm_min=36, tm_sec =46, tm_wday=5, tm_yday=221, tm_isdst=-1) >>> t2='Sat, 09 Aug 2014 07:36:46 -0700' >>> time.strptime(t2,"%a, %d %b %Y %H:%M:%S %z") time.struct_time(tm_year=2014, tm_mon=8, tm_mday=9, tm_hour=7, tm_min=36, tm_sec =46, tm_wday=5, tm_yday=221, tm_isdst=-1) t1 and t2 is different time ,the timezone in t2 is -0700 ,why we get the same result? >>> t3='Sat, 09 Aug 2014 07:36:46 +0400' >>> time.strptime(t3,"%a, %d %b %Y %H:%M:%S %z") time.struct_time(tm_year=2014, tm_mon=8, tm_mday=9, tm_hour=7, tm_min=36, tm_sec =46, tm_wday=5, tm_yday=221, tm_isdst=-1) The Directive %z has no any effect here,what is the matter? On 8/14/2014 10:01 AM, Ben Finney wrote: > luofeiyu writes: > >> s="Aug" >> >> how can i change it into 8 with some python time module? > What is your purpose here? If you want to parse a text value into a > structured time object, don't do it piece by piece. Use the > ?time.strptime? function. > > >>> import time > >>> input_time_text = "14 Aug 2014" > >>> input_time = time.strptime(input_text, "%d %b %Y") > >>> input_time.tm_mon > 8 > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bob.martin at excite.com Thu Aug 14 07:50:30 2014 From: bob.martin at excite.com (Bob Martin) Date: Thu, 14 Aug 2014 07:50:30 BST Subject: newbee References: Message-ID: in 726715 20140813 103037 Chris Angelico wrote: >On Wed, Aug 13, 2014 at 9:57 AM, Frank Scafidi wrote: >> I just acquired a Raspberry Pi and want to program in Python. I was a PL/1 >> programmer back in the 60's & 70's and Python is similar. I am struggling >> with some very fundamental things that I am not finding in the >> documentation. Can someone help me with the basics like how do I save a >> program I've written, reload it in Python, list the program once it's >> loaded? How do I edit a program? Are these command line functions? > >These sound like RPi questions, rather than Python questions. You may >find knowledgeable people here on this list, but if not, I would >advise hunting down an RPi mailing list or newsgroup and asking there. >Most of us here use full computers, where questions like "how do I >save a file?" are trivially easy... you may find, actually, that >starting on a PC and then pushing the file to the RPi is the easiest >way to work. comp.sys.rapberry-pi From cs at zip.com.au Thu Aug 14 02:56:02 2014 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 14 Aug 2014 16:56:02 +1000 Subject: a python console in bluestacks In-Reply-To: References: Message-ID: <20140814065602.GA32024@cskk.homeip.net> On 14Aug2014 08:25, Chris =?utf-8?B?4oCcS3dwb2xza2HigJ0=?= Warrick wrote: >On Aug 14, 2014 4:30 AM, "luofeiyu" wrote: >> I have installed bluestacks(an android phone emulator) on my pc,and SL4A on >it.Now i can run python thish way : >> 1.edit an file ending with .py, save it in /sdcard/sl4a/scripts/ >yourname.py. >> 2.open sl4a ,and click the file to make it run. >> >> Is there a python console to type python command to run python directly >such as in pc ? > >Why are you using an Android emulator to run Python, a PC-first software?! >Just install the Windows version from http://python.org/ and use that. Maybe he wants Python to run on the emulator? Just an idea... Cheers, Cameron Simpson The wonderous pulp and fibre of the brain had been substituted by brass and iron; he had taught wheelwork to think. - Harry Wilmot Buxton 1832, referring to Charles Babbage and his difference engine. From elearn2014 at gmail.com Thu Aug 14 03:19:51 2014 From: elearn2014 at gmail.com (luofeiyu) Date: Thu, 14 Aug 2014 15:19:51 +0800 Subject: what is the "/" mean in __init__(self, /, *args, **kwargs) ? In-Reply-To: <20140813211212.0c0843b8@bigbox.christie.dr> References: <53EC1887.6060205@gmail.com> <20140813211212.0c0843b8@bigbox.christie.dr> Message-ID: <53EC6317.9000507@gmail.com> python3.4 On 8/14/2014 10:12 AM, Tim Chase wrote: > On 2014-08-14 10:01, luofeiyu wrote: >> >>> help(int.__init__) >> Help on wrapper_descriptor: >> >> __init__(self, /, *args, **kwargs) >> Initialize self. See help(type(self)) for accurate signature. >> >> what is the "/" mean in __init__(self, /, *args, **kwargs) ? > Where are you seeing this? > > > > Python 2.7.3 (default, Mar 13 2014, 11:03:55) > [GCC 4.7.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> help(int.__init__) > Help on wrapper_descriptor: > > __init__(...) > x.__init__(...) initializes x; see help(type(x)) for signature >>>> ^D > > 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. >>>> help(int.__init__) > Help on wrapper_descriptor: > > __init__(...) > x.__init__(...) initializes x; see help(type(x)) for signature > > > > -tkc > > From ben+python at benfinney.id.au Thu Aug 14 03:22:09 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 14 Aug 2014 17:22:09 +1000 Subject: how to change the time string into number? References: <53EC14EC.2090503@gmail.com> <85mwb77rs8.fsf@benfinney.id.au> <53EC5CA1.5090002@gmail.com> Message-ID: <85a9777cym.fsf@benfinney.id.au> Please don't top-post your response. Instead, interleave your response and remove irrelevant quoted material. Use the Interleaved style . luofeiyu writes: > in the manual https://docs.python.org/3.4/library/time.html > > %z Time zone offset [?] > %Z Time zone name (no characters if no time zone exists). > t1='Sat, 09 Aug 2014 07:36:46 ' > time.strptime(t1,"%a, %d %b %Y %H:%M:%S ") > time.struct_time(tm_year=2014, tm_mon=8, tm_mday=9, tm_hour=7, > tm_min=36, tm_sec > =46, tm_wday=5, tm_yday=221, tm_isdst=-1) Your code examples will be easier to read if you follow PEP 8 (in this example, spaces around the operators as described in the style guide). > >>> t2='Sat, 09 Aug 2014 07:36:46 -0700' > >>> time.strptime(t2,"%a, %d %b %Y %H:%M:%S %z") > time.struct_time(tm_year=2014, tm_mon=8, tm_mday=9, tm_hour=7, > tm_min=36, tm_sec > =46, tm_wday=5, tm_yday=221, tm_isdst=-1) > > t1 and t2 is different time ,the timezone in t2 is -0700 ,why we get > the same result? The timezone in ?t2? will only be understood subject to the caveat: Support for the %Z directive is based on the values contained in tzname and whether daylight is true. Because of this, it is platform-specific except for recognizing UTC and GMT which are always known (and are considered to be non-daylight savings timezones). So you'll need to see what your Python implementation supports (see ?time.tzname?). The support for time zones is always a pain, because they *change* rapidly, arbitrarily, and with very little warning. Because of this, the Python standard library does not attempt to contain a timezone database, since it would almost immediately be out of date. Install the ?pytz? package to get the latest released timezone database supported in Python . -- \ ?It is better to have loft and lost than to never have loft at | `\ all.? ?Groucho Marx | _o__) | Ben Finney From elearn2014 at gmail.com Thu Aug 14 03:22:57 2014 From: elearn2014 at gmail.com (luofeiyu) Date: Thu, 14 Aug 2014 15:22:57 +0800 Subject: a python console in bluestacks In-Reply-To: <20140814065602.GA32024@cskk.homeip.net> References: <20140814065602.GA32024@cskk.homeip.net> Message-ID: <53EC63D1.50204@gmail.com> i want to run python on my android phone ,to install python on bluestacks is to emulate it . On 8/14/2014 2:56 PM, Cameron Simpson wrote: > On 14Aug2014 08:25, Chris =?utf-8?B?4oCcS3dwb2xza2HigJ0=?= Warrick > wrote: >> On Aug 14, 2014 4:30 AM, "luofeiyu" wrote: >>> I have installed bluestacks(an android phone emulator) on my pc,and >>> SL4A on >> it.Now i can run python thish way : >>> 1.edit an file ending with .py, save it in /sdcard/sl4a/scripts/ >> yourname.py. >>> 2.open sl4a ,and click the file to make it run. >>> >>> Is there a python console to type python command to run python directly >> such as in pc ? >> >> Why are you using an Android emulator to run Python, a PC-first >> software?! >> Just install the Windows version from http://python.org/ and use that. > > Maybe he wants Python to run on the emulator? Just an idea... > > Cheers, > Cameron Simpson > > The wonderous pulp and fibre of the brain had been substituted by > brass and > iron; he had taught wheelwork to think. - Harry Wilmot Buxton 1832, > referring to Charles Babbage and his difference engine. From elearn2014 at gmail.com Thu Aug 14 03:30:33 2014 From: elearn2014 at gmail.com (luofeiyu) Date: Thu, 14 Aug 2014 15:30:33 +0800 Subject: how to change the time string into number? In-Reply-To: <20140814072549.GA69472@cskk.homeip.net> References: <53EC5CA1.5090002@gmail.com> <20140814072549.GA69472@cskk.homeip.net> Message-ID: <53EC6599.1000106@gmail.com> >>> import sys >>> sys.version '3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:25:23) [MSC v.1600 64 bit (AMD64)]' >>> import time >>> time.tzname ('China Standard Time', 'China Daylight Time') On 8/14/2014 3:25 PM, Cameron Simpson wrote: > On 14Aug2014 14:52, luofeiyu wrote: >> in the manual https://docs.python.org/3.4/library/time.html >> >> ????????????????????????????????????????????????????????????????????????????? >> >> ? ?Time zone offset indicating a positive or negative time >> difference ? ? >> ?%z?from UTC/GMT of the form +HHMM or -HHMM, where H represents >> decimal ? ? >> ? ?hour digits and M represents decimal minute digits [-23:59, >> +23:59]. ? ? >> ????????????????????????????????????????????????????????????????????????????? >> >> ?%Z?Time zone name (no characters if no time zone >> exists). ? ? >> ????????????????????????????????????????????????????????????????????????????? >> >> >> t1='Sat, 09 Aug 2014 07:36:46 ' >> time.strptime(t1,"%a, %d %b %Y %H:%M:%S ") >> time.struct_time(tm_year=2014, tm_mon=8, tm_mday=9, tm_hour=7, >> tm_min=36, >> tm_sec >> =46, tm_wday=5, tm_yday=221, tm_isdst=-1) >> >>>>> t2='Sat, 09 Aug 2014 07:36:46 -0700' >>>>> time.strptime(t2,"%a, %d %b %Y %H:%M:%S %z") >> time.struct_time(tm_year=2014, tm_mon=8, tm_mday=9, tm_hour=7, >> tm_min=36, >> tm_sec >> =46, tm_wday=5, tm_yday=221, tm_isdst=-1) >> >> t1 and t2 is different time ,the timezone in t2 is -0700 ,why we get >> the same >> result? > > What you get back a struct_time, which is little more than the numeric > values extracted from a time string. And as far as the text you have > supplied in your example, those values are the same. > > Regarding the difference, string in t2 has a time zone offset. > > My Python 3.4 doco says (about struct_time): > > Changed in version 3.3: tm_gmtoff and tm_zone attributes are > available on platforms with C library supporting the corresponding > fields in struct tm. > > Judging by your output, your C library does not support the tm_gmtoff > and tm_zone fields in its C library "struct tm". > > Please: > > tell us what specific version of Python you are using > > tell us what OS you're running on > > Then look up the localtime() or gmtime() functions for you C library > and see what that documentation says about "struct tm", which is what > they and the C library strptime() return. > >>>>> t3='Sat, 09 Aug 2014 07:36:46 +0400' >>>>> time.strptime(t3,"%a, %d %b %Y %H:%M:%S %z") >> time.struct_time(tm_year=2014, tm_mon=8, tm_mday=9, tm_hour=7, >> tm_min=36, >> tm_sec >> =46, tm_wday=5, tm_yday=221, tm_isdst=-1) >> >> The Directive %z has no any effect here,what is the matter? > > The directive allows the strptime parser to keep recognising text. > Imagine, for example, that the timezone were embedded in the middle of > the string for some reason. > > It looks like you platform does not support storing the time zone > information in the C library "struct tm", and therefore it does not > get exposed to the Python interpreter. > > Cheers, > Cameron Simpson > > What I want is Facts. Teach these boys and girls nothing but Facts. > Facts > alone are wanted in life. Plant nothing else, and root out everything > else. > - Charles Dickens John Huffam 1812-1870 Hard Times [1854] From cs at zip.com.au Thu Aug 14 03:47:00 2014 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 14 Aug 2014 17:47:00 +1000 Subject: how to change the time string into number? In-Reply-To: <53EC6599.1000106@gmail.com> References: <53EC6599.1000106@gmail.com> Message-ID: <20140814074700.GA4813@cskk.homeip.net> On 14Aug2014 15:30, luofeiyu wrote: >>>> import sys >>>> sys.version >'3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:25:23) [MSC v.1600 64 bit >(AMD64)]' First, please post in an interleaved style so that we can see your responses underneath the text to which they relate. Thanks. Ok, you have Python 3.4.0. And (I am guessing from the "MSC"), some 64 bit Windows install? You will need to look up the Microsoft documentation to see whather your C library "struct tm" supports timezone information. Your Android phone will be running some flavour of Linux I believe. Someone who has used one may correct me here. >>>> import time >>>> time.tzname >('China Standard Time', 'China Daylight Time') Ok. Have a look at time.timezone. That may help you. Cheers, Cameron Simpson >On 8/14/2014 3:25 PM, Cameron Simpson wrote: >>On 14Aug2014 14:52, luofeiyu wrote: >>>in the manual https://docs.python.org/3.4/library/time.html >>> >>>????????????????????????????????????????????????????????????????????????????? >>> >>>? ?Time zone offset indicating a positive or negative time >>>difference ? ? >>>?%z?from UTC/GMT of the form +HHMM or -HHMM, where H represents >>>decimal ? ? >>>? ?hour digits and M represents decimal minute digits [-23:59, >>>+23:59]. ? ? >>>????????????????????????????????????????????????????????????????????????????? >>> >>>?%Z?Time zone name (no characters if no time zone exists). >>>? ? >>>????????????????????????????????????????????????????????????????????????????? >>> >>> >>>t1='Sat, 09 Aug 2014 07:36:46 ' >>>time.strptime(t1,"%a, %d %b %Y %H:%M:%S ") >>>time.struct_time(tm_year=2014, tm_mon=8, tm_mday=9, tm_hour=7, >>>tm_min=36, >>>tm_sec >>>=46, tm_wday=5, tm_yday=221, tm_isdst=-1) >>> >>>>>>t2='Sat, 09 Aug 2014 07:36:46 -0700' >>>>>>time.strptime(t2,"%a, %d %b %Y %H:%M:%S %z") >>>time.struct_time(tm_year=2014, tm_mon=8, tm_mday=9, tm_hour=7, >>>tm_min=36, >>>tm_sec >>>=46, tm_wday=5, tm_yday=221, tm_isdst=-1) >>> >>>t1 and t2 is different time ,the timezone in t2 is -0700 ,why we >>>get the same >>>result? >> >>What you get back a struct_time, which is little more than the >>numeric values extracted from a time string. And as far as the text >>you have supplied in your example, those values are the same. >> >>Regarding the difference, string in t2 has a time zone offset. >> >>My Python 3.4 doco says (about struct_time): >> >> Changed in version 3.3: tm_gmtoff and tm_zone attributes are >>available on platforms with C library supporting the corresponding >>fields in struct tm. >> >>Judging by your output, your C library does not support the >>tm_gmtoff and tm_zone fields in its C library "struct tm". >> >>Please: >> >> tell us what specific version of Python you are using >> >> tell us what OS you're running on >> >>Then look up the localtime() or gmtime() functions for you C library >>and see what that documentation says about "struct tm", which is >>what they and the C library strptime() return. >> >>>>>>t3='Sat, 09 Aug 2014 07:36:46 +0400' >>>>>>time.strptime(t3,"%a, %d %b %Y %H:%M:%S %z") >>>time.struct_time(tm_year=2014, tm_mon=8, tm_mday=9, tm_hour=7, >>>tm_min=36, >>>tm_sec >>>=46, tm_wday=5, tm_yday=221, tm_isdst=-1) >>> >>>The Directive %z has no any effect here,what is the matter? >> >>The directive allows the strptime parser to keep recognising text. >>Imagine, for example, that the timezone were embedded in the middle >>of the string for some reason. >> >>It looks like you platform does not support storing the time zone >>information in the C library "struct tm", and therefore it does not >>get exposed to the Python interpreter. >> >>Cheers, >>Cameron Simpson >> >>What I want is Facts. Teach these boys and girls nothing but Facts. >>Facts >>alone are wanted in life. Plant nothing else, and root out >>everything else. >> - Charles Dickens John Huffam 1812-1870 Hard Times [1854] From steve at pearwood.info Thu Aug 14 03:49:10 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 14 Aug 2014 07:49:10 GMT Subject: a python console in bluestacks References: <53EC15EF.3000601@gmail.com> Message-ID: <53ec69f5$0$11123$c3e8da3@news.astraweb.com> On Thu, 14 Aug 2014 08:25:00 +0200, Chris ?Kwpolska? Warrick wrote: > Why are you using an Android emulator to run Python, a PC-first > software?! Just install the Windows version from http://python.org/ and > use that. If the OP's ultimate aim is to run Python under Android, running it under an Android emulator is a good first step (assuming you trust the emulator is a good match to actual Android). Or perhaps he wants to run an Android-only application, but wants to run it on his PC. In that case, an Android emulator may allow him to do so. Or if he wishes to do Android development on his PC, instead of poking at the virtual keyboard on a screen the size of your palm, being able to test the software on the PC (under emulation) rather than having to upload it to your phone is very useful. -- Steven From cs at zip.com.au Thu Aug 14 03:25:49 2014 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 14 Aug 2014 17:25:49 +1000 Subject: how to change the time string into number? In-Reply-To: <53EC5CA1.5090002@gmail.com> References: <53EC5CA1.5090002@gmail.com> Message-ID: <20140814072549.GA69472@cskk.homeip.net> On 14Aug2014 14:52, luofeiyu wrote: >in the manual? https://docs.python.org/3.4/library/time.html > >????????????????????????????????????????????????????????????????????????????? >? ?Time zone offset indicating a positive or negative time difference ? ? >?%z?from UTC/GMT of the form +HHMM or -HHMM, where H represents decimal ??? >? ?hour digits and M represents decimal minute digits [-23:59, +23:59]. ? ? >????????????????????????????????????????????????????????????????????????????? >?%Z?Time zone name (no characters if no time zone exists). ? ? >????????????????????????????????????????????????????????????????????????????? > >t1='Sat, 09 Aug 2014? 07:36:46? ' >time.strptime(t1,"%a, %d %b %Y %H:%M:%S ") >time.struct_time(tm_year=2014, tm_mon=8, tm_mday=9, tm_hour=7, tm_min=36, >tm_sec >=46, tm_wday=5, tm_yday=221, tm_isdst=-1) > >>>> t2='Sat, 09 Aug 2014? 07:36:46? -0700' >>>> time.strptime(t2,"%a, %d %b %Y %H:%M:%S %z") >time.struct_time(tm_year=2014, tm_mon=8, tm_mday=9, tm_hour=7, tm_min=36, >tm_sec >=46, tm_wday=5, tm_yday=221, tm_isdst=-1) > >t1 and t2 is different time ,the timezone in t2 is -0700 ,why we get the same >result? What you get back a struct_time, which is little more than the numeric values extracted from a time string. And as far as the text you have supplied in your example, those values are the same. Regarding the difference, string in t2 has a time zone offset. My Python 3.4 doco says (about struct_time): Changed in version 3.3: tm_gmtoff and tm_zone attributes are available on platforms with C library supporting the corresponding fields in struct tm. Judging by your output, your C library does not support the tm_gmtoff and tm_zone fields in its C library "struct tm". Please: tell us what specific version of Python you are using tell us what OS you're running on Then look up the localtime() or gmtime() functions for you C library and see what that documentation says about "struct tm", which is what they and the C library strptime() return. >>>> t3='Sat, 09 Aug 2014? 07:36:46? +0400' >>>> time.strptime(t3,"%a, %d %b %Y %H:%M:%S %z") >time.struct_time(tm_year=2014, tm_mon=8, tm_mday=9, tm_hour=7, tm_min=36, >tm_sec >=46, tm_wday=5, tm_yday=221, tm_isdst=-1) > >The Directive?? %z? has no any effect here,what is the matter? The directive allows the strptime parser to keep recognising text. Imagine, for example, that the timezone were embedded in the middle of the string for some reason. It looks like you platform does not support storing the time zone information in the C library "struct tm", and therefore it does not get exposed to the Python interpreter. Cheers, Cameron Simpson What I want is Facts. Teach these boys and girls nothing but Facts. Facts alone are wanted in life. Plant nothing else, and root out everything else. - Charles Dickens John Huffam 1812-1870 Hard Times [1854] From elearn2014 at gmail.com Thu Aug 14 03:32:19 2014 From: elearn2014 at gmail.com (luofeiyu) Date: Thu, 14 Aug 2014 15:32:19 +0800 Subject: how to write a function to make operation as a argument in the function Message-ID: <53EC6603.5010906@gmail.com> I want to write a function to make operation as a argument in the function. |def fun(op,x,y): return(x op y)| it is my target for the funciton: if op ="+" fun(op,3,9) =12 if op ="*" fun(op,3,9) =27 How to write it? -------------- next part -------------- An HTML attachment was scrubbed... URL: From kwpolska at gmail.com Thu Aug 14 03:57:32 2014 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Thu, 14 Aug 2014 09:57:32 +0200 Subject: a python console in bluestacks In-Reply-To: <53EC63D1.50204@gmail.com> References: <20140814065602.GA32024@cskk.homeip.net> <53EC63D1.50204@gmail.com> Message-ID: On Aug 14, 2014 9:23 AM, "luofeiyu" wrote: > > i want to run python on my android phone ,to install python on bluestacks is to emulate it . In this case, you can install QPython, which supports the SL4A modules and has a console. Or, you can install an app to access sh, like ConnectBot (though better apps likely exist.) Another alternative might be to use a real device with adb shell. -- Chris ?Kwpolska? Warrick Sent from my SGS3. -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Thu Aug 14 04:35:17 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 14 Aug 2014 09:35:17 +0100 Subject: how to change the time string into number? In-Reply-To: <53EC14EC.2090503@gmail.com> References: <53EC14EC.2090503@gmail.com> Message-ID: On 14/08/2014 02:46, luofeiyu wrote: > s="Aug" > > how can i change it into 8 with some python time module? If all else fails, read the instructions, so start here https://docs.python.org/3/library/datetime.html#module-datetime -- 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 Thu Aug 14 04:41:05 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 14 Aug 2014 09:41:05 +0100 Subject: what is the "/" mean in __init__(self, /, *args, **kwargs) ? In-Reply-To: <85iolv7rhr.fsf@benfinney.id.au> References: <53EC1887.6060205@gmail.com> <85iolv7rhr.fsf@benfinney.id.au> Message-ID: On 14/08/2014 03:08, Ben Finney wrote: > luofeiyu writes: > >>>>> help(int.__init__) >> Help on wrapper_descriptor: >> >> __init__(self, /, *args, **kwargs) >> Initialize self. See help(type(self)) for accurate signature. >> >> what is the "/" mean in __init__(self, /, *args, **kwargs) ? > > I don't know, I haven't seen that before. It is confusing. > > At least it is acknowledged (?See [elsewhere] for accurate signature?) > to be unhelpful. > > I suspect this is an artefact of the impedance mismatch between Python > function signatures and the implementation of ?int? in C code. The ?/? > may be a placeholder for something the C implementation requires but > that Python's function signature expectation doesn't allow. > > Perhaps Python 3's keyword-only arguments may one day help functions > like that get implemented with a more useful signature, but I'm not > holding my breath for that. > Something to do with the Argement Clinic http://legacy.python.org/dev/peps/pep-0436/ ??? -- 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 Thu Aug 14 04:52:28 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 14 Aug 2014 09:52:28 +0100 Subject: how to write a function to make operation as a argument in the function In-Reply-To: <53EC6603.5010906@gmail.com> References: <53EC6603.5010906@gmail.com> Message-ID: On 14/08/2014 08:32, luofeiyu wrote: > I want to write a function to make operation as a argument in the function. > > |def fun(op,x,y): > return(x op y)| > > it is my target for the funciton: > > if op ="+" fun(op,3,9) =12 > if op ="*" fun(op,3,9) =27 > > How to write it? > With a text editor after you've taken the trouble to read the docs instead of bombarding us with your questions. Start here https://docs.python.org/3/library/operator.html#module-operator As a slight aside would you stop top posting as well. If you have the audacity to ask what that means rather than search I will be sending my boys around. Please be aware, the 17 year old is a very, very vicious thug. He was taught by his granddad, who used to work for the Piranha Brothers, see http://en.wikipedia.org/wiki/Piranha_Brothers :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From sj.constantine at gmail.com Thu Aug 14 04:59:42 2014 From: sj.constantine at gmail.com (sj.constantine at gmail.com) Date: Thu, 14 Aug 2014 01:59:42 -0700 (PDT) Subject: pexpect - logging input AND output Message-ID: i have a script running a few commands on a network device. i can't seem to figure out how to log both the input and output of what the pexpect script initiates and responds to. child = pexpect.spawn ('telnet '+ ip) child.expect ('.*:*') child.sendline (user) child.expect ('.*:*') child.sendline (password) child.expect(['.*#*', '.*>*']) child.sendline ('enable') child.expect (['Password:', '.*#*']) child.sendline (password) child.expect ('.*#*') child.sendline ('conf t') child.expect ('.*#*') child.sendline ('line vty 0 4') i have tried both these logging commands: child.logfile = open('log.txt', 'w') child.logfile=sys.stdout all i get is the input i send with expect/sendline combinations, i don't get any of what the device sends, only what i send the device: user password enable password conf t line vty 0 4 any ideas of what is the correct way to go about this? just can't get the output! From info at egenix.com Thu Aug 14 05:10:36 2014 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Thu, 14 Aug 2014 11:10:36 +0200 Subject: ANN: eGenix pyOpenSSL Distribution 0.13.4.1.0.1.9 Message-ID: <53EC7D0C.9090804@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix.com pyOpenSSL Distribution Version 0.13.4.1.0.1.9 An easy-to-install and easy-to-use distribution of the pyOpenSSL Python interface for OpenSSL - available for Windows, Mac OS X and Unix platforms This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-pyOpenSSL-Distribution-0.13.4.1.0.1.9.html ________________________________________________________________________ INTRODUCTION The eGenix.com pyOpenSSL Distribution includes everything you need to get started with SSL in Python. It comes with an easy-to-use installer that includes the most recent OpenSSL library versions in pre-compiled form, making your application independent of OS provided OpenSSL libraries: http://www.egenix.com/products/python/pyOpenSSL/ pyOpenSSL is an open-source Python add-on that allows writing SSL/TLS- aware network applications as well as certificate management tools: https://launchpad.net/pyopenssl/ OpenSSL is an open-source implementation of the SSL/TLS protocol: http://www.openssl.org/ ________________________________________________________________________ NEWS This new release of the eGenix.com pyOpenSSL Distribution updates the included OpenSSL version to the latest OpenSSL 1.0.1h version and adds a few more context options: New in OpenSSL -------------- * Updated included OpenSSL libraries from OpenSSL 1.0.1h to 1.0.1i. See https://www.openssl.org/news/secadv_20140806.txt for a complete list of changes. Most fixes apply to the OpenSSL DTLS implementation, which pyOpenSSL currently does not support. The following fix is relevant for pyOpenSSL applications: - CVE-2014-3511: A flaw in the OpenSSL TLS server code allows a man-in-the-middle attacker to force a downgrade to TLS 1.0. New in pyOpenSSL ---------------- * Compiled pyOpenSSL with OPENSSL_LOAD_CONF to have the OpenSSL libs automatically load the openssl.cnf configuration file. This allows easy configuration of additional OpenSSL parameters and defaults, locations of certificate files, hardware engines, etc. without having to change the application code. Please see the documentation for details. * Updated the included CA root certificate bundles to Mozilla's 2014-07-15 update. pyOpenSSL / OpenSSL Binaries Included ------------------------------------- In addition to providing sources, we make binaries available that include both pyOpenSSL and the necessary OpenSSL libraries for all supported platforms: Windows x86 and x64, Linux x86 and x64, Mac OS X PPC, x86 and x64. We've also added egg-file distribution versions of our eGenix.com pyOpenSSL Distribution for Windows, Linux and Mac OS X to the available download options. These make setups using e.g. zc.buildout and other egg-file based installers a lot easier. ________________________________________________________________________ DOWNLOADS The download archives and instructions for installing the package can be found at: http://www.egenix.com/products/python/pyOpenSSL/ ________________________________________________________________________ UPGRADING Before installing this version of pyOpenSSL, please make sure that you uninstall any previously installed pyOpenSSL version. Otherwise, you could end up not using the included OpenSSL libs. _______________________________________________________________________ SUPPORT Commercial support for these packages is available from eGenix.com. Please see http://www.egenix.com/services/support/ for details about our support offerings. ________________________________________________________________________ MORE INFORMATION For more information about the eGenix pyOpenSSL Distribution, licensing and download instructions, please visit our web-site or write to sales at egenix.com. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Aug 14 2014) >>> Python Projects, Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope/Plone.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::::: Try our mxODBC.Connect Python Database Interface for free ! :::::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From rosuav at gmail.com Thu Aug 14 05:14:51 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Aug 2014 19:14:51 +1000 Subject: pexpect - logging input AND output In-Reply-To: References: Message-ID: On Thu, Aug 14, 2014 at 6:59 PM, wrote: > i have a script running a few commands on a network device. i can't seem to figure out how to log both the input and output of what the pexpect script initiates and responds to. > > child = pexpect.spawn ('telnet '+ ip) If that's not working for you, would it be easier instead to simply open a socket connection to port 23 on that IP address? Then you'd just write to the socket (and log what you write) and read from it (and log that). It's possible you'll see some TELNET or ANSI codes coming back, but I expect you won't have to send any of them. ChrisA From kwatch at gmail.com Thu Aug 14 05:35:36 2014 From: kwatch at gmail.com (Makoto Kuwata) Date: Thu, 14 Aug 2014 18:35:36 +0900 Subject: [Q] is 'yield from' syntax sugar for 'for'+'yield'? Message-ID: Question about 'yield from'. I understand that:: yield from xs is syntax suger of:: for x in xs: yield x And:: val = yield from xs is same as:: for x in xs: ret = yield x val = ret Is it true? Do I understand correctly? quote from https://docs.python.org/3/whatsnew/3.3.html#pep-380-syntax-for-delegating-to-a-subgenerator > For simple iterators, yield from iterable is essentially > just a shortened form of for item in iterable: yield item: -- regards, kwatch -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu Aug 14 05:38:42 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Aug 2014 19:38:42 +1000 Subject: [Q] is 'yield from' syntax sugar for 'for'+'yield'? In-Reply-To: References: Message-ID: On Thu, Aug 14, 2014 at 7:35 PM, Makoto Kuwata wrote: > I understand that:: > > yield from xs > > is syntax suger of:: > > for x in xs: > yield x Not just. It's like that for simple cases, but there are edge cases that are much more complicated to do manually, and are simply taken care of. Best would be to read the PEP itself: http://www.python.org/dev/peps/pep-0380/ ChrisA From kwatch at gmail.com Thu Aug 14 05:59:25 2014 From: kwatch at gmail.com (Makoto Kuwata) Date: Thu, 14 Aug 2014 18:59:25 +0900 Subject: [Q] is 'yield from' syntax sugar for 'for'+'yield'? In-Reply-To: References: Message-ID: On Thu, Aug 14, 2014 at 6:38 PM, Chris Angelico wrote: > On Thu, Aug 14, 2014 at 7:35 PM, Makoto Kuwata wrote: > > I understand that:: > > > > yield from xs > > > > is syntax suger of:: > > > > for x in xs: > > yield x > > Not just. It's like that for simple cases, but there are edge cases > that are much more complicated to do manually, and are simply taken > care of. Best would be to read the PEP itself: > > http://www.python.org/dev/peps/pep-0380/ > > ChrisA > Thank you. It seems too complicated... I understand that 'val = yield from xs' is completely different from:: for x in xs: ret = yield x val = x Return value is propagated by StopIteration, like: it = iter(xs) try: while 1: yield next(it) except StopIteration as ex: val = ex.value Thanks. -- regards, kwatch -------------- next part -------------- An HTML attachment was scrubbed... URL: From marko at pacujo.net Thu Aug 14 05:57:05 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 14 Aug 2014 12:57:05 +0300 Subject: [Q] is 'yield from' syntax sugar for 'for'+'yield'? References: Message-ID: <87y4urtmvi.fsf@elektro.pacujo.net> Makoto Kuwata : > val = yield from xs > > is same as:: > > for x in xs: > ret = yield x > val = ret > > Is it true? Do I understand correctly? The return value is not one of the yielded values. Instead, it's the value returned by the generator/coroutine. Marko From rosuav at gmail.com Thu Aug 14 06:02:46 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Aug 2014 20:02:46 +1000 Subject: [Q] is 'yield from' syntax sugar for 'for'+'yield'? In-Reply-To: References: Message-ID: On Thu, Aug 14, 2014 at 7:59 PM, Makoto Kuwata wrote: > I understand that 'val = yield from xs' is completely different from:: > > for x in xs: > ret = yield x > val = x > > Return value is propagated by StopIteration, like: > > it = iter(xs) > try: > while 1: > yield next(it) > except StopIteration as ex: > val = ex.value It's even more complicated than that. The PEP specifies the exact semantics. ChrisA From marko at pacujo.net Thu Aug 14 06:32:05 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 14 Aug 2014 13:32:05 +0300 Subject: [Q] is 'yield from' syntax sugar for 'for'+'yield'? References: Message-ID: <87oavntl96.fsf@elektro.pacujo.net> Makoto Kuwata : > Thank you. It seems too complicated... I recommend you stop trying to associate the "old" yield with the "new" yield. Asyncio coroutines "abuse" "yield from" for a specific effect. The classic purpose of "yield" was to spoonfeed a sequence of return values to the caller. The coroutine meaning of "yield from" has nothing whatsoever to do about delivering computation results; instead, it denotes a state where a blocking operation is waited for and the control is handed off to other activities. Marko From michele.simionato at gmail.com Thu Aug 14 06:34:22 2014 From: michele.simionato at gmail.com (Michele Simionato) Date: Thu, 14 Aug 2014 03:34:22 -0700 (PDT) Subject: Python Object Systems In-Reply-To: <0299640d-310c-41c6-a308-5552c202e0a8@googlegroups.com> References: <2d41828e-19ac-4e46-a487-8700c22d9b92@googlegroups.com> <0299640d-310c-41c6-a308-5552c202e0a8@googlegroups.com> Message-ID: <490a3fc3-3090-47f8-9800-ef249d2e73d7@googlegroups.com> Il giorno mercoled? 13 agosto 2014 19:13:16 UTC+2, thequie... at gmail.com ha scritto: > What is the difference between traits and roles? People keep using the same names to mean different concepts. For me traits are the things described here: http://www.iam.unibe.ch/~scg/Archive/Papers/Scha03aTraits.pdf I have no idea of what you mean by roles. From alister.nospam.ware at ntlworld.com Thu Aug 14 07:42:02 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Thu, 14 Aug 2014 11:42:02 GMT Subject: Captcha identify References: <8c2e4bc2-4f46-4a68-83ed-469fe171de3a@googlegroups.com> <2320baf0-e097-4d67-97c1-dd37ca79fffb@googlegroups.com> <376a239c-77e8-4e0e-9300-847dfa8a8547@googlegroups.com> Message-ID: On Wed, 13 Aug 2014 07:39:20 -0400, Eric S. Johansson wrote: > On 8/12/2014 9:46 PM, Chris Angelico wrote: >> On Wed, Aug 13, 2014 at 11:36 AM, Wesley wrote: >>> If my questions make you guys not so happy, I am sorry and please just >>> ignore. >>> I just wanna a general suggestion here in the beginning. >>> Why I need to write such program is just having such requirements, and >>> has nothing to do with the coding work itself. Don't say something to >>> prove you're so noble. >> The general suggestion you're getting is: Do not do this. Many of us >> here use CAPTCHAs and spend time keeping one step ahead of those who >> try to break them with software. By writing something to solve >> CAPTCHAs, you would be stealing time from those people. Don't do it. >> >> Am I sufficiently clear? >> > you are clear but also missing a really good reason to break captchas. > handicapped accessibility. Captchas are a huge barrier to access and in > many cases push disabled users away from using a service with captchas. lots of very valid complaints about Captcha usability Decent (I use the term loosely because i am no fan either) Captcha systems also provide options for Audio to assist the Visually impaired. I am not sure how well it works but can only assume it is an improvement. One system I have seen removes the need fro captcha completly Instead it relies on Javascript & AJAX a short time after loading the page it it requests a unique serial number from the server using which is added to the form as a hidden field. if this field & SN is missing from the response then the request is rejected as coming from a Bot. since most bots do not (as far as I know) include a Javascript interpreter this process removes any additional burden from the end user. unfortunately at present in the battle between service providers & scumm* the disabled population is an unfortunate victim. I can't think of another slightly polite word for people who spam or hack websites. -- Zeus gave Leda the bird. From skip at pobox.com Thu Aug 14 07:52:18 2014 From: skip at pobox.com (Skip Montanaro) Date: Thu, 14 Aug 2014 06:52:18 -0500 Subject: Optional static typing In-Reply-To: <53ec42ca$0$11123$c3e8da3@news.astraweb.com> References: <53ec42ca$0$11123$c3e8da3@news.astraweb.com> Message-ID: On Thu, Aug 14, 2014 at 12:02 AM, Steven D'Aprano wrote: > Does anyone here use function annotations? If so, what do you use them > for? I've used them a little when converting Python to Cython, though I readily admit that I have no idea if what Cython accepts as a type declaration is compatible with whatever is being considered for 3.5. Skip From alister.nospam.ware at ntlworld.com Thu Aug 14 07:59:15 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Thu, 14 Aug 2014 11:59:15 GMT Subject: newbee References: Message-ID: On Wed, 13 Aug 2014 15:31:37 -0400, Terry Reedy wrote: > On 8/13/2014 7:55 AM, alister wrote: >> >> I am not in the same league as many of the posters here when it comes >> to Python but fortunately i do have two Raspberry Pi's :-) > > Great! We really someone with hands-on experience. I Hope the missing word there is welcome :-) > >> if you are running the Pi connected to a TV/Monitor with the Gui >> enabled then you should have access to Idle > > Have you verified that Idle *does* (not just *should*) run on RPi? (That > would mean having tcl/tk running, with whatever *it* requires on linux.) > I am working on Idle and the idea of people (especially hobbyists, > students, and other amateurs) running it on microsystems would really > please me. > Yes it does, but i tend to run mine headless (X forwarding is still an option though) but I prefer Geany, which i do run on the pi (with x forwarding) with no issues, just remember the Pi is not a particularly fast device. >> If you have any more questions post them back &I hope I can help (Maybe >> I can become useful to this group as the R-Pi expert, > > Answering questions, sometimes after experiment and research, is a great > way to learn. I would say it is the ONLY way to really learn, you never really understand something until you have broken it and then fixed it or tried to teach it to someone. -- Dungeons and Dragons is just a lot of Saxon Violence. From marc.vanhoomissen at gmail.com Thu Aug 14 08:35:51 2014 From: marc.vanhoomissen at gmail.com (marc.vanhoomissen at gmail.com) Date: Thu, 14 Aug 2014 05:35:51 -0700 (PDT) Subject: =?ISO-8859-1?Q?Unable_to_run_print=28=27R=E9ussi=27=29_on_windows_and_on_lin?= =?ISO-8859-1?Q?ux?= Message-ID: <4dd67a80-b466-4866-ab67-d9a94c0b7ddf@googlegroups.com> Hello, This very simple program runs well on windows 7 # -*- utf8 -*- print('R?ussi') But, when I start the vrey same file on Linux (ubuntu 14), I got: Traceback (most recent call last): File "/partages/bureau/PB/Dev/Python3/test.py", line 2, in print('R\xe9ussi') UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' in position 1: ordinal not in range(128) What should i do to let the same program run on both OS, without changes? Thank you for your answer Marc Vanhoomissen From kwa at kuwata-lab.com Thu Aug 14 08:57:43 2014 From: kwa at kuwata-lab.com (Makoto Kuwata) Date: Thu, 14 Aug 2014 21:57:43 +0900 Subject: [Q] is 'yield from' syntax sugar for 'for'+'yield'? In-Reply-To: References: Message-ID: On Thu, Aug 14, 2014 at 7:02 PM, Chris Angelico wrote: > On Thu, Aug 14, 2014 at 7:59 PM, Makoto Kuwata wrote: > > I understand that 'val = yield from xs' is completely different from:: > > > > for x in xs: > > ret = yield x > > val = x > > > > Return value is propagated by StopIteration, like: > > > > it = iter(xs) > > try: > > while 1: > > yield next(it) > > except StopIteration as ex: > > val = ex.value > > It's even more complicated than that. The PEP specifies the exact > semantics. > > ChrisA > Well, I wrote the above code in order to describe `value is propagated by StopIteration' because I misunderstood that it is propagated by return value of yield statement (see my first post). I have known that `yield from` is very complicated (thanks to your reply). -- regards, kwatch -------------- next part -------------- An HTML attachment was scrubbed... URL: From roy at panix.com Thu Aug 14 09:08:18 2014 From: roy at panix.com (Roy Smith) Date: Thu, 14 Aug 2014 09:08:18 -0400 Subject: how to change the time string into number? References: <53EC6599.1000106@gmail.com> <20140814074700.GA4813@cskk.homeip.net> Message-ID: In article , Dennis Lee Bieber wrote: > On Thu, 14 Aug 2014 17:47:00 +1000, Cameron Simpson > declaimed the following: > > > > >Your Android phone will be running some flavour of Linux I believe. Someone > >who > >has used one may correct me here. > > > "Android" /is/ the flavor > > Though Google has probably done some things to it that make it > "not-Linux". > > A closer description might be that the Android phone is running some > flavor of Android -- since the OEMs tend to put customized skins on the > user interface level. The OEM marketing folks call that "a product differentiator". Most everybody else calls it "crapware". From ben+python at benfinney.id.au Thu Aug 14 09:10:58 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 14 Aug 2014 23:10:58 +1000 Subject: how to change the time string into number? References: <53EC6599.1000106@gmail.com> <20140814074700.GA4813@cskk.homeip.net> Message-ID: <8561hv6wt9.fsf@benfinney.id.au> Dennis Lee Bieber writes: > "Android" /is/ the flavor > > Though Google has probably done some things to it that make it > "not-Linux". Android is definitely Linux, since that is the kernel Android runs. Remember that Linux is not an operating system; it is one part, the kernel. This is where it's very useful to have a distinct name to refer to the operating system. GNU is an operating system, Android is a completely different operating system. Both happen to have Linux as their kernel. -- \ ?I went to San Francisco. I found someone's heart.? ?Steven | `\ Wright | _o__) | Ben Finney From vincent.vande.vyvre at telenet.be Thu Aug 14 09:22:52 2014 From: vincent.vande.vyvre at telenet.be (Vincent Vande Vyvre) Date: Thu, 14 Aug 2014 15:22:52 +0200 Subject: Unable to run =?windows-1252?Q?print=28=27R=E9ussi=27=29_o?= =?windows-1252?Q?n_windows_and_on_linux?= In-Reply-To: <4dd67a80-b466-4866-ab67-d9a94c0b7ddf@googlegroups.com> References: <4dd67a80-b466-4866-ab67-d9a94c0b7ddf@googlegroups.com> Message-ID: <53ECB82C.7070408@telenet.be> Le 14/08/2014 14:35, marc.vanhoomissen at gmail.com a ?crit : > Hello, > > This very simple program runs well on windows 7 > > # -*- utf8 -*- > print('R?ussi') > > But, when I start the vrey same file on Linux (ubuntu 14), I got: > > Traceback (most recent call last): > File "/partages/bureau/PB/Dev/Python3/test.py", line 2, in > print('R\xe9ussi') > UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' in position 1: ordinal not in range(128) > > What should i do to let the same program run on both OS, without changes? > > Thank you for your answer > > Marc Vanhoomissen No problem on Ubuntu Python 3.2.3 (default, Feb 27 2014, 21:33:50) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> print("R?ussi") R?ussi Are you really using Python 3 ? $ python3 test.py From ybmess at nooos.fr.invalid Thu Aug 14 09:31:42 2014 From: ybmess at nooos.fr.invalid (YBM) Date: Thu, 14 Aug 2014 15:31:42 +0200 Subject: Unable to run =?windows-1252?Q?print=28=27R=E9ussi=27=29_o?= =?windows-1252?Q?n_windows_and_on_linux?= In-Reply-To: <4dd67a80-b466-4866-ab67-d9a94c0b7ddf@googlegroups.com> References: <4dd67a80-b466-4866-ab67-d9a94c0b7ddf@googlegroups.com> Message-ID: <53ecba3e$0$1989$426a74cc@news.free.fr> Le 14/08/2014 14:35, marc.vanhoomissen at gmail.com a ?crit : > Hello, > > This very simple program runs well on windows 7 > > # -*- utf8 -*- > print('R?ussi') > > But, when I start the vrey same file on Linux (ubuntu 14), I got: > > Traceback (most recent call last): > File "/partages/bureau/PB/Dev/Python3/test.py", line 2, in > print('R\xe9ussi') > UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' in position 1: ordinal not in range(128) > > What should i do to let the same program run on both OS, without changes? the correct comment line should be : # -*- encoding: utf-8 -*- and it could be usefull to begin with #!/usr/bin/env python or #!/usr/bin/env python3 : $ cat > r?ussi.py #!/usr/bin/env python # -*- encoding: utf-8 -*- print('R?ussi'); ^D $ chmod +x r?ussi.py $ ./r?ussi.py R?ussi $ python r?ussi.py R?ussi From steve+comp.lang.python at pearwood.info Thu Aug 14 09:43:22 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 14 Aug 2014 23:43:22 +1000 Subject: [Q] is 'yield from' syntax sugar for 'for'+'yield'? References: Message-ID: <53ecbcfb$0$29994$c3e8da3$5496439d@news.astraweb.com> Makoto Kuwata wrote: > Question about 'yield from'. > > I understand that:: > > yield from xs > > is syntax suger of:: > > for x in xs: > yield x Not quite syntactic sugar. For simple cases, it does exactly the same thing. For more complicated cases, no. Suppose you have a generator: def spam(): yield "Spam!" yield "More spam!" yield "Delicious spam!!!" and you have another generator which delegates to the spam generator: def lunch1(): for food in spam(): yield food yield "plus a fried egg" We can now re-write the generator using "yield from": def lunch2(): yield from spam() yield "plus a fried egg" That saves one line of code. Big deal. Here, it is pure syntactic sugar. There are more interesting cases, where "yield from" is more powerful than the for-loop version. Here is an example with throw: py> it = lunch1() # Create an iterator. py> next(it) 'Spam!' py> it.throw(ValueError) Traceback (most recent call last): File "", line 1, in File "", line 3, in lunch1 ValueError Notice that the ValueError is raised inside lunch1(). There is no easy way to push the exception back inside spam(). But with "yield from", it works: py> it = lunch2() # New "yield from" generator. py> next(it) 'Spam!' py> it.throw(ValueError) Traceback (most recent call last): File "", line 1, in File "", line 2, in lunch2 File "", line 2, in spam ValueError Of course, spam() is free to catch the exception and perform processing. > And:: > > val = yield from xs > > is same as:: > > for x in xs: > ret = yield x > val = ret No. This is closer to what happens: # Not exactly this. # This is a simplified version. try: for x in xs: yield x except StopIteration as err: val = err.value The real version is much more complicated, 39 lines of code, and deals with generator .close() and .throw() methods, error checking, and various other issues. That is why "yield from" was added to Python. The simple case is too simple to care about, the complicated cases are too complicated to expect people to write their own solutions, so it was added to the language. -- Steven From marc.vanhoomissen at gmail.com Thu Aug 14 10:01:41 2014 From: marc.vanhoomissen at gmail.com (marc.vanhoomissen at gmail.com) Date: Thu, 14 Aug 2014 07:01:41 -0700 (PDT) Subject: =?ISO-8859-1?Q?Re=3A_Unable_to_run_print=28=27R=E9ussi=27=29_on_windows_and_on?= =?ISO-8859-1?Q?_linux?= In-Reply-To: References: <4dd67a80-b466-4866-ab67-d9a94c0b7ddf@googlegroups.com> Message-ID: <41563121-149d-401c-94ed-9c5c74e55ba3@googlegroups.com> Le jeudi 14 ao?t 2014 15:22:52 UTC+2, Vincent Vande Vyvre a ?crit?: > Le 14/08/2014 14:35, marc.vanhoomissen at gmail.com a ???crit : > > > Hello, > > > > > > This very simple program runs well on windows 7 > > > > > > # -*- utf8 -*- > > > print('R???ussi') > > > > > > But, when I start the vrey same file on Linux (ubuntu 14), I got: > > > > > > Traceback (most recent call last): > > > File "/partages/bureau/PB/Dev/Python3/test.py", line 2, in > > > print('R\xe9ussi') > > > UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' in position 1: ordinal not in range(128) > > > > > > What should i do to let the same program run on both OS, without changes? > > > > > > Thank you for your answer > > > > > > Marc Vanhoomissen > > No problem on Ubuntu > > > > Python 3.2.3 (default, Feb 27 2014, 21:33:50) > > [GCC 4.6.3] on linux2 > > Type "help", "copyright", "credits" or "license" for more information. > > >>> print("R???ussi") > > R???ussi > > > > Are you really using Python 3 ? > > > > $ python3 test.py Actually, when I try using a terminal, it works: $ python3 test.py R?ussi But when I issue the same command using webmin (v. 1.700 - shell command), I got: > python3 test.py Traceback (most recent call last): File "test.py", line 2, in print('R\xe9ussi') UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' in position 1: ordinal not in range(128) So, I guess it is merely a problem of webmin. From marc.vanhoomissen at gmail.com Thu Aug 14 10:04:02 2014 From: marc.vanhoomissen at gmail.com (marc.vanhoomissen at gmail.com) Date: Thu, 14 Aug 2014 07:04:02 -0700 (PDT) Subject: =?ISO-8859-1?Q?Re=3A_Unable_to_run_print=28=27R=E9ussi=27=29_on_windows_and_on?= =?ISO-8859-1?Q?_linux?= In-Reply-To: <53ecba3e$0$1989$426a74cc@news.free.fr> References: <4dd67a80-b466-4866-ab67-d9a94c0b7ddf@googlegroups.com> <53ecba3e$0$1989$426a74cc@news.free.fr> Message-ID: Hello YBM, I tried your suggestions, without improvement. Further, see my answer to Vincent Vande Vyre Thanks anyway. From elearn2014 at gmail.com Thu Aug 14 10:10:36 2014 From: elearn2014 at gmail.com (luofeiyu) Date: Thu, 14 Aug 2014 22:10:36 +0800 Subject: get the min date from a list Message-ID: <53ECC35C.80608@gmail.com> I finished it ,but how to make it into more pythonic way such as min (dates, key = converter) here is my code times=['Sat, 09 Aug 2014 07:36:46 -0700', 'Fri, 8 Aug 2014 22:25:40 -0400', 'Sat, 9 Aug 2014 12:46:43 +1000', 'Sat, 9 Aug 2014 12:50:52 +1000', 'Sat, 9 Aug 2014 02:51:01 +0000 (UTC)', 'Sat, 9 Aug 2014 13:03:24 +1000', 'Sat, 09 Aug 2014 13:06:28 +1000', 'Fri, 8 Aug 2014 20:48:44 -0700 (PDT)', 'Fri, 8 Aug 2014 23:52:09 -0700 (PDT)', 'Sat, 09 Aug 2014 09:15:50 +0200', 'Sat, 9 Aug 2014 01:49:54 -0600', 'Sat, 9 Aug 2014 01:57:18 -0600', 'Sat, 9 Aug 2014 17:54:23 +0800 (CST)', 'Sat, 9 Aug 2014 12:49:08 +0200', 'Sat, 9 Aug 2014 07:31:09 -0400', 'Sat, 9 Aug 2014 07:34:16 -0400', 'Sat, 09 Aug 2014 11:39:16 +0000', 'Sat, 9 Aug 2014 07:40:41 -0400', 'Sat, 9 Aug 2014 11:46:54 +0000', 'Sat, 09 Aug 2014 13:48:17 +0200', 'Sat, 09 Aug 2014 21:53:11 +1000', 'Sat, 09 Aug 2014 14:13:13 +0200', 'Sat, 09 Aug 2014 08:16:08 -0400', 'Sat, 09 Aug 2014 22:17:25 +1000', 'Sat, 09 Aug 2014 14:33:54 +0200', 'Sat, 9 Aug 2014 14:46:01 +0200', 'Sat, 09 Aug 2014 10:34:58 -0300', 'Sat, 09 Aug 2014 11:34:22 -0400', 'Sat, 09 Aug 2014 12:16:56 -0400', 'Sat, 09 Aug 2014 12:26:38 -0400', 'Sat, 09 Aug 2014 13:29:59 -0400', 'Sat, 09 Aug 2014 13:43:33 -0400', 'Sat, 9 Aug 2014 11:30:35 -0300', 'Sat, 09 Aug 2014 20:14:20 +0200', 'Sun, 10 Aug 2014 08:18:34 +1000', 'Sat, 9 Aug 2014 18:23:08 -0400 (EDT)', 'Sat, 09 Aug 2014 18:30:17 -0400', 'Sat, 09 Aug 2014 18:31:38 -0400', 'Sun, 10 Aug 2014 09:43:44 +1000', 'Sat, 9 Aug 2014 18:27:15 -0700 (PDT)', 'Sun, 10 Aug 2014 03:44:56 +0200', 'Sun, 10 Aug 2014 01:55:24 +0000 (UTC)', 'Sun, 10 Aug 2014 02:01:06 +0000 (UTC)', 'Sat, 9 Aug 2014 19:41:08 -0700 (PDT)', 'Sat, 9 Aug 2014 22:51:29 -0400 (EDT)', 'Sun, 10 Aug 2014 07:34:44 +0200', 'Tue, 5 Aug 2014 01:55:24 +0000 (UTC)'] def changeToUnix(times): import time,calendar,re time_list=[] for time1 in times: pat='(.+?)([-|+]\d{4})(\(?.*\)?)' x=re.search(pat,time1) time_part=x.groups()[0].strip() tz_part=x.groups()[1] tz_acc=x.groups()[2].strip().replace('(','').replace(')','') num=int(tz_part[1:3]) if tz_acc in ["","UTC","CST","GMT","EST","CST","PST"]: num=num if tz_acc in ["EDT"]: num=num+2 if tz_acc in ["CDT"]: num=num+1 if tz_acc in ["PDT"]: num=num-1 op=tz_part[0] y=time.strptime(time_part,"%a, %d %b %Y %H:%M:%S") if op=="-": hour=int(y.tm_hour)-num if op=="+": hour=int(y.tm_hour)+num time2=(y.tm_year,y.tm_mon,y.tm_mday,hour,y.tm_min,y.tm_sec) time_list.append(calendar.timegm(time2)) return(time_list) >>>y=changeToUnix(times) >>>times[y.index(min(y))] 'Tue, 5 Aug 2014 01:55:24 +0000 (UTC)' You neglected to specify your Python version, but I'll assume at least 2.5. The min function did exactly as it's documented to do, found the minimum string, by alphabetical ordering. Since 'F' is less than 'T' it didn't need to look at the rest. If you had been sorting a list of datetime objects, it would have found the least of those. Your simplest answer is probably to write a function that converts a string like you have into a datetime object, say call it converter (). Then after testing it, you call min (dates, key = converter) Note I did NOT use parens on converter. I also used the name dates for the list, since it's a collection of dates. But that assumes you rename it in your code that gathered them. -- DaveA From breamoreboy at yahoo.co.uk Thu Aug 14 10:38:23 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 14 Aug 2014 15:38:23 +0100 Subject: Unable to run =?windows-1252?Q?print=28=27R=E9ussi=27=29_o?= =?windows-1252?Q?n_windows_and_on_linux?= In-Reply-To: References: <4dd67a80-b466-4866-ab67-d9a94c0b7ddf@googlegroups.com> <53ecba3e$0$1989$426a74cc@news.free.fr> Message-ID: On 14/08/2014 15:04, marc.vanhoomissen at gmail.com wrote: > Hello YBM, > I tried your suggestions, without improvement. > Further, see my answer to Vincent Vande Vyre > Thanks anyway. > I'm pleased to see that you have answers. In return would you please quote the context. Could you also access this list via https://mail.python.org/mailman/listinfo/python-list or read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing double line spacing and single line paragraphs, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From as at sci.fi Thu Aug 14 10:36:41 2014 From: as at sci.fi (Anssi Saari) Date: Thu, 14 Aug 2014 17:36:41 +0300 Subject: Unable to run =?iso-8859-1?Q?print=28'R=E9ussi'=29?= on windows and on linux References: <4dd67a80-b466-4866-ab67-d9a94c0b7ddf@googlegroups.com> Message-ID: marc.vanhoomissen at gmail.com writes: > What should i do to let the same program run on both OS, without changes? You'd want to set the locale on your Ubuntu box to a UTF8 locale. On the command line you'd run sudo dpkg-reconfigure locales and proceed from there, but I guess there might be gooey way to do that too. But really, it's a Linux configuration question, not a Python question. From breamoreboy at yahoo.co.uk Thu Aug 14 10:40:44 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 14 Aug 2014 15:40:44 +0100 Subject: get the min date from a list In-Reply-To: <53ECC35C.80608@gmail.com> References: <53ECC35C.80608@gmail.com> Message-ID: On 14/08/2014 15:10, luofeiyu wrote: How many times do you have to be asked not to top post before the message sinks in? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From vincent.vande.vyvre at telenet.be Thu Aug 14 10:46:23 2014 From: vincent.vande.vyvre at telenet.be (Vincent Vande Vyvre) Date: Thu, 14 Aug 2014 16:46:23 +0200 Subject: Unable to run =?windows-1252?Q?print=28=27R=E9ussi=27=29_o?= =?windows-1252?Q?n_windows_and_on_linux?= In-Reply-To: <53ecba3e$0$1989$426a74cc@news.free.fr> References: <4dd67a80-b466-4866-ab67-d9a94c0b7ddf@googlegroups.com> <53ecba3e$0$1989$426a74cc@news.free.fr> Message-ID: <53ECCBBF.5090107@telenet.be> Le 14/08/2014 15:31, YBM a ?crit : > Le 14/08/2014 14:35, marc.vanhoomissen at gmail.com a ?crit : >> Hello, >> >> This very simple program runs well on windows 7 >> >> # -*- utf8 -*- >> print('R?ussi') >> >> But, when I start the vrey same file on Linux (ubuntu 14), I got: >> >> Traceback (most recent call last): >> File "/partages/bureau/PB/Dev/Python3/test.py", line 2, in >> print('R\xe9ussi') >> UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' in >> position 1: ordinal not in range(128) >> >> What should i do to let the same program run on both OS, without >> changes? > > the correct comment line should be : # -*- encoding: utf-8 -*- > and it could be usefull to begin with #!/usr/bin/env python > or #!/usr/bin/env python3 : > > $ cat > r?ussi.py > #!/usr/bin/env python > # -*- encoding: utf-8 -*- > print('R?ussi'); > ^D > $ chmod +x r?ussi.py > $ ./r?ussi.py > R?ussi > $ python r?ussi.py > R?ussi > > Nothing to do with the file encoding. ... if the OP use really Python 3 From ybmess at nooos.fr.invalid Thu Aug 14 10:47:36 2014 From: ybmess at nooos.fr.invalid (YBM) Date: Thu, 14 Aug 2014 16:47:36 +0200 Subject: Unable to run =?windows-1252?Q?print=28=27R=E9ussi=27=29_o?= =?windows-1252?Q?n_windows_and_on_linux?= In-Reply-To: References: <4dd67a80-b466-4866-ab67-d9a94c0b7ddf@googlegroups.com> <53ecba3e$0$1989$426a74cc@news.free.fr> Message-ID: <53eccc08$0$2932$426a34cc@news.free.fr> Le 14/08/2014 16:04, marc.vanhoomissen at gmail.com a ?crit : > Hello YBM, > I tried your suggestions, without improvement. > Further, see my answer to Vincent Vande Vyre > Thanks anyway. This is indeed very surprising. Are you sure that you have *exactly* this line at the first or second (not later !) line of your script : # -*- encoding: utf-8 -*- if a single caracter differs, it would fail. From musicalhacksaw at yahoo.co.uk Thu Aug 14 11:09:11 2014 From: musicalhacksaw at yahoo.co.uk (Simon Evans) Date: Thu, 14 Aug 2014 08:09:11 -0700 (PDT) Subject: Code to Python 27 prompt to access a html file stored on C drive Message-ID: <4d7cb33a-ccb9-4961-94de-80d807084179@googlegroups.com> Dear Programmers, I want to access a html file on my C drive, in the Python 27 prompt, all the examples I come across seem to require for access for the html file be on a server, rather than on the same computer's C drive. I want to do this as a prerequisite to writing webscraping code, surmising that if I can get the Python 27 prompt (inclusive of 'Beautiful Soup''Urllib' 'Requests' downloads ) to output pertinent html code from a html document, then I can proceed to use similar code to ouput html code from URL addresses, such as 'RacingPost.com' 'SportingLife.com''Oddschecker.com' and 'Bestbetting.com' which is what I am interested in working on. Hope you can help. Yours Simon Evans. From steve+comp.lang.python at pearwood.info Thu Aug 14 11:21:41 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 15 Aug 2014 01:21:41 +1000 Subject: Unable to run =?UTF-8?B?cHJpbnQoJ1LDqXVzc2knKQ==?= on windows and on linux References: <4dd67a80-b466-4866-ab67-d9a94c0b7ddf@googlegroups.com> <53ecba3e$0$1989$426a74cc@news.free.fr> <53eccc08$0$2932$426a34cc@news.free.fr> Message-ID: <53ecd406$0$29971$c3e8da3$5496439d@news.astraweb.com> YBM wrote: > Le 14/08/2014 16:04, marc.vanhoomissen at gmail.com a ?crit : >> Hello YBM, >> I tried your suggestions, without improvement. >> Further, see my answer to Vincent Vande Vyre >> Thanks anyway. > > This is indeed very surprising. Are you sure that you > have *exactly* this line at the first or second (not > later !) line of your script : > > # -*- encoding: utf-8 -*- > > if a single caracter differs, it would fail. That's not correct. The encoding declaration is very flexible. Any of these will be accepted: # This file uses the encoding: utf_8 # coding=UTF-8 # -*- coding: utf8 -*- # vim: set fileencoding=utf-8 : # Uses encoding:utf8 # I want my encoding=UtF_8 okay! #### textencoding= UTf-8 blah blah blah and many, many other varieties. The rules are: (1) It must be a comment; (2) It must be in the first or second line of the file; (3) It must match the regular expression r"coding[:=]\s*([-\w.]+)" However, just because you declare the file to be UTF-8, doesn't mean it *actually is* UTF-8. If your text editor is configured to use (say) Latin-1, a UTF-8 encoding declaration will just give you garbage. * Fix your system to use UTF-8 by default. * Fix your editor to use UTF-8. * Add a UTF-8 encoding declaration. And then things should work. -- Steven From jamiemitchell1604 at gmail.com Thu Aug 14 11:22:55 2014 From: jamiemitchell1604 at gmail.com (Jamie Mitchell) Date: Thu, 14 Aug 2014 08:22:55 -0700 (PDT) Subject: Matplotlib Contour Plots Message-ID: Hello all, I want to contour a scatter plot but I don't know how. Can anyone help me out? Cheers, Jamie From alister.nospam.ware at ntlworld.com Thu Aug 14 11:33:09 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Thu, 14 Aug 2014 15:33:09 GMT Subject: Code to Python 27 prompt to access a html file stored on C drive References: <4d7cb33a-ccb9-4961-94de-80d807084179@googlegroups.com> Message-ID: On Thu, 14 Aug 2014 08:09:11 -0700, Simon Evans wrote: > Dear Programmers, I want to access a html file on my C drive, in the > > Python 27 prompt, all the examples I come across seem to require for > > access for the html file be on a server, rather than on the same > > computer's C drive. I want to do this as a prerequisite to writing > > webscraping code, surmising that if I can get the Python 27 > > prompt (inclusive of 'Beautiful Soup''Urllib' 'Requests' downloads ) to > > output pertinent html code from a html document, then I can proceed to > use > > similar code to ouput html code from URL addresses, such as > > 'RacingPost.com' 'SportingLife.com''Oddschecker.com' and > > 'Bestbetting.com' which is what I am interested in working on. > > Hope you can help. > > Yours Simon Evans. have you read the online tutorial http://crummy.com/software/BeautifulSoup/bs3/documentation.html modifying the example slightly to read from a file rather than inline code would give (typed direct so untested) from BeautifulSoup import BeautifulSoup as bs data =open('myfile').read() soup=bs(data) print soup.prettify() -- Due to the CDA, we no longer have a root account. From __peter__ at web.de Thu Aug 14 12:00:56 2014 From: __peter__ at web.de (Peter Otten) Date: Thu, 14 Aug 2014 18:00:56 +0200 Subject: Unable to run =?UTF-8?B?cHJpbnQoJ1LDqXVzc2knKQ==?= on windows and on linux References: <4dd67a80-b466-4866-ab67-d9a94c0b7ddf@googlegroups.com> <41563121-149d-401c-94ed-9c5c74e55ba3@googlegroups.com> Message-ID: marc.vanhoomissen at gmail.com wrote: > Le jeudi 14 ao?t 2014 15:22:52 UTC+2, Vincent Vande Vyvre a ?crit : >> Are you really using Python 3 ? >> $ python3 test.py > > Actually, when I try using a terminal, it works: > $ python3 test.py > R?ussi > > But when I issue the same command using webmin (v. 1.700 - shell command), > I got: >> python3 test.py > Traceback (most recent call last): > File "test.py", line 2, in > print('R\xe9ussi') > UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' in > position 1: ordinal not in range(128) > > So, I guess it is merely a problem of webmin. I have no idea how that might interact with webmin, but you could try to set the environment variable PYTHONIOENCODING=utf-8 From ian.g.kelly at gmail.com Thu Aug 14 12:04:32 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 14 Aug 2014 10:04:32 -0600 Subject: Code to Python 27 prompt to access a html file stored on C drive In-Reply-To: References: <4d7cb33a-ccb9-4961-94de-80d807084179@googlegroups.com> Message-ID: On Thu, Aug 14, 2014 at 9:33 AM, alister wrote: > On Thu, 14 Aug 2014 08:09:11 -0700, Simon Evans wrote: > >> Dear Programmers, I want to access a html file on my C drive, in the >> >> Python 27 prompt, all the examples I come across seem to require for >> >> access for the html file be on a server, rather than on the same >> >> computer's C drive. I want to do this as a prerequisite to writing >> >> webscraping code, surmising that if I can get the Python 27 >> >> prompt (inclusive of 'Beautiful Soup''Urllib' 'Requests' downloads ) to >> >> output pertinent html code from a html document, then I can proceed to >> use >> >> similar code to ouput html code from URL addresses, such as >> >> 'RacingPost.com' 'SportingLife.com''Oddschecker.com' and >> >> 'Bestbetting.com' which is what I am interested in working on. >> >> Hope you can help. >> >> Yours Simon Evans. > > have you read the online tutorial > > http://crummy.com/software/BeautifulSoup/bs3/documentation.html > > > modifying the example slightly to read from a file rather than inline > code would give (typed direct so untested) > > from BeautifulSoup import BeautifulSoup as bs > > data =open('myfile').read() > soup=bs(data) > print soup.prettify() Alternatively you can continue to use urlopen and just pass it a file:// URL. From ian.g.kelly at gmail.com Thu Aug 14 12:12:22 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 14 Aug 2014 10:12:22 -0600 Subject: =?UTF-8?Q?Re=3A_Unable_to_run_print=28=27R=C3=A9ussi=27=29_on_windows_and_on?= =?UTF-8?Q?_linux?= In-Reply-To: <53ecd406$0$29971$c3e8da3$5496439d@news.astraweb.com> References: <4dd67a80-b466-4866-ab67-d9a94c0b7ddf@googlegroups.com> <53ecba3e$0$1989$426a74cc@news.free.fr> <53eccc08$0$2932$426a34cc@news.free.fr> <53ecd406$0$29971$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Aug 14, 2014 at 9:21 AM, Steven D'Aprano wrote: > YBM wrote: > >> Le 14/08/2014 16:04, marc.vanhoomissen at gmail.com a ?crit : >>> Hello YBM, >>> I tried your suggestions, without improvement. >>> Further, see my answer to Vincent Vande Vyre >>> Thanks anyway. >> >> This is indeed very surprising. Are you sure that you >> have *exactly* this line at the first or second (not >> later !) line of your script : >> >> # -*- encoding: utf-8 -*- >> >> if a single caracter differs, it would fail. > > That's not correct. The encoding declaration is very flexible. Any of these > will be accepted: > > # This file uses the encoding: utf_8 > # coding=UTF-8 > # -*- coding: utf8 -*- > # vim: set fileencoding=utf-8 : > # Uses encoding:utf8 > # I want my encoding=UtF_8 okay! > #### textencoding= UTf-8 blah blah blah > > and many, many other varieties. The rules are: > > (1) It must be a comment; > > (2) It must be in the first or second line of the file; > > (3) It must match the regular expression r"coding[:=]\s*([-\w.]+)" > > > However, just because you declare the file to be UTF-8, doesn't mean it > *actually is* UTF-8. If your text editor is configured to use (say) > Latin-1, a UTF-8 encoding declaration will just give you garbage. > > * Fix your system to use UTF-8 by default. > > * Fix your editor to use UTF-8. > > * Add a UTF-8 encoding declaration. > > And then things should work. And apart from all of that, if the OP is really using Python 3 then UTF-8 is the default source encoding anyway. From ebizbytes at gmail.com Thu Aug 14 12:49:49 2014 From: ebizbytes at gmail.com (Richard Prosser) Date: Thu, 14 Aug 2014 09:49:49 -0700 (PDT) Subject: Which OAuth library? Message-ID: <1a2f3320-79eb-4055-a933-ea474595976e@googlegroups.com> I "need" one for use with Flask, as I don't really have time to implement my own. Initially this will be for the "Two-Legged" case but I may well have to support the "Three-Legged" version later on. "Open ID Connect" may also be an option eventually. The basic idea is to provide an authorization/authentication service in a fairly conventional manner. My boss has told me to use OAuth, probably because he has experience with it and also to allow for third-party transactions. However it is not clear to me how I should decide between the various packages on offer. Any advice from experienced/informed users would be very welcome. Thanks ... Richard From steve+comp.lang.python at pearwood.info Thu Aug 14 12:53:09 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 15 Aug 2014 02:53:09 +1000 Subject: Matplotlib Contour Plots References: Message-ID: <53ece976$0$29992$c3e8da3$5496439d@news.astraweb.com> Jamie Mitchell wrote: > Hello all, > > I want to contour a scatter plot but I don't know how. > > Can anyone help me out? Certainly. Which way did you come in? :-) Sorry, I couldn't resist. It took me literally 20 seconds to find this by googling for "matplotlib contour plot", and it only took that long because I misspelled "contour" the first time. http://matplotlib.org/examples/pylab_examples/contour_demo.html Does this help? If not, please explain what experience you have with matplotlib, what you have tried, what you expected it to do, and what it did instead. -- Steven From marko at pacujo.net Thu Aug 14 13:19:50 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 14 Aug 2014 20:19:50 +0300 Subject: get the min date from a list References: Message-ID: <87r40jaszt.fsf@elektro.pacujo.net> luofeiyu : > y=time.strptime(time_part,"%a, %d %b %Y %H:%M:%S") As I said, whether that works depends on your locale -- according to the reference documentation. In practice, I couldn't get that to fail in my tests. I would be on my guard, though. That might mean I couldn't use strptime to convert the dates. Marko From ian.g.kelly at gmail.com Thu Aug 14 13:24:59 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 14 Aug 2014 11:24:59 -0600 Subject: get the min date from a list In-Reply-To: <53ECC35C.80608@gmail.com> References: <53ECC35C.80608@gmail.com> Message-ID: On Thu, Aug 14, 2014 at 8:10 AM, luofeiyu wrote: > I finished it ,but how to make it into more pythonic way such as > > min (dates, key = converter) The converter will be your changeToUnix function, but you'll need to rework it to convert a single, rather than the whole list. > def changeToUnix(times): > import time,calendar,re > time_list=[] > for time1 in times: > pat='(.+?)([-|+]\d{4})(\(?.*\)?)' > x=re.search(pat,time1) > time_part=x.groups()[0].strip() > tz_part=x.groups()[1] > tz_acc=x.groups()[2].strip().replace('(','').replace(')','') > num=int(tz_part[1:3]) > if tz_acc in ["","UTC","CST","GMT","EST","CST","PST"]: num=num > if tz_acc in ["EDT"]: num=num+2 > if tz_acc in ["CDT"]: num=num+1 > if tz_acc in ["PDT"]: num=num-1 > op=tz_part[0] > y=time.strptime(time_part,"%a, %d %b %Y %H:%M:%S") > if op=="-": hour=int(y.tm_hour)-num > if op=="+": hour=int(y.tm_hour)+num > time2=(y.tm_year,y.tm_mon,y.tm_mday,hour,y.tm_min,y.tm_sec) > time_list.append(calendar.timegm(time2)) > return(time_list) This looks way overly complicated. Why are you trying to mess with the time zone offset? strptime has a %z format code for parsing that (although I would recommend using datetime.datetime.strptime since I'm not sure how well time.strptime supports it). By adding the offset to the hour like that, you could end up with an hour that falls outside the accepted range. And I think you have your addition and subtraction switched around anyway -- in effect you're doubling the time zone offset, not converting to UTC. Also you would be losing the minutes part of the time zone offset if you were to get something like +0545. I also don't understand why you're special-casing and modifying three of the time zones. All you need to do is strip the parenthesized timezone off the string if it's present, and pass the result to datetime.datetime.strptime. From breamoreboy at yahoo.co.uk Thu Aug 14 13:31:31 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 14 Aug 2014 18:31:31 +0100 Subject: Odd floor-division corner case Message-ID: From http://bugs.python.org/issue22198 >>> -0.5 // float('inf') -1.0 What should it be? -- 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 Thu Aug 14 13:46:30 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 14 Aug 2014 11:46:30 -0600 Subject: Odd floor-division corner case In-Reply-To: References: Message-ID: On Thu, Aug 14, 2014 at 11:31 AM, Mark Lawrence wrote: > From http://bugs.python.org/issue22198 > >>>> -0.5 // float('inf') > -1.0 Looks like the result is the same for any negative dividend. > What should it be? It's surprising, but I think it's correct. A negative infinitesimal would be less than 0, so its floor should be -1, not 0. From kwpolska at gmail.com Thu Aug 14 13:54:18 2014 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Thu, 14 Aug 2014 19:54:18 +0200 Subject: Which OAuth library? In-Reply-To: <1a2f3320-79eb-4055-a933-ea474595976e@googlegroups.com> References: <1a2f3320-79eb-4055-a933-ea474595976e@googlegroups.com> Message-ID: On 14 August 2014 18:51 "Richard Prosser" wrote: > > I "need" one for use with Flask, as I don't really have time to implement my own. You should not implement things on your own if there are existing and same implementations. > Initially this will be for the "Two-Legged" case but I may well have to support the "Three-Legged" version later on. "Open ID Connect" may also be an option eventually. > > The basic idea is to provide an authorization/authentication service in a fairly conventional manner. My boss has told me to use OAuth, probably because he has experience with it and also to allow for third-party transactions. > > However it is not clear to me how I should decide between the various packages on offer. Any advice from experienced/informed users would be very welcome. > > > Thanks ... > > Richard > -- > https://mail.python.org/mailman/listinfo/python-list Google hints at https://flask-oauthlib.readthedocs.org/en/latest/ and it's looking pretty good. There is also flask-oauth, but it seems quite outdated. -- Chris ?Kwpolska? Warrick Sent from my SGS3. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ppearson at nowhere.invalid Thu Aug 14 14:37:49 2014 From: ppearson at nowhere.invalid (Peter Pearson) Date: 14 Aug 2014 18:37:49 GMT Subject: Captcha identify References: <8c2e4bc2-4f46-4a68-83ed-469fe171de3a@googlegroups.com> <2320baf0-e097-4d67-97c1-dd37ca79fffb@googlegroups.com> <376a239c-77e8-4e0e-9300-847dfa8a8547@googlegroups.com> <53EB4E68.8050405@harvee.org> Message-ID: On Wed, 13 Aug 2014 14:16:02 -0600, Ian Kelly wrote: > > . . . and as computers get more powerful the intersection > of {problems machines can't solve} and {problems humans can reliably > solve} grows ever smaller. "Which of the following eight sentences are sarcastic in tone?" -- To email me, substitute nowhere->spamcop, invalid->net. From ian.g.kelly at gmail.com Thu Aug 14 15:42:29 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 14 Aug 2014 13:42:29 -0600 Subject: Captcha identify In-Reply-To: References: <8c2e4bc2-4f46-4a68-83ed-469fe171de3a@googlegroups.com> <2320baf0-e097-4d67-97c1-dd37ca79fffb@googlegroups.com> <376a239c-77e8-4e0e-9300-847dfa8a8547@googlegroups.com> <53EB4E68.8050405@harvee.org> Message-ID: On Thu, Aug 14, 2014 at 12:37 PM, Peter Pearson wrote: > On Wed, 13 Aug 2014 14:16:02 -0600, Ian Kelly wrote: >> >> . . . and as computers get more powerful the intersection >> of {problems machines can't solve} and {problems humans can reliably >> solve} grows ever smaller. > > "Which of the following eight sentences are sarcastic in tone?" People are actually pretty bad at identifying sarcasm, or at least agreeing on what it is [1] and there's a segment of the population who simply don't understand it at all, so you'd be trading one kind of inaccessibility for another. And you might be surprised at how good machines can be at identifying sarcasm [2]. Besides, this suffers from the problem of a limited pool of questions, in that the spambot could simply build up a database of which sentences that are used by the system are sarcastic and which are not, as determined by their human controllers. [1] http://psychcentral.com/blog/archives/2009/08/18/would-you-even-recognize-sarcasm/ [2] http://www.bbc.com/news/technology-23160583 From rafinha.unix at gmail.com Thu Aug 14 15:50:14 2014 From: rafinha.unix at gmail.com (rafinha.unix at gmail.com) Date: Thu, 14 Aug 2014 12:50:14 -0700 (PDT) Subject: PyMatch Tool. Message-ID: <198ac789-f8e3-4f81-b10f-d7b29c25a70f@googlegroups.com> Hello, I created this tool to help me develop on formatting text using regular expressions. Any questions, I am available. Thank you. Tool -> https://github.com/rfunix/PyMatch From esj at harvee.org Thu Aug 14 15:43:55 2014 From: esj at harvee.org (Eric S. Johansson) Date: Thu, 14 Aug 2014 15:43:55 -0400 Subject: Captcha identify In-Reply-To: References: <8c2e4bc2-4f46-4a68-83ed-469fe171de3a@googlegroups.com> <2320baf0-e097-4d67-97c1-dd37ca79fffb@googlegroups.com> <376a239c-77e8-4e0e-9300-847dfa8a8547@googlegroups.com> <53EB4E68.8050405@harvee.org> Message-ID: <53ED117B.7020503@harvee.org> On 8/14/2014 2:37 PM, Peter Pearson wrote: > On Wed, 13 Aug 2014 14:16:02 -0600, Ian Kelly wrote: >> . . . and as computers get more powerful the intersection >> of {problems machines can't solve} and {problems humans can reliably >> solve} grows ever smaller. > "Which of the following eight sentences are sarcastic in tone?" and responses on this list alone show problems with detecting sarcasm (or snark). From rosuav at gmail.com Thu Aug 14 18:22:59 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 15 Aug 2014 08:22:59 +1000 Subject: Captcha identify In-Reply-To: References: <8c2e4bc2-4f46-4a68-83ed-469fe171de3a@googlegroups.com> <2320baf0-e097-4d67-97c1-dd37ca79fffb@googlegroups.com> <376a239c-77e8-4e0e-9300-847dfa8a8547@googlegroups.com> <53EB4E68.8050405@harvee.org> Message-ID: On Fri, Aug 15, 2014 at 4:37 AM, Peter Pearson wrote: > "Which of the following eight sentences are sarcastic in tone?" "You have a sarcasm sign?" http://www.thinkgeek.com/product/e58f/ ChrisA From rosuav at gmail.com Thu Aug 14 18:49:17 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 15 Aug 2014 08:49:17 +1000 Subject: PyMatch Tool. In-Reply-To: <198ac789-f8e3-4f81-b10f-d7b29c25a70f@googlegroups.com> References: <198ac789-f8e3-4f81-b10f-d7b29c25a70f@googlegroups.com> Message-ID: On Fri, Aug 15, 2014 at 5:50 AM, wrote: > Hello, I created this tool to help me develop on formatting text using regular expressions. > Any questions, I am available. > Thank you. > > Tool -> https://github.com/rfunix/PyMatch How is this better than GNU sed? ChrisA From denismfmcmahon at gmail.com Thu Aug 14 19:15:00 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Thu, 14 Aug 2014 23:15:00 +0000 (UTC) Subject: Captcha identify References: <8c2e4bc2-4f46-4a68-83ed-469fe171de3a@googlegroups.com> <2320baf0-e097-4d67-97c1-dd37ca79fffb@googlegroups.com> <376a239c-77e8-4e0e-9300-847dfa8a8547@googlegroups.com> Message-ID: On Tue, 12 Aug 2014 18:36:21 -0700, Wesley wrote: > I just wanna a general suggestion here in the beginning. OK, the general suggestion is that you take your spambot software, print it out on spiky metal sheets and ram it up your rectum. > Why I need to write such program is just having such requirements. Yes, we understand that your spambot requires to decode captcha. We were just telling you in fairly polite terms that you should fuck off because we have no wish to help you. We tried polite, it didn't work, now I'm trying robustness and profanity. -- Denis McMahon, denismfmcmahon at gmail.com From denismfmcmahon at gmail.com Thu Aug 14 19:19:03 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Thu, 14 Aug 2014 23:19:03 +0000 (UTC) Subject: Captcha identify References: <8c2e4bc2-4f46-4a68-83ed-469fe171de3a@googlegroups.com> <2320baf0-e097-4d67-97c1-dd37ca79fffb@googlegroups.com> <376a239c-77e8-4e0e-9300-847dfa8a8547@googlegroups.com> Message-ID: On Wed, 13 Aug 2014 07:39:20 -0400, Eric S. Johansson wrote: > you are clear but also missing a really good reason to break captchas. > handicapped accessibility. Captchas are a huge barrier to access and in > many cases push disabled users away from using a service with captchas. That's as may be, but bozo is not trying to improve handicapped accessibility, he's trying to write a spambot. Please don't use the accessibility concerns surrounding captcha to justify writing spambot software. It doesn't help the accessibility argument to be seen to be pro spambot, in fact if anything it may damage it. I agree that there are more reasons not to use captcha these days than there are to use them, however I still don't advocate helping spambot bastards defeat them. -- Denis McMahon, denismfmcmahon at gmail.com From elearn2014 at gmail.com Thu Aug 14 19:22:21 2014 From: elearn2014 at gmail.com (luofeiyu) Date: Fri, 15 Aug 2014 07:22:21 +0800 Subject: get the min date from a list In-Reply-To: References: <53ECC35C.80608@gmail.com> Message-ID: <53ED44AD.605@gmail.com> I am glad to hear that it is no necessary to create a complicated my function to change the time string. But in my computer the timezone offset do not work for me. I am in win7+python34. >>> import sys >>> sys.version '3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:25:23) [MSC v.1600 64 bit (AMD64)]' >>> import time >>> time.tzname ('China Standard Time', 'China Daylight Time') >>> time.strptime(t1,"%a, %d %b %Y %H:%M:%S %z") time.struct_time(tm_year=2014, tm_mon=8, tm_mday=9, tm_hour=7, tm_min=36, tm_sec =46, tm_wday=5, tm_yday=221, tm_isdst=-1) >>> time.strptime(t2,"%a, %d %b %Y %H:%M:%S %z") time.struct_time(tm_year=2014, tm_mon=8, tm_mday=9, tm_hour=7, tm_min=36, tm_sec =46, tm_wday=5, tm_yday=221, tm_isdst=-1) >>> The %z does not work for me, how to adjust it my computer? On 8/15/2014 1:24 AM, Ian Kelly wrote: > On Thu, Aug 14, 2014 at 8:10 AM, luofeiyu wrote: >> I finished it ,but how to make it into more pythonic way such as >> >> min (dates, key = converter) > The converter will be your changeToUnix function, but you'll need to > rework it to convert a single, rather than the whole list. > >> def changeToUnix(times): >> import time,calendar,re >> time_list=[] >> for time1 in times: >> pat='(.+?)([-|+]\d{4})(\(?.*\)?)' >> x=re.search(pat,time1) >> time_part=x.groups()[0].strip() >> tz_part=x.groups()[1] >> tz_acc=x.groups()[2].strip().replace('(','').replace(')','') >> num=int(tz_part[1:3]) >> if tz_acc in ["","UTC","CST","GMT","EST","CST","PST"]: num=num >> if tz_acc in ["EDT"]: num=num+2 >> if tz_acc in ["CDT"]: num=num+1 >> if tz_acc in ["PDT"]: num=num-1 >> op=tz_part[0] >> y=time.strptime(time_part,"%a, %d %b %Y %H:%M:%S") >> if op=="-": hour=int(y.tm_hour)-num >> if op=="+": hour=int(y.tm_hour)+num >> time2=(y.tm_year,y.tm_mon,y.tm_mday,hour,y.tm_min,y.tm_sec) >> time_list.append(calendar.timegm(time2)) >> return(time_list) > This looks way overly complicated. Why are you trying to mess with the > time zone offset? strptime has a %z format code for parsing that > (although I would recommend using datetime.datetime.strptime since I'm > not sure how well time.strptime supports it). By adding the offset to > the hour like that, you could end up with an hour that falls outside > the accepted range. And I think you have your addition and subtraction > switched around anyway -- in effect you're doubling the time zone > offset, not converting to UTC. Also you would be losing the minutes > part of the time zone offset if you were to get something like +0545. > I also don't understand why you're special-casing and modifying three > of the time zones. > > All you need to do is strip the parenthesized timezone off the string > if it's present, and pass the result to datetime.datetime.strptime. From denismfmcmahon at gmail.com Thu Aug 14 19:37:03 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Thu, 14 Aug 2014 23:37:03 +0000 (UTC) Subject: how to change the time string into number? References: Message-ID: On Thu, 14 Aug 2014 09:46:20 +0800, luofeiyu wrote: > s="Aug" > > how can i change it into 8 with some python time module? You don't need a time module for this, just use a dictionary: months = { "Jan" : 1, ..... , "Dec": 12 } num = months[s] print num Fill in the rest of the months dictionary yourself, it shouldn't be too hard. -- Denis McMahon, denismfmcmahon at gmail.com From ian.g.kelly at gmail.com Thu Aug 14 19:57:40 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 14 Aug 2014 17:57:40 -0600 Subject: get the min date from a list In-Reply-To: <53ED44AD.605@gmail.com> References: <53ECC35C.80608@gmail.com> <53ED44AD.605@gmail.com> Message-ID: On Thu, Aug 14, 2014 at 5:22 PM, luofeiyu wrote: > I am glad to hear that it is no necessary to create a complicated my > function to change the time string. > But in my computer the timezone offset do not work for me. > I am in win7+python34. > >>>> import sys >>>> sys.version > '3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:25:23) [MSC v.1600 64 bit > (AMD64)]' > >>>> import time >>>> time.tzname > ('China Standard Time', 'China Daylight Time') >>>> time.strptime(t1,"%a, %d %b %Y %H:%M:%S %z") > time.struct_time(tm_year=2014, tm_mon=8, tm_mday=9, tm_hour=7, tm_min=36, > tm_sec > =46, tm_wday=5, tm_yday=221, tm_isdst=-1) >>>> time.strptime(t2,"%a, %d %b %Y %H:%M:%S %z") > time.struct_time(tm_year=2014, tm_mon=8, tm_mday=9, tm_hour=7, tm_min=36, > tm_sec > =46, tm_wday=5, tm_yday=221, tm_isdst=-1) >>>> > > The %z does not work for me, how to adjust it my computer? As I noted in my previous post, try using datetime.datetime.strptime instead. The time.strptime function depends on the C libraries to support it, while the datetime.strptime does not. From skip at pobox.com Thu Aug 14 20:31:03 2014 From: skip at pobox.com (Skip Montanaro) Date: Thu, 14 Aug 2014 19:31:03 -0500 Subject: PyMatch Tool. In-Reply-To: References: <198ac789-f8e3-4f81-b10f-d7b29c25a70f@googlegroups.com> Message-ID: On Thu, Aug 14, 2014 at 5:49 PM, Chris Angelico wrote: > > > Tool -> https://github.com/rfunix/PyMatch > > How is this better than GNU sed? I didn't look closely at the program, but I have an idea how I might use it. Back in the dawn of Internet time (before Y2K, Django, V8, etc) I developed and maintained a concert calendar website. It had a database of tour dates, and a bunch of handwritten HTML. And, I allowed people to describe their concert tour information in a slightly-higher-than-regex level (SLTRL). This facility allowed me to routinely process known tour date listings and update my listings with little, if any, manual intervention. Under the covers, of course, it used regular expressions. I had, as they say, two problems. My solution to failed matches (I was actually the heaviest user of the system) was to provide a