From torriem at gmail.com Mon Sep 1 00:15:58 2014 From: torriem at gmail.com (Michael Torrie) Date: Sun, 31 Aug 2014 22:15:58 -0600 Subject: This could be an interesting error In-Reply-To: <2jc70at4qcpqmbes72r2f0tsjk8up0j6mn@4ax.com> References: <2jc70at4qcpqmbes72r2f0tsjk8up0j6mn@4ax.com> Message-ID: <5403F2FE.1030403@gmail.com> On 08/31/2014 06:04 PM, Seymore4Head wrote: >> for x,letter in enumerate(word): >> # x is index (position), letter is the value at that index >> if letter in "AEIOUaeiou": > I tried changing: > for x in range(len(test)): > to > for x in enumerate(test): Read my example again. You missed something vital. enumerate returns both a position and the item: for x,letter in "hello": print (x, " ", letter) From torriem at gmail.com Mon Sep 1 00:52:13 2014 From: torriem at gmail.com (Michael Torrie) Date: Sun, 31 Aug 2014 22:52:13 -0600 Subject: This could be an interesting error In-Reply-To: <5403F2FE.1030403@gmail.com> References: <2jc70at4qcpqmbes72r2f0tsjk8up0j6mn@4ax.com> <5403F2FE.1030403@gmail.com> Message-ID: <5403FB7D.1090701@gmail.com> On 08/31/2014 10:15 PM, Michael Torrie wrote: > On 08/31/2014 06:04 PM, Seymore4Head wrote: >>> for x,letter in enumerate(word): >>> # x is index (position), letter is the value at that index >>> if letter in "AEIOUaeiou": >> I tried changing: >> for x in range(len(test)): >> to >> for x in enumerate(test): > > Read my example again. You missed something vital. enumerate returns > both a position and the item: > Sigh. Oops. Make that: for x,letter in enumerate("hello"): print (x, " ", letter) You definitely should start doing it this way. It's more "pythonic" and also cleaner and easier to understand when you're reading the code later. Also you did add Y to your list of vowels, but what about words that have no vowels and no Y? Maybe not real words, but things that might be likely to be in sentences: "I am from Washington, DC" It's way better to fix your logic so you have a fall-back. Hint: Set pigword before your enter the loop so that it always contains _something_, preferably the original word! From orgnut at yahoo.com Mon Sep 1 00:55:51 2014 From: orgnut at yahoo.com (Larry Hudson) Date: Sun, 31 Aug 2014 21:55:51 -0700 Subject: This could be an interesting error In-Reply-To: References: <4u870addqootc65rs6996s88fg3gihqc09@4ax.com> Message-ID: On 08/31/2014 07:54 PM, Seymore4Head wrote: [snip] > Since I don't ever expect to be able to type them without thinking > about them, a standard keyboard could come with half sized keys on the > sides. > While this is definitely OT, I strongly suggest you take the time to learn to touch-type. (Actually, I would recommend it for everyone.) It's true that it will take time, effort, practice and diligence, especially time and practice, but if you do make the effort you'll never regret it. Eventually you'll find that you think (or read) a word, your fingers will wiggle a little bit and that word suddenly appears on screen. It's an _*EXTREMELY*_ useful ability -- well worth the time and effort. I was able to take it as a summer class in high school some 60+ years ago (I'm old ;-) ), and I've always been very glad that I did. (Even though I'm still not highly accurate and fairly frequently make typos, it's still much better than hunt-and-peck typing.) I definitely suggest it is well worth learning. -=- Larry -=- From rosuav at gmail.com Mon Sep 1 01:12:46 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 1 Sep 2014 15:12:46 +1000 Subject: This could be an interesting error In-Reply-To: References: <4u870addqootc65rs6996s88fg3gihqc09@4ax.com> Message-ID: On Mon, Sep 1, 2014 at 2:55 PM, Larry Hudson wrote: > While this is definitely OT, I strongly suggest you take the time to learn > to touch-type. (Actually, I would recommend it for everyone.) It's true > that it will take time, effort, practice and diligence, especially time and > practice, but if you do make the effort you'll never regret it. > > Eventually you'll find that you think (or read) a word, your fingers will > wiggle a little bit and that word suddenly appears on screen. It's an > _*EXTREMELY*_ useful ability -- well worth the time and effort. Indeed. And once you have that skill, you basically spend most of your coding time thinking, rather than typing - and the exact keystroke costs stop mattering much. (It makes little difference whether you type at 100wpm or 300wpm if you don't have 100 words to type each minute.) As an added bonus, you'll be able to work blind with barely more difficulty than when you have a screen in front of you. That's not hugely beneficial, but when the time comes, you'll be glad of it. Earlier this year I was typing up a bug report in a program that somehow managed to be so flawed that it could take only two keystrokes per second - so I typed way WAY ahead, then went off and made myself a hot chocolate while it painstakingly processed everything I'd typed. Same goes if, for whatever reason, you can't see your fingers - maybe the lights in your office have gone out, the screen wasn't on UPS, and you need to key in an orderly shutdown command while you're unable to see *anything*. (Which is what the little F and J pips are for. You can align your fingers on the keyboard in the dark.) ChrisA From rosuav at gmail.com Mon Sep 1 01:39:47 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 1 Sep 2014 15:39:47 +1000 Subject: subprocess module usage In-Reply-To: References: Message-ID: On Mon, Sep 1, 2014 at 3:24 PM, Earl Lapus wrote: > On Mon, Sep 1, 2014 at 11:55 AM, Chris Angelico wrote: >> >> But secondly, you're already splitting the argument (or rather, taking >> it from your own parameters, already split), so you don't want to go >> through the shell. In fact, going through the shell would only make >> your life harder. Change that to shell=False and you'll see everything >> work. >> > > Changing shell value to False worked. I appreciate your help Chris, Thanks! Glad it's working! But please, don't just take my word for it and make a black-box change to your code. When you invoke subprocesses, be sure you understand what's going on, and when shell=True is appropriate and when shell=False is appropriate. The docs should be fairly clear on this. If you get this sort of thing wrong, you'll get weird errors like this (if you're lucky), or open yourself up to shell injection vulnerabilities (if you're not). ChrisA From earl.lapus at gmail.com Mon Sep 1 01:24:21 2014 From: earl.lapus at gmail.com (Earl Lapus) Date: Mon, 1 Sep 2014 13:24:21 +0800 Subject: subprocess module usage In-Reply-To: References: Message-ID: On Mon, Sep 1, 2014 at 11:55 AM, Chris Angelico wrote: > > But secondly, you're already splitting the argument (or rather, taking > it from your own parameters, already split), so you don't want to go > through the shell. In fact, going through the shell would only make > your life harder. Change that to shell=False and you'll see everything > work. > Changing shell value to False worked. I appreciate your help Chris, Thanks! -- There are seven words in this sentence. From earl.lapus at gmail.com Mon Sep 1 02:33:15 2014 From: earl.lapus at gmail.com (Earl Lapus) Date: Mon, 1 Sep 2014 14:33:15 +0800 Subject: subprocess module usage In-Reply-To: References: Message-ID: On Mon, Sep 1, 2014 at 1:39 PM, Chris Angelico wrote: > > Glad it's working! But please, don't just take my word for it and make > a black-box change to your code. When you invoke subprocesses, be sure > you understand what's going on, and when shell=True is appropriate and > when shell=False is appropriate. The docs should be fairly clear on > this. If you get this sort of thing wrong, you'll get weird errors > like this (if you're lucky), or open yourself up to shell injection > vulnerabilities (if you're not). > The command and arguments that will be passed to check_output will not depend on user input. So, the chances of malicious commands from being executed would be low (right?). What I'm really after is just to execute a specific command and 1) retrieve it's output (if any) 2) detect any error returned while executing the command. Anyway, I'll take your advise and review the documentation again. Cheers, Earl -- There are seven words in this sentence. From breamoreboy at yahoo.co.uk Mon Sep 1 02:34:50 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 01 Sep 2014 07:34:50 +0100 Subject: This could be an interesting error In-Reply-To: <5403dfc1$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <4u870addqootc65rs6996s88fg3gihqc09@4ax.com> <5403dfc1$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 01/09/2014 03:53, Steven D'Aprano wrote: > Mark Lawrence wrote: > >>>>>>> return (pigword) >>>> These ^ ^ >>> >>> Those are parenthesis :P >>> But not having to use them is a time saver. >>> Thanks >>> >> >> No they are round brackets, as opposed to square or curly. > > True, they are round brackets, but the word "parentheses" is actually older. > > According to the Oxford dictionary, the word "parentheses" dates from the > middle of the 16th century, although the use of it to refer specifically to > the ( and ) symbols is only from the early 20th century. "Bracket" is about > a hundred years later, the middle of the 17th century, and didn't start to > be used for the ( ) symbols themselves until the middle of the 18th. > For all I care they could have been around for the entire time that the Jurassic Coast has existed. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rustompmody at gmail.com Mon Sep 1 02:53:09 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 31 Aug 2014 23:53:09 -0700 (PDT) Subject: This could be an interesting error In-Reply-To: References: <4u870addqootc65rs6996s88fg3gihqc09@4ax.com> Message-ID: On Monday, September 1, 2014 10:42:46 AM UTC+5:30, Chris Angelico wrote: > On Mon, Sep 1, 2014 at 2:55 PM, Larry Hudson wrote: > > While this is definitely OT, I strongly suggest you take the time to learn > > to touch-type. (Actually, I would recommend it for everyone.) It's true > > that it will take time, effort, practice and diligence, especially time and > > practice, but if you do make the effort you'll never regret it. > > Eventually you'll find that you think (or read) a word, your fingers will > > wiggle a little bit and that word suddenly appears on screen. It's an > > _*EXTREMELY*_ useful ability -- well worth the time and effort. > Indeed. And once you have that skill, you basically spend most of your > coding time thinking, rather than typing - and the exact keystroke > costs stop mattering much. (It makes little difference whether you > type at 100wpm or 300wpm if you don't have 100 words to type each > minute.) > As an added bonus, you'll be able to work blind with barely more > difficulty than when you have a screen in front of you. That's not > hugely beneficial, but when the time comes, you'll be glad of it. > Earlier this year I was typing up a bug report in a program that > somehow managed to be so flawed that it could take only two keystrokes > per second - so I typed way WAY ahead, then went off and made myself a > hot chocolate while it painstakingly processed everything I'd typed. > Same goes if, for whatever reason, you can't see your fingers - maybe > the lights in your office have gone out, the screen wasn't on UPS, and > you need to key in an orderly shutdown command while you're unable to > see *anything*. (Which is what the little F and J pips are for. You > can align your fingers on the keyboard in the dark.) Right. And the next logical conclusion is to use emacs :-) Or vi. ie editors whose default mode of use is mouseless. | Using the mouse is almost always the worst possible violation of | economy of motion, because you have to pick your hand up and fumble | around with it. The mouse is a clumsy instrument, and Emacs gurus | consider it a cache miss when they have to resort to using it. Steve Yegge at https://sites.google.com/site/steveyegge2/effective-emacs Note: (In case its not quite clear) I am being part-facetious. In the emacs (and vi?) worlds this is carried to ridiculous cult-extremes. Yet there's some truth there, for those who are so inclined. From anddamNOALPASTICCIODICARNE+gruppi at brapi.net Mon Sep 1 03:07:01 2014 From: anddamNOALPASTICCIODICARNE+gruppi at brapi.net (Andrea D'Amore) Date: Mon, 1 Sep 2014 09:07:01 +0200 Subject: Psycopg2 package installation puzzle in Pycharm - any thoughts? References: Message-ID: You make hard to follow your messages both by sending lot of messages and not using an adequate quoting. Please pick a posting style [1] (possibly interleaved) and stick to it. On 2014-08-31 23:35:09 +0000, andydtaylor at gmail.com said: > Andrea - yes I am using the virtualenv interpreter as the Pycharm > project interpreter That statement needs to be backed by some proof, saying "I'm using such interpreter" doesn't necessarily mean it's true, print out sys.executable and check. I confirm I just downloaded PyCharm CE 3.4.1 (you didn't provide your PyCharm version), set up a virtualenv, created an empty project using the interpreter from that environment and was able to run the file with the import statement in PyCharm, so the IDE works as expected. It was actually quite straightforward and PyCharm also offered to create the virtualenv while selecting the interpreter. I suggest to stop messing with your environment (I would revert all those changes) and figure what the problem actually is. [1] http://en.wikipedia.org/wiki/Posting_style -- Andrea From greg.ewing at canterbury.ac.nz Mon Sep 1 03:25:33 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 01 Sep 2014 19:25:33 +1200 Subject: This could be an interesting error In-Reply-To: <5403d605$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <5403d605$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > or words in Foreign like "cwm" Seeing that "w" is a vowel in Welsh, there should probably be a special version of the program for Welsh speakers. (Welshlatin? Pigwelsh?) -- Greg From cs at zip.com.au Mon Sep 1 04:46:52 2014 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 1 Sep 2014 18:46:52 +1000 Subject: subprocess module usage In-Reply-To: References: Message-ID: <20140901084652.GA58412@cskk.homeip.net> On 01Sep2014 14:33, Earl Lapus wrote: >On Mon, Sep 1, 2014 at 1:39 PM, Chris Angelico wrote: >> Glad it's working! But please, don't just take my word for it and make >> a black-box change to your code. When you invoke subprocesses, be sure >> you understand what's going on, and when shell=True is appropriate and >> when shell=False is appropriate. The docs should be fairly clear on >> this. If you get this sort of thing wrong, you'll get weird errors >> like this (if you're lucky), or open yourself up to shell injection >> vulnerabilities (if you're not). > >The command and arguments that will be passed to check_output will not >depend on user input. So, the chances of malicious commands from being >executed would be low (right?). Not really. If the arguments are coming in from the command line, someone (a user, even if that user is the programmer) typed them. Even if not malicious, they can still be mistaken. Or just unfortunate. You should always want to do exactly what you're asked. If you misuse shell=True when the user is expecting shell=False (i.e. "just do what I said!"), then your program will not carry out the user's intent. If it does not fail outright, it will presumably do the _wrong_ thing. Cheers, Cameron Simpson Music journalism: People who can't write interviewing people who can't talk for people who can't read. - Frank Zappa From rosuav at gmail.com Mon Sep 1 04:59:45 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 1 Sep 2014 18:59:45 +1000 Subject: subprocess module usage In-Reply-To: <20140901084652.GA58412@cskk.homeip.net> References: <20140901084652.GA58412@cskk.homeip.net> Message-ID: On Mon, Sep 1, 2014 at 6:46 PM, Cameron Simpson wrote: > Not really. If the arguments are coming in from the command line, someone (a > user, even if that user is the programmer) typed them. Even if not > malicious, they can still be mistaken. Or just unfortunate. I'm guessing that what he means is that the example posted here used sys.argv but his actual code doesn't. It's still important to *understand* shell=True, but it can be perfectly safe to use it. ChrisA From andydtaylor at gmail.com Mon Sep 1 08:32:38 2014 From: andydtaylor at gmail.com (andydtaylor at gmail.com) Date: Mon, 1 Sep 2014 05:32:38 -0700 (PDT) Subject: Psycopg2 package installation puzzle in Pycharm - any thoughts? In-Reply-To: References: Message-ID: Posting style point taken. Google groups doesn't exactly help you with that. * You guys have probably been tinkering with this stuff for years. I haven't. * Your man on the street would say I described the error fairly well. * It's not like I wasn't trying my best to fix it myself * So far as environment tinkering is concerned I have entered a "launchctl setenv PATH" statement in two places. Both reversible. * I think what I have is an issue pertaining to OSX Mavericks and Pycharm. If you have nothing to add, just say it. * Statements like "Please equip yourself with a tool that provides us with some context" add nothing and are not exactly community inclusive. From anddamNOALPASTICCIODICARNE+gruppi at brapi.net Mon Sep 1 09:13:14 2014 From: anddamNOALPASTICCIODICARNE+gruppi at brapi.net (Andrea D'Amore) Date: Mon, 1 Sep 2014 15:13:14 +0200 Subject: Psycopg2 package installation puzzle in Pycharm - any thoughts? References: Message-ID: On 2014-09-01 12:32:38 +0000, andydtaylor at gmail.com said: > Google groups doesn't exactly help you with that. Drop it, get a usenet client or subscribe the mailing list (the newsgroup and the ml are bridged IIRC). > * Your man on the street would say I described the error fairly well. That man probably doesn't try to solve other people's issues. > * So far as environment tinkering is concerned I have entered a > "launchctl setenv PATH" statement in two places. Both reversible. That will affect your session environment (that is separated from your terminal environment), but since PyCharm doesn't pick a Python interpreter from PATH but rather let the user explicitly select one you're more intersted in just selecting a correct interpreter. > * I think what I have is an issue pertaining to OSX Mavericks and > Pycharm. If you have nothing to add, just say it. I forgot to mention it but I'm on Mavericks and downloaded the latest PyCharm just to check you issue, I never used it and just followed the new project wizard that asked me to select a python interpeter or to create a virtualenv. > * Statements like "Please equip yourself with a tool that provides us > with some context" add nothing and are not exactly community inclusive. Still you took the time to write the message I'm replying to, that won't help you much, rather than running """ import sys print(sys.executable) """ in your project, that would provide more information about your issue. -- Andrea From rosuav at gmail.com Mon Sep 1 09:16:20 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 1 Sep 2014 23:16:20 +1000 Subject: Psycopg2 package installation puzzle in Pycharm - any thoughts? In-Reply-To: References: Message-ID: On Mon, Sep 1, 2014 at 10:32 PM, wrote: > Posting style point taken. Google groups doesn't exactly help you with that. > > * You guys have probably been tinkering with this stuff for years. I haven't. > * Your man on the street would say I described the error fairly well. > * It's not like I wasn't trying my best to fix it myself > * So far as environment tinkering is concerned I have entered a "launchctl setenv PATH" statement in two places. Both reversible. > * I think what I have is an issue pertaining to OSX Mavericks and Pycharm. If you have nothing to add, just say it. > * Statements like "Please equip yourself with a tool that provides us with some context" add nothing and are not exactly community inclusive. Part of the point is that Google Groups is quite unhelpful in these areas. There are alternatives - you can get a newsreader, or you can join the mailing list. (I do the latter, and Gmail works fairly well.) Sometimes, the community is best served by telling people about flawed tools. It's more courteous than saying "You didn't quote any text, and that's making it really hard for us to follow" and blaming you personally for it :) But the fact is that it *does* make things harder for other people, and the onus is on you to follow the conventions of courtesy. That's why people are asking you to change software - because good software makes it easy to be courteous. ChrisA From breamoreboy at yahoo.co.uk Mon Sep 1 09:31:53 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 01 Sep 2014 14:31:53 +0100 Subject: Psycopg2 package installation puzzle in Pycharm - any thoughts? In-Reply-To: References: Message-ID: On 01/09/2014 13:32, andydtaylor at gmail.com wrote: > Posting style point taken. Google groups doesn't exactly help you with that. > Thunderbird is as good a solution as any although there are plenty of other choices. > * Statements like "Please equip yourself with a tool that provides us with some context" add nothing and are not exactly community inclusive. > So you promptly send another message and still no context, what do you think we are, mind readers? -- 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 Sep 1 10:44:59 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 02 Sep 2014 00:44:59 +1000 Subject: [Announce] tabhistory - tab completion and command history Message-ID: <5404866c$0$29972$c3e8da3$5496439d@news.astraweb.com> I am happy to announce an upgrade to the tabhistory module, which brings advanced tab completion and command history to Python 2.4 through 3.3 and beyond. ======== Features ======== Tab completion -------------- * At the beginning of lines, pressing the TAB key indents the line. * Inside strings, pressing TAB performs filename completion of the string. * Following the "import" and "from" keywords, pressing TAB completes on modules and module attributes. For security, module attributes are only checked if the module has already been imported and is in the sys.modules cache. * Everywhere else, pressing TAB completes on keywords, built-ins, globals, and references of the form "name.name". * Supports readline key binding and editing commands. Command history --------------- * Save command line history during interactive sessions, and automatically restore that history when you start up again. * Use the up-arrow to call up previous commands, and down-arrow for more recent ones. * Display the last N command lines. =============== Where to get it =============== Clone the Mercurial repository: hg clone https://code.google.com/p/tabhistory/ There is a single Python file, tabhistory.py. Put it somewhere on your Python path, launch the interactive interpreter, and run: import tabhistory and it will be enabled. If you don't have Mercurial, you can download the source code from here: http://code.google.com/p/tabhistory/ =========== Limitations =========== * This may not work on Windows at all. In theory, it might work if you install the pyreadline third-party module, but I have no way of testing this. Feedback from Windows users will be gratefully accepted. * There may be some issues on Mac OS X or other Unixes which use libedit instead of libreadline. I will be grateful for comments and bug fixes from any libedit users. * Python 3.0 is not officially supported (but it probably will work). Bug reports, feature requests and other comments are welcome. -- Steven From steve+comp.lang.python at pearwood.info Mon Sep 1 12:11:34 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 02 Sep 2014 02:11:34 +1000 Subject: Editing text with an external editor in Python Message-ID: <54049ab7$0$29972$c3e8da3$5496439d@news.astraweb.com> Python's input() or raw_input() function is good for getting a single line of text from the user. But what if you want a more substantial chunk of text from the user? Here's how to call out to an external editor such as ed, nano, vim, emacs, and even GUI text editors: import tempfile def edit(editor, content=''): f = tempfile.NamedTemporaryFile(mode='w+') if content: f.write(content) f.flush() command = editor + " " + f.name status = os.system(command) f.seek(0, 0) text = f.read() f.close() assert not os.path.exists(f.name) return (status, text) Anyone able to test it on Windows for me please? More here: https://code.activestate.com/recipes/578926/ -- Steven From rosuav at gmail.com Mon Sep 1 12:35:16 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Sep 2014 02:35:16 +1000 Subject: Editing text with an external editor in Python In-Reply-To: <54049ab7$0$29972$c3e8da3$5496439d@news.astraweb.com> References: <54049ab7$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Sep 2, 2014 at 2:11 AM, Steven D'Aprano wrote: > Anyone able to test it on Windows for me please? > Seems to partially work. I added an 'import os' at the top, and a simple test call to the function, and it did give me my editor (nano) and retrieved the text. It did give a warning, though: ---- C:\>Python34\python 123123123.py cygwin warning: MS-DOS style path detected: C:\DOCUME~1\M\LOCALS~1\Temp\tmp94rcwd57 Preferred POSIX equivalent is: /DOCUME~1/M/LOCALS~1/Temp/tmp94rcwd57 CYGWIN environment variable option "nodosfilewarning" turns off this warning. Consult the user's guide for more details about POSIX paths: http://cygwin.com/cygwin-ug-net/using.html#using-pathnames Your text is: asdf Hello, world! ---- Windows doesn't have a nice $EDITOR environment variable to call on, so I'm not sure what the best way to actually choose an editor is. I would hope that you can make it externally configurable (I've done some very weird things with changed editors, like one that connects to a TCP socket, alerts a server with its arguments, and then SIGSTOPs itself, and the server sends the file's contents to another socket-connected client that has a human at the other end, and when it gets back a response from that client, it rewrites the file and SIGCONTs the 'editor', which then terminates - so to all intents and purposes, it's as if that program really did edit the file), but doing that on Windows may not be easy. You'll also have to cope with some other possibilities. What happens if someone tries Notepad? (Don't try this at home. We are experts and are testing on a closed track. Do not use Notepad unless you, too, have thirty years of special effects experience.) Turns out it doesn't like working with a file that another process has open. Nor can SciTE; it shows an empty file on load, and then is unable to save. I suspect the comment here is what's biting you: https://docs.python.org/3.5/library/tempfile.html#tempfile.NamedTemporaryFile """Whether the name can be used to open the file a second time, while the named temporary file is still open, varies across platforms (it can be so used on Unix; it cannot on Windows NT or later).""" So it works fairly nicely as long as you're using a Cygwin editor. Otherwise, not so much. :( ChrisA From roy at panix.com Mon Sep 1 13:06:21 2014 From: roy at panix.com (Roy Smith) Date: Mon, 01 Sep 2014 13:06:21 -0400 Subject: Editing text with an external editor in Python References: <54049ab7$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <54049ab7$0$29972$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > import tempfile > > def edit(editor, content=''): > f = tempfile.NamedTemporaryFile(mode='w+') > [...] > command = editor + " " + f.name > status = os.system(command) Hmmm. Didn't we just have a thread about passing external data to shells? $ mkdir '/tmp/;rm -rf;' $ TMPDIR='/tmp/;rm -rf;' python Python 2.7.3 (default, Sep 26 2013, 20:03:06) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import tempfile >>> f = tempfile.NamedTemporaryFile() >>> f.name '/tmp/;rm -rf;/tmpW8HFTr' >>> From steve+comp.lang.python at pearwood.info Mon Sep 1 14:02:28 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 02 Sep 2014 04:02:28 +1000 Subject: Editing text with an external editor in Python References: <54049ab7$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5404b4b5$0$29976$c3e8da3$5496439d@news.astraweb.com> Roy Smith wrote: > Hmmm. Didn't we just have a thread about passing external data to > shells? > > $ mkdir '/tmp/;rm -rf;' > $ TMPDIR='/tmp/;rm -rf;' python > Python 2.7.3 (default, Sep 26 2013, 20:03:06) > [GCC 4.6.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import tempfile >>>> f = tempfile.NamedTemporaryFile() >>>> f.name > '/tmp/;rm -rf;/tmpW8HFTr' Seems like a lot of trouble to go to to erase your own system. Couldn't you just run rm -rf / on your own system prior to launching Python? But seriously, I'm not sure what attack vector you think you have found. By definition, this is calling out to an external application, which might do *anything*. It needs to be used in a trusted environment, like any other tool which calls out to external applications. [steve at ando ~]$ mkdir foo [steve at ando ~]$ cd foo [steve at ando foo]$ git init Initialized empty Git repository in /home/steve/foo/.git/ [steve at ando foo]$ echo Some content > stuff.txt [steve at ando foo]$ git add stuff.txt [steve at ando foo]$ GIT_EDITOR="echo 'you got pwned' #" git commit you got pwned Aborting commit due to empty commit message. I'm not really seeing how this is a security vulnerability. If somebody can break into my system and set a hostile GIT_EDITOR, or TMPDIR, environment variables, I've already lost. As written, the edit() function takes two arguments: the name of an application to call, and optionally initial contents to be edited. Obviously the name of the application has to be trusted: either hard code it, or get it from a trusted source like the VISUAL or EDITOR environment variables. (It's *your* environment, you can set them to whatever editor you want. If you want to set them to something hostile, that's your prerogative.) If an attacker has already compromised my editor, I've lost. If I naively run arbitrary code provided by *untrusted* sources (say, I get the editor from anonymous users over the internet), I've lost. I didn't think I needed to explicitly say that. On the other hand, the initial content need not be trusted, since it's just text. The worst somebody could do is hurt my feelings. (Well, they could in principle buffer-overflow the editor, or Python, but if you can't trust Python and your editor to be resistant to that, you shouldn't use them.) If the initial content could "leak" out and do bad things, that would be a vulnerability I care about. Having the user destroy their own system by deliberately misusing the function is not my problem: # Don't do this. It would be bad. edit("rm -rf / #") Have I missed something? I really don't think this is a vulnerability, and I don't see how using the subprocess module would make it safer. -- Steven From steve+comp.lang.python at pearwood.info Mon Sep 1 14:23:01 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 02 Sep 2014 04:23:01 +1000 Subject: Editing text with an external editor in Python References: <54049ab7$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5404b987$0$30001$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > On Tue, Sep 2, 2014 at 2:11 AM, Steven D'Aprano > wrote: >> Anyone able to test it on Windows for me please? >> > > Seems to partially work. I added an 'import os' at the top, and a > simple test call to the function, and it did give me my editor (nano) > and retrieved the text. It did give a warning, though: > > ---- > C:\>Python34\python 123123123.py > cygwin warning: > MS-DOS style path detected: C:\DOCUME~1\M\LOCALS~1\Temp\tmp94rcwd57 > Preferred POSIX equivalent is: /DOCUME~1/M/LOCALS~1/Temp/tmp94rcwd57 That's arguably a Python bug. Under Cygwin, it should use POSIX paths rather than Windows paths. I believe that sys.platform tells you if you are running under Cygwin. > Windows doesn't have a nice $EDITOR environment variable to call on, Why not? It's your environment, you can create any environment variable you like, even under Windows, right? > so I'm not sure what the best way to actually choose an editor is. I > would hope that you can make it externally configurable Read $VISUAL, if it exists, otherwise $EDITOR, if it exists, otherwise fall back on something hard coded. Or read it from an ini file. Or create an entry in the register. Whatever. That's up to the application which uses this function, not the function itself. Under XP and older the standard DOS editor is EDIT, but that's gone from Windows 7. Believe it or not, I understand that you can use: copy con [filename.???] to do basic line editing, which is terrifying, but I believe it works. http://stackoverflow.com/a/22000756 And of course, you can install whatever third-party editors you like. There are Windows ports of nano, vim and emacs. But fundamentally, the de facto "standard editor" on Windows is Notepad. > You'll also have to cope with some other possibilities. What happens > if someone tries Notepad? (Don't try this at home. We are experts and > are testing on a closed track. Do not use Notepad unless you, too, > have thirty years of special effects experience.) Turns out it doesn't > like working with a file that another process has open. Ah, I feared that would be the case. I'll have to think about a way around that. It won't be as neat, or as secure, but it should be doable. -- Steven From getachewagmuas at gmail.com Mon Sep 1 15:40:33 2014 From: getachewagmuas at gmail.com (getachewagmuas at gmail.com) Date: Mon, 1 Sep 2014 12:40:33 -0700 (PDT) Subject: Information Message-ID: Hey I am Getachew , I am using cantera, python xy 2.7.6. My question is how can i convert XML file to Ct. py file format. Thanks From 4kir4.1i at gmail.com Mon Sep 1 15:45:22 2014 From: 4kir4.1i at gmail.com (Akira Li) Date: Mon, 01 Sep 2014 23:45:22 +0400 Subject: subprocess module usage References: Message-ID: <87y4u3qg4t.fsf@gmail.com> Earl Lapus writes: > Hi, > > I made simple test program using the subprocess module (see attached: > exec_cmd.py). I ran it passing variations of 'ls' command options. > > I encounter exceptions every time I use '-l' options. Example runs > where exception occurs: > # ./exec_cmd.py ls -al > # ./exec_cmd.py ls -l > > However, if I pass 'ls' and arguments as one argument, like so: > #./exec_cmd.py 'ls -al' > exception does not occur. > > I logged output (see ls_test.out). > > So, what could be causing this behavior? Is this expected or is there > something wrong with how I'm using the subprocess module? You shouldn't use shell=True with a list argument (sys.argv[1:] is a list). Specify the command as a string or use shell=False. See http://bugs.python.org/issue21347 -- Akira From python.list at tim.thechases.com Mon Sep 1 16:06:04 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 1 Sep 2014 15:06:04 -0500 Subject: Editing text with an external editor in Python In-Reply-To: <5404b987$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <54049ab7$0$29972$c3e8da3$5496439d@news.astraweb.com> <5404b987$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20140901150604.4ba06ed5@bigbox.christie.dr> On 2014-09-02 04:23, Steven D'Aprano wrote: > Read $VISUAL, if it exists, otherwise $EDITOR, if it exists, > otherwise fall back on something hard coded. Or read it from an ini > file. Or create an entry in the register. Whatever. That's up to > the application which uses this function, not the function itself. > > Under XP and older the standard DOS editor is EDIT, but that's gone > from Windows 7. Believe it or not, I understand that you can use: > > copy con [filename.???] > > to do basic line editing, which is terrifying, but I believe it > works. And according to [1], the venerable edlin is still available on Win8, even if you don't have edit. Though according to [2], it sounds like MS-EDIT is still available on at least the 32-bit version of Win8 (it doesn't detail whether it comes out of the box on 64-bit Win8). I don't have Win8, so I can't corroborate either application. -tkc [1] http://en.wikipedia.org/wiki/Edlin#History [2] http://en.wikipedia.org/wiki/MS-DOS_Editor From joel.goldstick at gmail.com Mon Sep 1 16:19:16 2014 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Mon, 1 Sep 2014 16:19:16 -0400 Subject: Information In-Reply-To: References: Message-ID: On Mon, Sep 1, 2014 at 3:40 PM, wrote: > Hey > I am Getachew , I am using cantera, python xy 2.7.6. My question is how can i convert XML file to Ct. py file format. > > > Thanks > -- > https://mail.python.org/mailman/listinfo/python-list This is a general purpose python list. Googling a bit it looks like you are doing something in the genetics field. Python has several xml parsers -- Joel Goldstick http://joelgoldstick.com From cs at zip.com.au Mon Sep 1 18:14:14 2014 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 2 Sep 2014 08:14:14 +1000 Subject: Editing text with an external editor in Python In-Reply-To: <5404b4b5$0$29976$c3e8da3$5496439d@news.astraweb.com> References: <5404b4b5$0$29976$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20140901221414.GA46166@cskk.homeip.net> On 02Sep2014 04:02, Steven D'Aprano wrote: >Roy Smith wrote: >> Hmmm. Didn't we just have a thread about passing external data to >> shells? >> >> $ mkdir '/tmp/;rm -rf;' >> $ TMPDIR='/tmp/;rm -rf;' python >> Python 2.7.3 (default, Sep 26 2013, 20:03:06) >> [GCC 4.6.3] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >>>>> import tempfile >>>>> f = tempfile.NamedTemporaryFile() >>>>> f.name >> '/tmp/;rm -rf;/tmpW8HFTr' > >Seems like a lot of trouble to go to to erase your own system. Couldn't you >just run rm -rf / on your own system prior to launching Python? > >But seriously, I'm not sure what attack vector you think you have found. >By definition, this is calling out to an external application, which might >do *anything*. It needs to be used in a trusted environment, like any other >tool which calls out to external applications. [...] >I'm not really seeing how this is a security vulnerability. If somebody can >break into my system and set a hostile GIT_EDITOR, or TMPDIR, environment >variables, I've already lost. [...] >Have I missed something? I really don't think this is a vulnerability, and I >don't see how using the subprocess module would make it safer. It is not just about being hacked. It is about being robust in the face of unusual setups. If I were producing this function for general use (even my own personal general use) it would need to be reliable. That includes things like $TMPDIR having spaces in it (or other unfortunate punctuation). On any system where people use GUIs to manipulate files and folders, having spaces and arbitrary punctuation in pathnames is common. Pointing $TMPDIR at such a place for a special purpose is not unreasonable. People keep assuming injection is all about malice and being hacked. It is not. It is also about robustness and reliability, and possible silent failure/misfunction. Cheers, Cameron Simpson Steph at ensoniq.com says... | Motorcycle maintenence is an art, isn't it? By the time you've finished, it's a black art. - Dave Parry From rosuav at gmail.com Mon Sep 1 18:25:32 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Sep 2014 08:25:32 +1000 Subject: Editing text with an external editor in Python In-Reply-To: <5404b4b5$0$29976$c3e8da3$5496439d@news.astraweb.com> References: <54049ab7$0$29972$c3e8da3$5496439d@news.astraweb.com> <5404b4b5$0$29976$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Sep 2, 2014 at 4:02 AM, Steven D'Aprano wrote: > I'm not really seeing how this is a security vulnerability. If somebody can > break into my system and set a hostile GIT_EDITOR, or TMPDIR, environment > variables, I've already lost. Agreed. If I'm calling on your program and setting EDITOR or GIT_EDITOR or whatever to configure how you ask me to edit a file, that's because it's *my* system. The aforementioned setup is actually run as root; the 'editor' quite deliberately does almost nothing, but I know it's safe because I'm the one in control, not because the editor's sanitized. ChrisA From rosuav at gmail.com Mon Sep 1 18:30:01 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Sep 2014 08:30:01 +1000 Subject: Editing text with an external editor in Python In-Reply-To: <5404b987$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <54049ab7$0$29972$c3e8da3$5496439d@news.astraweb.com> <5404b987$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Sep 2, 2014 at 4:23 AM, Steven D'Aprano wrote: > Chris Angelico wrote: >> C:\>Python34\python 123123123.py >> cygwin warning: >> MS-DOS style path detected: C:\DOCUME~1\M\LOCALS~1\Temp\tmp94rcwd57 >> Preferred POSIX equivalent is: /DOCUME~1/M/LOCALS~1/Temp/tmp94rcwd57 > > That's arguably a Python bug. Under Cygwin, it should use POSIX paths rather > than Windows paths. Except that I wasn't; I ran Python 3.4 that was installed via the .msi package, and from that Python ran nano that was presumably compiled for Cygwin. >> Windows doesn't have a nice $EDITOR environment variable to call on, > > Why not? It's your environment, you can create any environment variable you > like, even under Windows, right? Sure, but what I mean is, there's a general convention on Unix that setting EDITOR will do that. You don't get to take advantage of expectations that easily on Windows. > But fundamentally, the de facto "standard editor" on Windows is Notepad. Sadly so. Which is why I tried it... >> You'll also have to cope with some other possibilities. What happens >> if someone tries Notepad? (Don't try this at home. We are experts and >> are testing on a closed track. Do not use Notepad unless you, too, >> have thirty years of special effects experience.) Turns out it doesn't >> like working with a file that another process has open. > > Ah, I feared that would be the case. I'll have to think about a way around > that. It won't be as neat, or as secure, but it should be doable. ... and yeah. That's the problem. ChrisA From andydtaylor at gmail.com Mon Sep 1 19:13:03 2014 From: andydtaylor at gmail.com (andydtaylor at gmail.com) Date: Mon, 1 Sep 2014 16:13:03 -0700 (PDT) Subject: Psycopg2 package installation puzzle in Pycharm - any thoughts? In-Reply-To: References: Message-ID: Mark - it's more that I just didn't understand what you mean. Here's you: Probably an out and out programmer; uses a number of languages; a decade of experience, educated in best practice via your experience. Here's me: Idiot. A decade of experience in VBA and Excel in mindless finance jobs, hoping to build a 'not shit" website for a refrigerated van courier company I am starting. I know enough to find my way around linux and mac for most things and that Python and Django are a great tool, yet I stumble in my environment setup. I have built a Django website before using Pycharm on an Ubuntu machine without this problem. So I wasn't seeking to be abrasive, it's just that I don't get it, nor do I understand the boundary of "it". Here's what I can do: 1. I will lookup Thunderbird and see if this makes posting easier to follow 2. I will reverse my launchctl setenv changes. 3. Is there anything else I can do to improve diagnosis and communication? Andy From torque.india at gmail.com Mon Sep 1 19:35:41 2014 From: torque.india at gmail.com (Om Prakash) Date: Tue, 02 Sep 2014 05:05:41 +0530 Subject: error while writing program to send mail. Message-ID: <540502CD.8030209@gmail.com> Hi, I am writing this program from https://docs.python.org/2/library/email-examples.html but getting the error as singhom at debian:~/pythons$ python send_email.py Traceback (most recent call last): File "send_email.py", line 18, in msg['Subject'] = 'The contents of $s' % message NameError: name 'message' is not defined i know the error would be something simple and i am overlooking it, any help would be highly appreciated, I am sorry, but I am very new to python programming. code starts here. #/usr/bin/python2.7 -tt ## sending a simple text message using python. import smtplib from email.mime.text import MIMEText # Open file for reading. fp = open("message", 'rb') # Create a plain text message. msg = MIMEText(fp.read()) fp.close me = "torque.india at gmail.com" you = "oomprakash at gmail.com" msg['Subject'] = 'The contents of $s' % message msg['From'] = me msg['To'] = you # Send message thorugh localhost but don't include the envelope headers. s = smtplib.SMTP('localhost') s.sendmail(me, [you], msg.as_string()) s.quit() From cs at zip.com.au Mon Sep 1 19:52:00 2014 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 2 Sep 2014 09:52:00 +1000 Subject: error while writing program to send mail. In-Reply-To: <540502CD.8030209@gmail.com> References: <540502CD.8030209@gmail.com> Message-ID: <20140901235200.GA58176@cskk.homeip.net> On 02Sep2014 05:05, Om Prakash wrote: >I am writing this program from >https://docs.python.org/2/library/email-examples.html > >but getting the error as > >singhom at debian:~/pythons$ python send_email.py >Traceback (most recent call last): > File "send_email.py", line 18, in > msg['Subject'] = 'The contents of $s' % message >NameError: name 'message' is not defined > >i know the error would be something simple and i am overlooking it, >any help would be highly appreciated, I am sorry, but I am very new to >python programming. This problem is generic to almost any programming language: you have not defined the variable "message" before you try to use it in the format string. In the example code, the variable is called "textfile" and is supposed to be the name of a file containing some message text. The example code does not define it; you need to do so. After you sort that, you then have a ython problem: you have said "$s" in your format string, but the python "%" operator expected "%s" in the format string. Sort these two things and see how things proceed. Cheers, Cameron Simpson Personally, I find blinking text on a page to be extraordinarily annoying and my first instinct is to back up one page, right away. - William Barr From python at mrabarnett.plus.com Mon Sep 1 19:59:49 2014 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 02 Sep 2014 00:59:49 +0100 Subject: error while writing program to send mail. In-Reply-To: <540502CD.8030209@gmail.com> References: <540502CD.8030209@gmail.com> Message-ID: <54050875.6060605@mrabarnett.plus.com> On 2014-09-02 00:35, Om Prakash wrote: > Hi, > > I am writing this program from > https://docs.python.org/2/library/email-examples.html > > but getting the error as > > singhom at debian:~/pythons$ python send_email.py > Traceback (most recent call last): > File "send_email.py", line 18, in > msg['Subject'] = 'The contents of $s' % message > NameError: name 'message' is not defined > > > i know the error would be something simple and i am overlooking it, any > help would be highly appreciated, I am sorry, but I am very new to > python programming. > > code starts here. > #/usr/bin/python2.7 -tt > > ## sending a simple text message using python. > import smtplib > > from email.mime.text import MIMEText > > # Open file for reading. > fp = open("message", 'rb') > # Create a plain text message. > msg = MIMEText(fp.read()) > > fp.close That should be: fp.close() > > me = "torque.india at gmail.com" > you = "oomprakash at gmail.com" > > msg['Subject'] = 'The contents of $s' % message You're trying to use the format operator, but: 1. You never bound the name 'message' to a value, hence: NameError: name 'message' is not defined 2. The format string contains '$s' instead of '%s'. > msg['From'] = me > msg['To'] = you > > # Send message thorugh localhost but don't include the envelope headers. > > s = smtplib.SMTP('localhost') > s.sendmail(me, [you], msg.as_string()) > s.quit() > From davea at davea.name Mon Sep 1 20:02:01 2014 From: davea at davea.name (Dave Angel) Date: Mon, 1 Sep 2014 20:02:01 -0400 (EDT) Subject: error while writing program to send mail. References: <540502CD.8030209@gmail.com> Message-ID: Om Prakash Wrote in message: > Hi, > > I am writing this program from > https://docs.python.org/2/library/email-examples.html > > but getting the error as > > singhom at debian:~/pythons$ python send_email.py > Traceback (most recent call last): > File "send_email.py", line 18, in > msg['Subject'] = 'The contents of $s' % message > NameError: name 'message' is not defined > > > i know the error would be something simple and i am overlooking it, any > help would be highly appreciated, I am sorry, but I am very new to > python programming. > > code starts here. > #/usr/bin/python2.7 -tt > > ## sending a simple text message using python. > import smtplib > > from email.mime.text import MIMEText > > # Open file for reading. > fp = open("message", 'rb') > # Create a plain text message. > msg = MIMEText(fp.read()) > > fp.close This line doesn't do anything. If you want to close the file, you need some parens, Or you can use the 'with' form instead of open. > > me = "torque.india at gmail.com" > you = "oomprakash at gmail.com" > > msg['Subject'] = 'The contents of $s' % message Just what did you plan to use here? You never defined a variable called message. If you intended to use msg, I presume you realize it could be quite large, -- DaveA From timr at probo.com Mon Sep 1 20:35:19 2014 From: timr at probo.com (Tim Roberts) Date: Mon, 01 Sep 2014 17:35:19 -0700 Subject: ANN: binario - simple work with binary files References: <33f920ca-16ce-40ce-ab3a-4479beeeae4e@googlegroups.com> <23onv9dom4ek64m273bfic5n0c2ldnij8b@4ax.com> <68d1665b-5369-43f0-8177-352b8949ab20@googlegroups.com> Message-ID: Rustom Mody wrote: >On Tuesday, August 26, 2014 6:58:42 AM UTC+5:30, Tim Roberts wrote: >> To the equivalent code with struct: > >> import struct > >> dscrp = "H?fs5B" > >> f = open('file.dat') >> stuff = struct.unpack( dscrp, f.read() ) > >> print stuff > >> In both cases, you have to KNOW the format of the data beforehand. If you >> do a read_short where you happen to have written a float, disaster ensues. > >> I don't really see that you've added very much. > >I thought much the same. >However notice your f.read(). Its type is string. > >What if file.dat is a 1GB wav file? f.seek(512000) stuff = struct.unpack( dscrp, f.read(128) ) The point is that files already know how to position themselves. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From torque.india at gmail.com Mon Sep 1 20:55:26 2014 From: torque.india at gmail.com (Om Prakash) Date: Tue, 02 Sep 2014 06:25:26 +0530 Subject: Define proxy in windows 7 Message-ID: <5405157E.3030508@gmail.com> Hi, I am wondering how to define proxy setting in env variable on windows 7, I want this so i can use pip to pull packages for me, the same setting though working earlier on windows xp. http_proxy = "proxy name:80" now this same setting doesn't work, i tried doing in the cmd.exe prompt. set http_proxy "proxy name:80" P.S. i am a normal user and don't have admin privleges. Regards, Om Prakash From torque.india at gmail.com Mon Sep 1 20:56:57 2014 From: torque.india at gmail.com (Om Prakash) Date: Tue, 02 Sep 2014 06:26:57 +0530 Subject: error while writing program to send mail. In-Reply-To: <54050875.6060605@mrabarnett.plus.com> References: <540502CD.8030209@gmail.com> <54050875.6060605@mrabarnett.plus.com> Message-ID: <540515D9.5060003@gmail.com> On 09/02/2014 05:29 AM, MRAB wrote: > On 2014-09-02 00:35, Om Prakash wrote: >> Hi, >> >> I am writing this program from >> https://docs.python.org/2/library/email-examples.html >> >> but getting the error as >> >> singhom at debian:~/pythons$ python send_email.py >> Traceback (most recent call last): >> File "send_email.py", line 18, in >> msg['Subject'] = 'The contents of $s' % message >> NameError: name 'message' is not defined >> >> >> i know the error would be something simple and i am overlooking it, any >> help would be highly appreciated, I am sorry, but I am very new to >> python programming. >> >> code starts here. >> #/usr/bin/python2.7 -tt >> >> ## sending a simple text message using python. >> import smtplib >> >> from email.mime.text import MIMEText >> >> # Open file for reading. >> fp = open("message", 'rb') >> # Create a plain text message. >> msg = MIMEText(fp.read()) >> >> fp.close > > That should be: > > fp.close() > >> >> me = "torque.india at gmail.com" >> you = "oomprakash at gmail.com" >> >> msg['Subject'] = 'The contents of $s' % message > > You're trying to use the format operator, but: > > 1. You never bound the name 'message' to a value, hence: > > NameError: name 'message' is not defined > > 2. The format string contains '$s' instead of '%s'. > >> msg['From'] = me >> msg['To'] = you >> >> # Send message thorugh localhost but don't include the envelope headers. >> >> s = smtplib.SMTP('localhost') >> s.sendmail(me, [you], msg.as_string()) >> s.quit() >> > Thanks a lot. will fix this and my overlooking of things too. :) From gschemenauer3 at gmail.com Mon Sep 1 22:24:13 2014 From: gschemenauer3 at gmail.com (gschemenauer3 at gmail.com) Date: Mon, 1 Sep 2014 19:24:13 -0700 (PDT) Subject: Editing text with an external editor in Python In-Reply-To: <54049ab7$0$29972$c3e8da3$5496439d@news.astraweb.com> References: <54049ab7$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <845f1fd1-db0d-4559-91ea-b50b34e1e03d@googlegroups.com> On Monday, September 1, 2014 11:11:34 AM UTC-5, Steven D'Aprano wrote: > Python's input() or raw_input() function is good for getting a single line > > of text from the user. But what if you want a more substantial chunk of > > text from the user? Here's how to call out to an external editor such as > > ed, nano, vim, emacs, and even GUI text editors: > > > > import tempfile > > > > def edit(editor, content=''): > > f = tempfile.NamedTemporaryFile(mode='w+') > > if content: > > f.write(content) > > f.flush() > > command = editor + " " + f.name > > status = os.system(command) > > f.seek(0, 0) > > text = f.read() > > f.close() > > assert not os.path.exists(f.name) > > return (status, text) > > > > > > Anyone able to test it on Windows for me please? > > > > > > More here: > > > > https://code.activestate.com/recipes/578926/ > > > > > > -- > > Steven here's a full blown text editor (GUI) that gets a "substantial chunk of text" from the user. It's almost finished but is perfectly functional right now. Two files: main file: #!/usr/bin/env python import os import sys import glob import webbrowser from GtkApp import * from GPYedit_conf import Preferences APPLICATION_NAME = 'GPYedit' class GPYedit(GtkApp_Toplevel): # For each tab in the notebook, we will store # our data representing each file (or empty buffer) # in a list. Each item is a dictionary keeping track of the: # - Python file object # - Three components of editing area: scrolled window, textview, and buffer (per tab) # - Full pathname of the file being edited # - Text shown in the notebook widget tabs open_files = [ ] # Keep track of which buffer we're dealing with. # Each time the notebook page is switched, this number # will change (see 'on_nb_page_switched' callback). This value # is used as the index into the open files list to get at the # file-specific information and widgets. current_tab = 0 # User preferences will be accessible through this attribute. # The Preferences class will be initialized from directives # found in the gpyedit_settings.ini file. preferences = Preferences() def __init__(this): """ This is where it all starts. Begin by setting the window geometry and title and decide whether to create a new empty file or use the arguments provided. """ GtkApp_Toplevel.__init__(this) this.window.set_title("GPYedit") (width, height) = GPYedit.preferences.get_window_dimensions() this.window.set_default_size(width, height) this.build_GUI() if len(sys.argv) > 1: names = sys.argv[1:] for name in names: if os.path.exists(name) and os.path.isfile(name): this.tab_new_from_contents(name) else: print 'File "' + name + '" doesn\'t exist.' else: this.create_new_file() def build_GUI(this): """ Create the main interface components. These are - vbox: Main vertical box for laying out widgets - menu_bar: self explanatory - notebook: The tabbed container holding our file buffers """ this.vbox = gtk.VBox(False, 0) this.menu_bar = gtk.MenuBar() this.notebook = gtk.Notebook() this.notebook.set_scrollable(True) this.notebook.connect("switch-page", this.on_nb_page_switch) this.create_menus() this.create_toolbar() this.vbox.pack_start(this.notebook, True, True, 0) this.window.add(this.vbox) def create_new_file(this, menu_item = None): """ Create a blank buffer with no associated Python file object or name (yet) NOTE: menu_item is a parameter here because this method will be used as a signal handler also for the File menu 'new' item and the prototype for that handler requires this parameter. It is not used though. """ (scrolled_win, textview, buf) = this.editing_area_new() label = gtk.Label("Untitled") edit_area = { 'scrolled_window': scrolled_win, 'textview': textview, 'buffer': buf } # Store everything we know GPYedit.open_files.append({'file_object': None, 'edit_area': edit_area, 'filename': None, 'label': label}) index = this.notebook.append_page(scrolled_win, label) this.notebook.show_all() return GPYedit.open_files[index] def tab_new_from_contents(this, filename): """ Open a new tab and dump the contents of a file into it. """ if this.check_for_used_file_name(filename): return (scrolled_win, textview, buf) = this.editing_area_new() fobj = open(filename, 'r+w') data = fobj.read() if data != '': buf.set_text(data) buf.set_modified(False) label = gtk.Label(os.path.basename(filename)) edit_area = { 'scrolled_window': scrolled_win, 'textview': textview, 'buffer': buf } # Store everything we know GPYedit.open_files.append({'file_object': fobj, 'edit_area': edit_area, 'filename': filename, 'label': label}) index = this.notebook.append_page(scrolled_win, label) this.notebook.show_all() return GPYedit.open_files[index] def open_file(this, menu_item = None): """ Open a file. The action performed depends on whether the current tab with focus has an associated file name. If it is an empty buffer, then the name the user selects in the file selector is opened in this tab otherwise a new one is created to house the new file contents. """ # May need to revise a little bit. What happens when there # is no tab? error = False chooser = gtk.FileChooserDialog("Open A File", this.window) chooser.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) chooser.add_button(gtk.STOCK_OPEN, gtk.RESPONSE_OK) response = chooser.run() if response == gtk.RESPONSE_OK: filename = chooser.get_filename() if os.path.exists(filename) and os.path.isfile(filename): if this.check_for_used_file_name(filename): # Throw error dialog box? gtk.Widget.destroy(chooser) return try: data = GPYedit.open_files[GPYedit.current_tab] except IndexError: # If there are no tabs, we can't grab the file data # so make sure there's something to work with. data = this.create_new_file() if data['filename'] is None and not data['edit_area']['buffer'].get_modified(): obj = open(filename, 'r+w') contents = obj.read() data['file_object'] = obj data['edit_area']['buffer'].set_text(contents) # Insertion.. data['edit_area']['buffer'].set_modified(False) # ..But no user interaction (yet) data['filename'] = filename data['label'] = os.path.basename(data['filename']) this.notebook.set_tab_label_text(data['edit_area']['scrolled_window'], data['label']) GPYedit.open_files[GPYedit.current_tab] = data this.set_window_title(filename) else: data = this.tab_new_from_contents(filename) else: error = gtk.MessageDialog(parent = this.window, type = gtk.MESSAGE_ERROR, buttons = gtk.BUTTONS_OK, message_format = "The file '" + filename + "' doesn't exist!") gtk.Widget.destroy(chooser) if error: error.run() error.destroy() def close_file(this, menu_item = None): """ Close a file. Determines whether the 'file' to be closed is just a scratch buffer with some text in it or if it has a file name (in which case there is an associated Python file object). If the buffer has been modified since it was either opened or the user typed some text in, give them a chance to save the data to a file on disk before removing the tab from the notebook widget. """ if this.notebook.get_n_pages() == 0: return current_file = GPYedit.open_files[GPYedit.current_tab] if current_file['edit_area']['buffer'].get_modified() == True: prompt = gtk.Dialog("Unsaved Changes", this.window) prompt.add_buttons(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_CLEAR, gtk.RESPONSE_NO, gtk.STOCK_YES, gtk.RESPONSE_YES) content_area = prompt.get_content_area() #name = this.notebook.get_tab_label_text(current_file['edit_area']['scrolled_window']) if current_file['filename'] is None: name = 'Untitled' else: name = os.path.basename(current_file['filename']) label = gtk.Label("Save changes to '" + name + "'?") content_area.pack_start(label, True, True, 0) prompt.show_all() response = prompt.run() prompt.destroy() if response == gtk.RESPONSE_CANCEL: return elif response == gtk.RESPONSE_NO: if current_file['file_object']: current_file['file_object'].close() elif response == gtk.RESPONSE_YES: (start, end) = current_file['edit_area']['buffer'].get_bounds() if current_file['filename'] is None: (action, selected_filename) = this.run_save_as_dialog() if action == gtk.RESPONSE_OK and selected_filename is not None: this.save_file(selected_filename, current_file['edit_area']['buffer'].get_text(start, end)) else: this.save_file() else: if current_file['filename'] is not None: current_file['file_object'].close() tab_to_remove = GPYedit.current_tab this.notebook.remove_page(tab_to_remove) if this.notebook.get_n_pages() == 0: this.set_window_title(alt_title = APPLICATION_NAME) del GPYedit.open_files[tab_to_remove] def save_file(this, filename = None, data = ''): """ Write the contents of a buffer to a file on disk. """ if this.notebook.get_n_pages() == 0: return current_file = GPYedit.open_files[GPYedit.current_tab] (start, end) = current_file['edit_area']['buffer'].get_bounds() text_to_write = current_file['edit_area']['buffer'].get_text(start, end) if filename is not None: if len(data) > 0: obj = open(filename, 'w') obj.write(data) obj.close() else: # Filename given but no data passed. Dump contents of current buffer # into a file specified by 'filename' argument. obj = open(filename, 'w') obj.write(text_to_write) obj.close() else: # Filename to save to was not provided. # If the current buffer has no file name, then show a "Save As" # dialog and prompt them to specify a file name. if current_file['filename'] is None: (action, selected_filename) = this.run_save_as_dialog() if action == gtk.RESPONSE_OK: current_file['filename'] = selected_filename current_file['file_object'] = open(selected_filename, 'w+') current_file['file_object'].write(text_to_write) current_file['label'].set_text(os.path.basename(selected_filename)) current_file['edit_area']['buffer'].set_modified(False) GPYedit.open_files[GPYedit.current_tab] = current_file this.set_window_title(selected_filename) else: # Current buffer has associated file name. # Save to that file. curr_file_obj = current_file['file_object'] curr_file_obj.truncate(0) curr_file_obj.seek(0) curr_file_obj.write(text_to_write) current_file['edit_area']['buffer'].set_modified(False) def set_window_title(this, filename = None, alt_title = ''): """ Set the window title to a specific string with alt_title or work with an expected file name. The format for showing the title information is: filename (directory path) - application name """ if alt_title: this.window.set_title(alt_title) elif filename is None: this.window.set_title("Untitled - " + APPLICATION_NAME) # Default title else: (dirpath, fname) = os.path.split(filename) this.window.set_title(fname + " (" + dirpath + ") - " + APPLICATION_NAME) def select_all(this): """ Select all the text in the editing area. """ current_file = GPYedit.open_files[GPYedit.current_tab] buf = current_file['edit_area']['buffer'] (start, end) = buf.get_bounds() buf.select_range(start, end) def copy_to_clipboard(this): """ Copy some selected text to the clipboard. """ current_file = GPYedit.open_files[GPYedit.current_tab] clipboard = gtk.clipboard_get() current_file['edit_area']['buffer'].copy_clipboard(clipboard) def popup_search_box(this, menu_item = None): """ Display the search dialog. """ dial = gtk.Dialog("Find and Replace", this.window) dial.add_buttons(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_CONVERT, gtk.RESPONSE_APPLY, gtk.STOCK_FIND, gtk.RESPONSE_OK) dial.set_response_sensitive(gtk.RESPONSE_OK, False) dial.set_response_sensitive(gtk.RESPONSE_APPLY, False) table = gtk.Table(4, 2, False) table.set_row_spacings(8) table.set_col_spacings(8) find_label = gtk.Label("Search for:") find_label.set_alignment(0, 0.5) replace_label = gtk.Label("Replace with:") replace_label.set_alignment(0, 0.5) find_entry = gtk.Entry() replace_entry = gtk.Entry() case_sens = gtk.CheckButton("Case sensitive") replace_all = gtk.CheckButton("Replace all occurences") table.attach(find_label, 0, 1, 0, 1) table.attach(find_entry, 1, 2, 0, 1) table.attach(replace_label, 0, 1, 1, 2) table.attach(replace_entry, 1, 2, 1, 2) table.attach(case_sens, 0, 2, 2, 3) table.attach(replace_all, 0, 2, 3, 4) content_area = dial.get_content_area() content_area.pack_start(table) table.set_border_width(8) find_entry.connect("insert-text", this.search_buttons_sensitive, dial) find_entry.connect("backspace", this.search_buttons_insensitive, dial) dt_id = find_entry.connect("delete-text", this.search_buttons_insensitive_del_text, dial) find_entry.set_data('del_text_sig_id', dt_id) widgets = {'find_entry': find_entry, 'replace_entry': replace_entry, 'match_case': case_sens, 'replace_all': replace_all} dial.connect("response", this.search_dialog_response, widgets) dial.show_all() dial.run() def search_dialog_response(this, dialog, response, widgets): """ Process the response returned from the search and replace dialog. """ if response == gtk.RESPONSE_OK: this.document_search(widgets) elif response == gtk.RESPONSE_CANCEL: dialog.destroy() elif response == gtk.RESPONSE_APPLY: this.document_replace(widgets) def document_search(this, widgets): """ Function not finished By default, do a forward search on the document in the tab with focus. To work, this function should get these widgets: - find entry text box with the search text - replace entry with replacement text - match case checkbox - text buffer for current file """ if widgets['match_case'].get_active(): case_sensitive = True else: case_sensitive = False current_file = GPYedit.open_files[GPYedit.current_tab] tbuffer = current_file['edit_area']['buffer'] start_iter = tbuffer.get_start_iter() search_text = widgets['find_entry'].get_text() (begin, end) = start_iter.forward_search(search_text, gtk.TEXT_SEARCH_TEXT_ONLY) tbuffer.select_range(begin, end) def document_replace(this, widgets): """ Find a search string and replace it with new text. By default, only one replacement is done but with the 'replace all occurences' checkbox selected then it will perform a global search and replace. """ current_file = GPYedit.open_files[GPYedit.current_tab] tbuffer = current_file['edit_area']['buffer'] start_iter = tbuffer.get_start_iter() search_text = widgets['find_entry'].get_text() if widgets['replace_entry'].get_text_length() > 0: (lower, upper) = tbuffer.get_bounds() bufdata = tbuffer.get_text(lower, upper) replace_str = widgets['replace_entry'].get_text() if widgets['replace_all'].get_active(): # REPLACE ALL updated_text = bufdata.replace(search_text, replace_str) else: # REPLACE ONCE updated_text = bufdata.replace(search_text, replace_str, 1) tbuffer.set_text(updated_text) tbuffer.set_modified(False) else: # ERROR: NO REPLACEMENT TEXT GIVEN pass def search_buttons_sensitive(this, editable, new_text, new_text_length, pos, search_dialog): """ Determine whether the buttons should be sensitive, thereby allowing the user to search, if there is text in the search box. """ if editable.get_text_length() > 0: return if new_text_length > 0: search_dialog.set_response_sensitive(gtk.RESPONSE_OK, True) search_dialog.set_response_sensitive(gtk.RESPONSE_APPLY, True) def search_buttons_insensitive(this, editable, search_dialog): """ Make the search buttons insensitive when there is no text in the search box. """ if editable.get_text_length() == 1: search_dialog.set_response_sensitive(gtk.RESPONSE_OK, False) search_dialog.set_response_sensitive(gtk.RESPONSE_APPLY, False) def search_buttons_insensitive_del_text(this, editable, start, end, search_dialog): """ Similar to search_buttons_insensitive(), except that this handler is connected for the 'delete-text' signal. It allows a user to highlight some text and delete it all at once. In the case where they select and delete everything in the search box, the buttons along the bottom of the search dialog should become unusable. """ if editable.get_text_length() > 0: editable.handler_block(editable.get_data('del_text_sig_id')) editable.delete_text(start, end) editable.handler_unblock(editable.get_data('del_text_sig_id')) if editable.get_text_length() == 0: search_dialog.set_response_sensitive(gtk.RESPONSE_OK, False) search_dialog.set_response_sensitive(gtk.RESPONSE_APPLY, False) def check_for_used_file_name(this, name): """ Any given file should only be opened in one tab. This method returns True if a specified file's name is already in use. """ for element in GPYedit.open_files: values = element.values() if name in values: return True def delete_event(this, widget, event, data = None): """ Override method to close all files if a user clicks the 'X' button to close the text editor without first manually closing them via the File > Close menu option. Just explicitly cleaning up. """ for element in GPYedit.open_files: file_to_clean_up = element['file_object'] if file_to_clean_up: file_to_clean_up.close() def run_save_as_dialog(this): """ Display a Save As dialog box and allow the user to specify a file name to save to. """ save_as = gtk.FileChooserDialog("Save As", this.window, gtk.FILE_CHOOSER_ACTION_SAVE, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, gtk.RESPONSE_OK)) action_id = save_as.run() save_as.hide() if action_id == gtk.RESPONSE_OK: ret_val = (action_id, save_as.get_filename()) else: ret_val = (action_id, None) save_as.destroy() return ret_val def editing_area_new(this): """ Build the set of widgets necessary to allow for the editing of text. This includes: - scrolled window: allow viewing area to scroll - text view: widget to edit text """ scrolled_win = gtk.ScrolledWindow() scrolled_win.set_shadow_type(gtk.SHADOW_ETCHED_IN) scrolled_win.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) scrolled_win.set_border_width(3) textview = gtk.TextView() textview.set_left_margin(3) textview.set_right_margin(3) textview.set_pixels_above_lines(1) buf = textview.get_buffer() scrolled_win.add(textview) textview.modify_base(gtk.STATE_NORMAL, gtk.gdk.Color(GPYedit.preferences.get_background_color())) textview.modify_text(gtk.STATE_NORMAL, gtk.gdk.Color(GPYedit.preferences.get_foreground_color())) # Set the default font used for editing textview.modify_font( pango.FontDescription(GPYedit.preferences.get_font())) # Return a tuple of the three elements. # Note that the scrolled window itself holds the # textview which in turn contains the buffer. But # this helps avoid having to extract the children of # the scrolled window every time we need access to either # the view or the buffer inside it. return (scrolled_win, textview, buf) def create_toolbar(this): """ Create toolbar and buttons before packing into the main window. """ this.toolbar = gtk.Toolbar() # Make toolbar widget buttons this.tb_new = gtk.ToolButton(gtk.STOCK_NEW) this.tb_open = gtk.ToolButton(gtk.STOCK_OPEN) this.tb_save = gtk.ToolButton(gtk.STOCK_SAVE) this.tb_save_as = gtk.ToolButton(gtk.STOCK_SAVE_AS) # Insert buttons into toolbar this.toolbar.insert(this.tb_new, 0) this.toolbar.insert(this.tb_open, 1) this.toolbar.insert(this.tb_save, 2) this.toolbar.insert(this.tb_save_as, 3) this.view_menu_toolbar.connect("toggled", this.toggle_tb_visible) # Tool bar 'new' button creates a new file. The method signature # doesn't match the required parameters for this signal though so # we use a sort of pass-through function to get there. this.tb_new.connect("clicked", lambda tool_item: this.create_new_file()) this.tb_open.connect("clicked", lambda tool_item: this.open_file()) this.tb_save.connect("clicked", lambda tool_item: this.save_file()) # Pack toolbar into window vbox this.vbox.pack_start(this.toolbar, False, False, 0) def toggle_tb_visible(this, widget, data = None): """ Callback to control visiblity of the toolbar """ if widget.get_active(): this.toolbar.show() else: this.toolbar.hide() def on_nb_page_switch(this, notebook, page, page_num): """ Each time the user selects a tab to work with, change the internal tab indicator so that it can be used to get the relevant data associated with that tab. This is a callback and there is no need to call directly. See GTK+ 'switch-page' signal. """ GPYedit.current_tab = page_num file_info = GPYedit.open_files[GPYedit.current_tab] if file_info['filename'] is not None: this.set_window_title(file_info['filename']) else: this.set_window_title() def open_by_pattern(this): """ Open all files that match a shell-style pattern. """ items = glob.glob(os.environ['HOME'] + os.sep + '*.php') for item in items: this.tab_new_from_contents(item) def create_menus(this): """ Create the menu bar and associated menu items. """ accel_group = gtk.AccelGroup() # Associate with main window this.window.add_accel_group(accel_group) # Create File menu this.file_menu = gtk.Menu() this.file_menu.set_accel_group(accel_group) this.file_menu_item = gtk.MenuItem("File") this.file_menu_item.set_submenu(this.file_menu) # Create menu items this.file_menu_new = gtk.ImageMenuItem(gtk.STOCK_NEW) this.file_menu_new.add_accelerator("activate", accel_group, ord('n'), gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE) this.file_menu_open = gtk.ImageMenuItem(gtk.STOCK_OPEN) this.file_menu_open.add_accelerator("activate", accel_group, ord('o'), gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE) this.file_menu_open_files_by_pattern = gtk.MenuItem("Open Files By Pattern") this.file_menu_save = gtk.ImageMenuItem(gtk.STOCK_SAVE) this.file_menu_save.add_accelerator("activate", accel_group, ord('s'), gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE) this.file_menu_save_as = gtk.ImageMenuItem(gtk.STOCK_SAVE_AS) this.file_menu_save_as.add_accelerator("activate", accel_group, ord('s'), gtk.gdk.SHIFT_MASK | gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE) this.file_menu_close = gtk.ImageMenuItem(gtk.STOCK_CLOSE) this.file_menu_close.add_accelerator("activate", accel_group, ord('w'), gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE) this.file_menu_quit = gtk.ImageMenuItem(gtk.STOCK_QUIT) this.file_menu_quit.add_accelerator("activate", accel_group, ord('q'), gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE) # Add them to File menu this.file_menu.append(this.file_menu_new) this.file_menu.append(this.file_menu_open) this.file_menu.append(this.file_menu_open_files_by_pattern) this.file_menu.append(this.file_menu_save) this.file_menu.append(this.file_menu_save_as) this.file_menu.append(this.file_menu_close) this.file_menu.append(this.file_menu_quit) # Connect signals this.file_menu_new.connect("activate", this.create_new_file) this.file_menu_open.connect("activate", this.open_file) this.file_menu_open_files_by_pattern.connect("activate", lambda menu_item: this.open_by_pattern()) this.file_menu_save.connect("activate", lambda menu_item: this.save_file()) this.file_menu_close.connect("activate", this.close_file) this.file_menu_quit.connect("activate", gtk.main_quit) # Create Edit menu this.edit_menu = gtk.Menu() this.edit_menu.set_accel_group(accel_group) this.edit_menu_item = gtk.MenuItem("Edit") this.edit_menu_item.set_submenu(this.edit_menu) # Create menu items this.edit_menu_cut = gtk.ImageMenuItem(gtk.STOCK_CUT) this.edit_menu_cut.add_accelerator("activate", accel_group, ord('x'), gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE) this.edit_menu_copy = gtk.ImageMenuItem(gtk.STOCK_COPY) this.edit_menu_copy.add_accelerator("activate", accel_group, ord('c'), gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE) this.edit_menu_paste = gtk.ImageMenuItem(gtk.STOCK_PASTE) this.edit_menu_paste.add_accelerator("activate", accel_group, ord('v'), gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE) this.edit_menu_select_all = gtk.MenuItem("Select All") this.edit_menu_select_all.add_accelerator("activate", accel_group, ord('a'), gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE) this.edit_menu_preferences = gtk.ImageMenuItem(gtk.STOCK_PREFERENCES) # Add them to Edit menu this.edit_menu.append(this.edit_menu_cut) this.edit_menu.append(this.edit_menu_copy) this.edit_menu.append(this.edit_menu_paste) this.edit_menu.append(this.edit_menu_select_all) this.edit_menu.append(this.edit_menu_preferences) # Connect signals this.edit_menu_copy.connect("activate", lambda menu_item: this.copy_to_clipboard()) this.edit_menu_select_all.connect("activate", lambda menu_item: this.select_all()) # Create View menu this.view_menu = gtk.Menu() this.view_menu_item = gtk.MenuItem("View") this.view_menu_item.set_submenu(this.view_menu) # Create menu items this.view_menu_toolbar = gtk.CheckMenuItem("Toolbar") this.view_menu_toolbar.set_active(True) this.view_menu_file_explorer_pane = gtk.CheckMenuItem("File Browser Pane") # Add them to View menu this.view_menu.append(this.view_menu_toolbar) this.view_menu.append(this.view_menu_file_explorer_pane) # Create Search menu this.search_menu = gtk.Menu() this.search_menu_item = gtk.MenuItem("Search") this.search_menu_item.set_submenu(this.search_menu) # Create menu items this.search_menu_s_and_r = gtk.ImageMenuItem(gtk.STOCK_FIND_AND_REPLACE) # Add them to Search menu this.search_menu.append(this.search_menu_s_and_r) # Connect signals this.search_menu_s_and_r.connect("activate", this.popup_search_box) # Create Help menu this.help_menu = gtk.Menu() this.help_menu_item = gtk.MenuItem("Help") this.help_menu_item.set_submenu(this.help_menu) # Create menu items this.help_menu_about = gtk.ImageMenuItem(gtk.STOCK_HELP) # Add them to Help menu this.help_menu.append(this.help_menu_about) # Add menus to the menubar this.menu_bar.append(this.file_menu_item) this.menu_bar.append(this.edit_menu_item) this.menu_bar.append(this.view_menu_item) this.menu_bar.append(this.search_menu_item) this.menu_bar.append(this.help_menu_item) # Pack menu bar into main window this.vbox.pack_start(this.menu_bar, False, False, 0) ########## Main ########## if __name__ == "__main__": GPYedit().main() ########################## second file: import os from utils import find_file CONFIG_FILE = "gpyedit_settings.ini" class Preferences: """ This class holds and manages the user's preferences which will be stored permanently in the gpyedit_settings.ini file. """ settings = \ { "window_width": 779, "window_height": 419, "font_face": "monospace", "background_color": "#FFFFFF", "foreground_color": "#000000" } def __init__(this): """ Read the configuration file and set up the preferences so that they are ready to be accessed by the main application. """ if not os.path.exists(CONFIG_FILE): config_file_location = find_file(CONFIG_FILE, os.environ["HOME"]) else: config_file_location = os.getcwd() + os.sep + CONFIG_FILE if config_file_location is None: return # Configuration not found. Use default settings else: this.process_options(open(config_file_location, "r").readlines()) def process_options(this, config): """ Parse configuration options in the gpyedit_settings.ini file. """ for option in config: data = option.split(":") # Get [option, value] if len(data) != 2: continue (opt, val) = (data[0].strip(), data[1].strip()) for setting in this.settings.keys(): if opt == setting: this.settings[setting] = val def get_font(this): """ Return the font that should be used for editing text. """ return Preferences.settings["font_face"] def get_background_color(this): """ Return the background color of the editing area. """ return Preferences.settings["background_color"] def get_foreground_color(this): """ Return the foreground color of the editing area. """ return Preferences.settings["foreground_color"] def get_window_dimensions(this): """ Retrieve the toplevel window dimensions as a width and height """ return (int(this.settings["window_width"]), int(this.settings["window_height"])) def run_dialog(this): """ Create the preferences dialog box accessible through Edit > Preferences in the menu bar. """ --------------------------------------------- maybe that'll help you see how it's done. From cs at zip.com.au Mon Sep 1 22:06:20 2014 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 2 Sep 2014 12:06:20 +1000 Subject: Define proxy in windows 7 In-Reply-To: <5405157E.3030508@gmail.com> References: <5405157E.3030508@gmail.com> Message-ID: <20140902020620.GA6776@cskk.homeip.net> On 02Sep2014 06:25, Om Prakash wrote: > >I am wondering how to define proxy setting in env variable on windows >7, I want this so i can use pip to pull packages for me, the same >setting though working earlier on windows xp. > >http_proxy = "proxy name:80" > >now this same setting doesn't work, i tried doing in the cmd.exe prompt. > >set http_proxy "proxy name:80" > >P.S. i am a normal user and don't have admin privleges. I am not a Windows user, but on UNIX systems the format of http_proxy and https_proxy is: http://proxyname:3128/ being the proxy hostname and port number respectively. You're saying: proxyname:8080 instead. (Note, https_proxy _also_ starts with "http:", not "https:" because the communication with the proxy is HTTP.) Try the longer form. And ensure you have the port number right; proxies do not normally listen on port 80; they tend to listen on port 3128 or 8080. Cheers, -- To understand recursion, you must first understand recursion. From rosuav at gmail.com Mon Sep 1 23:02:38 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Sep 2014 13:02:38 +1000 Subject: Define proxy in windows 7 In-Reply-To: <20140902020620.GA6776@cskk.homeip.net> References: <5405157E.3030508@gmail.com> <20140902020620.GA6776@cskk.homeip.net> Message-ID: On Tue, Sep 2, 2014 at 12:06 PM, Cameron Simpson wrote: > I am not a Windows user, but on UNIX systems the format of http_proxy and > https_proxy is: > > http://proxyname:3128/ > > being the proxy hostname and port number respectively. You're saying: > > proxyname:8080 > > instead. (Note, https_proxy _also_ starts with "http:", not "https:" because > the communication with the proxy is HTTP.) > > Try the longer form. And ensure you have the port number right; proxies do > not normally listen on port 80; they tend to listen on port 3128 or 8080. These tips may help. (Though on Windows, where port 80 requires no special privileges, it's more likely for a proxy to use that than it is under Unix. So it's entirely possible it is actually on 80.) But what I'm seeing is a problem with environment variable setting in the first place - or else a transcription problem in the original post. Try this: set http_proxy=proxy name:80 If that doesn't work,*copy and paste* what you're doing and what happens when you do. Include the prompt, the command, and its output. That'll make it easier for us to figure out what's going on. ChrisA From steve+comp.lang.python at pearwood.info Mon Sep 1 23:18:59 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 02 Sep 2014 13:18:59 +1000 Subject: Editing text with an external editor in Python References: <5404b4b5$0$29976$c3e8da3$5496439d@news.astraweb.com> Message-ID: <54053724$0$6599$c3e8da3$5496439d@news.astraweb.com> Cameron Simpson wrote: > It is not just about being hacked. > > It is about being robust in the face of unusual setups. > > If I were producing this function for general use (even my own personal > general use) it would need to be reliable. That includes things like > $TMPDIR having spaces in it (or other unfortunate punctuation). Ah, gotcha. That makes sense. -- Steven From denismfmcmahon at gmail.com Mon Sep 1 23:28:24 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Tue, 2 Sep 2014 03:28:24 +0000 (UTC) Subject: error while writing program to send mail. References: Message-ID: On Tue, 02 Sep 2014 05:05:41 +0530, Om Prakash wrote: > fp = open("message", 'rb') "message" here is a string literal > fp.close should be fp.close() > msg['Subject'] = 'The contents of $s' % message message here is a variable. The variable named message has not previously had a value assigned to it. $s should be %s If you want the subject to be the filename, then what you need to do is: 1) assign the filename to some variable 2) open the file using the variable that contains the filename 3) use the variable that contains the filename to generate the subject eg (assuming suitable imports etc) and the message is in a text file called message.txt: msgfile = "message.txt" fp = open( msgfile, "r" ) msg = MIMEText(fp.read()) fp.close() msg['Subject'] = 'The contents of %s' % msgfile -- Denis McMahon, denismfmcmahon at gmail.com From rustompmody at gmail.com Tue Sep 2 00:35:43 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 1 Sep 2014 21:35:43 -0700 (PDT) Subject: ANN: binario - simple work with binary files In-Reply-To: References: <33f920ca-16ce-40ce-ab3a-4479beeeae4e@googlegroups.com> <23onv9dom4ek64m273bfic5n0c2ldnij8b@4ax.com> <68d1665b-5369-43f0-8177-352b8949ab20@googlegroups.com> Message-ID: <85e4a393-c926-44cd-a0dd-1654cfaa6b4d@googlegroups.com> On Tuesday, September 2, 2014 6:05:19 AM UTC+5:30, Tim Roberts wrote: > Rustom Mody wrote: > >On Tuesday, August 26, 2014 6:58:42 AM UTC+5:30, Tim Roberts wrote: > >> To the equivalent code with struct: > >> import struct > >> dscrp = "H?fs5B" > >> f = open('file.dat') > >> stuff = struct.unpack( dscrp, f.read() ) > >> print stuff > >> In both cases, you have to KNOW the format of the data beforehand. If you > >> do a read_short where you happen to have written a float, disaster ensues. > >> I don't really see that you've added very much. > >I thought much the same. > >However notice your f.read(). Its type is string. > >What if file.dat is a 1GB wav file? > f.seek(512000) > stuff = struct.unpack( dscrp, f.read(128) ) And what if the struct you are (trying to) unpack is greater or less than 128 bytes? > The point is that files already know how to position themselves. Sure. But its not enough. One can write a generator that yields one char at a time. How to feed that to struct.unpack?? From sumitbu.ray at gmail.com Tue Sep 2 02:00:24 2014 From: sumitbu.ray at gmail.com (Sumit Ray) Date: Tue, 2 Sep 2014 02:00:24 -0400 Subject: urllib2 redirect error Message-ID: Hi, I've tried various versions but continue to get the following error: -------------- next part -------------- An HTML attachment was scrubbed... URL: From sumitbu.ray at gmail.com Tue Sep 2 02:08:47 2014 From: sumitbu.ray at gmail.com (Sumit Ray) Date: Tue, 2 Sep 2014 02:08:47 -0400 Subject: urllib2 redirect error Message-ID: Hi, I've tried versions of the following but continue to get errors: ------------- snip ------------- url = 'https://www.usps.com/send/official-abbreviations.htm' request = urllib2.build_opener(urllib2.HTTPRedirectHandler).open(url) ------------- snip ------------- Generates an exception: urllib2.HTTPError: HTTP Error 301: The HTTP server returned a redirect error that would lead to an infinite loop. The last 30x error message was: Moved Permanently The following using the requests library hangs: ------------- snip ------------- response = requests.get(url) ------------- snip ------------- I'm fresh out of ideas and any suggestions you may have would be greatly appreciated. Thanks in advance, Sumit -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Tue Sep 2 03:25:37 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 02 Sep 2014 08:25:37 +0100 Subject: Define proxy in windows 7 In-Reply-To: References: <5405157E.3030508@gmail.com> <20140902020620.GA6776@cskk.homeip.net> Message-ID: On 02/09/2014 04:02, Chris Angelico wrote: > > These tips may help. (Though on Windows, where port 80 requires no > special privileges, it's more likely for a proxy to use that than it > is under Unix. So it's entirely possible it is actually on 80.) But > what I'm seeing is a problem with environment variable setting in the > first place - or else a transcription problem in the original post. > > Try this: > > set http_proxy=proxy name:80 > Which reminds me of this nifty piece of work http://www.rapidee.com/en/about -- 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 Tue Sep 2 03:28:57 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 02 Sep 2014 07:28:57 GMT Subject: urllib2 redirect error References: Message-ID: <540571b8$0$29876$c3e8da3$5496439d@news.astraweb.com> On Tue, 02 Sep 2014 02:08:47 -0400, Sumit Ray wrote: > Hi, > > I've tried versions of the following but continue to get errors: > > ------------- snip ------------- > url = 'https://www.usps.com/send/official-abbreviations.htm' > request = urllib2.build_opener(urllib2.HTTPRedirectHandler).open(url) > ------------- snip ------------- > > Generates an exception: > urllib2.HTTPError: HTTP Error 301: The HTTP server returned a redirect > error that would lead to an infinite loop. The last 30x error message > was: > Moved Permanently I'm not an expert, but that sounds like a fault at the server end. I just tried it in Chrome, and it worked, and then with wget, and I get the same sort of error: steve at runes:~$ wget https://www.usps.com/send/official-abbreviations.htm --2014-09-02 17:22:31-- https://www.usps.com/send/official-abbreviations.htm Resolving www.usps.com... 23.9.230.219, 2600:1415:8:181::1bf2, 2600:1415:8:183::1bf2 Connecting to www.usps.com|23.9.230.219|:443... connected. HTTP request sent, awaiting response... 301 Moved Permanently Location: https://www.usps.com/root/global/server_responses/webtools-msg.htm [following] --2014-09-02 17:22:31-- https://www.usps.com/root/global/ server_responses/webtools-msg.htm Reusing existing connection to www.usps.com:443. HTTP request sent, awaiting response... 301 Moved Permanently Location: https://www.usps.com/root/global/server_responses/webtools-msg.htm [following] [...] --2014-09-02 17:22:32-- https://www.usps.com/root/global/server_responses/webtools-msg.htm Reusing existing connection to www.usps.com:443. HTTP request sent, awaiting response... 301 Moved Permanently Location: https://www.usps.com/root/global/server_responses/webtools-msg.htm [following] 20 redirections exceeded. Sounds like if the server doesn't recognise the browser, it gets confused and ends up in a redirect loop. You could try setting the user-agent and see if that helps: steve at runes:~$ wget -U "firefox 9999 (mozilla compatible)" https://www.usps.com/send/official-abbreviations.htm --2014-09-02 17:28:03-- https://www.usps.com/send/official-abbreviations.htm Resolving www.usps.com... 23.9.230.219, 2600:1415:8:183::1bf2, 2600:1415:8:181::1bf2 Connecting to www.usps.com|23.9.230.219|:443... connected. HTTP request sent, awaiting response... 200 OK Length: unspecified [text/html] Saving to: `official-abbreviations.htm' [ <=> ] 102,670 260K/s in 0.4s 2014-09-02 17:28:05 (260 KB/s) - `official-abbreviations.htm' saved [102670] -- Steven From alister.nospam.ware at ntlworld.com Tue Sep 2 04:35:43 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Tue, 02 Sep 2014 08:35:43 GMT Subject: Editing text with an external editor in Python References: <54049ab7$0$29972$c3e8da3$5496439d@news.astraweb.com> <5404b987$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, 01 Sep 2014 15:06:04 -0500, Tim Chase wrote: > On 2014-09-02 04:23, Steven D'Aprano wrote: >> Read $VISUAL, if it exists, otherwise $EDITOR, if it exists, otherwise >> fall back on something hard coded. Or read it from an ini file. Or >> create an entry in the register. Whatever. That's up to the application >> which uses this function, not the function itself. >> >> Under XP and older the standard DOS editor is EDIT, but that's gone >> from Windows 7. Believe it or not, I understand that you can use: >> >> copy con [filename.???] >> >> to do basic line editing, which is terrifying, but I believe it works. > > And according to [1], the venerable edlin is still available on Win8, > even if you don't have edit. Though according to [2], it sounds like > MS-EDIT is still available on at least the 32-bit version of Win8 (it > doesn't detail whether it comes out of the box on 64-bit Win8). > > I don't have Win8, so I can't corroborate either application. > > -tkc > > [1] http://en.wikipedia.org/wiki/Edlin#History [2] > http://en.wikipedia.org/wiki/MS-DOS_Editor if edlin is your only option then it would be better to spend you time writhing your own text editor! Neither edlin or ms-edit are available on my Win 7 installation so I doubt that it has been resurrected for win 8 -- Elbonics, n.: The actions of two people maneuvering for one armrest in a movie theatre. -- "Sniglets", Rich Hall & Friends From rosuav at gmail.com Tue Sep 2 04:45:54 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Sep 2014 18:45:54 +1000 Subject: Editing text with an external editor in Python In-Reply-To: References: <54049ab7$0$29972$c3e8da3$5496439d@news.astraweb.com> <5404b987$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Sep 2, 2014 at 6:35 PM, alister wrote: > if edlin is your only option then it would be better to spend you time > writhing your own text editor! Heh! Considering how easy it is to deploy a multi-line edit widget in any GUI toolkit, it shouldn't be too hard to write a GUI text editor. Now, writing a *good* GUI text editor, that's a bit harder. And of course, writing a text/console text editor, that's also less simple. But I put it to you: How do you write your editor up to the point where you can use it to write your editor? We have a bootstrapping problem! ChrisA From roland.hedberg at adm.umu.se Tue Sep 2 06:15:51 2014 From: roland.hedberg at adm.umu.se (Roland Hedberg) Date: Tue, 2 Sep 2014 12:15:51 +0200 Subject: Which OAuth library? In-Reply-To: References: <1a2f3320-79eb-4055-a933-ea474595976e@googlegroups.com> Message-ID: 14 aug 2014 kl. 19:54 skrev Chris ?Kwpolska? Warrick : > 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. I?m responsible for one implementation (pyoidc) that is primary a OpenID connect implementation. But since OpenID Connect is a profile of OAuth2 it will work in an OAuth2 context too. This implementation is special in that it?s the de facto reference implementation for OpenID Connect. It?s that, due to the fact that I?ve built the OpenID Connect test suit which most today available OpenID Provider implementations have verified themselves against. ? Roland ?Being able to think like a child is an important attribute of being an adult? - Eddie Izzard From rgaddi at technologyhighland.invalid Tue Sep 2 12:30:58 2014 From: rgaddi at technologyhighland.invalid (Rob Gaddi) Date: Tue, 2 Sep 2014 09:30:58 -0700 Subject: Raspberry pi, python and robotics References: Message-ID: <20140902093058.0ac902ed@rg.highlandtechnology.com> On Sat, 30 Aug 2014 23:39:01 -0700 (PDT) Nicholas Cannon wrote: > I really enjoy engineering at school and we make like fighting robots and stuff(simple stuff of course) and i really enjoy it. I have got a raspberry pi and a decent understanding of python and i want to do make stuff like RC cars and drones and stuff. Also I like electronics. Is there any good places to learn all this stuff like down to the basics of electronics because I have looked around and all the books I have seen just throw some electronics together and say yep thats done. I would like to work on my own projects after I get a grip on the basics. Where could I find some good recourses on this stuff. Learn electronics properly, then start thinking about interfacing one to the other. I say this as a professional circuit designer who spends a whole mess of time automating things in Python. If you don't have a firm grasp of the underlying basics of electronics as its own thing, trying to interface will eat you alive with problems that you don't understand because you can't understand the circuitry. The best teaching electronics resource I know, hands down, is Horowitz and Hill's "The Art of Electronics". The second edition is ancient now, but still will teach you everything you need to know. Even used copies are a bit expensive. That's because it's an excellent book. It's worth the money. Next, to learn electronics you need to do electronics. Theory talks the walk, molten lead walks the walk. That means copper boards, and a soldering iron, and parts, and a DVM, and an oscilloscope. A function generator is a great thing to have as well, but if desperately necessary you can live without one. You're still in school, so you hopefully have an EE lab there. Take advantage of it. If you don't, find some local hackerspace with some gear, otherwise getting up and running will cost you a solid $1200 just in gear. LTSpice is a great free simulator, and the simulator can help you understand what you should be seeing, but there's no substitute for getting your hands dirty. Start by building the simple stuff: resistor dividers, RC low pass filters, etc. They're trivial, they're boring, and you already understand what they should do. Do them anyhow, you need to get lead under your fingernails and a feel for how to make a decent solder joint while you're still working the easy stuff because if your solder's crap when you start trying to do the more complex stuff you'll never figure it out. Work your way through AofE. Do the problems, build the circuits. Plan on it taking a solid year before you become "good" at it; you're young and have it to spend. Actually do all that and you'll understand as much about circuits as anyone they're giving an EE degree to these days. Then you can start. -- 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 Sep 2 12:36:03 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 2 Sep 2014 16:36:03 +0000 (UTC) Subject: Typing help brings up a screen that says type help() References: <12p10atdufggrba3e5k9ie7kla17thh1ha@4ax.com> Message-ID: On 2014-08-29, Joel Goldstick wrote: > On this list I use reply all (using gmail) because reply takes the > first recipient, which is the poster. I am on another list where this > isn't true. It's because of people like you that people like me post with invalid addresses in the headers. But there Is a valid address below if needed. -- Grant Edwards grant.b.edwards Yow! Let's send the at Russians defective gmail.com lifestyle accessories! From invalid at invalid.invalid Tue Sep 2 12:43:09 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 2 Sep 2014 16:43:09 +0000 (UTC) Subject: I have tried and errored a reasonable amount of times References: Message-ID: On 2014-08-30, Tim Chase wrote: > On 2014-08-30 14:27, Seymore4Head wrote: >> I really tried to get this without asking for help. >> >> mylist = ["The", "earth", "Revolves", "around", "Sun"] >> print (mylist) >> for e in mylist: >> >> # one of these two choices should print something. Since neither >> does, I am missing something subtle. >> >> if e[0].isupper == False: >> print ("False") >> if e[0].isupper == True: >> print ("True") >> >> I am sure in the first , third and fifth choices should be true. >> Right now, I am just testing the first letter of each word. > > There's a difference between e[0].isupper which refers to the method > itself, and e[0].isupper() which then calls that method. Call the > method, and you should be good to go. I missed the beginning of the thread, but Why are you comparing things to True and False? What you should do is if not e[0].isupper(): asdf() or if e[0].isupper(): qwer() -- Grant Edwards grant.b.edwards Yow! My vaseline is at RUNNING... gmail.com From Seymore4Head at Hotmail.invalid Tue Sep 2 12:59:04 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Tue, 02 Sep 2014 12:59:04 -0400 Subject: I have tried and errored a reasonable amount of times References: Message-ID: On Tue, 2 Sep 2014 16:43:09 +0000 (UTC), Grant Edwards wrote: >On 2014-08-30, Tim Chase wrote: >> On 2014-08-30 14:27, Seymore4Head wrote: >>> I really tried to get this without asking for help. >>> >>> mylist = ["The", "earth", "Revolves", "around", "Sun"] >>> print (mylist) >>> for e in mylist: >>> >>> # one of these two choices should print something. Since neither >>> does, I am missing something subtle. >>> >>> if e[0].isupper == False: >>> print ("False") >>> if e[0].isupper == True: >>> print ("True") >>> >>> I am sure in the first , third and fifth choices should be true. >>> Right now, I am just testing the first letter of each word. >> >> There's a difference between e[0].isupper which refers to the method >> itself, and e[0].isupper() which then calls that method. Call the >> method, and you should be good to go. > >I missed the beginning of the thread, but Why are you comparing things >to True and False? > >What you should do is > > if not e[0].isupper(): > asdf() > >or > > if e[0].isupper(): > qwer() I wasn't really comparing it to True. I was trying to use it as a line of code, but since it wasn't working I just tried that to test it. Since neither one was working, I knew something was wrong. BTW I am very new to Python. Thanks From wanderer at dialup4less.com Tue Sep 2 13:27:58 2014 From: wanderer at dialup4less.com (Wanderer) Date: Tue, 2 Sep 2014 10:27:58 -0700 (PDT) Subject: PyDev Code Analysis Message-ID: <67700207-2d66-440b-ba9c-f33757cc9783@googlegroups.com> I'm trying to set up Eclipse with PyDev and I can't get the code analysis to work the way I want. Whenever I type 'def' it generates an error before I finish the line. I don't want to see errors until I finish typing. It's not an error I'm just not done yet. So I try to turn this off by going to Window>Preferences>PyDev>Editor>CodeAnalysis and setting the option When do we analyze? to Only on save. This doesn't stop these errors from showing up while I'm typing. What it does is stop checking for warnings like 'unused variable' even on save. If I set the option to 'On any successful parse' then it will check for these warning only on save. To summarize Setting 'Only on save', turns off warnings but keeps giving real time errors. Setting 'On any successful parse', checks for warnings only on save and keeps giving real time errors. I'm using Eclipse IDE for C/C++ Developers 4.4.0.21040612 Pydev for Eclipse 3.7.0.201408261926 What I am I doing wrong? Thanks From dream4soul at gmail.com Tue Sep 2 13:50:17 2014 From: dream4soul at gmail.com (dream4soul at gmail.com) Date: Tue, 2 Sep 2014 10:50:17 -0700 (PDT) Subject: crc algorithm Message-ID: <01aa8ab2-cceb-4219-8999-5c66520c128e@googlegroups.com> Dear all, I have trouble to implement crc algorithm in python 3.3 c version work perfect. I try to use bytes, int and c_types without any success can some who help me: c version: unsigned short calc_crc(const void *p_dat, int l_dat){ unsigned char *dat_ptr; int loopc; unsigned short crc_dat; unsigned char c_work; dat_ptr = (unsigned char*)p_dat; crc_dat = 0x0000; for (; l_dat > 0; l_dat--) { c_work = *(dat_ptr++); for (loopc = 0; loopc < 8; loopc++) { if ((((unsigned char )(crc_dat & 0x0001)) ^ (c_work & 0x01)) == 0x01) { crc_dat >>=1 ; crc_dat ^=0x8408; } else { crc_dat >>=1; } c_work >>=1; } } return(crc_dat); } python tries: def calc_crc(): crc_dat = c_ushort(0x0001) data = [0x00,0x00,0x34,0x35,0x38,0x35] for x in range(len(data)): pass c_work = c_ubyte(data[x]) #print(c_work) for x in range(8): pass if (c_ubyte(crc_dat.value & c_ushort(0x0001).value).value ^ c_ubyte(c_work.value & c_ubyte(0x01).value).value) == c_ubyte(0x01): crc_dat.value >>=1 crc_dat.value ^=0x8408 else: crc_dat.value >>=1 c_work.value >>=1 print(crc_dat) print(crc_dat.value) pass From gheskett at wdtv.com Tue Sep 2 14:09:07 2014 From: gheskett at wdtv.com (Gene Heskett) Date: Tue, 2 Sep 2014 14:09:07 -0400 Subject: Raspberry pi, python and robotics In-Reply-To: <20140902093058.0ac902ed@rg.highlandtechnology.com> References: <20140902093058.0ac902ed@rg.highlandtechnology.com> Message-ID: <201409021409.07684.gheskett@wdtv.com> On Tuesday 02 September 2014 12:30:58 Rob Gaddi did opine And Gene did reply: > On Sat, 30 Aug 2014 23:39:01 -0700 (PDT) > > Nicholas Cannon wrote: > > I really enjoy engineering at school and we make like fighting robots > > and stuff(simple stuff of course) and i really enjoy it. I have got > > a raspberry pi and a decent understanding of python and i want to do > > make stuff like RC cars and drones and stuff. Also I like > > electronics. Is there any good places to learn all this stuff like > > down to the basics of electronics because I have looked around and > > all the books I have seen just throw some electronics together and > > say yep thats done. I would like to work on my own projects after I > > get a grip on the basics. Where could I find some good recourses on > > this stuff. > > Learn electronics properly, then start thinking about interfacing one > to the other. I say this as a professional circuit designer who spends > a whole mess of time automating things in Python. If you don't have a > firm grasp of the underlying basics of electronics as its own thing, > trying to interface will eat you alive with problems that you don't > understand because you can't understand the circuitry. > > The best teaching electronics resource I know, hands down, is Horowitz > and Hill's "The Art of Electronics". The second edition is ancient now, > but still will teach you everything you need to know. Even used copies > are a bit expensive. That's because it's an excellent book. It's > worth the money. > > Next, to learn electronics you need to do electronics. Theory talks the > walk, molten lead walks the walk. That means copper boards, and a > soldering iron, and parts, and a DVM, and an oscilloscope. A function > generator is a great thing to have as well, but if desperately > necessary you can live without one. You're still in school, so you > hopefully have an EE lab there. Take advantage of it. If you don't, > find some local hackerspace with some gear, otherwise getting up and > running will cost you a solid $1200 just in gear. LTSpice is a great > free simulator, and the simulator can help you understand what you > should be seeing, but there's no substitute for getting your hands > dirty. > > Start by building the simple stuff: resistor dividers, RC low pass > filters, etc. They're trivial, they're boring, and you already > understand what they should do. Do them anyhow, you need to get lead > under your fingernails and a feel for how to make a decent solder joint > while you're still working the easy stuff because if your solder's crap > when you start trying to do the more complex stuff you'll never figure > it out. Work your way through AofE. Do the problems, build the > circuits. Plan on it taking a solid year before you become "good" at > it; you're young and have it to spend. > > Actually do all that and you'll understand as much about circuits as > anyone they're giving an EE degree to these days. Then you can start. That is some of the best advice I have seen on an email list, and I am on a bunch of them. Generally I will 2nd that, or 3rd it as the case may be. It simply cannot be emphasized enough. I am a retired (I'll be 80 on 2 months) broadcast engineer who got his diploma from the School of Hard Knocks. And I am still getting my hands dirty, they do fit the tools. Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page US V Castleman, SCOTUS, Mar 2014 is grounds for Impeaching SCOTUS From __peter__ at web.de Tue Sep 2 14:24:54 2014 From: __peter__ at web.de (Peter Otten) Date: Tue, 02 Sep 2014 20:24:54 +0200 Subject: crc algorithm References: <01aa8ab2-cceb-4219-8999-5c66520c128e@googlegroups.com> Message-ID: dream4soul at gmail.com wrote: > I have trouble to implement crc algorithm in python 3.3 > > c version work perfect. I try to use bytes, int and c_types without any > success can some who help me: ctypes is for interfacing with C; don't use it in regular code. > c version: > > unsigned short calc_crc(const void *p_dat, int l_dat){ > unsigned char *dat_ptr; > int loopc; > unsigned short crc_dat; > unsigned char c_work; > > dat_ptr = (unsigned char*)p_dat; > crc_dat = 0x0000; > for (; l_dat > 0; l_dat--) > { > c_work = *(dat_ptr++); > for (loopc = 0; loopc < 8; loopc++) > { > if ((((unsigned char )(crc_dat & 0x0001)) ^ > (c_work & 0x01)) == 0x01) > { > crc_dat >>=1 ; > crc_dat ^=0x8408; > } else { > crc_dat >>=1; > > } > c_work >>=1; > } > } > return(crc_dat); > } A near-literal translation would be: def calc_crc(data): crc = 0 for work in data: for i in range(8): if (crc & 1) ^ (work & 1): crc >>= 1 crc ^= 0x8408 else: crc >>= 1 work >>= 1 return crc I don't see any operation where the "unboundedness" of Python's integer type could be a problem -- but no guarantees. From ckaynor at zindagigames.com Tue Sep 2 14:43:52 2014 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Tue, 2 Sep 2014 11:43:52 -0700 Subject: crc algorithm In-Reply-To: References: <01aa8ab2-cceb-4219-8999-5c66520c128e@googlegroups.com> Message-ID: Also, depending on the use-case, binascii.crc32 might also work fine: https://docs.python.org/2/library/binascii.html#binascii.crc32 import binascii def calc_crc(data): return binascii.crc32(data) Much simpler. Chris On Tue, Sep 2, 2014 at 11:24 AM, Peter Otten <__peter__ at web.de> wrote: > dream4soul at gmail.com wrote: > > > I have trouble to implement crc algorithm in python 3.3 > > > > c version work perfect. I try to use bytes, int and c_types without any > > success can some who help me: > > ctypes is for interfacing with C; don't use it in regular code. > > > c version: > > > > unsigned short calc_crc(const void *p_dat, int l_dat){ > > unsigned char *dat_ptr; > > int loopc; > > unsigned short crc_dat; > > unsigned char c_work; > > > > dat_ptr = (unsigned char*)p_dat; > > crc_dat = 0x0000; > > for (; l_dat > 0; l_dat--) > > { > > c_work = *(dat_ptr++); > > for (loopc = 0; loopc < 8; loopc++) > > { > > if ((((unsigned char )(crc_dat & 0x0001)) ^ > > (c_work & 0x01)) == 0x01) > > { > > crc_dat >>=1 ; > > crc_dat ^=0x8408; > > } else { > > crc_dat >>=1; > > > > } > > c_work >>=1; > > } > > } > > return(crc_dat); > > } > > A near-literal translation would be: > > def calc_crc(data): > crc = 0 > for work in data: > for i in range(8): > if (crc & 1) ^ (work & 1): > crc >>= 1 > crc ^= 0x8408 > else: > crc >>= 1 > work >>= 1 > return crc > > I don't see any operation where the "unboundedness" of Python's integer > type > could be a problem -- but no guarantees. > > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From Seymore4Head at Hotmail.invalid Tue Sep 2 16:13:39 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Tue, 02 Sep 2014 16:13:39 -0400 Subject: Why doesn't this work Message-ID: I still can't get the syntax test='Hey buddy get away from my car' if test[0].alpha(): return True From ned at nedbatchelder.com Tue Sep 2 16:23:16 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 02 Sep 2014 16:23:16 -0400 Subject: Why doesn't this work In-Reply-To: References: Message-ID: On 9/2/14 4:13 PM, Seymore4Head wrote: > I still can't get the syntax > test='Hey buddy get away from my car' > if test[0].alpha(): > return True > A really good skill to learn early on is how to ask for help. You need to tell us what you expected it to do, and also what it did that displeased you. Be specific. We can't see your screen, and we can't read your mind :) -- Ned Batchelder, http://nedbatchelder.com From rosuav at gmail.com Tue Sep 2 16:23:13 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 3 Sep 2014 06:23:13 +1000 Subject: Why doesn't this work In-Reply-To: References: Message-ID: On Wed, Sep 3, 2014 at 6:13 AM, Seymore4Head wrote: > I still can't get the syntax > test='Hey buddy get away from my car' > if test[0].alpha(): > return True If that's not in a function, "return" makes no sense, as the SyntaxError will have told you. As to the actual check, that's isalpha(), not alpha(), as you can see from the docs. Suggestion: Choose subject lines that reflect the subject matter being discussed. "Why doesn't this work" isn't very helpful. :) ChrisA From breamoreboy at yahoo.co.uk Tue Sep 2 16:23:06 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 02 Sep 2014 21:23:06 +0100 Subject: Why doesn't this work In-Reply-To: References: Message-ID: On 02/09/2014 21:13, Seymore4Head wrote: > I still can't get the syntax > test='Hey buddy get away from my car' > if test[0].alpha(): > return True > isalpha? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From skip at pobox.com Tue Sep 2 16:42:48 2014 From: skip at pobox.com (Skip Montanaro) Date: Tue, 2 Sep 2014 15:42:48 -0500 Subject: Why doesn't this work In-Reply-To: References: Message-ID: On Tue, Sep 2, 2014 at 3:13 PM, Seymore4Head wrote: > I still can't get the syntax > test='Hey buddy get away from my car' > if test[0].alpha(): > return True > My guess is you meant isalpha(), as Mark indicated. Here's a cheap way to see what an object can do: >>> test='Hey buddy get away from my car' >>> dir(test) ['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_formatter_field_name_split', '_formatter_parser', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill'] or more precisely: >>> [attr for attr in dir(test) if "alpha" in attr] ['isalpha'] Skip -------------- next part -------------- An HTML attachment was scrubbed... URL: From Seymore4Head at Hotmail.invalid Tue Sep 2 16:50:53 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Tue, 02 Sep 2014 16:50:53 -0400 Subject: Why doesn't this work References: Message-ID: On Tue, 02 Sep 2014 16:13:39 -0400, Seymore4Head wrote: >I still can't get the syntax >test='Hey buddy get away from my car' >if test[0].alpha(): > return True I have a huge head cold right now. Never mind the question. Sorry From tjreedy at udel.edu Tue Sep 2 17:14:28 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 02 Sep 2014 17:14:28 -0400 Subject: Editing text with an external editor in Python In-Reply-To: References: <54049ab7$0$29972$c3e8da3$5496439d@news.astraweb.com> <5404b987$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 9/2/2014 4:45 AM, Chris Angelico wrote: > On Tue, Sep 2, 2014 at 6:35 PM, alister > wrote: >> if edlin is your only option then it would be better to spend you time >> writhing your own text editor! > > Heh! > > Considering how easy it is to deploy a multi-line edit widget in any > GUI toolkit, it shouldn't be too hard to write a GUI text editor. Most Python installations have tkinter available. I quickly wrote an absolutely minimal script. import tkinter as tk root = tk.Tk() text = tk.Text() text.pack() root.mainloop() I tested tested the functions and wrote the following. This is a test text entry. Enter and Tab work as expected. The Arrow (Cursor) keys work as expected. CntL-Left and Cntl-Right move a word at time. Home and End move to beginning and end of the line. Cntl-Home and Cntl-Up move to the beginning of the text. Cntl-End and Cntl-Donw move to the end of the text. Shift + cursor movement selects between the begin and end slice positions. PageUp and PageDown are inoperative. Delete and Backspace work as expected. At least on Windows, I can select text and delete, or cut or copy to Clipboard. I can also paste from the clipboard. In otherwords, this is a functional minimal text entry widget. I did not even know about Shift-movement selecting until I tried it. Notepad has this. Thunderbird's text entry does not. I think the above is adequate for most multi-line text entry. In use, a save function would have to be added. A help text with the above info would be good too (Idle needs this). -- Terry Jan Reedy From rosuav at gmail.com Tue Sep 2 17:36:21 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 3 Sep 2014 07:36:21 +1000 Subject: Editing text with an external editor in Python In-Reply-To: References: <54049ab7$0$29972$c3e8da3$5496439d@news.astraweb.com> <5404b987$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Sep 3, 2014 at 7:14 AM, Terry Reedy wrote: > import tkinter as tk > root = tk.Tk() > text = tk.Text() > text.pack() > root.mainloop() > > I tested tested the functions and wrote the following. > > This is a test text entry. > Enter and Tab work as expected. > The Arrow (Cursor) keys work as expected. > CntL-Left and Cntl-Right move a word at time. > Home and End move to beginning and end of the line. > Cntl-Home and Cntl-Up move to the beginning of the text. > Cntl-End and Cntl-Donw move to the end of the text. > Shift + cursor movement selects between the begin and end slice positions. > PageUp and PageDown are inoperative. > Delete and Backspace work as expected. > At least on Windows, I can select text and delete, > or cut or copy to Clipboard. > I can also paste from the clipboard. > In otherwords, this is a functional minimal text entry widget. Err, that's not all it takes to run an editor :) File opening and saving would be kinda helpful, for a start... But that's what I meant when I said that a multi-line entry field is an extremely standard widget. (I'm a bit surprised that PgUp/PgDn don't work, but the rest of what you say is perfectly standard.) It's a bit harder to do an editor that doesn't just call on a GUI, and more importantly, "tk.Text().pack()" does not make the world's best editor. But it sure is handy when you want to embed an editor in something else! ChrisA From fabiofz at gmail.com Tue Sep 2 20:29:32 2014 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Tue, 2 Sep 2014 21:29:32 -0300 Subject: PyDev Code Analysis In-Reply-To: <67700207-2d66-440b-ba9c-f33757cc9783@googlegroups.com> References: <67700207-2d66-440b-ba9c-f33757cc9783@googlegroups.com> Message-ID: On Tue, Sep 2, 2014 at 2:27 PM, Wanderer wrote: > > I'm trying to set up Eclipse with PyDev and I can't get the code analysis > to work the way I want. > > Whenever I type 'def' it generates an error before I finish the line. I > don't want to see errors until I finish typing. It's not an error I'm just > not done yet. So I try to turn this off by going to > Window>Preferences>PyDev>Editor>CodeAnalysis and setting the option When do > we analyze? to Only on save. This doesn't stop these errors from showing up > while I'm typing. What it does is stop checking for warnings like 'unused > variable' even on save. If I set the option to 'On any successful parse' > then it will check for these warning only on save. > > To summarize > Setting 'Only on save', turns off warnings but keeps giving real time > errors. > > Setting 'On any successful parse', checks for warnings only on save and > keeps giving real time errors. > > I'm using > Eclipse IDE for C/C++ Developers 4.4.0.21040612 > Pydev for Eclipse 3.7.0.201408261926 > > > What I am I doing wrong? > > Thanks > Well, there are 2 different things there: Code analysis and syntax analysis. Syntax analysis is always done on the fly (and you can't really turn it off -- the places which require an AST will usually use the AST which is computed there and when it's computed and there's a syntax error, that error will be shown). It should usually be computed when a new line is entered, on a save or after you entered some text and the timeout specified at preferences > pydev > builders is elapsed. As for the code analysis (which will check errors and warnings such as unused imports / unresolved imports / undefined variables, etc.), it has the options you saw (which are affected by the only on save/on any successful parse). Cheers, Fabio -------------- next part -------------- An HTML attachment was scrubbed... URL: From LlelanD at TheSnakePitDev.com Tue Sep 2 20:34:50 2014 From: LlelanD at TheSnakePitDev.com (Curtis Clauson) Date: Tue, 02 Sep 2014 17:34:50 -0700 Subject: Manually uninstall python 3.4.1 x64 In-Reply-To: References: <54014458.10405@TheSnakePitDev.com> Message-ID: On 8/29/2014 10:13 PM, Terry Reedy wrote: > Please file an issue on the tracker reporting the problem (you are not > the first!) and your suggested solutions and add steve.dower as nosy. He > is a MS employee - Python volunteer who has very recently assumed > maintenance of the msi installer. He wants to upgrade it. > > The installer is build with msilib. Feel free to take a look at that. Done: http://bugs.python.org/issue22329 I'm assuming that by "the tracker" you meant "bugs.python.org". There is no link to it from the Python home page and it was difficult to locate. I hope Mr. Dower finds it helpful. From wanderer at dialup4less.com Tue Sep 2 20:37:15 2014 From: wanderer at dialup4less.com (Wanderer) Date: Tue, 2 Sep 2014 17:37:15 -0700 (PDT) Subject: PyDev Code Analysis In-Reply-To: References: <67700207-2d66-440b-ba9c-f33757cc9783@googlegroups.com> Message-ID: On Tuesday, September 2, 2014 8:29:32 PM UTC-4, Fabio Zadrozny wrote: > On Tue, Sep 2, 2014 at 2:27 PM, Wanderer wrote: > > > > > I'm trying to set up Eclipse with PyDev and I can't get the code analysis to work the way I want. > > > > Whenever I type 'def' it generates an error before I finish the line. I don't want to see errors until I finish typing. It's not an error I'm just not done yet. So I try to turn this off by going to Window>Preferences>PyDev>Editor>CodeAnalysis and setting the option When do we analyze? to Only on save. This doesn't stop these errors from showing up while I'm typing. What it does is stop checking for warnings like 'unused variable' even on save. If I set the option to 'On any successful parse' then it will check for these warning only on save. > > > > > > To summarize > > Setting 'Only on save', turns off warnings but keeps giving real time errors. > > > > Setting 'On any successful parse', checks for warnings only on save and keeps giving real time errors. > > > > I'm using > > Eclipse IDE for C/C++ Developers 4.4.0.21040612 > > Pydev for Eclipse 3.7.0.201408261926 > > > > > > What I am I doing wrong? > > > > Thanks > > > Well, there are 2 different things there: > > > Code analysis and syntax analysis. > > > Syntax analysis is always done on the fly (and you can't really turn it off -- the places which require an AST will usually use the AST which is computed there and when it's computed and there's a syntax error, that error will be shown). It should usually be computed when a new line is entered, on a save or after you entered some text and the timeout specified at preferences > pydev > builders is elapsed. > > > > > As for the code analysis (which will check errors and warnings such as unused imports / unresolved imports / undefined variables, etc.), it has the options you saw (which are affected by the only on save/on any successful parse). > > > > > Cheers, > > > Fabio? Changing the time in builders is what I needed. Thanks From steve+comp.lang.python at pearwood.info Tue Sep 2 21:44:14 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 03 Sep 2014 11:44:14 +1000 Subject: I have tried and errored a reasonable amount of times References: Message-ID: <5406726f$0$6512$c3e8da3$5496439d@news.astraweb.com> Grant Edwards wrote: > I missed the beginning of the thread, but Why are you comparing things > to True and False? I don't understand why people do it, but it's *incredibly* common. A couple of weeks ago at work, I had to (gently, in a friendly manner) mock one of our most senior and accomplished developers for doing exactly that. He was suitably chagrined :-) And then I wondered back to my desk and promptly found myself doing the same thing :-( I think it may have something to do with the linguistic idiom in English where we distinguish between logical statements and logical statements about logical statements for emphasis. E.g., suppose we have a syllogism: Plato is a mortal. All mortals must eat. Therefore Plato must eat. and we wanted to analyse it, we might say something like: Given the undeniable truth that Plato is, in fact, a mortal, then if the statement `all mortals must eat` is true [i.e. is a true statement], then `Plato must eat` likewise is true. to emphasis that we are making a statement about the truth of the statement `all mortals must eat`. I'm not suggesting that this is the only way to talk about the truth or falsity of statements in English, but it is a very common one: https://www.google.com.au/search?q=%22if+*+is+true%22 -- Steven From tjreedy at udel.edu Tue Sep 2 21:49:25 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 02 Sep 2014 21:49:25 -0400 Subject: Editing text with an external editor in Python In-Reply-To: References: <54049ab7$0$29972$c3e8da3$5496439d@news.astraweb.com> <5404b987$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 9/2/2014 5:36 PM, Chris Angelico wrote: > On Wed, Sep 3, 2014 at 7:14 AM, Terry Reedy wrote: >> import tkinter as tk >> root = tk.Tk() >> text = tk.Text() >> text.pack() >> root.mainloop() >> >> I tested tested the functions and wrote the following. >> >> This is a test text entry. >> Enter and Tab work as expected. >> The Arrow (Cursor) keys work as expected. >> CntL-Left and Cntl-Right move a word at time. >> Home and End move to beginning and end of the line. >> Cntl-Home and Cntl-Up move to the beginning of the text. >> Cntl-End and Cntl-Donw move to the end of the text. >> Shift + cursor movement selects between the begin and end slice positions. >> PageUp and PageDown are inoperative. My mistake. See below. >> Delete and Backspace work as expected. >> At least on Windows, I can select text and delete, >> or cut or copy to Clipboard. >> I can also paste from the clipboard. >> In otherwords, this is a functional minimal text entry widget. 'Minimal' mean minimal, as in the minimal number of lines of code to actually work (4), as a the minimum needed to prove the concept, and a starting point for adding more things. > Err, that's not all it takes to run an editor :) File opening The opening premise of the thread was something like "Input() is good for getting a single line of text input from a user. What about getting multiple lines of text?" Opening a non-empty existing file is not relevant to the purpose of extending input(). I intentionally said 'text entry widget', not 'editor'. For editing a particular existing text, the app might pre-load the widget with that text. > saving would be kinda helpful, for a start... It is really annoying when someone clips (erases) something I said and then says that I should have said what I did say. Here it is again! >> In use, a save function would have to be added. The function does not have to be attached to menu widget. When one imports a patch into a mercurial repository, hg offers the opportunity to enter a multi-line commit message. Just the scenario this thread started with. It opens a text entry window something like tkinter.Text. It is preloaded with something like the following. -----------------------------------X| | | |===================================| |Enter commit message above the line| |or leave blank to abort commit. | |Close window when done. | ------------------------------------- Hg intercepts the window close event to grab the entered text, if any, before it disappears. > But that's what I meant when I said that a multi-line entry field is > an extremely standard widget. (I'm a bit surprised that PgUp/PgDn > don't work, My mistake. They do when I add more lines than fit in the window. -- Terry Jan Reedy From tjreedy at udel.edu Tue Sep 2 22:01:30 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 02 Sep 2014 22:01:30 -0400 Subject: Manually uninstall python 3.4.1 x64 In-Reply-To: References: <54014458.10405@TheSnakePitDev.com> Message-ID: On 9/2/2014 8:34 PM, Curtis Clauson wrote: > On 8/29/2014 10:13 PM, Terry Reedy wrote: >> Please file an issue on the tracker reporting the problem (you are not >> the first!) and your suggested solutions and add steve.dower as nosy. He >> is a MS employee - Python volunteer who has very recently assumed >> maintenance of the msi installer. He wants to upgrade it. >> >> The installer is build with msilib. Feel free to take a look at that. > Done: http://bugs.python.org/issue22329 > > I'm assuming that by "the tracker" you meant "bugs.python.org". There is > no link to it from the Python home page and it was difficult to locate. Sorry, I am usually specific. Each doc main page, such as https://docs.python.org/3/ has the Reporting Bugs document listed. > I hope Mr. Dower finds it helpful. -- Terry Jan Reedy From zachary.ware+pylist at gmail.com Tue Sep 2 23:03:25 2014 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Tue, 2 Sep 2014 22:03:25 -0500 Subject: Editing text with an external editor in Python In-Reply-To: References: <54049ab7$0$29972$c3e8da3$5496439d@news.astraweb.com> <5404b987$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Sep 2, 2014 at 3:45 AM, Chris Angelico wrote: > Considering how easy it is to deploy a multi-line edit widget in any > GUI toolkit, it shouldn't be too hard to write a GUI text editor. Coincidentally, I was annoyed enough to write the following program sometime last week. I was sick of messing with Notepad or Notepad++ as the git editor (and don't feel like learning vim just to write a commit message), so I took 10 minutes to write this, packaged it up with py2exe and pointed git at it. Works like a charm for me! #!C:/Python34/python.exe """Simple commit message tool. Dead simple tkinter GUI for writing commit messages for git without messing around with Notepad's line ending stupidity or Notepad++ being open or not. """ import os import sys import tkinter as tk class Committer: def __init__(self, root, filename): self.root = root self.root.protocol('WM_DELETE_WINDOW', self.destroy) self.filename = filename self.text = tk.Text(root) self.text['width'] = 80 self.text['height'] = 25 self.text.pack() self.text.focus() with open(self.filename) as f: self.text.insert('end', f.read()) self.text.mark_set("insert", "1.0") def destroy(self): message = self.text.get('1.0', 'end') with open(self.filename, 'w') as f: f.write(message) self.root.destroy() def main(): root = tk.Tk() assert os.path.exists(sys.argv[1]), sys.argv[1] committer = Committer(root, sys.argv[1]) root.mainloop() if __name__ == '__main__': main() -- Zach From rustompmody at gmail.com Tue Sep 2 23:14:51 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 2 Sep 2014 20:14:51 -0700 (PDT) Subject: I have tried and errored a reasonable amount of times In-Reply-To: <5406726f$0$6512$c3e8da3$5496439d@news.astraweb.com> References: <5406726f$0$6512$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4af60c7a-f4d6-4aa7-b181-fe768ea6f731@googlegroups.com> On Wednesday, September 3, 2014 7:14:14 AM UTC+5:30, Steven D'Aprano wrote: > Grant Edwards wrote: > > I missed the beginning of the thread, but Why are you comparing things > > to True and False? > I don't understand why people do it, but it's *incredibly* common. A couple > of weeks ago at work, I had to (gently, in a friendly manner) mock one of > our most senior and accomplished developers for doing exactly that. He was > suitably chagrined :-) > And then I wondered back to my desk and promptly found myself doing the same > thing :-( Logically the boolean domain is a domain over which the natural algebra is boolean algebra, just like there are arithmetic operators over numbers, string operators over strings etc. Intuitively its a different story. Booleans as an (algebraically manipulable) domain is just plain weird. Not sure why... Perhaps because it reifies the structure of our more intimate thinking more than the other domains? Also as you point out, language probably has much to do with it. Dijkstra used to point out A ? (B ? C) ? (A ? B) ? (A ? C) A ? (B ? C) ? (A ? B) ? (A ? C) look normal enough in this form Put then into the way engineers do it and they become A(B + C) = AB + AC A + BC = (A+B)(A+C) and Dijkstra would (gleefully!) point out that the engineers were much more unfamiliar/uneasy with the second than the first. In effect the perfect symmetry of the boolean operators get marred in our intuition when we use poor notation. From dream4soul at gmail.com Wed Sep 3 02:19:07 2014 From: dream4soul at gmail.com (dream4soul at gmail.com) Date: Tue, 2 Sep 2014 23:19:07 -0700 (PDT) Subject: crc algorithm In-Reply-To: References: <01aa8ab2-cceb-4219-8999-5c66520c128e@googlegroups.com> Message-ID: On Tuesday, September 2, 2014 9:24:54 PM UTC+3, Peter Otten wrote: > dream4soul at gmail.com wrote: > > > > > I have trouble to implement crc algorithm in python 3.3 > > > > > > c version work perfect. I try to use bytes, int and c_types without any > > > success can some who help me: > > > > ctypes is for interfacing with C; don't use it in regular code. > > > > > c version: > > > > > > unsigned short calc_crc(const void *p_dat, int l_dat){ > > > unsigned char *dat_ptr; > > > int loopc; > > > unsigned short crc_dat; > > > unsigned char c_work; > > > > > > dat_ptr = (unsigned char*)p_dat; > > > crc_dat = 0x0000; > > > for (; l_dat > 0; l_dat--) > > > { > > > c_work = *(dat_ptr++); > > > for (loopc = 0; loopc < 8; loopc++) > > > { > > > if ((((unsigned char )(crc_dat & 0x0001)) ^ > > > (c_work & 0x01)) == 0x01) > > > { > > > crc_dat >>=1 ; > > > crc_dat ^=0x8408; > > > } else { > > > crc_dat >>=1; > > > > > > } > > > c_work >>=1; > > > } > > > } > > > return(crc_dat); > > > } > > > > A near-literal translation would be: > > > > def calc_crc(data): > > crc = 0 > > for work in data: > > for i in range(8): > > if (crc & 1) ^ (work & 1): > > crc >>= 1 > > crc ^= 0x8408 > > else: > > crc >>= 1 > > work >>= 1 > > return crc > > > > I don't see any operation where the "unboundedness" of Python's integer type > > could be a problem -- but no guarantees. this doesn't work calc_crc(b'\x00\x00\x34\x35\x38\x35') rsult 0x9f41 , but c function gives us 0x8c40 From dieter at handshake.de Wed Sep 3 02:29:44 2014 From: dieter at handshake.de (dieter) Date: Wed, 03 Sep 2014 08:29:44 +0200 Subject: urllib2 redirect error References: <540571b8$0$29876$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87ppfddxnr.fsf@handshake.de> Steven D'Aprano writes: > ... > I'm not an expert, but that sounds like a fault at the server end. I just > tried it in Chrome, and it worked, and then with wget, and I get the same > sort of error: > ... > Sounds like if the server doesn't recognise the browser, it gets > confused and ends up in a redirect loop. > > You could try setting the user-agent and see if that helps: Excellent analysis and advice. From dream4soul at gmail.com Wed Sep 3 02:25:05 2014 From: dream4soul at gmail.com (dream4soul at gmail.com) Date: Tue, 2 Sep 2014 23:25:05 -0700 (PDT) Subject: crc algorithm In-Reply-To: References: <01aa8ab2-cceb-4219-8999-5c66520c128e@googlegroups.com> Message-ID: <1d54dfb1-a4da-4924-b5a6-661e74d76820@googlegroups.com> On Tuesday, September 2, 2014 9:43:52 PM UTC+3, Chris Kaynor wrote: > Also, depending on the use-case, binascii.crc32 might also work fine: https://docs.python.org/2/library/binascii.html#binascii.crc32 > > > > > import binascii > def calc_crc(data): > ? ? return binascii.crc32(data) > > > Much simpler. > > > > > Chris > > > > > > On Tue, Sep 2, 2014 at 11:24 AM, Peter Otten <__pe... at web.de> wrote: > > > > dream... at gmail.com wrote: > > > > > I have trouble to implement crc algorithm in python 3.3 > > > > > > c version work? perfect. I try to use bytes, int and c_types without any > > > success can some who help me: > > > > ctypes is for interfacing with C; don't use it in regular code. > > > > > > c version: > > > > > > unsigned short calc_crc(const void *p_dat, int l_dat){ > > >? ? ? ? ?unsigned char *dat_ptr; > > >? ? ? ? ?int loopc; > > >? ? ? ? ?unsigned short crc_dat; > > >? ? ? ? ?unsigned char c_work; > > > > > >? ? ? ? ?dat_ptr = (unsigned char*)p_dat; > > >? ? ? ? ?crc_dat = 0x0000; > > >? ? ? ? ?for (; l_dat > 0; l_dat--) > > >? ? ? ? ?{ > > >? ? ? ? ? ? ? ? ?c_work = *(dat_ptr++); > > >? ? ? ? ? ? ? ? ?for (loopc = 0; loopc < 8; loopc++) > > >? ? ? ? ? ? ? ? ?{ > > >? ? ? ? ? ? ? ? ? ? ? ? ?if ((((unsigned char )(crc_dat & 0x0001)) ^ > > >? ? ? ? ? ? ? ? ? ? ? ? ?(c_work & 0x01)) == 0x01) > > >? ? ? ? ? ? ? ? ? ? ? ? ?{ > > >? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?crc_dat >>=1 ; > > >? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?crc_dat ^=0x8408; > > >? ? ? ? ? ? ? ? ? ? ? ? ?} else { > > >? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?crc_dat >>=1; > > > > > >? ? ? ? ? ? ? ? ? ? ? ? ?} > > >? ? ? ? ? ? ? ? ? ? ? ? ?c_work >>=1; > > >? ? ? ? ? ? ? ? ?} > > >? ? ? ? ?} > > >? ? ? ? ?return(crc_dat); > > > } > > > > A near-literal translation would be: > > > > def calc_crc(data): > > ? ? crc = 0 > > ? ? for work in data: > > ? ? ? ? for i in range(8): > > ? ? ? ? ? ? if (crc & 1) ^ (work & 1): > > ? ? ? ? ? ? ? ? crc >>= 1 > > ? ? ? ? ? ? ? ? crc ^= 0x8408 > > ? ? ? ? ? ? else: > > ? ? ? ? ? ? ? ? crc >>= 1 > > ? ? ? ? ? ? work >>= 1 > > ? ? return crc > > > > I don't see any operation where the "unboundedness" of Python's integer type > > could be a problem -- but no guarantees. > > > > -- > > https://mail.python.org/mailman/listinfo/python-list this doesn't work binascii.crc32(data) return 32 bit data , c function crc return 16 bit and it is not standard crc From __peter__ at web.de Wed Sep 3 03:19:29 2014 From: __peter__ at web.de (Peter Otten) Date: Wed, 03 Sep 2014 09:19:29 +0200 Subject: crc algorithm References: <01aa8ab2-cceb-4219-8999-5c66520c128e@googlegroups.com> Message-ID: dream4soul at gmail.com wrote: > On Tuesday, September 2, 2014 9:24:54 PM UTC+3, Peter Otten wrote: >> dream4soul at gmail.com wrote: >> >> >> >> > I have trouble to implement crc algorithm in python 3.3 >> >> > >> >> > c version work perfect. I try to use bytes, int and c_types without >> > any >> >> > success can some who help me: >> >> >> >> ctypes is for interfacing with C; don't use it in regular code. >> >> >> >> > c version: >> >> > >> >> > unsigned short calc_crc(const void *p_dat, int l_dat){ >> >> > unsigned char *dat_ptr; >> >> > int loopc; >> >> > unsigned short crc_dat; >> >> > unsigned char c_work; >> >> > >> >> > dat_ptr = (unsigned char*)p_dat; >> >> > crc_dat = 0x0000; >> >> > for (; l_dat > 0; l_dat--) >> >> > { >> >> > c_work = *(dat_ptr++); >> >> > for (loopc = 0; loopc < 8; loopc++) >> >> > { >> >> > if ((((unsigned char )(crc_dat & 0x0001)) ^ >> >> > (c_work & 0x01)) == 0x01) >> >> > { >> >> > crc_dat >>=1 ; >> >> > crc_dat ^=0x8408; >> >> > } else { >> >> > crc_dat >>=1; >> >> > >> >> > } >> >> > c_work >>=1; >> >> > } >> >> > } >> >> > return(crc_dat); >> >> > } >> >> >> >> A near-literal translation would be: >> >> >> >> def calc_crc(data): >> >> crc = 0 >> >> for work in data: >> >> for i in range(8): >> >> if (crc & 1) ^ (work & 1): >> >> crc >>= 1 >> >> crc ^= 0x8408 >> >> else: >> >> crc >>= 1 >> >> work >>= 1 >> >> return crc >> >> >> >> I don't see any operation where the "unboundedness" of Python's integer >> type >> >> could be a problem -- but no guarantees. > > this doesn't work > > calc_crc(b'\x00\x00\x34\x35\x38\x35') > rsult 0x9f41 , but c function gives us 0x8c40 Are you sure? I get 0x9f41 with the C version you posted: $ cat crc.c #include unsigned short calc_crc(const void *p_dat, int l_dat){ unsigned char *dat_ptr; int loopc; unsigned short crc_dat; unsigned char c_work; dat_ptr = (unsigned char*)p_dat; crc_dat = 0x0000; for (; l_dat > 0; l_dat--) { c_work = *(dat_ptr++); for (loopc = 0; loopc < 8; loopc++) { if ((((unsigned char )(crc_dat & 0x0001)) ^ (c_work & 0x01)) == 0x01) { crc_dat >>=1 ; crc_dat ^=0x8408; } else { crc_dat >>=1; } c_work >>=1; } } return(crc_dat); } main() { unsigned char data[] = "\x00\x00\x34\x35\x38\x35"; unsigned short crc = calc_crc(data, 6); printf("%x\n", crc); } $ gcc crc.c $ ./a.out 9f41 From steve at pearwood.info Wed Sep 3 03:16:34 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 03 Sep 2014 07:16:34 GMT Subject: I have tried and errored a reasonable amount of times References: <5406726f$0$6512$c3e8da3$5496439d@news.astraweb.com> <4af60c7a-f4d6-4aa7-b181-fe768ea6f731@googlegroups.com> Message-ID: <5406c052$0$29876$c3e8da3$5496439d@news.astraweb.com> On Tue, 02 Sep 2014 20:14:51 -0700, Rustom Mody wrote: > Dijkstra > used to point out > > A ? (B ? C) ? (A ? B) ? (A ? C) A ? (B ? C) ? (A ? B) ? (A ? C) look > normal enough in this form > > Put then into the way engineers do it and they become A(B + C) = AB + AC > A + BC = (A+B)(A+C) o_O Who uses + for disjunction (? OR) and concatenation for conjunction (? AND)? That's crazy notation. -- Steven From breamoreboy at yahoo.co.uk Wed Sep 3 03:22:34 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 03 Sep 2014 08:22:34 +0100 Subject: crc algorithm In-Reply-To: References: <01aa8ab2-cceb-4219-8999-5c66520c128e@googlegroups.com> Message-ID: On 03/09/2014 07:19, dream4soul at gmail.com wrote: 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 greg.ewing at canterbury.ac.nz Wed Sep 3 03:42:07 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 03 Sep 2014 19:42:07 +1200 Subject: Raspberry pi, python and robotics In-Reply-To: <20140902093058.0ac902ed@rg.highlandtechnology.com> References: <20140902093058.0ac902ed@rg.highlandtechnology.com> Message-ID: Rob Gaddi wrote: > otherwise getting up and > running will cost you a solid $1200 just in gear. While having fancy gear certainly helps, it's not *strictly* necessary. When I first started dabbling in electronics, the most sophisticated piece of equipment I had was an analog multimeter. It got me through a lot of projects, including a couple of homebrew computers. It's surprising how much you can deduce about what's happening in a digital circuit by watching a needle bouncing around! -- Greg From marko at pacujo.net Wed Sep 3 03:44:34 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 03 Sep 2014 10:44:34 +0300 Subject: I have tried and errored a reasonable amount of times References: <5406726f$0$6512$c3e8da3$5496439d@news.astraweb.com> <4af60c7a-f4d6-4aa7-b181-fe768ea6f731@googlegroups.com> <5406c052$0$29876$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87a96hcfml.fsf@elektro.pacujo.net> Steven D'Aprano : > Who uses + for disjunction (? OR) and concatenation for conjunction (? > AND)? That's crazy notation. That's the classic Boolean algebraic notation. In basic algebra, the two interesting operations are "addition" and "multiplication". Boolean math works like elementary arithmetics, with the exception that 1 + 1 = 1 I'm guessing the modern symbols ? and ? were derived from the set-theoretical analogues, ? and ?, which were also formerly used for the same purpose. Marko From alister.nospam.ware at ntlworld.com Wed Sep 3 04:06:21 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Wed, 03 Sep 2014 08:06:21 GMT Subject: Editing text with an external editor in Python References: <54049ab7$0$29972$c3e8da3$5496439d@news.astraweb.com> <5404b987$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1_zNv.229859$an2.171403@fx09.am4> On Tue, 02 Sep 2014 18:45:54 +1000, Chris Angelico wrote: > On Tue, Sep 2, 2014 at 6:35 PM, alister > wrote: >> if edlin is your only option then it would be better to spend you time >> writhing your own text editor! > > Heh! > > Considering how easy it is to deploy a multi-line edit widget in any GUI > toolkit, it shouldn't be too hard to write a GUI text editor. Now, > writing a *good* GUI text editor, that's a bit harder. And of course, > writing a text/console text editor, that's also less simple. But I put > it to you: How do you write your editor up to the point where you can > use it to write your editor? We have a bootstrapping problem! > > ChrisA fortunately i have a proper operating system now so I don't have have to use edlin. in the unlikely event that a reasonably featured editor is not available I can always use cat :-) -- Nothing is finished until the paperwork is done. From dream4soul at gmail.com Wed Sep 3 04:43:37 2014 From: dream4soul at gmail.com (dream4soul at gmail.com) Date: Wed, 3 Sep 2014 01:43:37 -0700 (PDT) Subject: crc algorithm In-Reply-To: References: <01aa8ab2-cceb-4219-8999-5c66520c128e@googlegroups.com> Message-ID: <9e5c2de2-5c96-468d-84b4-3db511117ea0@googlegroups.com> On Wednesday, September 3, 2014 10:19:29 AM UTC+3, Peter Otten wrote: > dream4soul at gmail.com wrote: > > > > > On Tuesday, September 2, 2014 9:24:54 PM UTC+3, Peter Otten wrote: > > >> dream4soul at gmail.com wrote: > > >> > > >> > > >> > > >> > I have trouble to implement crc algorithm in python 3.3 > > >> > > >> > > > >> > > >> > c version work perfect. I try to use bytes, int and c_types without > > >> > any > > >> > > >> > success can some who help me: > > >> > > >> > > >> > > >> ctypes is for interfacing with C; don't use it in regular code. > > >> > > >> > > >> > > >> > c version: > > >> > > >> > > > >> > > >> > unsigned short calc_crc(const void *p_dat, int l_dat){ > > >> > > >> > unsigned char *dat_ptr; > > >> > > >> > int loopc; > > >> > > >> > unsigned short crc_dat; > > >> > > >> > unsigned char c_work; > > >> > > >> > > > >> > > >> > dat_ptr = (unsigned char*)p_dat; > > >> > > >> > crc_dat = 0x0000; > > >> > > >> > for (; l_dat > 0; l_dat--) > > >> > > >> > { > > >> > > >> > c_work = *(dat_ptr++); > > >> > > >> > for (loopc = 0; loopc < 8; loopc++) > > >> > > >> > { > > >> > > >> > if ((((unsigned char )(crc_dat & 0x0001)) ^ > > >> > > >> > (c_work & 0x01)) == 0x01) > > >> > > >> > { > > >> > > >> > crc_dat >>=1 ; > > >> > > >> > crc_dat ^=0x8408; > > >> > > >> > } else { > > >> > > >> > crc_dat >>=1; > > >> > > >> > > > >> > > >> > } > > >> > > >> > c_work >>=1; > > >> > > >> > } > > >> > > >> > } > > >> > > >> > return(crc_dat); > > >> > > >> > } > > >> > > >> > > >> > > >> A near-literal translation would be: > > >> > > >> > > >> > > >> def calc_crc(data): > > >> > > >> crc = 0 > > >> > > >> for work in data: > > >> > > >> for i in range(8): > > >> > > >> if (crc & 1) ^ (work & 1): > > >> > > >> crc >>= 1 > > >> > > >> crc ^= 0x8408 > > >> > > >> else: > > >> > > >> crc >>= 1 > > >> > > >> work >>= 1 > > >> > > >> return crc > > >> > > >> > > >> > > >> I don't see any operation where the "unboundedness" of Python's integer > > >> type > > >> > > >> could be a problem -- but no guarantees. > > > > > > this doesn't work > > > > > > calc_crc(b'\x00\x00\x34\x35\x38\x35') > > > rsult 0x9f41 , but c function gives us 0x8c40 > > > > Are you sure? I get 0x9f41 with the C version you posted: > > > > $ cat crc.c > > #include > > > > unsigned short calc_crc(const void *p_dat, int l_dat){ > > unsigned char *dat_ptr; > > int loopc; > > unsigned short crc_dat; > > unsigned char c_work; > > > > dat_ptr = (unsigned char*)p_dat; > > crc_dat = 0x0000; > > for (; l_dat > 0; l_dat--) > > { > > c_work = *(dat_ptr++); > > for (loopc = 0; loopc < 8; loopc++) > > { > > if ((((unsigned char )(crc_dat & 0x0001)) ^ (c_work > > & 0x01)) == 0x01) > > { > > crc_dat >>=1 ; > > crc_dat ^=0x8408; > > } else { > > crc_dat >>=1; > > > > } > > c_work >>=1; > > } > > } > > return(crc_dat); > > } > > > > main() > > { > > unsigned char data[] = "\x00\x00\x34\x35\x38\x35"; > > unsigned short crc = calc_crc(data, 6); > > printf("%x\n", crc); > > } > > $ gcc crc.c > > $ ./a.out > > 9f41 int main(int argc, char const *argv[]) { unsigned short rez; unsigned char a[]={0x30,0x30,0x34,0x35,0x38,0x35}; unsigned short val; rez=calc_crc(a,(int)sizeof(a)); printf("%#hx\n",rez ); return 0; } From dream4soul at gmail.com Wed Sep 3 04:46:34 2014 From: dream4soul at gmail.com (dream4soul at gmail.com) Date: Wed, 3 Sep 2014 01:46:34 -0700 (PDT) Subject: crc algorithm In-Reply-To: References: <01aa8ab2-cceb-4219-8999-5c66520c128e@googlegroups.com> Message-ID: On Wednesday, September 3, 2014 10:19:29 AM UTC+3, Peter Otten wrote: > dream4soul at gmail.com wrote: > > > > > On Tuesday, September 2, 2014 9:24:54 PM UTC+3, Peter Otten wrote: > > >> dream4soul at gmail.com wrote: > > >> > > >> > > >> > > >> > I have trouble to implement crc algorithm in python 3.3 > > >> > > >> > > > >> > > >> > c version work perfect. I try to use bytes, int and c_types without > > >> > any > > >> > > >> > success can some who help me: > > >> > > >> > > >> > > >> ctypes is for interfacing with C; don't use it in regular code. > > >> > > >> > > >> > > >> > c version: > > >> > > >> > > > >> > > >> > unsigned short calc_crc(const void *p_dat, int l_dat){ > > >> > > >> > unsigned char *dat_ptr; > > >> > > >> > int loopc; > > >> > > >> > unsigned short crc_dat; > > >> > > >> > unsigned char c_work; > > >> > > >> > > > >> > > >> > dat_ptr = (unsigned char*)p_dat; > > >> > > >> > crc_dat = 0x0000; > > >> > > >> > for (; l_dat > 0; l_dat--) > > >> > > >> > { > > >> > > >> > c_work = *(dat_ptr++); > > >> > > >> > for (loopc = 0; loopc < 8; loopc++) > > >> > > >> > { > > >> > > >> > if ((((unsigned char )(crc_dat & 0x0001)) ^ > > >> > > >> > (c_work & 0x01)) == 0x01) > > >> > > >> > { > > >> > > >> > crc_dat >>=1 ; > > >> > > >> > crc_dat ^=0x8408; > > >> > > >> > } else { > > >> > > >> > crc_dat >>=1; > > >> > > >> > > > >> > > >> > } > > >> > > >> > c_work >>=1; > > >> > > >> > } > > >> > > >> > } > > >> > > >> > return(crc_dat); > > >> > > >> > } > > >> > > >> > > >> > > >> A near-literal translation would be: > > >> > > >> > > >> > > >> def calc_crc(data): > > >> > > >> crc = 0 > > >> > > >> for work in data: > > >> > > >> for i in range(8): > > >> > > >> if (crc & 1) ^ (work & 1): > > >> > > >> crc >>= 1 > > >> > > >> crc ^= 0x8408 > > >> > > >> else: > > >> > > >> crc >>= 1 > > >> > > >> work >>= 1 > > >> > > >> return crc > > >> > > >> > > >> > > >> I don't see any operation where the "unboundedness" of Python's integer > > >> type > > >> > > >> could be a problem -- but no guarantees. > > > > > > this doesn't work > > > > > > calc_crc(b'\x00\x00\x34\x35\x38\x35') > > > rsult 0x9f41 , but c function gives us 0x8c40 > > > > Are you sure? I get 0x9f41 with the C version you posted: > > > > $ cat crc.c > > #include > > > > unsigned short calc_crc(const void *p_dat, int l_dat){ > > unsigned char *dat_ptr; > > int loopc; > > unsigned short crc_dat; > > unsigned char c_work; > > > > dat_ptr = (unsigned char*)p_dat; > > crc_dat = 0x0000; > > for (; l_dat > 0; l_dat--) > > { > > c_work = *(dat_ptr++); > > for (loopc = 0; loopc < 8; loopc++) > > { > > if ((((unsigned char )(crc_dat & 0x0001)) ^ (c_work > > & 0x01)) == 0x01) > > { > > crc_dat >>=1 ; > > crc_dat ^=0x8408; > > } else { > > crc_dat >>=1; > > > > } > > c_work >>=1; > > } > > } > > return(crc_dat); > > } > > > > main() > > { > > unsigned char data[] = "\x00\x00\x34\x35\x38\x35"; > > unsigned short crc = calc_crc(data, 6); > > printf("%x\n", crc); > > } > > $ gcc crc.c > > $ ./a.out > > 9f41 int main(int argc, char const *argv[]) { unsigned short rez; unsigned char a[]={0x30,0x30,0x34,0x35,0x38,0x35}; unsigned short val; rez=calc_crc(a,(int)sizeof(a)); printf("%#hx\n",rez ); return 0; } o$ gcc main.c o$ ./a.out 0x8c40 From __peter__ at web.de Wed Sep 3 05:00:10 2014 From: __peter__ at web.de (Peter Otten) Date: Wed, 03 Sep 2014 11:00:10 +0200 Subject: crc algorithm References: <01aa8ab2-cceb-4219-8999-5c66520c128e@googlegroups.com> Message-ID: dream4soul at gmail.com wrote: > calc_crc(b'\x00\x00\x34\x35\x38\x35') > unsigned char a[]={0x30,0x30,0x34,0x35,0x38,0x35}; The first two bytes differ; you made an error on the input. From frank at chagford.com Wed Sep 3 06:47:18 2014 From: frank at chagford.com (Frank Millman) Date: Wed, 3 Sep 2014 12:47:18 +0200 Subject: AccInABox now has a wiki page (almost) Message-ID: Hi all After putting my AccInABox package up on GitHub and letting a few people know about it, I received the following response - > > From: "St?fan van der Walt" > > Hi Frank > > It would be great if the readme would list some features of the software > > so that one can decide whether it is suitable for one's own application. > Thanks for the interest, St?fan. > I will spend some time over the weekend to draw something up, and I will > post it here. I am working on a 'feature list', but it is taking longer than expected, so here is a progress report and a preview. I decided to use the wiki page on my GitHub account. It took me a while to figure out how to use it effectively, but I think I have the hang of it now. I created a separate 'test' account to use while I am working on it, because each update to the wiki results in a 'revision', and I did not want to clutter up my main GitHub page with all my initial attempts. Once I am happy with it, I will upload the whole lot to my main page in one update. Here is a link to the test page - https://github.com/FrankMillman/test/wiki If anyone wants to have a look and offer feedback while I am working on it, that would be appreciated. Frank From dream4soul at gmail.com Wed Sep 3 07:00:06 2014 From: dream4soul at gmail.com (dream4soul at gmail.com) Date: Wed, 3 Sep 2014 04:00:06 -0700 (PDT) Subject: crc algorithm In-Reply-To: References: <01aa8ab2-cceb-4219-8999-5c66520c128e@googlegroups.com> Message-ID: On Wednesday, September 3, 2014 12:00:10 PM UTC+3, Peter Otten wrote: > dream4soul at gmail.com wrote: > > > > > calc_crc(b'\x00\x00\x34\x35\x38\x35') > > > > > unsigned char a[]={0x30,0x30,0x34,0x35,0x38,0x35}; > > > > The first two bytes differ; you made an error on the input. Dear Peter, my apologies it's my mistake. Thank you for help. Problem solved. From cl at isbd.net Wed Sep 3 08:27:29 2014 From: cl at isbd.net (cl at isbd.net) Date: Wed, 3 Sep 2014 13:27:29 +0100 Subject: How to turn a string into a list of integers? Message-ID: I know I can get a list of the characters in a string by simply doing:- listOfCharacters = list("This is a string") ... but how do I get a list of integers? -- Chris Green ? From __peter__ at web.de Wed Sep 3 08:52:57 2014 From: __peter__ at web.de (Peter Otten) Date: Wed, 03 Sep 2014 14:52:57 +0200 Subject: How to turn a string into a list of integers? References: Message-ID: cl at isbd.net wrote: > I know I can get a list of the characters in a string by simply doing:- > > listOfCharacters = list("This is a string") > > ... but how do I get a list of integers? > >>> [ord(c) for c in "This is a string"] [84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 115, 116, 114, 105, 110, 103] There are other ways, but you have to describe the use case and your Python version for us to recommend the most appropriate. From obedrios at gmail.com Wed Sep 3 10:30:28 2014 From: obedrios at gmail.com (obedrios at gmail.com) Date: Wed, 3 Sep 2014 07:30:28 -0700 (PDT) Subject: How to turn a string into a list of integers? In-Reply-To: References: Message-ID: El mi?rcoles, 3 de septiembre de 2014 05:27:29 UTC-7, c... at isbd.net escribi?: > I know I can get a list of the characters in a string by simply doing:- > > > > listOfCharacters = list("This is a string") > > > > ... but how do I get a list of integers? > > > > -- > > Chris Green > > ? You Can Apply either, a map function or a list comprehension as follow: Using Map: >>> list(map(ord, listOfCharacters)) [84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 115, 116, 114, 105, 110, 103] Using List Comprehension: >>> [ord(n) for n in listOfCharacters] [84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 115, 116, 114, 105, 110, 103] Very Best Regards From dream4soul at gmail.com Wed Sep 3 10:31:58 2014 From: dream4soul at gmail.com (dream4soul at gmail.com) Date: Wed, 3 Sep 2014 07:31:58 -0700 (PDT) Subject: crc algorithm In-Reply-To: References: <01aa8ab2-cceb-4219-8999-5c66520c128e@googlegroups.com> Message-ID: <8304747e-ef5c-4e73-a2b6-1c54071ef35c@googlegroups.com> On Wednesday, September 3, 2014 12:00:10 PM UTC+3, Peter Otten wrote: > dream4soul at gmail.com wrote: > > > > > calc_crc(b'\x00\x00\x34\x35\x38\x35') > > > > > unsigned char a[]={0x30,0x30,0x34,0x35,0x38,0x35}; > > > > The first two bytes differ; you made an error on the input. Dear Peter, my apologies it's my mistake. Thank you for help. Problem solved From cl at isbd.net Wed Sep 3 10:48:01 2014 From: cl at isbd.net (cl at isbd.net) Date: Wed, 3 Sep 2014 15:48:01 +0100 Subject: How to turn a string into a list of integers? References: Message-ID: <1amjdb-p3n.ln1@chris.zbmc.eu> Peter Otten <__peter__ at web.de> wrote: > cl at isbd.net wrote: > > > I know I can get a list of the characters in a string by simply doing:- > > > > listOfCharacters = list("This is a string") > > > > ... but how do I get a list of integers? > > > > >>> [ord(c) for c in "This is a string"] > [84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 115, 116, 114, 105, 110, 103] > > There are other ways, but you have to describe the use case and your Python > version for us to recommend the most appropriate. > That looks OK to me. It's just for outputting a string to the block write command in python-smbus which expects an integer array. Thanks. -- Chris Green ? From antoine at python.org Wed Sep 3 11:58:47 2014 From: antoine at python.org (Antoine Pitrou) Date: Wed, 3 Sep 2014 15:58:47 +0000 (UTC) Subject: [ANN] pathlib 1.0.1 Message-ID: Hello, I am announcing the release of pathlib 1.0.1. This version makes pathlib Python 2.6-compatible. Note that 2.6 compatibility may not have been as well tested as more recent Python versions (especially on non-Unix platforms). As a reminder, the standalone (PyPI) version of pathlib will not receive any new features or general improvements. New developments and regular bug fixes will happen mostly in the Python standard library, and be publicly available in official Python releases. See https://pypi.python.org/pypi/pathlib Overview -------- pathlib offers a set of classes to handle filesystem paths. It offers the following advantages over using string objects: * No more cumbersome use of os and os.path functions. Everything can be done easily through operators, attribute accesses, and method calls. * Embodies the semantics of different path types. For example, comparing Windows paths ignores casing. * Well-defined semantics, eliminating any warts or ambiguities (forward vs. backward slashes, etc.). Requirements ------------ Python 3.2 or later is recommended, but pathlib is also usable with Python 2.6 and 2.7. Install ------- In Python 3.4, pathlib is now part of the standard library. For Python 3.3 and earlier, ``easy_install pathlib`` or ``pip install pathlib`` should do the trick. Changelog for version 1.0.1 --------------------------- - Pull request #4: Python 2.6 compatibility by eevee. Regards Antoine. From Seymore4Head at Hotmail.invalid Wed Sep 3 14:10:42 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Wed, 03 Sep 2014 14:10:42 -0400 Subject: Python is going to be hard Message-ID: import math import random import sys b=[] steve = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] for x in steve: print (steve[x]) Traceback (most recent call last): File "C:\Functions\blank.py", line 7, in print (steve[x]) IndexError: list index out of range From miguelglafuente at gmail.com Wed Sep 3 14:16:56 2014 From: miguelglafuente at gmail.com (Rock Neurotiko) Date: Wed, 3 Sep 2014 20:16:56 +0200 Subject: Python is going to be hard In-Reply-To: References: Message-ID: print(x) :) 2014-09-03 20:10 GMT+02:00 Seymore4Head : > import math > import random > import sys > b=[] > steve = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] > for x in steve: > print (steve[x]) > > Traceback (most recent call last): > File "C:\Functions\blank.py", line 7, in > print (steve[x]) > IndexError: list index out of range > -- > https://mail.python.org/mailman/listinfo/python-list > -- Miguel Garc?a Lafuente - Rock Neurotiko Do it, the devil is in the details. The quieter you are, the more you are able to hear. Happy Coding. Code with Passion, Decode with Patience. If we make consistent effort, based on proper education, we can change the world. El contenido de este e-mail es privado, no se permite la revelacion del contenido de este e-mail a gente ajena a ?l. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gordon at panix.com Wed Sep 3 14:17:27 2014 From: gordon at panix.com (John Gordon) Date: Wed, 3 Sep 2014 18:17:27 +0000 (UTC) Subject: Python is going to be hard References: Message-ID: In Seymore4Head writes: > import math > import random > import sys Why are you importing these modules if they're not used? > b=[] Likewise b is not used. > steve = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] > for x in steve: > print (steve[x]) As you step through the loop, x becomes each successive item in the 'steve' list. Therefore, you probably want to print just plain x, not steve[x]. > Traceback (most recent call last): > File "C:\Functions\blank.py", line 7, in > print (steve[x]) > IndexError: list index out of range There are fewer than 13 items in steve, so when x reaches 13 this error pops up. -- 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 rgaddi at technologyhighland.invalid Wed Sep 3 14:19:04 2014 From: rgaddi at technologyhighland.invalid (Rob Gaddi) Date: Wed, 3 Sep 2014 11:19:04 -0700 Subject: Python is going to be hard References: Message-ID: <20140903111904.0500bd47@rg.highlandtechnology.com> On Wed, 03 Sep 2014 14:10:42 -0400 Seymore4Head wrote: > import math > import random > import sys > b=[] > steve = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] > for x in steve: > print (steve[x]) > > Traceback (most recent call last): > File "C:\Functions\blank.py", line 7, in > print (steve[x]) > IndexError: list index out of range You're failing to go through the basic tutorials, and blaming the language when you don't understand things. 'for x in steve' does not sweep x over the indices of steve. 'for x in steve' sweeps x over the sequential _values_ in steve. This would have been clear if you were to add a print(x) into the loop. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From python at mrabarnett.plus.com Wed Sep 3 14:24:38 2014 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 03 Sep 2014 19:24:38 +0100 Subject: Python is going to be hard In-Reply-To: References: Message-ID: <54075CE6.20405@mrabarnett.plus.com> On 2014-09-03 19:10, Seymore4Head wrote: > import math > import random > import sys > b=[] > steve = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] > for x in steve: > print (steve[x]) > > Traceback (most recent call last): > File "C:\Functions\blank.py", line 7, in > print (steve[x]) > IndexError: list index out of range > Iterating over a list yields its contents, not indexes. From skip at pobox.com Wed Sep 3 14:28:39 2014 From: skip at pobox.com (Skip Montanaro) Date: Wed, 3 Sep 2014 13:28:39 -0500 Subject: Python is going to be hard In-Reply-To: <54075CE6.20405@mrabarnett.plus.com> References: <54075CE6.20405@mrabarnett.plus.com> Message-ID: On Wed, Sep 3, 2014 at 1:24 PM, MRAB wrote: > Iterating over a list yields its contents, not indexes. Unlike in JavaScript. Not sure where the OP is coming from, but that "feature" of JavaScript threw me when I first encountered it. My guess would be that his prior experience includes (at least) JS. Skip From ethan at stoneleaf.us Wed Sep 3 14:33:46 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 03 Sep 2014 11:33:46 -0700 Subject: Python is going to be hard In-Reply-To: References: Message-ID: <54075F0A.60300@stoneleaf.us> On 09/03/2014 11:10 AM, Seymore4Head wrote: > import math > import random > import sys > b=[] > steve = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] > for x in steve: > print (steve[x]) > > Traceback (most recent call last): > File "C:\Functions\blank.py", line 7, in > print (steve[x]) > IndexError: list index out of range Python will be incredibly hard if you don't read any of the docs or tutorials available. -- ~Ethan~ From Seymore4Head at Hotmail.invalid Wed Sep 3 14:41:31 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Wed, 03 Sep 2014 14:41:31 -0400 Subject: Python is going to be hard References: Message-ID: On Wed, 03 Sep 2014 11:33:46 -0700, Ethan Furman wrote: >On 09/03/2014 11:10 AM, Seymore4Head wrote: >> import math >> import random >> import sys >> b=[] >> steve = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] >> for x in steve: >> print (steve[x]) >> >> Traceback (most recent call last): >> File "C:\Functions\blank.py", line 7, in >> print (steve[x]) >> IndexError: list index out of range > >Python will be incredibly hard if you don't read any of the docs or tutorials available. You can't accuse me of that. I have actually read quite a bit. I may not be picking it up, but I am trying. From juan0christian at gmail.com Wed Sep 3 14:44:47 2014 From: juan0christian at gmail.com (Juan Christian) Date: Wed, 3 Sep 2014 15:44:47 -0300 Subject: Python is going to be hard In-Reply-To: <54075F0A.60300@stoneleaf.us> References: <54075F0A.60300@stoneleaf.us> Message-ID: I'm learning Python using this mailist, and the Tutor mailist, reading the docs and watching this course, Python Fundamentals ( http://www.pluralsight.com/training/Courses/TableOfContents/python-fundamentals ). Python is really easy and useful, OP don't blame the language because you didn't understood it yet, just persist. On Wed, Sep 3, 2014 at 3:33 PM, Ethan Furman wrote: > On 09/03/2014 11:10 AM, Seymore4Head wrote: > >> import math >> import random >> import sys >> b=[] >> steve = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] >> for x in steve: >> print (steve[x]) >> >> Traceback (most recent call last): >> File "C:\Functions\blank.py", line 7, in >> print (steve[x]) >> IndexError: list index out of range >> > > Python will be incredibly hard if you don't read any of the docs or > tutorials available. > > -- > ~Ethan~ > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From Seymore4Head at Hotmail.invalid Wed Sep 3 14:49:01 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Wed, 03 Sep 2014 14:49:01 -0400 Subject: Python is going to be hard References: Message-ID: <9eoe0apt76pbd5slks20bjaq24m5mrqe3f@4ax.com> On Wed, 03 Sep 2014 14:10:42 -0400, Seymore4Head wrote: >import math >import random >import sys >b=[] >steve = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] >for x in steve: > print (steve[x]) > >Traceback (most recent call last): > File "C:\Functions\blank.py", line 7, in > print (steve[x]) >IndexError: list index out of range Ok, I understand now that x is actually the first item in the list. What I want is a loop that goes from 1 to the total number of items in the list steve. Thanks From Seymore4Head at Hotmail.invalid Wed Sep 3 14:50:23 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Wed, 03 Sep 2014 14:50:23 -0400 Subject: Python is going to be hard References: <20140903111904.0500bd47@rg.highlandtechnology.com> Message-ID: On Wed, 3 Sep 2014 11:19:04 -0700, Rob Gaddi wrote: >On Wed, 03 Sep 2014 14:10:42 -0400 >Seymore4Head wrote: > >> import math >> import random >> import sys >> b=[] >> steve = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] >> for x in steve: >> print (steve[x]) >> >> Traceback (most recent call last): >> File "C:\Functions\blank.py", line 7, in >> print (steve[x]) >> IndexError: list index out of range > >You're failing to go through the basic tutorials, and blaming the >language when you don't understand things. > >'for x in steve' does not sweep x over the indices of steve. 'for x in >steve' sweeps x over the sequential _values_ in steve. This would have >been clear if you were to add a print(x) into the loop. Yes print(x) does make that clear Thanks From Seymore4Head at Hotmail.invalid Wed Sep 3 14:52:18 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Wed, 03 Sep 2014 14:52:18 -0400 Subject: Python is going to be hard References: <54075CE6.20405@mrabarnett.plus.com> Message-ID: On Wed, 3 Sep 2014 13:28:39 -0500, Skip Montanaro wrote: >On Wed, Sep 3, 2014 at 1:24 PM, MRAB wrote: >> Iterating over a list yields its contents, not indexes. > >Unlike in JavaScript. Not sure where the OP is coming from, but that >"feature" of JavaScript threw me when I first encountered it. My guess >would be that his prior experience includes (at least) JS. > >Skip Actually it was BASIC some 30 years ago. I never got too good at BASIC and it doesn't look like I am going to get too good at Python either. :) From Seymore4Head at Hotmail.invalid Wed Sep 3 14:52:56 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Wed, 03 Sep 2014 14:52:56 -0400 Subject: Python is going to be hard References: Message-ID: On Wed, 3 Sep 2014 18:17:27 +0000 (UTC), John Gordon wrote: >In Seymore4Head writes: > >> import math >> import random >> import sys > >Why are you importing these modules if they're not used? > >> b=[] > >Likewise b is not used. > >> steve = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] >> for x in steve: >> print (steve[x]) > >As you step through the loop, x becomes each successive item in the 'steve' >list. Therefore, you probably want to print just plain x, not steve[x]. > >> Traceback (most recent call last): >> File "C:\Functions\blank.py", line 7, in >> print (steve[x]) >> IndexError: list index out of range > >There are fewer than 13 items in steve, so when x reaches 13 this error >pops up. I see that now. Thanks From ethan at stoneleaf.us Wed Sep 3 14:55:13 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 03 Sep 2014 11:55:13 -0700 Subject: Python is going to be hard In-Reply-To: <9eoe0apt76pbd5slks20bjaq24m5mrqe3f@4ax.com> References: <9eoe0apt76pbd5slks20bjaq24m5mrqe3f@4ax.com> Message-ID: <54076411.8080507@stoneleaf.us> On 09/03/2014 11:49 AM, Seymore4Head wrote: > On Wed, 03 Sep 2014 14:10:42 -0400, Seymore4Head > wrote: > >> import math >> import random >> import sys >> b=[] >> steve = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] >> for x in steve: >> print (steve[x]) >> >> Traceback (most recent call last): >> File "C:\Functions\blank.py", line 7, in >> print (steve[x]) >> IndexError: list index out of range > > Ok, I understand now that x is actually the first item in the list. > What I want is a loop that goes from 1 to the total number of items in > the list steve. No, you don't understand yet. The /first/ time through the loop 'x' is the first item in the list. The /second/ time through the loop 'x' is the second item in the list. The /third/ time through the loop 'x' is the third item in the list. . . . Keep persisting! -- ~Ethan~ From Seymore4Head at Hotmail.invalid Wed Sep 3 14:56:46 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Wed, 03 Sep 2014 14:56:46 -0400 Subject: Python is going to be hard References: <54075F0A.60300@stoneleaf.us> Message-ID: On Wed, 3 Sep 2014 15:44:47 -0300, Juan Christian wrote: >I'm learning Python using this mailist, and the Tutor mailist, reading the >docs and watching this course, Python Fundamentals ( >http://www.pluralsight.com/training/Courses/TableOfContents/python-fundamentals >). > >Python is really easy and useful, OP don't blame the language because you >didn't understood it yet, just persist. > I don't think I have seen a link to that one yet. I have saved all the links I have seen posted here. I haven't tried all of them yet. Thanks From rgaddi at technologyhighland.invalid Wed Sep 3 15:01:18 2014 From: rgaddi at technologyhighland.invalid (Rob Gaddi) Date: Wed, 3 Sep 2014 12:01:18 -0700 Subject: Python is going to be hard References: <9eoe0apt76pbd5slks20bjaq24m5mrqe3f@4ax.com> Message-ID: <20140903120118.550e36ef@rg.highlandtechnology.com> On Wed, 03 Sep 2014 11:55:13 -0700 Ethan Furman wrote: > On 09/03/2014 11:49 AM, Seymore4Head wrote: > > On Wed, 03 Sep 2014 14:10:42 -0400, Seymore4Head > > wrote: > > > >> import math > >> import random > >> import sys > >> b=[] > >> steve = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] > >> for x in steve: > >> print (steve[x]) > >> > >> Traceback (most recent call last): > >> File "C:\Functions\blank.py", line 7, in > >> print (steve[x]) > >> IndexError: list index out of range > > > > Ok, I understand now that x is actually the first item in the list. > > What I want is a loop that goes from 1 to the total number of items in > > the list steve. > > No, you don't understand yet. > > The /first/ time through the loop 'x' is the first item in the list. > > The /second/ time through the loop 'x' is the second item in the list. > > The /third/ time through the loop 'x' is the third item in the list. > > . . . > > Keep persisting! > > -- > ~Ethan~ Python 'for' is better read as 'for each'. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From ian.g.kelly at gmail.com Wed Sep 3 15:11:51 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 3 Sep 2014 13:11:51 -0600 Subject: Python is going to be hard In-Reply-To: <9eoe0apt76pbd5slks20bjaq24m5mrqe3f@4ax.com> References: <9eoe0apt76pbd5slks20bjaq24m5mrqe3f@4ax.com> Message-ID: On Wed, Sep 3, 2014 at 12:49 PM, Seymore4Head wrote: > On Wed, 03 Sep 2014 14:10:42 -0400, Seymore4Head > wrote: > >>import math >>import random >>import sys >>b=[] >>steve = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] >>for x in steve: >> print (steve[x]) >> >>Traceback (most recent call last): >> File "C:\Functions\blank.py", line 7, in >> print (steve[x]) >>IndexError: list index out of range > > Ok, I understand now that x is actually the first item in the list. > What I want is a loop that goes from 1 to the total number of items in > the list steve. If you want the indexes also, you can do this: for i, x in enumerate(steve): print(i, x) If you really want just the indexes and not the values, then you can do this: for i in range(len(steve)): print(i) Most of the time though you will not need the indexes, and it will be simpler just to work with the values by looping directly over the list. From Seymore4Head at Hotmail.invalid Wed Sep 3 15:22:24 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Wed, 03 Sep 2014 15:22:24 -0400 Subject: Python is going to be hard References: <9eoe0apt76pbd5slks20bjaq24m5mrqe3f@4ax.com> Message-ID: <1dqe0a5p2eepuie3nhi6tiul7aah70jnjl@4ax.com> On Wed, 3 Sep 2014 13:11:51 -0600, Ian Kelly wrote: >On Wed, Sep 3, 2014 at 12:49 PM, Seymore4Head > wrote: >> On Wed, 03 Sep 2014 14:10:42 -0400, Seymore4Head >> wrote: >> >>>import math >>>import random >>>import sys >>>b=[] >>>steve = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] >>>for x in steve: >>> print (steve[x]) >>> >>>Traceback (most recent call last): >>> File "C:\Functions\blank.py", line 7, in >>> print (steve[x]) >>>IndexError: list index out of range >> >> Ok, I understand now that x is actually the first item in the list. >> What I want is a loop that goes from 1 to the total number of items in >> the list steve. > >If you want the indexes also, you can do this: > >for i, x in enumerate(steve): > print(i, x) > >If you really want just the indexes and not the values, then you can do this: > >for i in range(len(steve)): > print(i) > >Most of the time though you will not need the indexes, and it will be >simpler just to work with the values by looping directly over the >list. I figured it out now. I was expecting x to be a number and not an item. I used for i in range(len(steve)): Thanks Printing x to see what it is instead of assuming what it is really helps. I am getting there. I just have to take smaller steps. From ethan at stoneleaf.us Wed Sep 3 15:49:23 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 03 Sep 2014 12:49:23 -0700 Subject: Python is going to be hard In-Reply-To: References: Message-ID: <540770C3.1030708@stoneleaf.us> On 09/03/2014 11:41 AM, Seymore4Head wrote: > On Wed, 03 Sep 2014 11:33:46 -0700, Ethan Furman wrote: >> >> Python will be incredibly hard if you don't read any of the docs or tutorials available. > > You can't accuse me of that. I have actually read quite a bit. I may > not be picking it up, but I am trying. In that case I apologize for my remark. Keep trying -- once you get a handle on Python it is a very enjoyable language to use. -- ~Ethan~ From Joshua.R.English at gmail.com Wed Sep 3 16:32:12 2014 From: Joshua.R.English at gmail.com (Josh English) Date: Wed, 3 Sep 2014 13:32:12 -0700 (PDT) Subject: Storing instances using jsonpickle Message-ID: I am using jsonpickle to store instances of an object into separate data files. If I make any changes to the original class definition of the object, when I recreate my stored instances, they are recreated using the original class definition, so any new attributes, methods, or properties, are lost. I think this is happening because JSON is internalizing the class definition, ignoring the updates. Is this true? Is it possible to refresh JSON's knowledge of a class? From ned at nedbatchelder.com Wed Sep 3 16:52:50 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Wed, 03 Sep 2014 16:52:50 -0400 Subject: Storing instances using jsonpickle In-Reply-To: References: Message-ID: On 9/3/14 4:32 PM, Josh English wrote: > I am using jsonpickle to store instances of an object into separate data files. > > If I make any changes to the original class definition of the object, when I recreate my stored instances, they are recreated using the original class definition, so any new attributes, methods, or properties, are lost. > > I think this is happening because JSON is internalizing the class definition, ignoring the updates. Is this true? Is it possible to refresh JSON's knowledge of a class? > Pickle (and it looks like jsonpickle) does not invoke the class' __init__ method when it reconstitutes objects. Your new __init__ is not being run, so new attributes it defines are not being created. This is one of the reasons that people avoid pickle: being completely implicit is very handy, but also fragile. -- Ned Batchelder, http://nedbatchelder.com From denismfmcmahon at gmail.com Wed Sep 3 16:55:27 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Wed, 3 Sep 2014 20:55:27 +0000 (UTC) Subject: Python is going to be hard References: Message-ID: On Wed, 03 Sep 2014 14:10:42 -0400, Seymore4Head wrote: > import math import random import sys b=[] > steve = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] > for x in steve: > print (steve[x]) > > Traceback (most recent call last): > File "C:\Functions\blank.py", line 7, in > print (steve[x]) > IndexError: list index out of range x is the value, not the index Try: steve = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] for x in steve: print (x) or if you want to use the index: for x in range(len(steve)): print (steve[x]) -- Denis McMahon, denismfmcmahon at gmail.com From none at mailinator.com Wed Sep 3 17:37:58 2014 From: none at mailinator.com (mm0fmf) Date: Wed, 03 Sep 2014 22:37:58 +0100 Subject: Python is going to be hard In-Reply-To: References: Message-ID: On 03/09/2014 19:52, Seymore4Head wrote: > I see that now. > Thanks > Maybe some comments in your code would help you? And also posting an on-topic title would help too. From jaron.breen at gmail.com Wed Sep 3 17:52:54 2014 From: jaron.breen at gmail.com (jaron.breen at gmail.com) Date: Wed, 3 Sep 2014 14:52:54 -0700 (PDT) Subject: O'Reilly Python Certification In-Reply-To: References: Message-ID: Ethan, Steve, Tim, and others: I'm thinking of taking the program. How long, in hours, does it take to complete all four Python courses? -Jaron Breen On Wednesday, December 15, 2010 12:54:27 PM UTC-5, Ethan Furman wrote: > So I just got an e-mail from O'Reilly and their School of Technology > about a Python Certification course... anybody have any experience with > this? > > It also says Steve Holden is involved -- is this True? (Steve?) > > ~Ethan~ > > PS > > Can you tell I've been programming? ;) From ethan at stoneleaf.us Wed Sep 3 18:12:16 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 03 Sep 2014 15:12:16 -0700 Subject: O'Reilly Python Certification In-Reply-To: References: Message-ID: <54079240.5080007@stoneleaf.us> On 09/03/2014 02:52 PM, jaron.breen at gmail.com wrote: > Ethan, Steve, Tim, and others: > > I'm thinking of taking the program. How long, in hours, does it take to complete all four Python courses? That is an impossible question to answer accurately. I took the classes already having extensive knowledge of Python, which meant basically reading through the material, and doing the homework -- so probably an hour for reading, hour for the homework, or two hours per chapter, blah, blah, blah, roughly 30 hours for each class. So that's probably a mininum. Oh, and I also read pretty quickly. So if your reading speed is average or slow you should probably add another 30; if you're learning instead of reviewing add another 30; if applying new concepts to code does not come easy add another 30... So anywhere from 30 - 120 hours per class, or 120 - 480 for the course. I did say you wouldn't get an accurate answer, right? ;) I don't know who's teaching the classes now, but I was lucky enough to work with Kirby Urner and Steve Holden, and they were both great instructors. -- ~Ethan~ From Joshua.R.English at gmail.com Wed Sep 3 18:30:00 2014 From: Joshua.R.English at gmail.com (Josh English) Date: Wed, 3 Sep 2014 15:30:00 -0700 (PDT) Subject: Storing instances using jsonpickle In-Reply-To: References: Message-ID: <46e782a5-b087-4f95-aadb-26e233bf5419@googlegroups.com> On Wednesday, September 3, 2014 1:53:23 PM UTC-7, Ned Batchelder wrote: > Pickle (and it looks like jsonpickle) does not invoke the class' > __init__ method when it reconstitutes objects. Your new __init__ is not > being run, so new attributes it defines are not being created. > > This is one of the reasons that people avoid pickle: being completely > implicit is very handy, but also fragile. > I seem to remember having this exact same frustration when I used pickle and shelve 15 years ago. I had hoped to have another way around this. I spent over a decade trying to make an XML-based database work, in part because of this limitation. Some days I get so frustrated I think the only data structure I should ever use is a dictionary. I suppose to make this sort of thing work, I should look at creating custom json encoders and decoders. Thanks, Josh From chris.hinsley at gmail.com Wed Sep 3 19:05:37 2014 From: chris.hinsley at gmail.com (Chris Hinsley) Date: Thu, 4 Sep 2014 00:05:37 +0100 Subject: Latest Chess prog Message-ID: <2014090400053721671-chrishinsley@gmailcom> Latest version of Chess test prog for anyone who might be interested. It does not do en-passon or castling. Best Regards Chris #!/opt/local/bin/pypy -u -tt #!/opt/local/bin/pypy -u -tt -m cProfile # -*- coding: utf-8 -*- # Copyright (C) 2013-2014 Chris Hinsley, GPL V3 License import sys, os, time from operator import itemgetter from array import array MAX_PLY = 10 MAX_TIME_PER_MOVE = 10 PIECE_VALUE_FACTOR = 3 KING_VALUE, QUEEN_VALUE, ROOK_VALUE = 1000000, 9 * PIECE_VALUE_FACTOR, 5 * PIECE_VALUE_FACTOR BISHOP_VALUE, KNIGHT_VALUE, PAWN_VALUE = 3 * PIECE_VALUE_FACTOR, 3 * PIECE_VALUE_FACTOR, 1 * PIECE_VALUE_FACTOR EMPTY, WHITE, BLACK = 0, 1, -1 NO_CAPTURE, MAY_CAPTURE, MUST_CAPTURE = 0, 1, 2 piece_type = {' ' : EMPTY, 'K' : BLACK, 'Q' : BLACK, 'R' : BLACK, 'B' : BLACK, 'N' : BLACK, 'P' : BLACK, \ 'k' : WHITE, 'q' : WHITE, 'r' : WHITE, 'b' : WHITE, 'n' : WHITE, 'p' : WHITE} def display_board(board): print print ' a b c d e f g h' print '+---+---+---+---+---+---+---+---+' for row in range(8): for col in range(8): print '| %c' % board[row * 8 + col], print '|', 8 - row print '+---+---+---+---+---+---+---+---+' print def piece_moves(board, index, vectors): piece = board[index] type = piece_type[piece] promote = 'QRBN' if type == BLACK else 'qrbn' cy, cx = divmod(index, 8) for dx, dy, length, flag in vectors: x, y = cx, cy if length == 0: if piece == 'P': length = 2 if (y == 1) else 1 else: length = 2 if (y == 6) else 1 while length > 0: x += dx; y += dy; length -= 1 if (x < 0) or (x >=8) or (y < 0) or (y >= 8): break newindex = y * 8 + x newpiece = board[newindex] newtype = piece_type[newpiece] if newtype == type: break if (flag == NO_CAPTURE) and (newtype != EMPTY): break if (flag == MUST_CAPTURE) and (newtype == EMPTY): break board[index] = ' ' if (y == 0 or y == 7) and piece in 'Pp': for promote_piece in promote: board[newindex] = promote_piece yield board else: board[newindex] = piece yield board board[index], board[newindex] = piece, newpiece if (flag == MAY_CAPTURE) and (newtype != EMPTY): break def piece_scans(board, index, vectors): cy, cx = divmod(index, 8) for dx, dy, length in vectors: x, y = cx, cy while length > 0: x += dx; y += dy; length -= 1 if (0 <= x < 8) and (0 <= y < 8): piece = board[y * 8 + x] if piece != ' ': yield piece break black_pawn_vectors = [(-1, 1, 1), (1, 1, 1)] white_pawn_vectors = [(-1, -1, 1), (1, -1, 1)] bishop_vectors = [(x, y, 7) for x, y in [(-1, -1), (1, 1), (-1, 1), (1, -1)]] rook_vectors = [(x, y, 7) for x, y in [(0, -1), (-1, 0), (0, 1), (1, 0)]] knight_vectors = [(x, y, 1) for x, y in [(-2, 1), (2, -1), (2, 1), (-2, -1), (-1, -2), (-1, 2), (1, -2), (1, 2)]] queen_vectors = bishop_vectors + rook_vectors king_vectors = [(x, y, 1) for x, y, _ in queen_vectors] black_pawn_moves = [(0, 1, 0, NO_CAPTURE), (-1, 1, 1, MUST_CAPTURE), (1, 1, 1, MUST_CAPTURE)] white_pawn_moves = [(x, -1, length, flag) for x, _, length, flag in black_pawn_moves] rook_moves = [(x, y, length, MAY_CAPTURE) for x, y, length in rook_vectors] bishop_moves = [(x, y, length, MAY_CAPTURE) for x, y, length in bishop_vectors] knight_moves = [(x, y, length, MAY_CAPTURE) for x, y, length in knight_vectors] queen_moves = bishop_moves + rook_moves king_moves = [(x, y, 1, flag) for x, y, _, flag in queen_moves] moves = {'P' : black_pawn_moves, 'p' : white_pawn_moves, 'R' : rook_moves, 'r' : rook_moves, \ 'B' : bishop_moves, 'b' : bishop_moves, 'N' : knight_moves, 'n' : knight_moves, \ 'Q' : queen_moves, 'q' : queen_moves, 'K' : king_moves, 'k' : king_moves} white_scans = [('QB', bishop_vectors), ('QR', rook_vectors), ('N', knight_vectors), ('K', king_vectors), ('P', white_pawn_vectors)] black_scans = [('qb', bishop_vectors), ('qr', rook_vectors), ('n', knight_vectors), ('k', king_vectors), ('p', black_pawn_vectors)] def in_check(board, colour): if colour == BLACK: king_piece, scans = 'K', black_scans else: king_piece, scans = 'k', white_scans king_index = array.index(board, king_piece) for test_pieces, vectors in scans: pieces = [piece for piece in piece_scans(board, king_index, vectors)] for piece in test_pieces: if piece in pieces: return True return False def all_moves(board, colour): for index, piece in enumerate(board): if piece_type[piece] == colour: for new_board in piece_moves(board, index, moves[piece]): if not in_check(new_board, colour): yield new_board piece_values = {'K' : (KING_VALUE, 0), 'k' : (0, KING_VALUE), 'Q' : (QUEEN_VALUE, 0), 'q' : (0, QUEEN_VALUE), \ 'R' : (ROOK_VALUE, 0), 'r' : (0, ROOK_VALUE), 'B' : (BISHOP_VALUE, 0), 'b' : (0, BISHOP_VALUE), \ 'N' : (KNIGHT_VALUE, 0), 'n' : (0, KNIGHT_VALUE), 'P' : (PAWN_VALUE, 0), 'p' : (0, PAWN_VALUE)} generic_position_values = [0, 0, 0, 0, 0, 0, 0, 0, \ 0, 1, 1, 1, 1, 1, 1, 0, \ 0, 1, 2, 2, 2, 2, 1, 0, \ 0, 1, 2, 3, 3, 2, 1, 0, \ 0, 1, 2, 3, 3, 2, 1, 0, \ 0, 1, 2, 2, 2, 2, 1, 0, \ 0, 1, 1, 1, 1, 1, 1, 0, \ 0, 0, 0, 0, 0, 0, 0, 0] white_king_position_values = [0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 3, 3, 3, 3, 3, 3, 3, 3] black_king_position_values = [3, 3, 3, 3, 3, 3, 3, 3, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0] piece_positions = {'K' : black_king_position_values, 'k' : white_king_position_values, \ 'P' : generic_position_values, 'p' : generic_position_values, \ 'N' : generic_position_values, 'n' : generic_position_values, \ 'B' : generic_position_values, 'b' : generic_position_values, \ 'R' : generic_position_values, 'r' : generic_position_values, \ 'Q' : generic_position_values, 'q' : generic_position_values} def evaluate(board): black_score, white_score = 0, 0 for index, piece in enumerate(board): type = piece_type[piece] if type != EMPTY: position_value = piece_positions[piece][index] if type == BLACK: black_score += position_value else: white_score += position_value black_value, white_value = piece_values[piece] black_score += black_value white_score += white_value return white_score - black_score start_time = time.time() def next_move(board, colour, alpha, beta, ply): global start_time if ply <= 0: return evaluate(board) * colour for new_board in all_moves(board[:], colour): alpha = max(alpha, -next_move(new_board, -colour, -beta, -alpha, ply - 1)) if alpha >= beta: break if (time.time() - start_time) > MAX_TIME_PER_MOVE: break return alpha def best_move(board, colour): global start_time all_boards = [(evaluate(new_board) * colour, new_board[:]) for new_board in all_moves(board, colour)] all_boards = sorted(all_boards, key = itemgetter(0), reverse = True) best_board, best_ply_board, start_time = board, board, time.time() for ply in range(1, MAX_PLY): print '\nPly =', ply alpha, beta = -KING_VALUE * 10, KING_VALUE * 10 for new_board in all_boards: score = -next_move(new_board[1], -colour, -beta, -alpha, ply - 1) if (time.time() - start_time) > MAX_TIME_PER_MOVE: return best_board if score > alpha: alpha, best_ply_board = score, new_board[1] print '\b*', else: print '\b.', best_board = best_ply_board return best_board def main(): board = array('c', 'RNBQKBNRPPPPPPPP pppppppprnbqkbnr') colour = WHITE os.system(['clear','cls'][os.name=='nt']) display_board(board) while True: print 'White to move:' if colour == WHITE else 'Black to move:' board = best_move(board, colour) colour = -colour os.system(['clear','cls'][os.name=='nt']) display_board(board) #raw_input() if __name__ == '__main__': main() From python at mrabarnett.plus.com Wed Sep 3 19:39:07 2014 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 04 Sep 2014 00:39:07 +0100 Subject: Storing instances using jsonpickle In-Reply-To: <46e782a5-b087-4f95-aadb-26e233bf5419@googlegroups.com> References: <46e782a5-b087-4f95-aadb-26e233bf5419@googlegroups.com> Message-ID: <5407A69B.3030707@mrabarnett.plus.com> On 2014-09-03 23:30, Josh English wrote: > On Wednesday, September 3, 2014 1:53:23 PM UTC-7, Ned Batchelder > wrote: > >> Pickle (and it looks like jsonpickle) does not invoke the class' >> __init__ method when it reconstitutes objects. Your new __init__ >> is not being run, so new attributes it defines are not being >> created. >> >> This is one of the reasons that people avoid pickle: being >> completely implicit is very handy, but also fragile. >> > > I seem to remember having this exact same frustration when I used > pickle and shelve 15 years ago. I had hoped to have another way > around this. I spent over a decade trying to make an XML-based > database work, in part because of this limitation. > > Some days I get so frustrated I think the only data structure I > should ever use is a dictionary. > > I suppose to make this sort of thing work, I should look at creating > custom json encoders and decoders. > I occasionally think about a superset of JSON, called, say, "pyson" ... ah, name already taken! :-( In summary, it would be something like this: JSON supports int, float, string, None (as 'null'), list and dict (the key must be string). It would add tuples, delimited by (...), which are not used otherwise (no expressions): () => () (0, ) => (0) (0, 1) => (0, 1) The key of a dict could also be int, float, or tuple. It could support other classes, and could handle named arguments. For example, sets: To encode {0, 1, 2): Look in encoder dict for encoder function with class's name ('set') and call it, passing object. Encoder returns positional and keyword arguments: [0, 1, 2] and {}. Output name, followed by encoded arguments in parentheses. Encoder for set: def encode_set(obj): return list(obj), {} To decode 'set(0, 1, 2)': Parse name: 'set'. Parse contents of parentheses: [0, 1, 2] and {}. Look in decoder dict for decoder function with given name ('set') and call it, passing arguments. Result would be {0, 1, 2}. Decoder for set: def decode_set(*args): return set(args) pyson.dumps({0, 1, 2}, decoders={'set': decode_set}) would return 'set(0, 1, 2)'. pyson.loads('set(0, 1, 2)', encoders={'set': encode_set}) would return {0, 1, 2}. From denismfmcmahon at gmail.com Wed Sep 3 21:11:32 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Thu, 4 Sep 2014 01:11:32 +0000 (UTC) Subject: Storing instances using jsonpickle References: <46e782a5-b087-4f95-aadb-26e233bf5419@googlegroups.com> Message-ID: On Thu, 04 Sep 2014 00:39:07 +0100, MRAB wrote: > It would add tuples, delimited by (...), which are not used otherwise > (no expressions): I guess <> and () are both unused as delims by json at present. I like the idea of other key types than string. -- Denis McMahon, denismfmcmahon at gmail.com From rustompmody at gmail.com Wed Sep 3 21:48:47 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 3 Sep 2014 18:48:47 -0700 (PDT) Subject: Python is going to be hard In-Reply-To: References: Message-ID: <51acfec6-6b7b-4773-8d70-0360381bbed1@googlegroups.com> On Wednesday, September 3, 2014 11:41:27 PM UTC+5:30, Seymore4Head wrote: > import math > import random > import sys > b=[] > steve = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] > for x in steve: > print (steve[x]) > Traceback (most recent call last): > print (steve[x]) > IndexError: list index out of range $ python Python 2.7.8 (default, Aug 23 2014, 21:00:50) [GCC 4.9.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> steve = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] >>> steve [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] >>> # You can see steve (strange name choice) without any printing >>> [x for x in steve] [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] >>> # A bit long-winded but good to get used to; And NO PRINT >>> [(x,y) for (x,y) in zip(steve, range(100))] [(1, 0), (1, 1), (2, 2), (3, 3), (5, 4), (8, 5), (13, 6), (21, 7), (34, 8), (55, 9), (89, 10)] >>> # NO PRINT; but whats that 100 there? >>> [(x,y) for (x,y) in zip(steve, range(len(steve)))] [(1, 0), (1, 1), (2, 2), (3, 3), (5, 4), (8, 5), (13, 6), (21, 7), (34, 8), (55, 9), (89, 10)] >>> # NO PRINT; but sufficiently common that it needs a shortform >>> [(x,y) for (x,y) in enumerate(steve)] [(0, 1), (1, 1), (2, 2), (3, 3), (4, 5), (5, 8), (6, 13), (7, 21), (8, 34), (9, 55), (10, 89)] >>> # NO PRINT but why not just the simple >>> enumerate(steve) >>> # Hmm whats that?? >>> list(enumerate(steve)) [(0, 1), (1, 1), (2, 2), (3, 3), (4, 5), (5, 8), (6, 13), (7, 21), (8, 34), (9, 55), (10, 89)] >>> NO PRINT From steve+comp.lang.python at pearwood.info Wed Sep 3 21:54:04 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 04 Sep 2014 11:54:04 +1000 Subject: I have tried and errored a reasonable amount of times References: <5406726f$0$6512$c3e8da3$5496439d@news.astraweb.com> <4af60c7a-f4d6-4aa7-b181-fe768ea6f731@googlegroups.com> <5406c052$0$29876$c3e8da3$5496439d@news.astraweb.com> <87a96hcfml.fsf@elektro.pacujo.net> Message-ID: <5407c63c$0$29967$c3e8da3$5496439d@news.astraweb.com> Marko Rauhamaa wrote: > Steven D'Aprano : > >> Who uses + for disjunction (? OR) and concatenation for conjunction (? >> AND)? That's crazy notation. > > That's the classic Boolean algebraic notation. Says who? (Apart from you, obviously :-) Since when? I've never seen it in *any* discussion of Boolean algebra. Since I answer my own question below (spoiler: George Boole), my questions are rhetorical. Mathworld says: A Boolean algebra is a mathematical structure that is similar to a Boolean ring, but that is defined using the meet and join operators instead of the usual addition and multiplication operators. and lists the operators as: ^ (logical AND, or "wedge") and v (logical OR, or "vee") http://mathworld.wolfram.com/BooleanAlgebra.html Wikipedia lists the operators as And (conjunction), denoted x?y (sometimes x AND y or Kxy) Or (disjunction), denoted x?y (sometimes x OR y or Axy) https://en.wikipedia.org/wiki/Boolean_algebra#Operations So it seems that mathematicians have all but entirely abandoned the old notation, although they are certainly aware that x?y is analogous to xy with both x, y elements of {0, 1}, and similarly for x?y, although the analogy is terrible for ?. 1+1 = 2, not 1. If you perform the addition modulo 2, then 1+1 = 0, which would make + analogous to XOR, not OR. I had to go all the way back to George Boole's seminal work "An Investigation Of The Laws Of Thought" in 1854 to find somebody using that notation, and he had an excuse, namely he was inventing the subject. http://gutenberg.org/ebooks/15114 Since Boole isn't with us any more, having died in 1864, my question still stands: who would be so foolish to use this notation in the 21st century? Answer: engineers. http://www.allaboutcircuits.com/vol_4/chpt_7/2.html -- Steven From rosuav at gmail.com Wed Sep 3 21:56:31 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 4 Sep 2014 11:56:31 +1000 Subject: Python is going to be hard In-Reply-To: <51acfec6-6b7b-4773-8d70-0360381bbed1@googlegroups.com> References: <51acfec6-6b7b-4773-8d70-0360381bbed1@googlegroups.com> Message-ID: On Thu, Sep 4, 2014 at 11:48 AM, Rustom Mody wrote: >>>> NO PRINT Yes, or the OP could work with actual saved .py files and the reliability that comes from predictable execution environments... and use print. Why are you so dead against print? ChrisA From python.list at tim.thechases.com Wed Sep 3 21:59:58 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 3 Sep 2014 20:59:58 -0500 Subject: Best way to filter parts of a email.message.Message Message-ID: <20140903205958.119351c8@bigbox.christie.dr> I'd like to do something like the following pseudocode existing_message = mailbox[key] # an email.message.Message new_message = email.message.Message() for part in existing_message.walk(): if passes_test(part): new_message.add(part) # need proper call here else: log("skipping %r" % part) or alternatively something like this pseudocode inverse new_message = copy.copy(existing_message) for part in new_message.walk(): if fails_test(part): new_message.magic_delete_part_method(part) However, I want to make sure that just the selected mime-parts get eliminated and that everything else (other mime-parts as well as headers) gets copied over. Points giving me minor fits: - mime-parts can be nested, so I need to recursively handle them - making sure that if the source is/isn't multipart, that the resulting new message is the same - ensuring that headers get preserved (including the order) Is there an obvious way to do this without rolling up my sleeves and getting into the source for email.message and friends? Thanks, -tkc From rosuav at gmail.com Wed Sep 3 22:03:06 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 4 Sep 2014 12:03:06 +1000 Subject: I have tried and errored a reasonable amount of times In-Reply-To: <5407c63c$0$29967$c3e8da3$5496439d@news.astraweb.com> References: <5406726f$0$6512$c3e8da3$5496439d@news.astraweb.com> <4af60c7a-f4d6-4aa7-b181-fe768ea6f731@googlegroups.com> <5406c052$0$29876$c3e8da3$5496439d@news.astraweb.com> <87a96hcfml.fsf@elektro.pacujo.net> <5407c63c$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Sep 4, 2014 at 11:54 AM, Steven D'Aprano wrote: > although the > analogy is terrible for ?. 1+1 = 2, not 1. I wouldn't say terrible. Unclear perhaps, but functional. Try this exercise: false, true = 0, 1 # or use an old Python if true + true: print("true OR true is true") As long as you accept that any non-zero value is true, and as long as 'and' and 'or' are the only operations you use (you can add 'not' as long as it's defined the same way: "false if x else true"), addition for or works fine. ChrisA From rustompmody at gmail.com Wed Sep 3 22:10:57 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 3 Sep 2014 19:10:57 -0700 (PDT) Subject: Python is going to be hard In-Reply-To: References: <51acfec6-6b7b-4773-8d70-0360381bbed1@googlegroups.com> Message-ID: <612dd9e6-653b-4e07-aebe-ffd31eec2a9e@googlegroups.com> On Thursday, September 4, 2014 7:26:56 AM UTC+5:30, Chris Angelico wrote: > On Thu, Sep 4, 2014 at 11:48 AM, Rustom Mody wrote: > >>>> NO PRINT > Why are you so dead against print? Because it heralds a typical noob code-smell [especially when the OP admits that BASIC is his background] > Yes, or the OP could work with actual saved .py files and the > reliability that comes from predictable execution environments... and > use print. Dunno what you are talking about The interpreter-REPL is less reliable than a script? From steve+comp.lang.python at pearwood.info Wed Sep 3 22:11:15 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 04 Sep 2014 12:11:15 +1000 Subject: Python is going to be hard References: <9eoe0apt76pbd5slks20bjaq24m5mrqe3f@4ax.com> Message-ID: <5407ca43$0$29980$c3e8da3$5496439d@news.astraweb.com> Seymore4Head wrote: > Ok, I understand now that x is actually the first item in the list. > What I want is a loop that goes from 1 to the total number of items in > the list steve. 99% of the time, you don't want that at all. Trust me, iterating over the values in the list is *nearly* always the right solution. But for those times you actually do want 1...N, use the range() function. Remember that in Python, ranges are "half open": the start value is *included*, but the end value is *excluded*. Also, the start value defaults to 0. So for example, if you wanted the numbers 1...5: range(5) --> range(0, 5) --> [0, 1, 2, 3, 4] range(1, 5+1) --> range(1, 6) --> [1, 2, 3, 4, 5] So to iterate over 1 to the number of items in list `steve`: for i in range(1, len(steve)+1): print(i) But if you are ever tempted to write something like this: for i in range(1, len(steve)+1): x = steve[i-i] # adjust the index from 1-based to 0-based print(i, x) we will take you out and slap you with a rather large hallibut https://www.youtube.com/watch?v=IhJQp-q1Y1s *wink* The right way to do that is: for i, x in enumerate(steve, 1): print(i, x) -- Steven From ned at nedbatchelder.com Wed Sep 3 22:18:29 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Wed, 03 Sep 2014 22:18:29 -0400 Subject: Storing instances using jsonpickle In-Reply-To: <46e782a5-b087-4f95-aadb-26e233bf5419@googlegroups.com> References: <46e782a5-b087-4f95-aadb-26e233bf5419@googlegroups.com> Message-ID: On 9/3/14 6:30 PM, Josh English wrote: > On Wednesday, September 3, 2014 1:53:23 PM UTC-7, Ned Batchelder wrote: > >> Pickle (and it looks like jsonpickle) does not invoke the class' >> __init__ method when it reconstitutes objects. Your new __init__ is not >> being run, so new attributes it defines are not being created. >> >> This is one of the reasons that people avoid pickle: being completely >> implicit is very handy, but also fragile. >> > > I seem to remember having this exact same frustration when I used pickle and shelve 15 years ago. I had hoped to have another way around this. I spent over a decade trying to make an XML-based database work, in part because of this limitation. > > Some days I get so frustrated I think the only data structure I should ever use is a dictionary. > > I suppose to make this sort of thing work, I should look at creating custom json encoders and decoders. > Typically, you need to decide explicitly on a serialized representation for your data. Even if it's JSON, you need to decide what that JSON looks like. Then you need to write code that converts the JSON-able data structure (dict of lists, whatever) into your object. Often a version number is a good idea so that you have some chance of using old data as your code changes. -- Ned Batchelder, http://nedbatchelder.com From rustompmody at gmail.com Wed Sep 3 22:23:19 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 3 Sep 2014 19:23:19 -0700 (PDT) Subject: I have tried and errored a reasonable amount of times In-Reply-To: <5407c63c$0$29967$c3e8da3$5496439d@news.astraweb.com> References: <5406726f$0$6512$c3e8da3$5496439d@news.astraweb.com> <4af60c7a-f4d6-4aa7-b181-fe768ea6f731@googlegroups.com> <5406c052$0$29876$c3e8da3$5496439d@news.astraweb.com> <87a96hcfml.fsf@elektro.pacujo.net> <5407c63c$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8ca0209e-42a8-4a0b-b91a-27fd3670a275@googlegroups.com> On Thursday, September 4, 2014 7:24:19 AM UTC+5:30, Steven D'Aprano wrote: > Marko Rauhamaa wrote: > > Steven D'Aprano: > >> Who uses + for disjunction (? OR) and concatenation for conjunction (? > >> AND)? That's crazy notation. > > That's the classic Boolean algebraic notation. > Says who? (Apart from you, obviously :-) Since when? I've never seen it in > *any* discussion of Boolean algebra. There are the mathematician/logicians who do boolean algebra (usually as part of lattice theory). They usually use ? ? ? The guys who (ab)use the add/multiply notations of school algebra are the electronics books ? Karnaugh maps, minimization all that stuff. One or two pages of truth tables, some of this add/mul notation and then on its all the standard logic-circuit diagrams for combinational and sequential circuits. From rosuav at gmail.com Wed Sep 3 22:25:48 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 4 Sep 2014 12:25:48 +1000 Subject: Python is going to be hard In-Reply-To: <612dd9e6-653b-4e07-aebe-ffd31eec2a9e@googlegroups.com> References: <51acfec6-6b7b-4773-8d70-0360381bbed1@googlegroups.com> <612dd9e6-653b-4e07-aebe-ffd31eec2a9e@googlegroups.com> Message-ID: On Thu, Sep 4, 2014 at 12:10 PM, Rustom Mody wrote: > On Thursday, September 4, 2014 7:26:56 AM UTC+5:30, Chris Angelico wrote: >> On Thu, Sep 4, 2014 at 11:48 AM, Rustom Mody wrote: >> >>>> NO PRINT > > >> Why are you so dead against print? > > Because it heralds a typical noob code-smell > [especially when the OP admits that BASIC is his background] And, of course, all those lovely Unix programs that produce output on stdout, they're full of code smell too, right? I don't care what someone's background is; console output is *not* code smell. Anyway, all you're doing is relying on the magic of interactive mode to call repr() and print() for you. >> Yes, or the OP could work with actual saved .py files and the >> reliability that comes from predictable execution environments... and >> use print. > > Dunno what you are talking about > > The interpreter-REPL is less reliable than a script? When you start a script, you have a consistent environment - an empty one. When you write a series of commands in the interactive interpreter, the environment for each one depends on all the preceding commands. So when you have a problem, you might have to copy and paste the entire interpreter session, rather than just the one command. ChrisA From rustompmody at gmail.com Wed Sep 3 22:33:41 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 3 Sep 2014 19:33:41 -0700 (PDT) Subject: Python is going to be hard In-Reply-To: References: <51acfec6-6b7b-4773-8d70-0360381bbed1@googlegroups.com> <612dd9e6-653b-4e07-aebe-ffd31eec2a9e@googlegroups.com> Message-ID: <08de12b8-274d-44c8-a08a-5aef2f12deee@googlegroups.com> On Thursday, September 4, 2014 7:56:31 AM UTC+5:30, Chris Angelico wrote: > On Thu, Sep 4, 2014 at 12:10 PM, Rustom Mody wrote: > > On Thursday, September 4, 2014 7:26:56 AM UTC+5:30, Chris Angelico wrote: > >> On Thu, Sep 4, 2014 at 11:48 AM, Rustom Mody wrote: > >> >>>> NO PRINT > >> Why are you so dead against print? > > Because it heralds a typical noob code-smell > > [especially when the OP admits that BASIC is his background] > And, of course, all those lovely Unix programs that produce output on > stdout, they're full of code smell too, right? I don't care what > someone's background is; console output is *not* code smell. Tell me the same after having taught a few thousand students If you are at the level of writing useful unix scripts, you are not going to be asking these questions. > Anyway, all you're doing is relying on the magic of interactive mode > to call repr() and print() for you. Yes its usually called DRY. That P in the REPL is put in a neat and nifty place. Why repeat? > >> Yes, or the OP could work with actual saved .py files and the > >> reliability that comes from predictable execution environments... and > >> use print. > > Dunno what you are talking about > > The interpreter-REPL is less reliable than a script? > When you start a script, you have a consistent environment - an empty > one. When you write a series of commands in the interactive > interpreter, the environment for each one depends on all the preceding > commands. So when you have a problem, you might have to copy and paste > the entire interpreter session, rather than just the one command. Agreed. Thats a downside. Very minor compared to the mess induced by unstructured print-filled noob code. From rustompmody at gmail.com Wed Sep 3 23:22:47 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 3 Sep 2014 20:22:47 -0700 (PDT) Subject: Python is going to be hard In-Reply-To: References: <51acfec6-6b7b-4773-8d70-0360381bbed1@googlegroups.com> Message-ID: On Thursday, September 4, 2014 7:26:56 AM UTC+5:30, Chris Angelico wrote: > On Thu, Sep 4, 2014 at 11:48 AM, Rustom Mody wrote: > >>>> NO PRINT > Yes, or the OP could work with actual saved .py files and the > reliability that comes from predictable execution environments... and > use print. Why are you so dead against print? Here is the most recent (2013) ACM/IEEE CS curriculum: www.acm.org/education/CS2013-final-report.pdf It is divided into tiers with core-tier1 being the bare minimum that all CS graduate need to know. One of (the many!) things there is this (pg 158) | Functional Programming (3 Core-Tier1 hours) | Effect-free programming | -- Function calls have no side effects, facilitating compositional reasoning | -- Variables are immutable, preventing unexpected changes to program data by other code | -- Data can be freely aliased or copied without introducing unintended effects from mutation So to answer your question: print statements are side-effecting and therefore obstruct compositional reasoning. From rosuav at gmail.com Wed Sep 3 23:49:33 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 4 Sep 2014 13:49:33 +1000 Subject: Python is going to be hard In-Reply-To: References: <51acfec6-6b7b-4773-8d70-0360381bbed1@googlegroups.com> Message-ID: On Thu, Sep 4, 2014 at 1:22 PM, Rustom Mody wrote: > | Effect-free programming > | -- Function calls have no side effects, facilitating compositional reasoning > | -- Variables are immutable, preventing unexpected changes to program data by other code > | -- Data can be freely aliased or copied without introducing unintended effects from mutation > > So to answer your question: print statements are side-effecting and therefore obstruct > compositional reasoning. Yeah, fine. One small problem: Computers aren't built to do nothing. "Effect-free programming" is utterly valueless and purposeless. To make a program actually useful, you need to have some effect somewhere. So where do you do that? Where do you permit a function with side effects? If you force *everything* to be in the return value, you lose any possibility of partial results - for instance, if it takes two weeks to render a ray-traced animation, you actually spend the entire two weeks building up a single, gigantic return value, which some outside system (which is presumably allowed to have side effects) then saves somewhere. In the meantime, you have absolutely no idea how far it's progressed - no information that it's completed frame 6 and is working on frame 7, nothing. Because telling the user anything is a side effect. And if my function f calls show_status_to_user() which has side effects, then f has side effects too, and you can no longer reason purely about f. The impurity that makes for practicality (hey, isn't there something in the Zen of Python about that?) pollutes upwards until all you'll have will be pockets of pure functional code that execute quickly enough to not need any intermediate output. That doesn't equate to "abolish print", that just means that you separate the guts from the UI - which is good advice for any system, no matter what its structure. ChrisA From cs at zip.com.au Wed Sep 3 23:52:40 2014 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 4 Sep 2014 13:52:40 +1000 Subject: Best way to filter parts of a email.message.Message In-Reply-To: <20140903205958.119351c8@bigbox.christie.dr> References: <20140903205958.119351c8@bigbox.christie.dr> Message-ID: <20140904035240.GA75238@cskk.homeip.net> On 03Sep2014 20:59, Tim Chase wrote: >- mime-parts can be nested, so I need to recursively handle them Just to this. IIRC, the MIME part delimiter is supposed to be absolute. That is, it will not occur in the nested subparts, if any. Of course that is no good to you working from outside via the email package, only if you're writing your own message dissector. Cheers, Cameron Simpson You can't wait for inspiration. You have to go after it with a club. - Jack London From ethan at stoneleaf.us Thu Sep 4 00:06:45 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 03 Sep 2014 21:06:45 -0700 Subject: Python is going to be hard In-Reply-To: References: <51acfec6-6b7b-4773-8d70-0360381bbed1@googlegroups.com> Message-ID: <5407E555.4080200@stoneleaf.us> On 09/03/2014 08:22 PM, Rustom Mody wrote: > On Thursday, September 4, 2014 7:26:56 AM UTC+5:30, Chris Angelico wrote: >> On Thu, Sep 4, 2014 at 11:48 AM, Rustom Mody wrote: >>>>>> NO PRINT > >> Yes, or the OP could work with actual saved .py files and the >> reliability that comes from predictable execution environments... and >> use print. Why are you so dead against print? > > Here is the most recent (2013) ACM/IEEE CS curriculum: > www.acm.org/education/CS2013-final-report.pdf > > It is divided into tiers with core-tier1 being the bare minimum that > all CS graduate need to know. > > One of (the many!) things there is this (pg 158) > > | Functional Programming (3 Core-Tier1 hours) > > | Effect-free programming > | -- Function calls have no side effects, facilitating compositional reasoning Lots of Python functions have side effects. > | -- Variables are immutable, preventing unexpected changes to program data by other code Lots of Python core data types are mutable. > | -- Data can be freely aliased or copied without introducing unintended effects from mutation Every mutable Python data type that is aliased can be affected by unintended mutational effects -- as well as intentional ones. > So to answer your question: print statements are side-effecting and therefore obstruct > compositional reasoning. Ridiculous argument after ridiculous argument. Please do not waste our time with nonsense. -- ~Ethan~ From rosuav at gmail.com Thu Sep 4 00:08:43 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 4 Sep 2014 14:08:43 +1000 Subject: Best way to filter parts of a email.message.Message In-Reply-To: <20140904035240.GA75238@cskk.homeip.net> References: <20140903205958.119351c8@bigbox.christie.dr> <20140904035240.GA75238@cskk.homeip.net> Message-ID: On Thu, Sep 4, 2014 at 1:52 PM, Cameron Simpson wrote: > On 03Sep2014 20:59, Tim Chase wrote: >> >> - mime-parts can be nested, so I need to recursively handle them > > > Just to this. IIRC, the MIME part delimiter is supposed to be absolute. That > is, it will not occur in the nested subparts, if any. I think the point here is that the validity check of a mime-part may involve checking sub-parts - eg the message is a mailing list digest (with one part per actual message), and some of those have attachments, which are to be stripped off if over 1MB. ChrisA From rustompmody at gmail.com Thu Sep 4 00:11:27 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 3 Sep 2014 21:11:27 -0700 (PDT) Subject: Python is going to be hard In-Reply-To: References: <51acfec6-6b7b-4773-8d70-0360381bbed1@googlegroups.com> Message-ID: <4c873e02-93b1-4ad3-bc91-566a72b8e729@googlegroups.com> On Thursday, September 4, 2014 9:20:02 AM UTC+5:30, Chris Angelico wrote: > On Thu, Sep 4, 2014 at 1:22 PM, Rustom Mody wrote: > > | Effect-free programming > > | -- Function calls have no side effects, facilitating compositional reasoning > > | -- Variables are immutable, preventing unexpected changes to program data by other code > > | -- Data can be freely aliased or copied without introducing unintended effects from mutation > > So to answer your question: print statements are side-effecting and therefore obstruct > > compositional reasoning. > Yeah, fine. One small problem: Computers aren't built to do nothing. > "Effect-free programming" is utterly valueless and purposeless. To > make a program actually useful, you need to have some effect > somewhere. So where do you do that? Where do you permit a function > with side effects? > If you force *everything* to be in the return value, you lose any > possibility of partial results - for instance, if it takes two weeks > to render a ray-traced animation, you actually spend the entire two > weeks building up a single, gigantic return value, which some outside > system (which is presumably allowed to have side effects) then saves > somewhere. In the meantime, you have absolutely no idea how far it's > progressed - no information that it's completed frame 6 and is working > on frame 7, nothing. Because telling the user anything is a side > effect. > And if my function f calls show_status_to_user() which has side > effects, then f has side effects too, and you can no longer reason > purely about f. The impurity that makes for practicality (hey, isn't > there something in the Zen of Python about that?) pollutes upwards > until all you'll have will be pockets of pure functional code that > execute quickly enough to not need any intermediate output. That > doesn't equate to "abolish print", Is there some PEP filed called "Abolish print in python 4" ? I dont remember filing any such... Perhaps you should think of the relevance (rather than the correctness) of your arguments Chris! Are you arguing 1. With me? 2. With the OP? 3. With ACM/IEEE? If 1 then yeah I know when to use prints and when not If 2, are examples like ray-tracing animation remotely relevant (at this stage)? If 3 Sure! Take it up with ACM&IEEE if you feel something in their recommended curriculum is "valueless? and purposeless" > that just means that you separate > the guts from the UI - which is good advice for any system, no matter > what its structure. Yes thats the whole point -- computers do computing. IO should be conceptualized separately. -------------- ? Strange choice of word considering that one principal agenda of functional programming is to replace state-change thinking with value-oriented thinking From rustompmody at gmail.com Thu Sep 4 00:15:35 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 3 Sep 2014 21:15:35 -0700 (PDT) Subject: Python is going to be hard In-Reply-To: References: <51acfec6-6b7b-4773-8d70-0360381bbed1@googlegroups.com> Message-ID: On Thursday, September 4, 2014 9:37:05 AM UTC+5:30, Ethan Furman wrote: > Ridiculous argument after ridiculous argument. Please do not waste our time with nonsense. See my answer (3.) to Chris above. From sam.raker at gmail.com Thu Sep 4 00:52:40 2014 From: sam.raker at gmail.com (Sam Raker) Date: Wed, 3 Sep 2014 21:52:40 -0700 (PDT) Subject: Storing instances using jsonpickle In-Reply-To: References: <46e782a5-b087-4f95-aadb-26e233bf5419@googlegroups.com> Message-ID: 1) There are, if you want to mess around with them, ways to make pickle "smarter" about class stuff: https://docs.python.org/2/library/pickle.html#pickling-and-unpickling-normal-class-instances . I've never worked with any of this stuff (and people don't seem to like pickle all that much), and I honestly think it might just be easier to serialize class _data_ and then either create a factory that reads in e.g. a json file and outputs class instances, or tweak __init__/__new__ to take the data as an input. 2) re: "pyson," I'm pretty sure there are serialization formats that let you do this kind of thing. I feel like I was _just_ reading about one somewhere, but scrolling back through my browser history for the last 10 days or so turns up nothing (it definitely included some kind of extension functionality, though...). You could possibly approximate something like that with e.g. JSON and some crafty en-/decoding, maybe like '"mySet: {"set": [0,1,2]}, "myTuple": {"tuple": [0,1,2]}, "myObj": {"ClassName": {"foo": "bar", "baz": "quux"}}" + a parser? On Wednesday, September 3, 2014 10:19:07 PM UTC-4, Ned Batchelder wrote: > On 9/3/14 6:30 PM, Josh English wrote: > > > On Wednesday, September 3, 2014 1:53:23 PM UTC-7, Ned Batchelder wrote: > > > > > >> Pickle (and it looks like jsonpickle) does not invoke the class' > > >> __init__ method when it reconstitutes objects. Your new __init__ is not > > >> being run, so new attributes it defines are not being created. > > >> > > >> This is one of the reasons that people avoid pickle: being completely > > >> implicit is very handy, but also fragile. > > >> > > > > > > I seem to remember having this exact same frustration when I used pickle and shelve 15 years ago. I had hoped to have another way around this. I spent over a decade trying to make an XML-based database work, in part because of this limitation. > > > > > > Some days I get so frustrated I think the only data structure I should ever use is a dictionary. > > > > > > I suppose to make this sort of thing work, I should look at creating custom json encoders and decoders. > > > > > > > Typically, you need to decide explicitly on a serialized representation > > for your data. Even if it's JSON, you need to decide what that JSON > > looks like. Then you need to write code that converts the JSON-able > > data structure (dict of lists, whatever) into your object. Often a > > version number is a good idea so that you have some chance of using old > > data as your code changes. > > > > -- > > Ned Batchelder, http://nedbatchelder.com From rosuav at gmail.com Thu Sep 4 01:02:30 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 4 Sep 2014 15:02:30 +1000 Subject: Python is going to be hard In-Reply-To: <4c873e02-93b1-4ad3-bc91-566a72b8e729@googlegroups.com> References: <51acfec6-6b7b-4773-8d70-0360381bbed1@googlegroups.com> <4c873e02-93b1-4ad3-bc91-566a72b8e729@googlegroups.com> Message-ID: On Thu, Sep 4, 2014 at 2:11 PM, Rustom Mody wrote: > Is there some PEP filed called "Abolish print in python 4" ? > I dont remember filing any such... You screamed "NO PRINT" at us in the voice of Edna Mode. (At least, that's how I imagined it being said. YMMV.) > Perhaps you should think of the relevance (rather than the > correctness) of your arguments Chris! Are you arguing > > 1. With me? > > If 1 then yeah I know when to use prints and when not This. Then why are you advocating their non-use to new programmers? Are you really saying print() is for experienced people only? Or, more generally, that it should be possible for new programmers to do absolutely all their coding at the REPL, never using any function with side effects or mutating any state? (I was going to say "or using any mutable objects", but since Python doesn't have tuple comprehensions, you'd have to use lists. But if you never change what a list contains, it comes to the same thing.) Because that is what I'm arguing against. New programmers and experienced programmers alike need their code to produce output, and return values are just one form of that. Excluding all other forms is unnecessary. ChrisA From rosuav at gmail.com Thu Sep 4 01:17:17 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 4 Sep 2014 15:17:17 +1000 Subject: Storing instances using jsonpickle In-Reply-To: <5407A69B.3030707@mrabarnett.plus.com> References: <46e782a5-b087-4f95-aadb-26e233bf5419@googlegroups.com> <5407A69B.3030707@mrabarnett.plus.com> Message-ID: On Thu, Sep 4, 2014 at 9:39 AM, MRAB wrote: > I occasionally think about a superset of JSON, called, say, "pyson" ... > ah, name already taken! :-( While I'm somewhat sympathetic to the concept, there are some parts of your description that I disagree with. Am I misreading something? Are there typos in the description and I'm making something out of nothing? > It would add tuples, delimited by (...), which are not used otherwise (no > expressions): > > () => () > (0, ) => (0) This seems odd. Part of JSON's convenience is that it's a subset of JavaScript syntax, so you can just plop a block of JSON into a REPL and it'll decode correctly. With PyON (or whatever you call it), it'd be nice to have the same correspondence; for a start, I would strongly encourage the "trailing comma is permitted" rule (so [1,2,3,] is equivalent to [1,2,3]), and then I'd have the default encoding for a single-element tuple include that trailing comma. If (0) is a one-element tuple, you end up with a subtle difference between a PyON decode and the Python interpreter, which is likely to cause problems. It might even be worth actually mandating (not just encouraging) that one-element tuples have the trailing comma, just to prevent that. > The key of a dict could also be int, float, or tuple. Yes! Yes! DEFINITELY do this!! Ahem. Calm down a little, it's not that outlandish an idea... > It could support other classes, and could handle named arguments. > > For example, sets: > > To encode {0, 1, 2): Do you mean {0, 1, 2} here? I'm hoping you aren't advocating a syntax that mismatches bracket types. That's only going to cause confusion. > Look in encoder dict for encoder function with class's name ('set') and > call it, passing object. > > Encoder returns positional and keyword arguments: [0, 1, 2] and {}. > > Output name, followed by encoded arguments in parentheses. > > Encoder for set: > > def encode_set(obj): > return list(obj), {} > > To decode 'set(0, 1, 2)': > > Parse name: 'set'. > > Parse contents of parentheses: [0, 1, 2] and {}. > > Look in decoder dict for decoder function with given name ('set') and > call it, passing arguments. > > Result would be {0, 1, 2}. > > Decoder for set: > > def decode_set(*args): > return set(args) > > pyson.dumps({0, 1, 2}, decoders={'set': decode_set}) would return 'set(0, 1, > 2)'. > > pyson.loads('set(0, 1, 2)', encoders={'set': encode_set}) would return {0, > 1, 2}. This seems very much overengineered. Keep it much more simple; adding set notation is well and good, but keyword arguments aren't necessary there, and I'm not seeing a tremendous use-case for them. It's a pity Python has the collision of sets and dicts both using braces. Pike went for two-character delimiters, which might be better suited here; round brackets aren't used in JSON anywhere, so you can afford to steal them: {'this':'is', 'a':'dict'} ({'this','is','a','set'}) Empty sets would be an issue, though, as they'll be different in Python and this format. But everything else would work fine. You have a two-character delimiter in PyON, and superfluous parentheses around set notation in Python. (Sadly, this doesn't make it Pike-compatible, as Pike uses () for sets. But it wouldn't have been anyway.) ChrisA From marko at pacujo.net Thu Sep 4 01:36:40 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 04 Sep 2014 08:36:40 +0300 Subject: I have tried and errored a reasonable amount of times References: <5406726f$0$6512$c3e8da3$5496439d@news.astraweb.com> <4af60c7a-f4d6-4aa7-b181-fe768ea6f731@googlegroups.com> <5406c052$0$29876$c3e8da3$5496439d@news.astraweb.com> <87a96hcfml.fsf@elektro.pacujo.net> <5407c63c$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87mwagkkuv.fsf@elektro.pacujo.net> Steven D'Aprano : > Marko Rauhamaa wrote: >> That's the classic Boolean algebraic notation. > > Says who? (Apart from you, obviously :-) Since when? I've never seen > it in *any* discussion of Boolean algebra. I have only run into George Boole, Boolean algebra and booleans in engineering textbooks (digital electronics, software programming). IIRC, they *always* used the multiplication and addition symbols. When studying symbolic logic, I never ran into that notation or Boole or Boolean algebra or booleans. For example, ? and ? are called connectors instead of operations. IOW, they are symbols of a language instead of functions. Marko From rustompmody at gmail.com Thu Sep 4 02:23:04 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 3 Sep 2014 23:23:04 -0700 (PDT) Subject: Python is going to be hard In-Reply-To: References: <51acfec6-6b7b-4773-8d70-0360381bbed1@googlegroups.com> <4c873e02-93b1-4ad3-bc91-566a72b8e729@googlegroups.com> Message-ID: <99df9997-474e-4190-8179-6c1442b622a2@googlegroups.com> On Thursday, September 4, 2014 10:33:38 AM UTC+5:30, Chris Angelico wrote: > On Thu, Sep 4, 2014 at 2:11 PM, Rustom Mody wrote: > > Is there some PEP filed called "Abolish print in python 4" ? > > I dont remember filing any such... > You screamed "NO PRINT" at us in the voice of Edna Mode. (At least, > that's how I imagined it being said. YMMV.) > > Perhaps you should think of the relevance (rather than the > > correctness) of your arguments Chris! Are you arguing > > 1. With me? > > If 1 then yeah I know when to use prints and when not > This. Then why are you advocating their non-use to new programmers? > Are you really saying print() is for experienced people only? Or, more > generally, that it should be possible for new programmers to do > absolutely all their coding at the REPL, never using any function with > side effects or mutating any state? (I was going to say "or using any > mutable objects", but since Python doesn't have tuple comprehensions, > you'd have to use lists. But if you never change what a list contains, > it comes to the same thing.) A patient goes to hospital. The first thing the nurses do (even before the doctor arrives) is to stick all kinds of tubes into... eyes, nose, ears and other unmentionable places. The doctor arrives and orders a few more invasions. Some of these are for helping eg a saline drip to a dehydrated patient, mostly they are for 'debugging' the patient -- what things are there in the blood (etc) that should not be or what is defcient that should be etc etc Would you consider it acceptable that when the patient is declared cured, he/she is sent home with these tubes hanging out? Sure there are exceptions -- eg a patient needs a plaster/pacemaker etc. As a rule he/she should be freed from all this. You seem to think a print hanging out of a program to be ok, normal. I consider it exceptional. At the level of expertise of the OP -- this thread starts with confusion about a for -- the foll. is totally irrelevant. However since you are bringing in heavy-duty examples like 'ray-tracing animation' lets see a few examples: 1. Program is a gui -- There can be no meaningful prints, only GUI-toolkit dialogs. 2. Program is a web-app -- It is painful and inefficient to generate the html with prints. The correct approach is to use a templating engine 3. Program is a classic unix filter. If it is doing something entirely trivial -- eg cat -- it matters little how its written. If it is doing something significant it is best structured into IO and computation separated 4. Programmer is a noob. You would start him on scripts. I would start him in the REPL > Because that is what I'm arguing against. New programmers and > experienced programmers alike need their code to produce output, and > return values are just one form of that. Excluding all other forms is > unnecessary. There is such a thing as law of primacy -- what is learnt first is remembered most. And there are many important things when learning programming/python. One of them is debugging. print is excellent for that. But there are more important things than that -- like structuring code and using appropriate data structures. Putting print in the place of primacy screws up that learning curve > > Is there some PEP filed called "Abolish print in python 4" ? > > I dont remember filing any such... > You screamed "NO PRINT" at us in the voice of Edna Mode. (At least, > that's how I imagined it being said. YMMV.) Dos and donts for adults and for children are different (at least in my part of the world) ;-) From rosuav at gmail.com Thu Sep 4 02:39:45 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 4 Sep 2014 16:39:45 +1000 Subject: Python is going to be hard In-Reply-To: <99df9997-474e-4190-8179-6c1442b622a2@googlegroups.com> References: <51acfec6-6b7b-4773-8d70-0360381bbed1@googlegroups.com> <4c873e02-93b1-4ad3-bc91-566a72b8e729@googlegroups.com> <99df9997-474e-4190-8179-6c1442b622a2@googlegroups.com> Message-ID: On Thu, Sep 4, 2014 at 4:23 PM, Rustom Mody wrote: > A patient goes to hospital. The first thing the nurses do (even before the > doctor arrives) is to stick all kinds of tubes into... eyes, nose, ears and > other unmentionable places. The doctor arrives and orders a few more invasions. > Some of these are for helping eg a saline drip to a dehydrated patient, mostly > they are for 'debugging' the patient -- what things are there in the blood (etc) > that should not be or what is defcient that should be etc etc > > Would you consider it acceptable that when the patient is declared cured, > he/she is sent home with these tubes hanging out? > > Sure there are exceptions -- eg a patient needs a plaster/pacemaker etc. > As a rule he/she should be freed from all this. > > You seem to think a print hanging out of a program to be ok, normal. > I consider it exceptional. You keep saying that it's exceptional. You haven't really said why. It's the simplest form of "program produces output for the human to see", which all of your subsequent examples are more complicated versions of: > 1. Program is a gui -- There can be no meaningful prints, only > GUI-toolkit dialogs. (I actually disagree - several of my GUI programs have consoles for debug output - but that's a separate point.) GUI toolkit dialogs are inherently more complicated than simple print() calls, so they can be learned later. "See, this is how you print to a console. Now, if you do this, this, and this, you instead get a dialog." > 2. Program is a web-app -- It is painful and inefficient to generate > the html with prints. The correct approach is to use a templating engine The templating engine is just another more complicated form of output. Once again, learn the simple and fundamental first, and then add complexity - starting with small levels of complexity like "You are user %d of %d."%(user_num, concurrent_limit) and going up from there. > 3. Program is a classic unix filter. If it is doing something entirely trivial > -- eg cat -- it matters little how its written. If it is doing something significant > it is best structured into IO and computation separated And how is the first of those going to be done? Somewhere, you need to do I/O, and that's going to involve something very like print. > 4. Programmer is a noob. You would start him on scripts. > I would start him in the REPL I would actually start on both. But if you're going to copy and paste a bunch of stuff to python-list and say "here's what's going wrong, can you help", it is MUCH easier if that's a script than an interactive session that might have had almost anything preceding it. > There is such a thing as law of primacy -- what is learnt first is remembered > most. And there are many important things when learning programming/python. > One of them is debugging. print is excellent for that. > > But there are more important things than that -- like structuring code and > using appropriate data structures. Putting print in the place of primacy > screws up that learning curve Okay. Here's the thing I most want people to remember: Make the program tell you stuff. Because that's more important as a debugging help than *anything* in the world. No matter how beautiful your data structure is, it's useless if you don't know how to get the program to tell you about it. You might like the idea of pure mathematical thinking, and that's fine as a theory. If you want to teach programming on a blackboard, go ahead, and use extremely functional style. Me, I've been tutoring several Python students over the past few weeks, and I want to see them get info back from the program. Using print() is perfect for them, and it won't be a bad thing in the future. Maybe it's ugly and messy and offends your theory-clean sensibilities, but it solves real-world problems. Practicality beats purity. Especially when it actually solves real problems that people pay money to get solved. ChrisA From alister.nospam.ware at ntlworld.com Thu Sep 4 06:29:41 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Thu, 04 Sep 2014 10:29:41 GMT Subject: Python is going to be hard References: <51acfec6-6b7b-4773-8d70-0360381bbed1@googlegroups.com> <612dd9e6-653b-4e07-aebe-ffd31eec2a9e@googlegroups.com> <08de12b8-274d-44c8-a08a-5aef2f12deee@googlegroups.com> Message-ID: On Wed, 03 Sep 2014 19:33:41 -0700, Rustom Mody wrote: > On Thursday, September 4, 2014 7:56:31 AM UTC+5:30, Chris Angelico > wrote: >> On Thu, Sep 4, 2014 at 12:10 PM, Rustom Mody wrote: >> > On Thursday, September 4, 2014 7:26:56 AM UTC+5:30, Chris Angelico >> > wrote: >> >> On Thu, Sep 4, 2014 at 11:48 AM, Rustom Mody wrote: >> >> >>>> NO PRINT >> >> Why are you so dead against print? >> > Because it heralds a typical noob code-smell [especially when the OP >> > admits that BASIC is his background] > >> And, of course, all those lovely Unix programs that produce output on >> stdout, they're full of code smell too, right? I don't care what >> someone's background is; console output is *not* code smell. > > Tell me the same after having taught a few thousand students If you are > at the level of writing useful unix scripts, you are not going to be > asking these questions. > >> Anyway, all you're doing is relying on the magic of interactive mode to >> call repr() and print() for you. > > Yes its usually called DRY. > That P in the REPL is put in a neat and nifty place. Why repeat? > >> >> Yes, or the OP could work with actual saved .py files and the >> >> reliability that comes from predictable execution environments... >> >> and use print. >> > Dunno what you are talking about The interpreter-REPL is less >> > reliable than a script? > >> When you start a script, you have a consistent environment - an empty >> one. When you write a series of commands in the interactive >> interpreter, the environment for each one depends on all the preceding >> commands. So when you have a problem, you might have to copy and paste >> the entire interpreter session, rather than just the one command. > > Agreed. Thats a downside. > Very minor compared to the mess induced by unstructured print-filled > noob code. until the New programmer (I hate the word noob, it looks too derogatory even when that is not the intention) has learnt enough to be using a logging module i can see no alternative to using print for debugging purposes. I would agree that in production code they are often the wrong option (although still valid for CLI applications.) -- You can't get there from here. From python.list at tim.thechases.com Thu Sep 4 06:45:03 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 4 Sep 2014 05:45:03 -0500 Subject: Best way to filter parts of a email.message.Message In-Reply-To: References: <20140903205958.119351c8@bigbox.christie.dr> <20140904035240.GA75238@cskk.homeip.net> Message-ID: <20140904054503.0524caca@bigbox.christie.dr> On 2014-09-04 14:08, Chris Angelico wrote: > On Thu, Sep 4, 2014 at 1:52 PM, Cameron Simpson wrote: >> On 03Sep2014 20:59, Tim Chase wrote: >>> - mime-parts can be nested, so I need to recursively handle them >> >> Just to this. IIRC, the MIME part delimiter is supposed to be >> absolute. That is, it will not occur in the nested subparts, if >> any. > > I think the point here is that the validity check of a mime-part may > involve checking sub-parts - eg the message is a mailing list digest > (with one part per actual message), and some of those have > attachments, which are to be stripped off if over 1MB. Indeed, ChrisA divined my intent--an attachment remover based on various types of mime-type and size tests. A cursory search didn't turn up any pre-existing utilities that did quite what I wanted. Perhaps my previous message about detecting mbox-vs-maildir-vs-mh format mailboxes hinted at this. Thanks to all who answered there (though I encountered a possible bug, as Claws Mail doesn't put a .mh_sequences file in what it claims are MH local folders which causes issues with MH() http://bugs.python.org/issue22319 ). So the goal is to keep the original message with highest fidelity while still stripping out the undesirable attachments. Thanks for your thoughts, -tkc From python at mrabarnett.plus.com Thu Sep 4 07:07:14 2014 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 04 Sep 2014 12:07:14 +0100 Subject: Storing instances using jsonpickle In-Reply-To: References: <46e782a5-b087-4f95-aadb-26e233bf5419@googlegroups.com> <5407A69B.3030707@mrabarnett.plus.com> Message-ID: <540847E2.1060804@mrabarnett.plus.com> On 2014-09-04 06:17, Chris Angelico wrote:> On Thu, Sep 4, 2014 at 9:39 AM, MRAB wrote: >> I occasionally think about a superset of JSON, called, say, "pyson" >> ... ah, name already taken! :-( > > While I'm somewhat sympathetic to the concept, there are some parts > of your description that I disagree with. Am I misreading something? > Are there typos in the description and I'm making something out of > nothing? > >> It would add tuples, delimited by (...), which are not used >> otherwise (no expressions): >> >> () => () >> (0, ) => (0) > I'm thinking now that it might be better to have 'tuple()' and 'tuple(0)'. > This seems odd. Part of JSON's convenience is that it's a subset of > JavaScript syntax, so you can just plop a block of JSON into a REPL > and it'll decode correctly. With PyON (or whatever you call it), it'd > be nice to have the same correspondence; for a start, I would > strongly> encourage the "trailing comma is permitted" rule (so > [1,2,3,] is equivalent to [1,2,3]), and then I'd have the default > encoding for a single-element tuple include that trailing comma. If > (0) is a one-element tuple, you end up with a subtle difference > between a PyON decode and the Python interpreter, which is likely to > cause problems. It might even be worth actually mandating (not just > encouraging) that one-element tuples have the trailing comma, just to > prevent that. > In that case, if you wanted to encode a (0, ), it would have to be 'tuple([0])', whereas 1+2j would have to be 'complex(i, 2)'. The encoder would need to return [[0]] for the first case and [1, 2] for the second. >> The key of a dict could also be int, float, or tuple. > > Yes! Yes! DEFINITELY do this!! Ahem. Calm down a little, it's not > that outlandish an idea... > >> It could support other classes, and could handle named arguments. >> >> For example, sets: >> >> To encode {0, 1, 2): > > Do you mean {0, 1, 2} here? I'm hoping you aren't advocating a syntax > that mismatches bracket types. That's only going to cause confusion. > Yes, that's a typo. >> Look in encoder dict for encoder function with class's name >> ('set') and call it, passing object. >> >> Encoder returns positional and keyword arguments: [0, 1, 2] and >> {}. >> >> Output name, followed by encoded arguments in parentheses. >> >> Encoder for set: >> >> def encode_set(obj): >> return list(obj), {} >> >> To decode 'set(0, 1, 2)': >> >> Parse name: 'set'. >> >> Parse contents of parentheses: [0, 1, 2] and {}. >> >> Look in decoder dict for decoder function with given name >> ('set') and call it, passing arguments. >> >> Result would be {0, 1, 2}. >> >> Decoder for set: >> >> def decode_set(*args): >> return set(args) >> >> pyson.dumps({0, 1, 2}, decoders={'set': decode_set}) would return >> 'set(0, 1, 2)'. >> >> pyson.loads('set(0, 1, 2)', encoders={'set': encode_set}) would >> return {0, 1, 2}. > > This seems very much overengineered. Keep it much more simple; adding > set notation is well and good, but keyword arguments aren't necessary > there, and I'm not seeing a tremendous use-case for them. > > It's a pity Python has the collision of sets and dicts both using > braces. Pike went for two-character delimiters, which might be better > suited here; round brackets aren't used in JSON anywhere, so you can > afford to steal them: > > {'this':'is', 'a':'dict'} > ({'this','is','a','set'}) > > Empty sets would be an issue, though, as they'll be different in > Python and this format. But everything else would work fine. You have > a two-character delimiter in PyON, and superfluous parentheses around > set notation in Python. > > (Sadly, this doesn't make it Pike-compatible, as Pike uses () > for sets. But it wouldn't have been anyway.) > To encode {0, 1, 2}: Look in encoder dict for encoder function with class's name ('set') and call it, passing object. Encoder returns name and list of arguments: 'set' and [[0, 1, 2]]. Output name, followed by encoded arguments in parentheses: 'set([0, 1, 2])'. Encoder for set: def encode_set(obj): return 'set', [list(obj)] To decode 'set([0, 1, 2])': Parse name: 'set'. Parse contents of parentheses as list: [[0, 1, 2]]. Look in decoder dict for decoder function with given name ('set') and call it, passing arguments. Result would be {0, 1, 2}. Decoder for set: def decode_set(args): # Error-checking omitted. return set(args[0]) pyson.dumps({0, 1, 2}, decoders={'set': decode_set}) would return 'set([0, 1, 2])'. pyson.loads('set([0, 1, 2])', encoders={'set': encode_set}) would return {0, 1, 2}. From denismfmcmahon at gmail.com Thu Sep 4 07:17:04 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Thu, 4 Sep 2014 11:17:04 +0000 (UTC) Subject: I have tried and errored a reasonable amount of times References: <5406726f$0$6512$c3e8da3$5496439d@news.astraweb.com> <4af60c7a-f4d6-4aa7-b181-fe768ea6f731@googlegroups.com> <5406c052$0$29876$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, 03 Sep 2014 07:16:34 +0000, Steven D'Aprano wrote: > Who uses + for disjunction (? OR) and concatenation for conjunction (? > AND)? That's crazy notation. The way I was taught it in the mid 1980s, a.b === a and b, a+b === a or b. -- Denis McMahon, denismfmcmahon at gmail.com From rosuav at gmail.com Thu Sep 4 07:42:56 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 4 Sep 2014 21:42:56 +1000 Subject: I have tried and errored a reasonable amount of times In-Reply-To: References: <5406726f$0$6512$c3e8da3$5496439d@news.astraweb.com> <4af60c7a-f4d6-4aa7-b181-fe768ea6f731@googlegroups.com> <5406c052$0$29876$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Sep 4, 2014 at 9:17 PM, Denis McMahon wrote: > On Wed, 03 Sep 2014 07:16:34 +0000, Steven D'Aprano wrote: > >> Who uses + for disjunction (? OR) and concatenation for conjunction (? >> AND)? That's crazy notation. > > The way I was taught it in the mid 1980s, a.b === a and b, a+b === a or b. The middle dot is another notation for multiplication, as is abuttal (not actually concatenation, in this context). So they're all saying the same thing: boolean 'and' is multiplication, boolean 'or' is addition. ChrisA From rustompmody at gmail.com Thu Sep 4 09:08:27 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 4 Sep 2014 06:08:27 -0700 (PDT) Subject: Python is going to be hard In-Reply-To: References: <51acfec6-6b7b-4773-8d70-0360381bbed1@googlegroups.com> <612dd9e6-653b-4e07-aebe-ffd31eec2a9e@googlegroups.com> <08de12b8-274d-44c8-a08a-5aef2f12deee@googlegroups.com> Message-ID: <48292a2b-5704-4164-aaa8-d041bd45a6c1@googlegroups.com> On Thursday, September 4, 2014 3:59:57 PM UTC+5:30, alister wrote: > On Wed, 03 Sep 2014 19:33:41 -0700, Rustom Mody wrote: > > On Thursday, September 4, 2014 7:56:31 AM UTC+5:30, Chris Angelico > > wrote: > >> When you start a script, you have a consistent environment - an empty > >> one. When you write a series of commands in the interactive > >> interpreter, the environment for each one depends on all the preceding > >> commands. So when you have a problem, you might have to copy and paste > >> the entire interpreter session, rather than just the one command. > > Agreed. Thats a downside. > > Very minor compared to the mess induced by unstructured print-filled > > noob code. > until the New programmer (I hate the word noob, it looks too derogatory > even when that is not the intention) has learnt enough to be using a > logging module i can see no alternative to using print for debugging > purposes. Fully agree. If the one giving the instruction makes it clear that this thing called a print statement (expression) is something -- a probe -- you stick into the program to figure out whats happening, thats fine. If its presented as something that a program can have any amount of then its not. From rustompmody at gmail.com Thu Sep 4 09:15:24 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 4 Sep 2014 06:15:24 -0700 (PDT) Subject: Python is going to be hard In-Reply-To: References: <51acfec6-6b7b-4773-8d70-0360381bbed1@googlegroups.com> <4c873e02-93b1-4ad3-bc91-566a72b8e729@googlegroups.com> <99df9997-474e-4190-8179-6c1442b622a2@googlegroups.com> Message-ID: On Thursday, September 4, 2014 12:10:04 PM UTC+5:30, Chris Angelico wrote: > Practicality beats purity. Nice statement! Now where did I see it?? Let me see... I see next to it some others: - Beautiful is better than ugly. - Explicit is better than implicit. - Simple is better than complex. - Complex is better than complicated. - Readability counts. - If the implementation is hard to explain, it's a bad idea. How do each of these apply when comparing a. A program that defaults to passing and returning data structures and uses print in a very controlled way b. A program that randomly mixes call/return with input/print ?? From steve+comp.lang.python at pearwood.info Thu Sep 4 09:25:39 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 04 Sep 2014 23:25:39 +1000 Subject: Python is going to be hard References: <51acfec6-6b7b-4773-8d70-0360381bbed1@googlegroups.com> <612dd9e6-653b-4e07-aebe-ffd31eec2a9e@googlegroups.com> Message-ID: <54086853$0$6574$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > On Thu, Sep 4, 2014 at 12:10 PM, Rustom Mody > wrote: >> On Thursday, September 4, 2014 7:26:56 AM UTC+5:30, Chris Angelico wrote: >>> On Thu, Sep 4, 2014 at 11:48 AM, Rustom Mody wrote: >>> >>>> NO PRINT >> >> >>> Why are you so dead against print? >> >> Because it heralds a typical noob code-smell >> [especially when the OP admits that BASIC is his background] > > And, of course, all those lovely Unix programs that produce output on > stdout, they're full of code smell too, right? I don't care what > someone's background is; console output is *not* code smell. I cautiously agree with Rustom on this one. Of course console output is often useful, but it is slightly smelly: - beginners have a tendency to use print when they should be using return, and consequently can't easily chain functions together; - languages like shell scripting languages, which are designed to chain such printing functions together, suffer because of it: * they're less efficient, due to having to convert to and from text repeatedly; * as a programming language, they're rather impoverished, even if they have internal data types which aren't text, they can't pass output to other programs except as text; (very occasionally, they support a hybrid "text separated by NUL bytes" mode) * they tend to be rather less resilient since they cannot easily separate presentation from calculation; any change to the presentation, or unexpected presentation, is likely to break your code silently. Think of how many broken bash scripts there are out there which assume that files names can never contain newlines. Or, for that matter, spaces. Even in Python, consider how limiting something like dis.dis() is, seeing how it prints its output instead of returning it. > Anyway, all you're doing is relying on the magic of interactive mode > to call repr() and print() for you. Well, yes, but isn't that the point? Let your tools do most of the work. [...] >> The interpreter-REPL is less reliable than a script? > > When you start a script, you have a consistent environment - an empty > one. When you write a series of commands in the interactive > interpreter, the environment for each one depends on all the preceding > commands. So when you have a problem, you might have to copy and paste > the entire interpreter session, rather than just the one command. True, but the same applies to a script. If you have a problem with line 100, you can't just post line 100, you may have to post the entire 100 lines before it. Being able to isolate the problem to the minimal amount of code needed to demonstrate it is an important skill for all developers. -- Steven From rosuav at gmail.com Thu Sep 4 09:30:10 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 4 Sep 2014 23:30:10 +1000 Subject: Python is going to be hard In-Reply-To: References: <51acfec6-6b7b-4773-8d70-0360381bbed1@googlegroups.com> <4c873e02-93b1-4ad3-bc91-566a72b8e729@googlegroups.com> <99df9997-474e-4190-8179-6c1442b622a2@googlegroups.com> Message-ID: On Thu, Sep 4, 2014 at 11:15 PM, Rustom Mody wrote: > How do each of these apply when comparing > a. A program that defaults to passing and returning data structures and > uses print in a very controlled way > > b. A program that randomly mixes call/return with input/print Considering that I've never seen anything that *randomly* mixes them, I can't really say. But you clearly don't dislike print nearly as much as your earlier posts imply, because it can be used in a "controlled way" as your potent comparison point. So how about you show me some real example code, something real-world that you hate, and show me how you'd rewrite it to not use print() calls "randomly mixed" with other stuff, and then we can discuss. I think we'll find that our views aren't as much different as it would seem; both of us believe in separating guts from UI, both of us believe that side-effect-free functions are easier to comprehend than those that unexpectedly change state, and both of us want to make programs that can be read and reasoned about. The only difference is that I see print as an important tool as part of a balanced meal, and you see it as something distasteful that you regrettably have to include. But we both use it. ChrisA From steve+comp.lang.python at pearwood.info Thu Sep 4 09:37:25 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 04 Sep 2014 23:37:25 +1000 Subject: Python is going to be hard References: <51acfec6-6b7b-4773-8d70-0360381bbed1@googlegroups.com> <4c873e02-93b1-4ad3-bc91-566a72b8e729@googlegroups.com> <99df9997-474e-4190-8179-6c1442b622a2@googlegroups.com> Message-ID: <54086b15$0$29977$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > On Thu, Sep 4, 2014 at 4:23 PM, Rustom Mody wrote: >> You seem to think a print hanging out of a program to be ok, normal. >> I consider it exceptional. > > You keep saying that it's exceptional. You haven't really said why. > It's the simplest form of "program produces output for the human to > see", which all of your subsequent examples are more complicated > versions of: Out of the Python built-ins, how many functions (apart from print itself!) print output instead of, or as well as, returning? Out of the standard library, what percentage of functions and methods print output instead of, or as well as, returning? I haven't counted, but I'm guessing it will be well under 1%. There's a few obvious examples: pprint.pprint, calendar.pr*, dis.dis, maybe a few more. But I think they should be considered *exceptional*. We often recommend using print as an easy and effective debugging tool. But we don't (well, I don't) recommend leaving those print statements in the code once the problem is debugged. -- Steven From rosuav at gmail.com Thu Sep 4 09:55:48 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 4 Sep 2014 23:55:48 +1000 Subject: Python is going to be hard In-Reply-To: <54086853$0$6574$c3e8da3$5496439d@news.astraweb.com> References: <51acfec6-6b7b-4773-8d70-0360381bbed1@googlegroups.com> <612dd9e6-653b-4e07-aebe-ffd31eec2a9e@googlegroups.com> <54086853$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Sep 4, 2014 at 11:25 PM, Steven D'Aprano wrote: > Of course console output is > often useful, but it is slightly smelly: > > - beginners have a tendency to use print when they should be using > return, and consequently can't easily chain functions together; > > - languages like shell scripting languages, which are designed to > chain such printing functions together, suffer because of it: > > Think of how many broken bash scripts there are out there which assume that > files names can never contain newlines. Or, for that matter, spaces. Focusing everything on output, yes that's a problem. (Look at the ob_* functions in PHP - they are an abomination built to cope with other abominations.) > Even in Python, consider how limiting something like dis.dis() is, seeing > how it prints its output instead of returning it. I agree that it's limited - but how would you do it differently? Python's repr for multiline text is pretty unreadable. The only way I could imagine it being done is if it returns a custom object whose repr is the text we usually see. If you want to send it somewhere other than the console. dis.dis(file=...) works; and if you want to do something other than simple output, you probably want one of the lower-level functions (which I haven't personally dug into, but I'm thinking get_instructions is probably more useful than dis for more complicated jobs). >> Anyway, all you're doing is relying on the magic of interactive mode >> to call repr() and print() for you. > > Well, yes, but isn't that the point? Let your tools do most of the work. Sure, but if you hate something enough to scream "NO PRINT" at us, isn't it a bit odd to advocate something that does the exact same thing only hidden? Why is it somehow okay to rely on the side effect of intermediate expression results getting printed, while decrying side effects anywhere else? >>> The interpreter-REPL is less reliable than a script? >> >> When you start a script, you have a consistent environment - an empty >> one. When you write a series of commands in the interactive >> interpreter, the environment for each one depends on all the preceding >> commands. So when you have a problem, you might have to copy and paste >> the entire interpreter session, rather than just the one command. > > True, but the same applies to a script. If you have a problem with line 100, > you can't just post line 100, you may have to post the entire 100 lines > before it. Being able to isolate the problem to the minimal amount of code > needed to demonstrate it is an important skill for all developers. Yes, that's true. But a dozen-line script that's been through a dozen iterations of editing is still a dozen lines of script, whereas it might be sixty or seventy lines of interactive output. It's generally easier to "isolate to the minimum" when you start with something that's inherently shorter. It's also easier to isolate to the minimum when you work with a consistent starting position, rather than have each one build on the preceding ones. Like I said in my most recent response to Rustom, we probably don't disagree nearly as much as it seemed at the first couple of responses. ChrisA From breamoreboy at yahoo.co.uk Thu Sep 4 10:04:17 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 04 Sep 2014 15:04:17 +0100 Subject: Python is going to be hard In-Reply-To: <54086b15$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <51acfec6-6b7b-4773-8d70-0360381bbed1@googlegroups.com> <4c873e02-93b1-4ad3-bc91-566a72b8e729@googlegroups.com> <99df9997-474e-4190-8179-6c1442b622a2@googlegroups.com> <54086b15$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 04/09/2014 14:37, Steven D'Aprano wrote: > > We often recommend using print as an easy and effective debugging tool. But > we don't (well, I don't) recommend leaving those print statements in the > code once the problem is debugged. > I've given up completely with print for debugging. I start with the logging module and change one line to effectively switch it off. Admittedly that's easy for me as I'm only writing code for my own use, I'm fairly sure that some of the bigger applications simply couldn't take the performance hit. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rosuav at gmail.com Thu Sep 4 10:08:22 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 5 Sep 2014 00:08:22 +1000 Subject: Python is going to be hard In-Reply-To: <54086b15$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <51acfec6-6b7b-4773-8d70-0360381bbed1@googlegroups.com> <4c873e02-93b1-4ad3-bc91-566a72b8e729@googlegroups.com> <99df9997-474e-4190-8179-6c1442b622a2@googlegroups.com> <54086b15$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Sep 4, 2014 at 11:37 PM, Steven D'Aprano wrote: > Chris Angelico wrote: > >> On Thu, Sep 4, 2014 at 4:23 PM, Rustom Mody wrote: >>> You seem to think a print hanging out of a program to be ok, normal. >>> I consider it exceptional. >> >> You keep saying that it's exceptional. You haven't really said why. >> It's the simplest form of "program produces output for the human to >> see", which all of your subsequent examples are more complicated >> versions of: > > Out of the Python built-ins, how many functions (apart from print itself!) > print output instead of, or as well as, returning? > > Out of the standard library, what percentage of functions and methods print > output instead of, or as well as, returning? > > I haven't counted, but I'm guessing it will be well under 1%. There's a few > obvious examples: pprint.pprint, calendar.pr*, dis.dis, maybe a few more. > But I think they should be considered *exceptional*. This is an unfair comparison, though. There's a vast difference between library and application code. You also don't find library code that changes the current directory, but on the flip side, *every* job control system needs that facility. (With sysvinit, job control is shell scripts. With upstart and systemd, there are directives to set the working directory. Etcetera.) It's bad form for a library to produce console output, because it doesn't own the console; but the application does. The logger module will, by default, produce stderr output, because it's assuming the application owns it. Otherwise, it's generally up to the application to print stuff out. So a fairer comparison is: How many applications produce non-debug output on stderr or stdout? And that would be a much larger percentage. Even GUI programs will, in some cases - for instance, try firing up your favorite GUI text editor with no X server active, or with invalid .Xauthority. You'll get some sort of error message - on the console. Which means that somewhere in the GUI library, there's fall-back code that produces console output. That's why I say it's the most basic of all forms of that fundamental of programming, producing output that a human can read. It's the simple one that you teach first; everything else is built on that. ChrisA From SGraff at vcentertainment.com Thu Sep 4 13:51:22 2014 From: SGraff at vcentertainment.com (Stewart Graff (Visual Concepts)) Date: Thu, 4 Sep 2014 17:51:22 +0000 Subject: bicyclerepairman python24 windows idle :( Message-ID: Lines 304 - 318 contain non-ascii characters. You need to rewrite all of the leading whitespace for the function def confirm_buffer_is_saved(self, editwin): Make sure you also replace the "&nbs p; " with spaces on line 313. -------------- next part -------------- An HTML attachment was scrubbed... URL: From sohi.khushi7 at gmail.com Thu Sep 4 14:13:16 2014 From: sohi.khushi7 at gmail.com (sohi.khushi7 at gmail.com) Date: Thu, 4 Sep 2014 11:13:16 -0700 (PDT) Subject: Looking for a suitable Python resource Message-ID: <0010118c-9586-47df-b8e6-5bc0653a4786@googlegroups.com> Hello group members, I have worked with languages like C, C++, C#, Java and Objective C before. Now I want to learn Python. Most of the resources that I have seen online are oriented mainly towards beginners to programming. Is there any other good source which can be used by a person who knows the basics of programming already? Thanks, Khushi From kwpolska at gmail.com Thu Sep 4 14:29:33 2014 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Thu, 4 Sep 2014 20:29:33 +0200 Subject: Looking for a suitable Python resource In-Reply-To: <0010118c-9586-47df-b8e6-5bc0653a4786@googlegroups.com> References: <0010118c-9586-47df-b8e6-5bc0653a4786@googlegroups.com> Message-ID: On Thu, Sep 4, 2014 at 8:13 PM, wrote: > Hello group members, > > I have worked with languages like C, C++, C#, Java and Objective C before. > > Now I want to learn Python. Most of the resources that I have seen online are oriented mainly towards beginners to programming. Is there any other good source which can be used by a person who knows the basics of programming already? The official Python tutorial should suit you: version 2 ? https://docs.python.org/2/tutorial/index.html version 3 ? https://docs.python.org/3/tutorial/index.html -- Chris ?Kwpolska? Warrick PGP: 5EAAEA16 stop html mail | always bottom-post | only UTF-8 makes sense From alister.nospam.ware at ntlworld.com Thu Sep 4 14:34:30 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Thu, 04 Sep 2014 18:34:30 GMT Subject: Looking for a suitable Python resource References: <0010118c-9586-47df-b8e6-5bc0653a4786@googlegroups.com> Message-ID: On Thu, 04 Sep 2014 11:13:16 -0700, sohi.khushi7 wrote: > Hello group members, > > I have worked with languages like C, C++, C#, Java and Objective C > before. > > Now I want to learn Python. Most of the resources that I have seen > online are oriented mainly towards beginners to programming. Is there > any other good source which can be used by a person who knows the basics > of programming already? > > Thanks, > Khushi the python tutorial on Python.org is probably a good place to start it may seem a bit basic fro your current level but will quickly highlight the differences between python & the other languages you know. You may also want to check the comments on google groups before you proceed much further. it makes a poor job of presenting your posts and alienates many valuable members of this community -- The rule on staying alive as a forecaster is to give 'em a number or give 'em a date, but never give 'em both at once. -- Jane Bryant Quinn From joel.goldstick at gmail.com Thu Sep 4 14:41:55 2014 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Thu, 4 Sep 2014 14:41:55 -0400 Subject: Looking for a suitable Python resource In-Reply-To: References: <0010118c-9586-47df-b8e6-5bc0653a4786@googlegroups.com> Message-ID: On Thu, Sep 4, 2014 at 2:34 PM, alister wrote: > On Thu, 04 Sep 2014 11:13:16 -0700, sohi.khushi7 wrote: > >> Hello group members, >> >> I have worked with languages like C, C++, C#, Java and Objective C >> before. >> >> Now I want to learn Python. Most of the resources that I have seen >> online are oriented mainly towards beginners to programming. Is there >> any other good source which can be used by a person who knows the basics >> of programming already? >> >> Thanks, >> Khushi > > This might suit you http://python4java.necaiseweb.org/Main/TableOfContents -- Joel Goldstick http://joelgoldstick.com From sohi.khushi7 at gmail.com Thu Sep 4 14:45:13 2014 From: sohi.khushi7 at gmail.com (sohi.khushi7 at gmail.com) Date: Thu, 4 Sep 2014 11:45:13 -0700 (PDT) Subject: Looking for a suitable Python resource In-Reply-To: References: <0010118c-9586-47df-b8e6-5bc0653a4786@googlegroups.com> Message-ID: <2bc7dda0-394a-428b-b520-121ba0d04148@googlegroups.com> Thanks Chris! I think this is the best resource I have found so far as well. :) From sohi.khushi7 at gmail.com Thu Sep 4 14:47:01 2014 From: sohi.khushi7 at gmail.com (sohi.khushi7 at gmail.com) Date: Thu, 4 Sep 2014 11:47:01 -0700 (PDT) Subject: Looking for a suitable Python resource In-Reply-To: References: <0010118c-9586-47df-b8e6-5bc0653a4786@googlegroups.com> Message-ID: <85af6d21-78d5-45ef-a778-c6ef64c8388c@googlegroups.com> Thanks Alister! From breamoreboy at yahoo.co.uk Thu Sep 4 16:21:27 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 04 Sep 2014 21:21:27 +0100 Subject: Looking for a suitable Python resource In-Reply-To: <0010118c-9586-47df-b8e6-5bc0653a4786@googlegroups.com> References: <0010118c-9586-47df-b8e6-5bc0653a4786@googlegroups.com> Message-ID: On 04/09/2014 19:13, sohi.khushi7 at gmail.com wrote: > Hello group members, > > I have worked with languages like C, C++, C#, Java and Objective C before. > > Now I want to learn Python. Most of the resources that I have seen online are oriented mainly towards beginners to programming. Is there any other good source which can be used by a person who knows the basics of programming already? > > Thanks, > Khushi > http://www.diveintopython.net/ -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From bv4bv4bv4 at gmail.com Thu Sep 4 16:44:03 2014 From: bv4bv4bv4 at gmail.com (bv4bv4bv4 at gmail.com) Date: Thu, 4 Sep 2014 13:44:03 -0700 (PDT) Subject: "We made from water every living thing"... Message-ID: "We made from water every living thing"... http://upload.7hob.com/images2014/www.7hob.com1370521056748.jpg Allah (s.w.t.) said in the Holy book (... We have made from water every living thing.) Everything has been designated water district great glory Glory to God Almighty Allah, these scientific miracles in the Holy Book ( The Qur'an ) the scientists know that water entered in the installation of every living creature while it is stated in the holy Qur'an since more than 1400 years. First: Children, where children need good amounts of fluid, which helps growth and the reduction of any health problems. Second: The elderly as the elderly needs to be good amounts of water to minimize any problems resulting from drought, especially since he loses the sense of thirst with age... Third: Athletes need to adequate amounts of fluids because they are losing large quantities of water as well as the need to increase muscle and especially that water is one of the essential components of muscles, and in these days and we are in the holy month of Ramadan, we will refrain from the consumption of food and fluids for a period of more than 13 hours a day Therefore, the need to consume good amounts of fluids, especially water in times of breakfast is very necessary, since the water works and contributes to many of the core functions and mission of the human body . Water and digestion: - Water solvent for vitamins, minerals, amino acids, glucose and many other nutritional elements. - Water plays a vital role in digestion, absorption, transport, and use of nutrients. - Safe water is the center to get rid of toxins and waste. - Supports all the thermoregulation of the body on the water. - Is essential in the production of energy, the lubrication of joints. Loss of water affects the comatose: How many hours can a person live without water? What happens to him after that time period? - Man cannot live without drinking water for more than 72 hours (three days). If the period exceeds that may have a human fell into a coma due to the cessation of construction and demolition and stop the movement of the interactions within the body, so water is the lifeblood of every living organism. And Allah Almighty says: (and we have made from water every living thing). Subhanallah ...see how Allah Almigthy created us in this world. Weigth gain : How much is water weight? As for people believing that drinking water frequently can lead to weight gain or large abdomen, etc. So of course this belief is wrong, the water is normal does not cause obesity or weight gain, but soda water or fruit juices containing large amounts of sugar can cause obesity, especially the breeding of them, and in especially soft drinks known food empty, contain any calories without many nutrients they contain. When human needs for drinking, and when should I drink? Should drink water when we feel thirsty, and there are physiological mechanisms working to move the sense of thirst when a natural person healthy. The important note here is: It may weaken the sense of thirst when some people, for many reasons, especially in the elderly, and therefore must be drawn, drinking water and fluids to work on submission to the people who suffer from this problem, such as elderly patients, children and infants. What are the effects of consumption of water and fluids of sick? Lack of fluid consumption in general and water consumption in particular, may have a risk of infection and the impact on: Renal stones ...Obesity or obesity, childhood and adolescence. dehydration: What is a drought or dehydration? Dehydration : Is the lack of adequate rehydration (Perfusion enough) after the loss of water daily, for a long time and knows the chronic drought Poor sense of thirst mechanism Non-tasting water and a sense of complacency Consumption of common diuretics ... In Addition , Water is a major source of the life of a people , But not only a people ; every living things. According to the verse in the Holy Book , which is The Qur'an , Allah (swt) said : (and sent down, from the rain clouds pouring water, that we may bring forth thereby grain and vegetable, and Gardens of entwined growth...Surah Annaba.( 14-15-16-) in the another verses on the Qur'an , Allah said : (But when we send down water on it, it is stirred (to life), and it swells and puts forth every lovely kind (of growth).surah Al-Hajj: 5 Means; when Allah sends the rain upon it, it is stirred to life, that is, vegetation begins to grow and it comes alive after it was dead. Then it rises after the soil had settled, then it puts forth its different kinds of fruit and crops with all their variedcolours, tastes, fragrances, shapes and benefits. Allah says: (And puts forth every lovely kind (of growth) Meaning, beautiful in appearance and with delightful fragrance...Subhanallah ... (That is because Allah: He is the truth,) means the creator, the controller, the one who does as He. ... (And it is He who gives life to the dead)... ... (Verily, He who gives it life surely is able to give life to the dead. Indeed He is able to do all things....) Qur'an, 41:39 http://ipcblogger.net/noraisa/?p=453 Thank you From ned at nedbatchelder.com Thu Sep 4 16:52:11 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Thu, 04 Sep 2014 16:52:11 -0400 Subject: bicyclerepairman python24 windows idle :( In-Reply-To: References: Message-ID: On 9/4/14 1:51 PM, Stewart Graff (Visual Concepts) wrote: > Lines 304 ? 318 contain non-ascii characters. > > You need to rewrite all of the leading whitespace for the function > > def confirm_buffer_is_saved(self, editwin): > > Make sure you also replace the ?&nbs p; ? with spaces on line 313. > > > This seems like enough of a non-sequitur that I wonder if you posted it in the wrong place? -- Ned Batchelder, http://nedbatchelder.com From joshua at landau.ws Thu Sep 4 17:06:23 2014 From: joshua at landau.ws (Joshua Landau) Date: Thu, 4 Sep 2014 22:06:23 +0100 Subject: How to turn a string into a list of integers? In-Reply-To: <1amjdb-p3n.ln1@chris.zbmc.eu> References: <1amjdb-p3n.ln1@chris.zbmc.eu> Message-ID: On 3 September 2014 15:48, wrote: > Peter Otten <__peter__ at web.de> wrote: >> >>> [ord(c) for c in "This is a string"] >> [84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 115, 116, 114, 105, 110, 103] >> >> There are other ways, but you have to describe the use case and your Python >> version for us to recommend the most appropriate. >> > That looks OK to me. It's just for outputting a string to the block > write command in python-smbus which expects an integer array. Just be careful about Unicode characters. From john_ladasky at sbcglobal.net Thu Sep 4 17:57:04 2014 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Thu, 4 Sep 2014 14:57:04 -0700 (PDT) Subject: bicyclerepairman python24 windows idle :( In-Reply-To: References: Message-ID: <193c3544-26f7-4aa7-a570-d9b3afd0e4a9@googlegroups.com> On Thursday, September 4, 2014 1:52:37 PM UTC-7, Ned Batchelder wrote: > This seems like enough of a non-sequitur that I wonder if you posted it > in the wrong place? Maybe someone is trying out a new chatbot program? From rosuav at gmail.com Thu Sep 4 20:12:41 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 5 Sep 2014 10:12:41 +1000 Subject: How to turn a string into a list of integers? In-Reply-To: References: <1amjdb-p3n.ln1@chris.zbmc.eu> Message-ID: On Fri, Sep 5, 2014 at 7:06 AM, Joshua Landau wrote: > On 3 September 2014 15:48, wrote: >> Peter Otten <__peter__ at web.de> wrote: >>> >>> [ord(c) for c in "This is a string"] >>> [84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 115, 116, 114, 105, 110, 103] >>> >>> There are other ways, but you have to describe the use case and your Python >>> version for us to recommend the most appropriate. >>> >> That looks OK to me. It's just for outputting a string to the block >> write command in python-smbus which expects an integer array. > > Just be careful about Unicode characters. If it's a Unicode string (which is the default in Python 3), all Unicode characters will work correctly. If it's a byte string (the default in Python 2), then you can't actually have any Unicode characters in it at all, you have bytes; Py2 lets you be a bit sloppy with the ASCII range, but technically, you still have bytes, not characters.. ChrisA From rustompmody at gmail.com Thu Sep 4 21:39:50 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 4 Sep 2014 18:39:50 -0700 (PDT) Subject: bicyclerepairman python24 windows idle :( In-Reply-To: References: Message-ID: <3ec4118f-b537-4119-91b3-19e1e02b4cda@googlegroups.com> On Friday, September 5, 2014 2:22:37 AM UTC+5:30, Ned Batchelder wrote: > On 9/4/14 1:51 PM, Stewart Graff (Visual Concepts) wrote: > > Lines 304 - 318 contain non-ascii characters. > > You need to rewrite all of the leading whitespace for the function > > def confirm_buffer_is_saved(self, editwin): > > Make sure you also replace the "&nbs p; " with spaces on line 313. > This seems like enough of a non-sequitur that I wonder if you posted it > in the wrong place? Bicycle repair man is a refactoring plugin for python http://bicyclerepair.sourceforge.net/ Last I knew it hadnt worked for some years though I see an update in 2013 Its closest successor is rope I guess. If you want this though, pydev (eclipse) is probably more appropriate today From ian.g.kelly at gmail.com Thu Sep 4 22:09:01 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 4 Sep 2014 20:09:01 -0600 Subject: How to turn a string into a list of integers? In-Reply-To: References: <1amjdb-p3n.ln1@chris.zbmc.eu> Message-ID: On Thu, Sep 4, 2014 at 6:12 PM, Chris Angelico wrote: > If it's a Unicode string (which is the default in Python 3), all > Unicode characters will work correctly. Assuming the library that needs this is expecting codepoints and will accept integers greater than 255. > If it's a byte string (the > default in Python 2), then you can't actually have any Unicode > characters in it at all, you have bytes; Py2 lets you be a bit sloppy > with the ASCII range, but technically, you still have bytes, not > characters.. In that case the library will almost certainly accept it, but could be expecting a different encoding. From rosuav at gmail.com Thu Sep 4 22:15:14 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 5 Sep 2014 12:15:14 +1000 Subject: How to turn a string into a list of integers? In-Reply-To: References: <1amjdb-p3n.ln1@chris.zbmc.eu> Message-ID: On Fri, Sep 5, 2014 at 12:09 PM, Ian Kelly wrote: > On Thu, Sep 4, 2014 at 6:12 PM, Chris Angelico wrote: >> If it's a Unicode string (which is the default in Python 3), all >> Unicode characters will work correctly. > > Assuming the library that needs this is expecting codepoints and will > accept integers greater than 255. They're still valid integers. It's just that someone might not know how to work with them. Everyone has limits - I don't think repr() would like to be fed Graham's Number, for instance, but we still say that it accepts integers :) >> If it's a byte string (the >> default in Python 2), then you can't actually have any Unicode >> characters in it at all, you have bytes; Py2 lets you be a bit sloppy >> with the ASCII range, but technically, you still have bytes, not >> characters.. > > In that case the library will almost certainly accept it, but could be > expecting a different encoding. Yeah. Either way, the problem isn't "be careful about Unicode characters". One option has Unicode characters, the other doesn't, and you need to know which one it is. I just don't like people talking about "Unicode characters" being somehow different from "normal text" or something, and being something that you need to be careful of. It's not that there are some characters that behave nicely, and then other ones ("Unicode" ones) that don't. ChrisA From rustompmody at gmail.com Thu Sep 4 22:24:21 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 4 Sep 2014 19:24:21 -0700 (PDT) Subject: Python is going to be hard In-Reply-To: References: <51acfec6-6b7b-4773-8d70-0360381bbed1@googlegroups.com> <4c873e02-93b1-4ad3-bc91-566a72b8e729@googlegroups.com> <99df9997-474e-4190-8179-6c1442b622a2@googlegroups.com> <54086b15$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <24e13972-bda0-48fb-bc70-81861ae43eff@googlegroups.com> On Thursday, September 4, 2014 7:38:40 PM UTC+5:30, Chris Angelico wrote: > So a fairer comparison is: How many applications produce non-debug > output on stderr or stdout? And that would be a much larger > percentage. Even GUI programs will, in some cases - for instance, try > firing up your favorite GUI text editor with no X server active, or > with invalid .Xauthority. You'll get some sort of error message - on > the console. Which means that somewhere in the GUI library, there's > fall-back code that produces console output. That's why I say it's the > most basic of all forms of that fundamental of programming, producing > output that a human can read. It's the simple one that you teach > first; everything else is built on that. Seeing the unix-centricity of this -- What's .Xauthority?? -- reminds me of this story/joke (apocryphal) that floats around the net. ---------------------------------------------------------------- Word Perfect helpline story: Customer support officer was sacked because of the following conversation Customer Support: Ridge Hall computer assistant; may I help you? Caller: Yes, well, I'm having trouble with WordPerfect. CS: What sort of trouble? C: Well, I was just typing along, and all of a sudden the words went away. CS: Went away? C: They disappeared. CS: Hmm. So what does your screen look like now? C: Nothing. CS: Nothing? C: It's blank; it won't accept anything when I type. CS: Are you still in WordPerfect, or did you get out? C: How do I tell? CS: Can you see the C: prompt on the screen? C: What's a sea-prompt? CS: Never mind. Can you move the cursor around on the screen? C: There isn't any cursor, I told you, it won't accept anything I type. CS: Does your monitor have a power indicator? C: What's a monitor? CS: It's the thing with the screen on it that looks like a TV. Does it have a little light that tells you when it's on? C: I don't know. CS: Well, then look on the back of the monitor and find where the power cord goes into it. Can you see that? C: Yes, I think so. CS: Great. Follow the cord to the plug, and tell me if it's plugged into the wall. C: .......Yes, it is. CS: When you were behind the monitor, did you notice that there were two cables plugged into the back of it, not just one? C: No. CS: Well, there are. I need you to look back there again and find the other cable. C: .......Okay, here it is. CS: Follow it for me, and tell me if it's plugged securely into the back of your computer. C: I can't reach. CS: Uh huh. Well, can you see if it is? C: No. CS: Even if you maybe put your knee on something and lean way over? C: Oh, it's not because I don't have the right angle - it's because it's dark. CS: Dark? C: Yes - the office light is off, and the only light I have is coming in from the window. CS: Well, turn on the office light then. C: I can't. CS: No? Why not? C: Because there's a power outage. CS: A power... A power outage? Ah, Okay, we've got it licked now. Do you still have the boxes and manuals and packing stuff your computer came in? C: Well, yes, I keep them in the closet. CS: Good. Go get them, and unplug your system and pack it up just like it was when you got it. Then take it back to the store you bought it from. C: Really? Is it that bad? CS: Yes, I'm afraid it is. C: Well, all right then, I suppose. What do I tell them? CS: Tell them you're too stupid to own a computer. -------------------------------------------------------------------- Yeah its funny... But it tells a serious story in the context of this thread. We make a large number of assumptions which may seem obvious to some and not to others -- "Machine is powered on" is of course an extreme. One can think of more such. eg for running a python .. 1. We need a machine. What is "machine"? Washing machine? No computer! Will IBM 360 do? EDSAC? *&*(&^%$# I mean a reasonably modern computer! The most modern and widespread computing devices are smartphones. Will that do? Ok so lets assume that the not exactly trivial question "What is an appropriate machine for running python?" has been settled (And its powered on!) Is that enough? 2. I am playing around with the "rm" command. So I rm /lib/x86_64-linux-gnu/libc.so.6 3. Ok so I have a 'running' system. And its asking me for something called a login and password etc ... 4. Running system. Python script not running. Is python installed? All of which is to say that for meaningfully discussing python we make a fairly large number of assumptions. You assume that this thing called bash/cmd is a given. What is bash? An OS-level REPL. [Linux-kernel programmers cant assume such] If we can assume all the above, how much extra is it to assume one more level of REPL called 'python'? And what are the pedagogic advantages to this assumption? From rosuav at gmail.com Thu Sep 4 22:30:44 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 5 Sep 2014 12:30:44 +1000 Subject: Python is going to be hard In-Reply-To: <24e13972-bda0-48fb-bc70-81861ae43eff@googlegroups.com> References: <51acfec6-6b7b-4773-8d70-0360381bbed1@googlegroups.com> <4c873e02-93b1-4ad3-bc91-566a72b8e729@googlegroups.com> <99df9997-474e-4190-8179-6c1442b622a2@googlegroups.com> <54086b15$0$29977$c3e8da3$5496439d@news.astraweb.com> <24e13972-bda0-48fb-bc70-81861ae43eff@googlegroups.com> Message-ID: On Fri, Sep 5, 2014 at 12:24 PM, Rustom Mody wrote: > On Thursday, September 4, 2014 7:38:40 PM UTC+5:30, Chris Angelico wrote: > >> So a fairer comparison is: How many applications produce non-debug >> output on stderr or stdout? And that would be a much larger >> percentage. Even GUI programs will, in some cases - for instance, try >> firing up your favorite GUI text editor with no X server active, or >> with invalid .Xauthority. You'll get some sort of error message - on >> the console. Which means that somewhere in the GUI library, there's >> fall-back code that produces console output. That's why I say it's the >> most basic of all forms of that fundamental of programming, producing >> output that a human can read. It's the simple one that you teach >> first; everything else is built on that. > > Seeing the unix-centricity of this -- What's .Xauthority?? -- That's one particular example that's from Unix. I've seen (and written) Windows GUI programs that use consoles, too. And OS/2 ones. Can't speak for Mac OS Classic as I've never used it, but I'd be surprised if it's not possible. So I still stand by my statement that console output is a fundamental, and it's not a bad thing to teach it. ChrisA From roy at panix.com Thu Sep 4 22:51:40 2014 From: roy at panix.com (Roy Smith) Date: Thu, 04 Sep 2014 22:51:40 -0400 Subject: Python is going to be hard References: <51acfec6-6b7b-4773-8d70-0360381bbed1@googlegroups.com> <4c873e02-93b1-4ad3-bc91-566a72b8e729@googlegroups.com> <99df9997-474e-4190-8179-6c1442b622a2@googlegroups.com> <54086b15$0$29977$c3e8da3$5496439d@news.astraweb.com> <24e13972-bda0-48fb-bc70-81861ae43eff@googlegroups.com> Message-ID: In article , Chris Angelico wrote: > On Fri, Sep 5, 2014 at 12:24 PM, Rustom Mody wrote: > > On Thursday, September 4, 2014 7:38:40 PM UTC+5:30, Chris Angelico wrote: > > > >> So a fairer comparison is: How many applications produce non-debug > >> output on stderr or stdout? And that would be a much larger > >> percentage. Even GUI programs will, in some cases - for instance, try > >> firing up your favorite GUI text editor with no X server active, or > >> with invalid .Xauthority. You'll get some sort of error message - on > >> the console. Which means that somewhere in the GUI library, there's > >> fall-back code that produces console output. That's why I say it's the > >> most basic of all forms of that fundamental of programming, producing > >> output that a human can read. It's the simple one that you teach > >> first; everything else is built on that. > > > > Seeing the unix-centricity of this -- What's .Xauthority?? -- > > That's one particular example that's from Unix. I've seen (and > written) Windows GUI programs that use consoles, too. And OS/2 ones. > Can't speak for Mac OS Classic as I've never used it, but I'd be > surprised if it's not possible. > > So I still stand by my statement that console output is a fundamental, > and it's not a bad thing to teach it. > > ChrisA write(6, 11) 11 format(21H.XAUTHORITY NOT FOUND) From denismfmcmahon at gmail.com Thu Sep 4 22:53:13 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Fri, 5 Sep 2014 02:53:13 +0000 (UTC) Subject: I have tried and errored a reasonable amount of times References: <5406726f$0$6512$c3e8da3$5496439d@news.astraweb.com> <4af60c7a-f4d6-4aa7-b181-fe768ea6f731@googlegroups.com> <5406c052$0$29876$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, 04 Sep 2014 21:42:56 +1000, Chris Angelico wrote: > On Thu, Sep 4, 2014 at 9:17 PM, Denis McMahon > wrote: >> On Wed, 03 Sep 2014 07:16:34 +0000, Steven D'Aprano wrote: >> >>> Who uses + for disjunction (? OR) and concatenation for conjunction (? >>> AND)? That's crazy notation. >> >> The way I was taught it in the mid 1980s, a.b === a and b, a+b === a or >> b. > > The middle dot is another notation for multiplication, as is abuttal > (not actually concatenation, in this context). So they're all saying the > same thing: boolean 'and' is multiplication, boolean 'or' is addition. Yes Chris, I know that. I was responding to Stephen's statement that using + for or was crazy notation, and pointing out that 30 years ago, that's what UK colleges were teaching! -- Denis McMahon, denismfmcmahon at gmail.com From rustompmody at gmail.com Thu Sep 4 22:56:58 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 4 Sep 2014 19:56:58 -0700 (PDT) Subject: Python is going to be hard In-Reply-To: References: <51acfec6-6b7b-4773-8d70-0360381bbed1@googlegroups.com> <4c873e02-93b1-4ad3-bc91-566a72b8e729@googlegroups.com> <99df9997-474e-4190-8179-6c1442b622a2@googlegroups.com> <54086b15$0$29977$c3e8da3$5496439d@news.astraweb.com> <24e13972-bda0-48fb-bc70-81861ae43eff@googlegroups.com> Message-ID: <1e22e301-7e16-4168-9f04-d994c1fb53bf@googlegroups.com> On Friday, September 5, 2014 8:01:00 AM UTC+5:30, Chris Angelico wrote: > That's one particular example that's from Unix. I've seen (and > written) Windows GUI programs that use consoles, too. And OS/2 ones. > Can't speak for Mac OS Classic as I've never used it, but I'd be > surprised if it's not possible. > So I still stand by my statement that console output is a fundamental, > and it's not a bad thing to teach it. If what is fundamental is what should be taught (first) then we should start with machine language because everything bottoms out into that. Yes? The most logical order and the optimal pedagogical order are not usually the same and they may both differ from the factual historical order. In here Ive laid out the history of CS as it unfolded blog.languager.org/2011/02/cs-education-is-fat-and-weak-1.html And the consequent pedagogical confusions and logical inconsistencies of choosing not to 'reconfigure' our history: blog.languager.org/2011/02/cs-education-is-fat-and-weak-2.html Including this that my teacher's teacher of programming was taught assembly as the first programming language because it was easy and Fortran (II??) only later because it was advanced and difficult. This was right in 1960. Its wrong today. Likewise here. In C we have no choice but to produce standalone executables. Imposing the same impoverishment onto a beginner by teaching script-writing before the REPL is a miserable choice. From rosuav at gmail.com Thu Sep 4 23:02:47 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 5 Sep 2014 13:02:47 +1000 Subject: I have tried and errored a reasonable amount of times In-Reply-To: References: <5406726f$0$6512$c3e8da3$5496439d@news.astraweb.com> <4af60c7a-f4d6-4aa7-b181-fe768ea6f731@googlegroups.com> <5406c052$0$29876$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Sep 5, 2014 at 12:53 PM, Denis McMahon wrote: > On Thu, 04 Sep 2014 21:42:56 +1000, Chris Angelico wrote: > >> On Thu, Sep 4, 2014 at 9:17 PM, Denis McMahon >> wrote: >>> On Wed, 03 Sep 2014 07:16:34 +0000, Steven D'Aprano wrote: >>> >>>> Who uses + for disjunction (? OR) and concatenation for conjunction (? >>>> AND)? That's crazy notation. >>> >>> The way I was taught it in the mid 1980s, a.b === a and b, a+b === a or >>> b. >> >> The middle dot is another notation for multiplication, as is abuttal >> (not actually concatenation, in this context). So they're all saying the >> same thing: boolean 'and' is multiplication, boolean 'or' is addition. > > Yes Chris, I know that. I was responding to Stephen's statement that > using + for or was crazy notation, and pointing out that 30 years ago, > that's what UK colleges were teaching! Ah, okay. Wasn't sure if you meant to be agreeing with multiplication or offering an alternative. ChrisA From rosuav at gmail.com Thu Sep 4 23:08:49 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 5 Sep 2014 13:08:49 +1000 Subject: Python is going to be hard In-Reply-To: <1e22e301-7e16-4168-9f04-d994c1fb53bf@googlegroups.com> References: <51acfec6-6b7b-4773-8d70-0360381bbed1@googlegroups.com> <4c873e02-93b1-4ad3-bc91-566a72b8e729@googlegroups.com> <99df9997-474e-4190-8179-6c1442b622a2@googlegroups.com> <54086b15$0$29977$c3e8da3$5496439d@news.astraweb.com> <24e13972-bda0-48fb-bc70-81861ae43eff@googlegroups.com> <1e22e301-7e16-4168-9f04-d994c1fb53bf@googlegroups.com> Message-ID: On Fri, Sep 5, 2014 at 12:56 PM, Rustom Mody wrote: > On Friday, September 5, 2014 8:01:00 AM UTC+5:30, Chris Angelico wrote: > >> That's one particular example that's from Unix. I've seen (and >> written) Windows GUI programs that use consoles, too. And OS/2 ones. >> Can't speak for Mac OS Classic as I've never used it, but I'd be >> surprised if it's not possible. > >> So I still stand by my statement that console output is a fundamental, >> and it's not a bad thing to teach it. > > If what is fundamental is what should be taught (first) then we should > start with machine language because everything bottoms out into > that. Yes? No, that's not what fundamental means. And if you try to say "teach the lowest abstraction first", then you have to teach electrical engineering... oh wait, that's just an abstraction over physics... which is an abstraction over mathematics... which gets us right back to the top of the stack. The fundamental is the thing that's most basic in *usage*, not implementation. Console output on a modern GUI system ends up becoming GUI display, so if you go by the "most concrete wins" then you should start by teaching a GUI. But the console has been implemented for you, and in usage, it's the simplest and most basic form of output available. It's also the most cross-platform - there's no form of output more available than stdout. > Likewise here. In C we have no choice but to produce standalone > executables. Technically wrong, I've seen interactive C interpreters :) Language doesn't mandate usage structure. > Imposing the same impoverishment onto a beginner by > teaching script-writing before the REPL is a miserable choice. Personally, I'd teach both very early. Whether you teach scripts first or REPL first doesn't make much difference - just teach both. I'm not sure what this has to do with print, though, nor how you propose to make useful programs without side effects. ChrisA From dan at tombstonezero.net Fri Sep 5 00:38:17 2014 From: dan at tombstonezero.net (Dan Sommers) Date: Fri, 5 Sep 2014 04:38:17 +0000 (UTC) Subject: Storing instances using jsonpickle References: <46e782a5-b087-4f95-aadb-26e233bf5419@googlegroups.com> <5407A69B.3030707@mrabarnett.plus.com> Message-ID: On Thu, 04 Sep 2014 15:17:17 +1000, Chris Angelico wrote: > On Thu, Sep 4, 2014 at 9:39 AM, MRAB wrote: >> The key of a dict could also be int, float, or tuple. > > Yes! Yes! DEFINITELY do this!! Ahem. Calm down a little, it's not that > outlandish an idea... Using floats is a bad idea. Consider this python code: dictionary = dict() original = get_some_floating_point_value() dictionary[original] = 'foo' string_version = str(original) # this is where things head south duplicate = float(string_version) value = dictionary.get(duplicate) Okay, so what is value? Is it 'foo'? Is it None? (Yes, I can fix this. If I *know* that original is a float, then I could use original.hex() instead of str(original).) HTH, Dan From rosuav at gmail.com Fri Sep 5 01:08:09 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 5 Sep 2014 15:08:09 +1000 Subject: Storing instances using jsonpickle In-Reply-To: References: <46e782a5-b087-4f95-aadb-26e233bf5419@googlegroups.com> <5407A69B.3030707@mrabarnett.plus.com> Message-ID: On Fri, Sep 5, 2014 at 2:38 PM, Dan Sommers wrote: > On Thu, 04 Sep 2014 15:17:17 +1000, Chris Angelico wrote: > >> On Thu, Sep 4, 2014 at 9:39 AM, MRAB wrote: > >>> The key of a dict could also be int, float, or tuple. >> >> Yes! Yes! DEFINITELY do this!! Ahem. Calm down a little, it's not that >> outlandish an idea... > > Using floats is a bad idea. Consider this python code: > > dictionary = dict() > original = get_some_floating_point_value() > dictionary[original] = 'foo' > string_version = str(original) # this is where things head south > duplicate = float(string_version) > value = dictionary.get(duplicate) > > Okay, so what is value? Is it 'foo'? Is it None? > > (Yes, I can fix this. If I *know* that original is a float, then I > could use original.hex() instead of str(original).) There are issues with direct lookups, yes, but you can safely and easily iterate over that dictionary, and that's going to have plenty of use. ChrisA From fk26541598fk at gmail.com Fri Sep 5 03:02:02 2014 From: fk26541598fk at gmail.com (Frank Liou) Date: Fri, 5 Sep 2014 00:02:02 -0700 (PDT) Subject: Python Crypto Singature do not support Android??? Message-ID: <614897cb-6a2f-4059-a713-05c0cd2b3cd5@googlegroups.com> I use Privatekey sign a signature by android and then send to python python can't use public key to verify and python signature result all is number but android is number and english words is that no support?? From rosuav at gmail.com Fri Sep 5 03:11:11 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 5 Sep 2014 17:11:11 +1000 Subject: Python Crypto Singature do not support Android??? In-Reply-To: <614897cb-6a2f-4059-a713-05c0cd2b3cd5@googlegroups.com> References: <614897cb-6a2f-4059-a713-05c0cd2b3cd5@googlegroups.com> Message-ID: On Fri, Sep 5, 2014 at 5:02 PM, Frank Liou wrote: > I use Privatekey sign a signature by android > > and then send to python > > python can't use public key to verify > > and > > python signature result all is number > > but > > android is number and english words > > is that no support?? It would help if you showed us (a) the code, (b) the two different results, and (c) what you're expecting to see. ChrisA From fk26541598fk at gmail.com Fri Sep 5 03:23:51 2014 From: fk26541598fk at gmail.com (Frank Liou) Date: Fri, 5 Sep 2014 00:23:51 -0700 (PDT) Subject: Python Crypto Singature do not support Android??? In-Reply-To: <614897cb-6a2f-4059-a713-05c0cd2b3cd5@googlegroups.com> References: <614897cb-6a2f-4059-a713-05c0cd2b3cd5@googlegroups.com> Message-ID: <5bacfff0-246f-4c97-b8ba-5f6ce45acf29@googlegroups.com> Sorry!! here is my code python : msg = '123' msg = msg.encode('utf-8') digest = SHA.new(msg).digest() signature = APP_key_Private.sign(digest, '') signature like: (3313609575189770456309776952388055366479183814159935747487353823698464644111856144652004406811762087026328804664486509214841694613481763164909855307029962363047099944520695429504224843583313164533334332743470132105629096577439312314814238554088472504815623363978006284897433036223490623530076474911740732410,) and android : InputStream inPrivate = getResources().getAssets().open("PR1.pem"); PrivateKey privateKey = RSAUtils.loadPrivateKey(inPrivate); Log.d("privateKey------",privateKey.toString()); byte[] a = Sign.digest("123".getBytes()); String test_a_to64 = Base64.encodeToString(a,Base64.DEFAULT); Log.d("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX------",test_a_to64); Log.d("sdfgserthwrthhsrethwegerg------",Arrays.toString(a)); String sdf = Sign.sign(a,privateKey); Log.d("000000000000000000000------",Arrays.toString(sdf.getBytes())); Android like: [34, 68, 28, 72, -43, 7, -64, -127, -119, -44, 61, -53, -22, 112, -74, -122, -19, -127, -120, -43, 1, -55, 66, -47, -63, -128, 104, -97, 104, 65, -48, -120, -50, 117, 85, 86, -33, 37, -77, -26, -46, -59, -43, -42, -79, -9, -78, -26, -25, 5, 4, -104, 95, -120, -73, 123, 70, -11, 56, -10, -99, -126, -30, -3, -63, 42, 45, 33, 36, 23, -52, 10, -4, -17, 8, 82, -61, 74, 43, -5, 44, 29, 127, 78, 100, -88, -24, -61, -24, 3, -105, 4, 117, 71, 41, 74, 99, 23, 68, 112, -8, -105, 67, -68, -115, -27, -24, 114, -108, 28, 15, -85, -77, 49, -110, -10, -83, -58, -27, 34, 90, -52, 71, -72, 73, -5, -2, -56] please help From frank at chagford.com Fri Sep 5 03:26:43 2014 From: frank at chagford.com (Frank Millman) Date: Fri, 5 Sep 2014 09:26:43 +0200 Subject: Run an http server on Apache without wsgi? Message-ID: Hi all My AccInABox project runs an http server. Previously I used the cherry.py wsgiserver, but I have now switched to asyncio. I tried to use the wsgi interface, but I have a particular requirement and found that wsgi got in the way, so I dropped it and now handle all requests directly. Now the question arises, what if someone wants to run my program under Apache or nginx? I have had some feedback from a sysadmin, whose main concern is how to deploy my program, which is something I have not given serious thought to. If the answer is that I really should be using wsgi, I will explain my specific requirement in more detail, and see if anyone can suggest a workaround. But at this stage, I would like to discuss whether it is possible to avoid using wsgi. Should I be looking at FastCGI, or is that now considered outdated? I would appreciate any pointers or links to get me started. Thanks Frank Millman From rosuav at gmail.com Fri Sep 5 03:47:55 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 5 Sep 2014 17:47:55 +1000 Subject: Python Crypto Singature do not support Android??? In-Reply-To: <5bacfff0-246f-4c97-b8ba-5f6ce45acf29@googlegroups.com> References: <614897cb-6a2f-4059-a713-05c0cd2b3cd5@googlegroups.com> <5bacfff0-246f-4c97-b8ba-5f6ce45acf29@googlegroups.com> Message-ID: On Fri, Sep 5, 2014 at 5:23 PM, Frank Liou wrote: > here is my code > > python : > > msg = '123' > msg = msg.encode('utf-8') > digest = SHA.new(msg).digest() > signature = APP_key_Private.sign(digest, '') That code is incomplete, I can't run it. Ditto your Java code. But what seems to be happening is that you're getting data back in two very different formats, plus you're generating one signature based on a UTF-8 stream and one based on a Base-64 stream. Start by writing *simple* code that does what you want, and then porting that to the other language exactly. Also, please don't use Google Groups, or if you must, please remember to include context. ChrisA From cl at isbd.net Fri Sep 5 04:42:09 2014 From: cl at isbd.net (cl at isbd.net) Date: Fri, 5 Sep 2014 09:42:09 +0100 Subject: How to turn a string into a list of integers? References: <1amjdb-p3n.ln1@chris.zbmc.eu> Message-ID: <1k9odb-1qs.ln1@chris.zbmc.eu> Joshua Landau wrote: > On 3 September 2014 15:48, wrote: > > Peter Otten <__peter__ at web.de> wrote: > >> >>> [ord(c) for c in "This is a string"] > >> [84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 115, 116, 114, 105, 110, 103] > >> > >> There are other ways, but you have to describe the use case and your Python > >> version for us to recommend the most appropriate. > >> > > That looks OK to me. It's just for outputting a string to the block > > write command in python-smbus which expects an integer array. > > Just be careful about Unicode characters. I have to avoid them completely because I'm sending the string to a character LCD with a limited 8-bit only character set. -- Chris Green ? From jldunn2000 at gmail.com Fri Sep 5 06:20:35 2014 From: jldunn2000 at gmail.com (loial) Date: Fri, 5 Sep 2014 03:20:35 -0700 (PDT) Subject: reading file in for loop Message-ID: <8452f1f9-521c-4301-8051-1dc0905e5576@googlegroups.com> If I read a file using a for loop, as follows, is the file left open if I execute a break in the for loop? for line in open(myFile).readlines(): if something: break From rosuav at gmail.com Fri Sep 5 06:31:02 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 5 Sep 2014 20:31:02 +1000 Subject: reading file in for loop In-Reply-To: <8452f1f9-521c-4301-8051-1dc0905e5576@googlegroups.com> References: <8452f1f9-521c-4301-8051-1dc0905e5576@googlegroups.com> Message-ID: On Fri, Sep 5, 2014 at 8:20 PM, loial wrote: > If I read a file using a for loop, as follows, is the file left open if I execute a break in the for loop? > > > for line in open(myFile).readlines(): > > if something: > break It'll be closed when the object expires. With CPython, that's probably going to happen fairly soon, but it's not guaranteed in any way. If you want to be sure it's closed, use a 'with' statement - look it up in the docs. ChrisA From __peter__ at web.de Fri Sep 5 06:50:18 2014 From: __peter__ at web.de (Peter Otten) Date: Fri, 05 Sep 2014 12:50:18 +0200 Subject: reading file in for loop References: <8452f1f9-521c-4301-8051-1dc0905e5576@googlegroups.com> Message-ID: loial wrote: > If I read a file using a for loop, as follows, is the file left open if I > execute a break in the for loop? > > > for line in open(myFile).readlines(): > > if something: > break Whether the file is left open has nothing to do with how you leave the loop. The way you wrote it (readlines() reads all lines into a list and there is no reference to the file object left) CPython will close the file before you enter the loop: $ python Python 2.7.6 (default, Mar 22 2014, 22:59:56) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> for line in open("tmp.txt").readlines(): ... raw_input("you are here") ... break ... you are here [1]+ Angehalten python $ lsof * Other implementations take a bit more time: $ jython "my" variable $jythonHome masks earlier declaration in same scope at /usr/bin/jython line 15. Jython 2.5.3 (, Nov 21 2013, 23:15:42) [OpenJDK 64-Bit Server VM (Oracle Corporation)] on java1.7.0_65 Type "help", "copyright", "credits" or "license" for more information. >>> for line in open("tmp.txt"): pass ... >>> [2]+ Angehalten jython $ lsof * COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME java 9396 xxxxx 34r REG 8,23 17 5906455 tmp.txt $ From studio-pm at hotmail.com Fri Sep 5 07:16:10 2014 From: studio-pm at hotmail.com (Pietro Moras) Date: Fri, 5 Sep 2014 11:16:10 +0000 Subject: =?Windows-1252?Q?=93Eric_Pyth?= =?Windows-1252?Q?on_3_(&_2)?= =?Windows-1252?Q?_IDE=94_Tech?= =?Windows-1252?Q?.Doc:__How?= =?Windows-1252?Q?_useful=3F?= Message-ID: So to schedule my next year's ?free? (in all senses) activity, I'd appreciate your remarks about your perceived practical usefulness of the Tech. Documentation of Eric advanced Python IDE, as available at URL: http://eric-ide.python-projects.org/eric-documentation.html For private answers: [Studio-PM hotmail com]. Critical remarks welcome too. Thanks. - P.M. -------------- next part -------------- An HTML attachment was scrubbed... URL: From bc at freeuk.com Fri Sep 5 08:37:00 2014 From: bc at freeuk.com (BartC) Date: Fri, 5 Sep 2014 13:37:00 +0100 Subject: Raspberry pi, python and robotics In-Reply-To: References: <20140902093058.0ac902ed@rg.highlandtechnology.com> Message-ID: "Gregory Ewing" wrote in message news:c6nv2hF8q6aU1 at mid.individual.net... > Rob Gaddi wrote: >> otherwise getting up and >> running will cost you a solid $1200 just in gear. > > While having fancy gear certainly helps, it's not > *strictly* necessary. When I first started dabbling > in electronics, the most sophisticated piece of > equipment I had was an analog multimeter. > > It got me through a lot of projects, including a > couple of homebrew computers. It's surprising how > much you can deduce about what's happening in a > digital circuit by watching a needle bouncing > around! I also used LEDs (even showing complex signals, as they will dim in different ways, or you could sometimes view them through a flipped mirror to show the patterns). Sometimes I fed a digital output to the video input of my TV (it was 5V to 1V, some care was needed), and the waveform became visible, although unsynchronised to anything. With one line representing about 50us, you could get a lot of clues about what was going on. (What I never tried with a TV, because I later had a scope, was to arrange for the line-sync to trigger some repeatable event I was trying to monitor. By using it as the /reset signal of a microprocessor for example.) Anyway, there were all sorts of tricks. I didn't have a proper knowledge of (analogue) electronics either, just enough to get by, or picked up what I needed as I went. (You tended to copy or adapt someone else's circuits.) Besides, a normal non-storage oscilloscope wasn't directly useful for the complex non-repeating signals you get with computer boards. -- Bartc From invalid at invalid.invalid Fri Sep 5 10:54:36 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 5 Sep 2014 14:54:36 +0000 (UTC) Subject: I have tried and errored a reasonable amount of times References: <5406726f$0$6512$c3e8da3$5496439d@news.astraweb.com> <4af60c7a-f4d6-4aa7-b181-fe768ea6f731@googlegroups.com> <5406c052$0$29876$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2014-09-05, Denis McMahon wrote: > On Thu, 04 Sep 2014 21:42:56 +1000, Chris Angelico wrote: >> On Thu, Sep 4, 2014 at 9:17 PM, Denis McMahon wrote: >>> On Wed, 03 Sep 2014 07:16:34 +0000, Steven D'Aprano wrote: >>> >>>> Who uses + for disjunction (? OR) and concatenation for conjunction >>>> (? AND)? That's crazy notation. >>> >>> The way I was taught it in the mid 1980s, a.b === a and b, a+b === a >>> or b. >> >> The middle dot is another notation for multiplication, as is abuttal >> (not actually concatenation, in this context). So they're all saying >> the same thing: boolean 'and' is multiplication, boolean 'or' is >> addition. > > Yes Chris, I know that. I was responding to Stephen's statement that > using + for or was crazy notation, and pointing out that 30 years > ago, that's what UK colleges were teaching! AFAIK, that's the standard notation in both CS and EE university classes in the US also: + for 'or' and dot or abuttal for 'and'. Well, it was 30 years ago... -- Grant Edwards grant.b.edwards Yow! But was he mature at enough last night at the gmail.com lesbian masquerade? From marko at pacujo.net Fri Sep 5 12:45:56 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 05 Sep 2014 19:45:56 +0300 Subject: I have tried and errored a reasonable amount of times References: <5406726f$0$6512$c3e8da3$5496439d@news.astraweb.com> <4af60c7a-f4d6-4aa7-b181-fe768ea6f731@googlegroups.com> <5406c052$0$29876$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87lhpyj9rv.fsf@elektro.pacujo.net> Grant Edwards : >>>>> Who uses + for disjunction (? OR) and concatenation for >>>>> conjunction (? AND)? That's crazy notation. > > AFAIK, that's the standard notation in both CS and EE university > classes in the US also: + for 'or' and dot or abuttal for 'and'. Besides, it's no crazier for Boolean algebra than real algebra. For some reason, mathematicians use + for addition and concatenation for multiplication... Marko From Seymore4Head at Hotmail.invalid Fri Sep 5 12:48:56 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Fri, 05 Sep 2014 12:48:56 -0400 Subject: My backwards logic Message-ID: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> I'm still doing practice problems. I haven't heard from the library on any of the books I have requested. http://www.practicepython.org/exercise/2014/04/16/11-check-primality-functions.html This is not a hard problem, but it got me to thinking a little. A prime number will divide by one and itself. When setting up this loop, if I start at 2 instead of 1, that automatically excludes one of the factors. Then, by default, Python goes "to" the chosen count and not "through" the count, so just the syntax causes Python to rule out the other factor (the number itself). So this works: while True: a=random.randrange(1,8) print (a) for x in range(2,a): if a%x==0: print ("Number is not prime") break wait = input (" "*40 + "Wait") But, what this instructions want printed is "This is a prime number" So how to I use this code logic NOT print (not prime) and have the logic print "This number is prime" From python at mrabarnett.plus.com Fri Sep 5 12:57:56 2014 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 05 Sep 2014 17:57:56 +0100 Subject: My backwards logic In-Reply-To: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> References: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> Message-ID: <5409EB94.9020602@mrabarnett.plus.com> On 2014-09-05 17:48, Seymore4Head wrote: > I'm still doing practice problems. I haven't heard from the library > on any of the books I have requested. > > http://www.practicepython.org/exercise/2014/04/16/11-check-primality-functions.html > > This is not a hard problem, but it got me to thinking a little. A > prime number will divide by one and itself. When setting up this > loop, if I start at 2 instead of 1, that automatically excludes one of > the factors. Then, by default, Python goes "to" the chosen count and > not "through" the count, so just the syntax causes Python to rule out > the other factor (the number itself). > > So this works: > while True: > a=random.randrange(1,8) > print (a) > for x in range(2,a): > if a%x==0: > print ("Number is not prime") > break > wait = input (" "*40 + "Wait") > > But, what this instructions want printed is "This is a prime number" > So how to I use this code logic NOT print (not prime) and have the > logic print "This number is prime" > Look for a factor. If you don't find one, it's a prime number. From python at mrabarnett.plus.com Fri Sep 5 13:04:11 2014 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 05 Sep 2014 18:04:11 +0100 Subject: Storing instances using jsonpickle In-Reply-To: References: <46e782a5-b087-4f95-aadb-26e233bf5419@googlegroups.com> <5407A69B.3030707@mrabarnett.plus.com> Message-ID: <5409ED0B.2030902@mrabarnett.plus.com> On 2014-09-04 06:17, Chris Angelico wrote: > On Thu, Sep 4, 2014 at 9:39 AM, MRAB wrote: >> I occasionally think about a superset of JSON, called, say, "pyson" ... >> ah, name already taken! :-( > > While I'm somewhat sympathetic to the concept, there are some parts of > your description that I disagree with. Am I misreading something? Are > there typos in the description and I'm making something out of > nothing? > >> It would add tuples, delimited by (...), which are not used otherwise (no >> expressions): >> >> () => () >> (0, ) => (0) > > This seems odd. Part of JSON's convenience is that it's a subset of > JavaScript syntax, so you can just plop a block of JSON into a REPL > and it'll decode correctly. With PyON (or whatever you call it), it'd > be nice to have the same correspondence; for a start, I would strongly > encourage the "trailing comma is permitted" rule (so [1,2,3,] is > equivalent to [1,2,3]), and then I'd have the default encoding for a > single-element tuple include that trailing comma. If (0) is a > one-element tuple, you end up with a subtle difference between a PyON > decode and the Python interpreter, which is likely to cause problems. > It might even be worth actually mandating (not just encouraging) that > one-element tuples have the trailing comma, just to prevent that. > [snip] JSON has 'true' and 'false'. Python has 'True' and 'False'. Therefore, if you want it to be able to drop it into Python's REPL, it won't be compatible with JSON anyway! (Well, not unless you define 'true' and 'false' first.) From bgailer at gmail.com Fri Sep 5 13:04:30 2014 From: bgailer at gmail.com (Bob Gailer) Date: Fri, 5 Sep 2014 13:04:30 -0400 Subject: My backwards logic In-Reply-To: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> References: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> Message-ID: Bob gailer On Sep 5, 2014 12:51 PM, "Seymore4Head" wrote: > > I'm still doing practice problems. I haven't heard from the library > on any of the books I have requested. > > http://www.practicepython.org/exercise/2014/04/16/11-check-primality-functions.html > > This is not a hard problem, but it got me to thinking a little. A > prime number will divide by one and itself. When setting up this > loop, if I start at 2 instead of 1, that automatically excludes one of > the factors. Then, by default, Python goes "to" the chosen count and > not "through" the count, so just the syntax causes Python to rule out > the other factor (the number itself). > > So this works: > while True: > a=random.randrange(1,8) > print (a) > for x in range(2,a): > if a%x==0: > print ("Number is not prime") > break else: print ... > wait = input (" "*40 + "Wait") > > But, what this instructions want printed is "This is a prime number" > So how to I use this code logic NOT print (not prime) and have the > logic print "This number is prime" > > -- > https://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Fri Sep 5 13:08:18 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 05 Sep 2014 10:08:18 -0700 Subject: My backwards logic In-Reply-To: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> References: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> Message-ID: <5409EE02.7030308@stoneleaf.us> On 09/05/2014 09:48 AM, Seymore4Head wrote: > I'm still doing practice problems. I haven't heard from the library > on any of the books I have requested. > > http://www.practicepython.org/exercise/2014/04/16/11-check-primality-functions.html > > This is not a hard problem, but it got me to thinking a little. A > prime number will divide by one and itself. When setting up this > loop, if I start at 2 instead of 1, that automatically excludes one of > the factors. Then, by default, Python goes "to" the chosen count and > not "through" the count, so just the syntax causes Python to rule out > the other factor (the number itself). > > So this works: > while True: > a=random.randrange(1,8) > print (a) > for x in range(2,a): > if a%x==0: > print ("Number is not prime") > break > wait = input (" "*40 + "Wait") > > But, what this instructions want printed is "This is a prime number" > So how to I use this code logic NOT print (not prime) and have the > logic print "This number is prime" Python's 'for' loop has a handy 'else' extension which is perfect for the search-type of 'for' loop: while True: a=random.randrange(1,8) print (a) for x in range(2,a): if a%x==0: print ("Number is not prime") break else: print ("Number is prime") wait = input (" "*40 + "Wait") Note the two lines I added after the 'break' and before the 'wait'. -- ~Ethan~ From ckaynor at zindagigames.com Fri Sep 5 13:09:05 2014 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Fri, 5 Sep 2014 10:09:05 -0700 Subject: My backwards logic In-Reply-To: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> References: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> Message-ID: On Fri, Sep 5, 2014 at 9:48 AM, Seymore4Head wrote: > I'm still doing practice problems. I haven't heard from the library > on any of the books I have requested. > > > http://www.practicepython.org/exercise/2014/04/16/11-check-primality-functions.html > > This is not a hard problem, but it got me to thinking a little. A > prime number will divide by one and itself. When setting up this > loop, if I start at 2 instead of 1, that automatically excludes one of > the factors. Then, by default, Python goes "to" the chosen count and > not "through" the count, so just the syntax causes Python to rule out > the other factor (the number itself). > > So this works: > while True: > a=random.randrange(1,8) > print (a) > for x in range(2,a): > if a%x==0: > print ("Number is not prime") > break > wait = input (" "*40 + "Wait") > > But, what this instructions want printed is "This is a prime number" > So how to I use this code logic NOT print (not prime) and have the > logic print "This number is prime" > > One neat feature of Python is the for...else function. The code inside the else block will run only if the loop ran to completion (untested code follows): while True: a=random.randrange(1,8) print (a) for x in range(2,a): if a%x==0: print ("Number is not prime") break else: print("Number is prime") wait = input (" "*40 + "Wait") Depending on how advanced you want to get (I know you are relatively new to Python), another decent way would be to extract the prime check to a function, and return the result, and print based on that result (again, untested code): def isPrime(number): for x in range(2,a): if a%x==0: return False return True while True: a=random.randrange(1,8) print (a) if isPrime(a): print("Number is prime") else: print("Number is not prime") wait = input (" "*40 + "Wait") -------------- next part -------------- An HTML attachment was scrubbed... URL: From gordon at panix.com Fri Sep 5 13:08:05 2014 From: gordon at panix.com (John Gordon) Date: Fri, 5 Sep 2014 17:08:05 +0000 (UTC) Subject: My backwards logic References: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> Message-ID: In <1enj0att6bkrnvb81rhma5dbuk3h28agl8 at 4ax.com> Seymore4Head writes: > I'm still doing practice problems. I haven't heard from the library > on any of the books I have requested. > http://www.practicepython.org/exercise/2014/04/16/11-check-primality-functions.html > This is not a hard problem, but it got me to thinking a little. A > prime number will divide by one and itself. When setting up this > loop, if I start at 2 instead of 1, that automatically excludes one of > the factors. Then, by default, Python goes "to" the chosen count and > not "through" the count, so just the syntax causes Python to rule out > the other factor (the number itself). > So this works: > while True: > a=random.randrange(1,8) > print (a) > for x in range(2,a): > if a%x==0: > print ("Number is not prime") > break > wait = input (" "*40 + "Wait") > But, what this instructions want printed is "This is a prime number" > So how to I use this code logic NOT print (not prime) and have the > logic print "This number is prime" There are two basic tactics you can use: 1. Initialize an "isprime" flag to True at the top of the while loop. In the for loop, replace the print statement with a statement that sets isprime to False. After the for loop, insert a check on isprime, and print "This number is prime" if isprime is still True. 2. Create a separate function just for testing if a number is prime, which returns True or False. Then call that function within your while loop. -- 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 davea at davea.name Fri Sep 5 13:15:23 2014 From: davea at davea.name (Dave Angel) Date: Fri, 5 Sep 2014 13:15:23 -0400 (EDT) Subject: My backwards logic References: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> Message-ID: Seymore4Head Wrote in message: > I'm still doing practice problems. I haven't heard from the library > on any of the books I have requested. > > http://www.practicepython.org/exercise/2014/04/16/11-check-primality-functions.html > > This is not a hard problem, but it got me to thinking a little. A > prime number will divide by one and itself. When setting up this > loop, if I start at 2 instead of 1, that automatically excludes one of > the factors. Then, by default, Python goes "to" the chosen count and > not "through" the count, so just the syntax causes Python to rule out > the other factor (the number itself). > > So this works: > while True: > a=random.randrange(1,8) > print (a) > for x in range(2,a): > if a%x==0: > print ("Number is not prime") > break > wait = input (" "*40 + "Wait") > > But, what this instructions want printed is "This is a prime number" > So how to I use this code logic NOT print (not prime) and have the > logic print "This number is prime" > > The traditional way of telling whether something happened in a loop is to set a flag to False outside the loop, and conditionally set it to True in the if test. Then after the loop, check your flag. Python however has a better way. You can put an else clause on the for loop: for x in range(2,a): if a%x==0: print ("Number is not prime") break else: print ("Number is prime") The else clause fires if no break executed. There are also ways to do it using not, any, and a list comprehension, no explicit loop at all. -- DaveA From ian.g.kelly at gmail.com Fri Sep 5 13:17:40 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 5 Sep 2014 11:17:40 -0600 Subject: My backwards logic In-Reply-To: <5409EE02.7030308@stoneleaf.us> References: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> <5409EE02.7030308@stoneleaf.us> Message-ID: On Fri, Sep 5, 2014 at 11:08 AM, Ethan Furman wrote: > Python's 'for' loop has a handy 'else' extension which is perfect for the > search-type of 'for' loop: > > while True: > a=random.randrange(1,8) > print (a) > for x in range(2,a): > if a%x==0: > print ("Number is not prime") > break > else: > print ("Number is prime") > wait = input (" "*40 + "Wait") > > Note the two lines I added after the 'break' and before the 'wait'. Also note that this construct tends to be particularly sensitive to indentation. If you accidentally indent the else block one level too many (which your editor may well do for you to "helpfully" match it up with the if), then you'll get a completely different result. I would not worry about the else clause as a beginner, as it's relatively unique to Python and tends to be somewhat confusing. Use a flag or refactor the function instead. From marko at pacujo.net Fri Sep 5 13:16:01 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 05 Sep 2014 20:16:01 +0300 Subject: Storing instances using jsonpickle References: <46e782a5-b087-4f95-aadb-26e233bf5419@googlegroups.com> <5407A69B.3030707@mrabarnett.plus.com> Message-ID: <87fvg6j8dq.fsf@elektro.pacujo.net> MRAB : > Therefore, if you want it to be able to drop it into Python's REPL, it > won't be compatible with JSON anyway! (Well, not unless you define > 'true' and 'false' first.) Sigh. I was so hopeful JSON would be great. Unfortunately, it flopped by requiring the parser to heuristically support 5 encoding systems. Thus, ast.literal_eval() is superior to anything JSON has to offer. Marko From ned at nedbatchelder.com Fri Sep 5 13:30:14 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 05 Sep 2014 13:30:14 -0400 Subject: Storing instances using jsonpickle In-Reply-To: <87fvg6j8dq.fsf@elektro.pacujo.net> References: <46e782a5-b087-4f95-aadb-26e233bf5419@googlegroups.com> <5407A69B.3030707@mrabarnett.plus.com> <87fvg6j8dq.fsf@elektro.pacujo.net> Message-ID: On 9/5/14 1:16 PM, Marko Rauhamaa wrote: > MRAB : > >> Therefore, if you want it to be able to drop it into Python's REPL, it >> won't be compatible with JSON anyway! (Well, not unless you define >> 'true' and 'false' first.) > > Sigh. I was so hopeful JSON would be great. Unfortunately, it flopped by > requiring the parser to heuristically support 5 encoding systems. I don't understand how JSON has flopped? The parser may be a bit more complex (but not much, it isn't hard to examine the first few bytes), but you're using off-the-shelf parsers anyway, so why are you concerned by this? > > Thus, ast.literal_eval() is superior to anything JSON has to offer. > > > Marko > -- Ned Batchelder, http://nedbatchelder.com From juan0christian at gmail.com Fri Sep 5 13:35:48 2014 From: juan0christian at gmail.com (Juan Christian) Date: Fri, 5 Sep 2014 14:35:48 -0300 Subject: My backwards logic In-Reply-To: References: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> <5409EE02.7030308@stoneleaf.us> Message-ID: I made this code just for fun and learning, it's working, but would this be a good approach? Thanks. import sys def prime_checker(start = 1, stop = 1): for number in range(start, stop + 1): divisors = [(number % x) for x in range(1, number + 1)] print("{n} prime? {r}".format(n = number, r = (divisors.count(0) == 2))) if __name__ == '__main__': prime_checker(int(sys.argv[1]), int(sys.argv[2])) On Fri, Sep 5, 2014 at 2:17 PM, Ian Kelly wrote: > On Fri, Sep 5, 2014 at 11:08 AM, Ethan Furman wrote: > > Python's 'for' loop has a handy 'else' extension which is perfect for the > > search-type of 'for' loop: > > > > while True: > > a=random.randrange(1,8) > > print (a) > > for x in range(2,a): > > if a%x==0: > > print ("Number is not prime") > > break > > else: > > print ("Number is prime") > > wait = input (" "*40 + "Wait") > > > > Note the two lines I added after the 'break' and before the 'wait'. > > Also note that this construct tends to be particularly sensitive to > indentation. If you accidentally indent the else block one level too > many (which your editor may well do for you to "helpfully" match it up > with the if), then you'll get a completely different result. > > I would not worry about the else clause as a beginner, as it's > relatively unique to Python and tends to be somewhat confusing. Use a > flag or refactor the function instead. > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From Seymore4Head at Hotmail.invalid Fri Sep 5 13:44:47 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Fri, 05 Sep 2014 13:44:47 -0400 Subject: My backwards logic References: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> Message-ID: On Fri, 05 Sep 2014 10:08:18 -0700, Ethan Furman wrote: >On 09/05/2014 09:48 AM, Seymore4Head wrote: >> I'm still doing practice problems. I haven't heard from the library >> on any of the books I have requested. >> >> http://www.practicepython.org/exercise/2014/04/16/11-check-primality-functions.html >> >> This is not a hard problem, but it got me to thinking a little. A >> prime number will divide by one and itself. When setting up this >> loop, if I start at 2 instead of 1, that automatically excludes one of >> the factors. Then, by default, Python goes "to" the chosen count and >> not "through" the count, so just the syntax causes Python to rule out >> the other factor (the number itself). >> >> So this works: >> while True: >> a=random.randrange(1,8) >> print (a) >> for x in range(2,a): >> if a%x==0: >> print ("Number is not prime") >> break >> wait = input (" "*40 + "Wait") >> >> But, what this instructions want printed is "This is a prime number" >> So how to I use this code logic NOT print (not prime) and have the >> logic print "This number is prime" > >Python's 'for' loop has a handy 'else' extension which is perfect for the search-type of 'for' loop: > > while True: > a=random.randrange(1,8) > print (a) > for x in range(2,a): > if a%x==0: > print ("Number is not prime") > break > else: > print ("Number is prime") > wait = input (" "*40 + "Wait") > >Note the two lines I added after the 'break' and before the 'wait'. I had already tried this one. The solution I want should only print: "This number is prime" Adding else causes the program to also print "This number is not prime" I also tried the flag=True suggestion, but never got one that worked. I am unsure when to use flag=True and flag==True Then there is flag="True" and flag=="True" What I really wanted was something like: if !(a%x==0) BTW since I am getting no grade, I much prefer the answer than a hint. The best hint IMO is to tell me how you would do it. Thanks everyone From kurt.alfred.mueller at gmail.com Fri Sep 5 13:56:16 2014 From: kurt.alfred.mueller at gmail.com (Kurt Mueller) Date: Fri, 5 Sep 2014 19:56:16 +0200 Subject: How to turn a string into a list of integers? In-Reply-To: <1k9odb-1qs.ln1@chris.zbmc.eu> References: <1amjdb-p3n.ln1@chris.zbmc.eu> <1k9odb-1qs.ln1@chris.zbmc.eu> Message-ID: Am 05.09.2014 um 10:42 schrieb cl at isbd.net: > Joshua Landau wrote: >> On 3 September 2014 15:48, wrote: >>> Peter Otten <__peter__ at web.de> wrote: >>>>>>> [ord(c) for c in "This is a string"] >>>> [84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 115, 116, 114, 105, 110, 103] >>>> >>>> There are other ways, but you have to describe the use case and your Python >>>> version for us to recommend the most appropriate. >>>> >>> That looks OK to me. It's just for outputting a string to the block >>> write command in python-smbus which expects an integer array. >> >> Just be careful about Unicode characters. > > I have to avoid them completely because I'm sending the string to a > character LCD with a limited 8-bit only character set. Could someone please explain the following behavior to me: Python 2.7.7, MacOS 10.9 Mavericks >>> import sys >>> sys.getdefaultencoding() 'ascii' >>> [ord(c) for c in 'A?'] [65, 195, 132] >>> [ord(c) for c in u'A?'] [65, 196] My obviously wrong understanding: ?A?? in ?ascii? are two characters one with ord A=65 and one with ord ?=196 ISO8859-1 ?-> why [65, 195, 132] u?A?? is an Unicode string ?-> why [65, 196] It is just the other way round as I would expect. Thank you -- Kurt Mueller, kurt.alfred.mueller at gmail.com From marko at pacujo.net Fri Sep 5 14:04:44 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 05 Sep 2014 21:04:44 +0300 Subject: Storing instances using jsonpickle References: <46e782a5-b087-4f95-aadb-26e233bf5419@googlegroups.com> <5407A69B.3030707@mrabarnett.plus.com> <87fvg6j8dq.fsf@elektro.pacujo.net> Message-ID: <87bnquj64j.fsf@elektro.pacujo.net> Ned Batchelder : > I don't understand how JSON has flopped? The parser may be a bit more > complex (but not much, it isn't hard to examine the first few bytes), > but you're using off-the-shelf parsers anyway, so why are you > concerned by this? There are occasions where you need to take shortcuts. Say you need to glean information from JSON with bash, grep, awk or straight C. If JSON was fixed to UTF-8, that would be quite feasible. Being as it is, you are bound to 3rd-party libraries. That alone invites ad-hoc encodings. For example, I have run into "asterisked" JSON, libraries that limit themselves to UTF-8. Compare that with HTTP, SMTP, or even XML(!). They fix the encoding to the bit. No need for completely unnecessary options. Marko From ckaynor at zindagigames.com Fri Sep 5 14:17:05 2014 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Fri, 5 Sep 2014 11:17:05 -0700 Subject: My backwards logic In-Reply-To: References: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> Message-ID: On Fri, Sep 5, 2014 at 10:44 AM, Seymore4Head wrote: > On Fri, 05 Sep 2014 10:08:18 -0700, Ethan Furman > wrote: > > >On 09/05/2014 09:48 AM, Seymore4Head wrote: > >> I'm still doing practice problems. I haven't heard from the library > >> on any of the books I have requested. > >> > >> > http://www.practicepython.org/exercise/2014/04/16/11-check-primality-functions.html > >> > >> This is not a hard problem, but it got me to thinking a little. A > >> prime number will divide by one and itself. When setting up this > >> loop, if I start at 2 instead of 1, that automatically excludes one of > >> the factors. Then, by default, Python goes "to" the chosen count and > >> not "through" the count, so just the syntax causes Python to rule out > >> the other factor (the number itself). > >> > >> So this works: > >> while True: > >> a=random.randrange(1,8) > >> print (a) > >> for x in range(2,a): > >> if a%x==0: > >> print ("Number is not prime") > >> break > >> wait = input (" "*40 + "Wait") > >> > >> But, what this instructions want printed is "This is a prime number" > >> So how to I use this code logic NOT print (not prime) and have the > >> logic print "This number is prime" > > > >Python's 'for' loop has a handy 'else' extension which is perfect for the > search-type of 'for' loop: > > > > while True: > > a=random.randrange(1,8) > > print (a) > > for x in range(2,a): > > if a%x==0: > > print ("Number is not prime") > > break > > else: > > print ("Number is prime") > > wait = input (" "*40 + "Wait") > > > >Note the two lines I added after the 'break' and before the 'wait'. > > I had already tried this one. > The solution I want should only print: > "This number is prime" > > Adding else causes the program to also print "This number is not > prime" > If you do not want it to print the "Number is not prime", just remove the print("Number is not prime") line. > I also tried the flag=True suggestion, but never got one that worked. > I am unsure when to use flag=True and flag==True > Then there is flag="True" and flag=="True" > Generally, you would want to use: flag = False before the loop, and flag = True inside the loop (once you know the number is not prime). After the loop, you would typically just use: if flag: # This could be "if flag == True:", however the plain "if flag:" is more Pythonic. print("Number is prime") The "=" operator is assignment - storing a new value. The "==" operator is for equality checking. The inverse is the "!=" operator which checks for inequality. What I really wanted was something like: > if !(a%x==0) In this case, that will not work, as you only know that the number is prime after checking all the values, which means after the loop has completed. Ignoring the fact that it would not function for this use case, the proper Python syntax for that would be one of: - if a%x != 0: # Probably the clearest for this case. - if not (a%x==0): -------------- next part -------------- An HTML attachment was scrubbed... URL: From kwpolska at gmail.com Fri Sep 5 14:25:16 2014 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Fri, 5 Sep 2014 20:25:16 +0200 Subject: How to turn a string into a list of integers? In-Reply-To: References: <1amjdb-p3n.ln1@chris.zbmc.eu> <1k9odb-1qs.ln1@chris.zbmc.eu> Message-ID: On Sep 5, 2014 7:57 PM, "Kurt Mueller" wrote: > Could someone please explain the following behavior to me: > Python 2.7.7, MacOS 10.9 Mavericks > > >>> import sys > >>> sys.getdefaultencoding() > 'ascii' > >>> [ord(c) for c in 'A?'] > [65, 195, 132] > >>> [ord(c) for c in u'A?'] > [65, 196] > > My obviously wrong understanding: > ?A?? in ?ascii? are two characters > one with ord A=65 and > one with ord ?=196 ISO8859-1 > ?-> why [65, 195, 132] > u?A?? is an Unicode string > ?-> why [65, 196] > > It is just the other way round as I would expect. Basically, the first string is just a bunch of bytes, as provided by your terminal ? which sounds like UTF-8 (perfectly logical in 2014). The second one is converted into a real Unicode representation. The codepoint for ? is U+00C4 (196 decimal). It's just a coincidence that it also matches latin1 aka ISO 8859-1 as Unicode starts with all 256 latin1 codepoints. Please kindly forget encodings other than UTF-8. BTW: ASCII covers only the first 128 bytes. -- Chris ?Kwpolska? Warrick Sent from my Galaxy S3. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Fri Sep 5 14:41:23 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 05 Sep 2014 11:41:23 -0700 Subject: My backwards logic In-Reply-To: References: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> <5409EE02.7030308@stoneleaf.us> Message-ID: <540A03D3.2010500@stoneleaf.us> On 09/05/2014 10:17 AM, Ian Kelly wrote: > > I would not worry about the else clause as a beginner, as it's > relatively unique to Python and tends to be somewhat confusing. Use a > flag or refactor the function instead. I don't disagree with this, but early exposure to "for..else is for search loops" is a good thing. I still get tripped up by this as I didn't learn it that way. -- ~Ethan~ From python at mrabarnett.plus.com Fri Sep 5 14:48:34 2014 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 05 Sep 2014 19:48:34 +0100 Subject: My backwards logic In-Reply-To: References: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> <5409EE02.7030308@stoneleaf.us> Message-ID: <540A0582.1010403@mrabarnett.plus.com> On 2014-09-05 18:35, Juan Christian wrote: > I made this code just for fun and learning, it's working, but would this > be a good approach? Thanks. > > import sys > > > def prime_checker(start = 1, stop = 1): In Python, the standard is to use a half-open range. > for number in range(start, stop + 1): > divisors = [(number % x) for x in range(1, number + 1)] > print("{n} prime? {r}".format(n = number, r = (divisors.count(0) == 2))) > You want to know only whether it's prime, so why continue looking after finding a factor? > > if __name__ == '__main__': > prime_checker(int(sys.argv[1]), int(sys.argv[2])) > [snip] From kekeje at gmail.com Fri Sep 5 14:55:47 2014 From: kekeje at gmail.com (kekeje at gmail.com) Date: Fri, 5 Sep 2014 11:55:47 -0700 (PDT) Subject: Anyway to reduce size of pdf using python script. In-Reply-To: References: Message-ID: <034629a4-a045-4509-9b30-dcd6aea9c3e8@googlegroups.com> On Friday, February 1, 2013 8:03:41 PM UTC-5, access... at gmail.com wrote: > I have a batch file that exports ArcGIS pdf maps to a directory. I would like to include a step in the script where the pdf file is reduced in size instead of manually opening each file in Acrobat X Pro after the script has run and doing it there. > > > > Can this be done using python scripting or does the automation stop at exporting the map? > > > > Thanks Have you found the solution? I am having exactly the same problem and happen to see your post here. Please let me know how you did it, thanks! From kurt.alfred.mueller at gmail.com Fri Sep 5 15:16:54 2014 From: kurt.alfred.mueller at gmail.com (Kurt Mueller) Date: Fri, 5 Sep 2014 21:16:54 +0200 Subject: How to turn a string into a list of integers? In-Reply-To: References: <1amjdb-p3n.ln1@chris.zbmc.eu> <1k9odb-1qs.ln1@chris.zbmc.eu> Message-ID: Am 05.09.2014 um 20:25 schrieb Chris ?Kwpolska? Warrick : > On Sep 5, 2014 7:57 PM, "Kurt Mueller" wrote: > > Could someone please explain the following behavior to me: > > Python 2.7.7, MacOS 10.9 Mavericks > > > > >>> import sys > > >>> sys.getdefaultencoding() > > 'ascii' > > >>> [ord(c) for c in 'A?'] > > [65, 195, 132] > > >>> [ord(c) for c in u'A?'] > > [65, 196] > > > > My obviously wrong understanding: > > ?A?? in ?ascii? are two characters > > one with ord A=65 and > > one with ord ?=196 ISO8859-1 > > ?-> why [65, 195, 132] > > u?A?? is an Unicode string > > ?-> why [65, 196] > > > > It is just the other way round as I would expect. > > Basically, the first string is just a bunch of bytes, as provided by your terminal ? which sounds like UTF-8 (perfectly logical in 2014). The second one is converted into a real Unicode representation. The codepoint for ? is U+00C4 (196 decimal). It's just a coincidence that it also matches latin1 aka ISO 8859-1 as Unicode starts with all 256 latin1 codepoints. Please kindly forget encodings other than UTF-8. So: ?A?? is an UTF-8 string represented by 3 bytes: A -> 41 -> 65 first byte decimal ? -> c384 -> 195 and 132 second and third byte decimal u?A?? is an Unicode string represented by 2 bytes?: A -> U+0041 -> 65 first byte decimal, 00 is omitted or not yielded by ord()? ? -> U+00C4 -> 196 second byte decimal, 00 is ommited or not yielded by ord()? > BTW: ASCII covers only the first 128 bytes. ACK -- Kurt Mueller, kurt.alfred.mueller at gmail.com From jtim.arnold at gmail.com Fri Sep 5 15:36:34 2014 From: jtim.arnold at gmail.com (Tim) Date: Fri, 5 Sep 2014 12:36:34 -0700 (PDT) Subject: Anyway to reduce size of pdf using python script. In-Reply-To: References: Message-ID: <93a9cc4e-6e80-43dc-bf40-61d2995c18ae@googlegroups.com> On Friday, February 1, 2013 8:03:41 PM UTC-5, access... at gmail.com wrote: > I have a batch file that exports ArcGIS pdf maps to a directory. I would like to include a step in the script where the pdf file is reduced in size instead of manually opening each file in Acrobat X Pro after the script has run and doing it there. > > Can this be done using python scripting or does the automation stop at exporting the map? > > Thanks I don't have a definitive answer but I use qpdf to optimize my pdf files. Whether that reduces the size I'm not sure. http://qpdf.sourceforge.net/ --Tim From juan0christian at gmail.com Fri Sep 5 15:34:21 2014 From: juan0christian at gmail.com (Juan Christian) Date: Fri, 5 Sep 2014 16:34:21 -0300 Subject: My backwards logic In-Reply-To: <540A0582.1010403@mrabarnett.plus.com> References: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> <5409EE02.7030308@stoneleaf.us> <540A0582.1010403@mrabarnett.plus.com> Message-ID: What's [snip] ?? On Fri, Sep 5, 2014 at 3:48 PM, MRAB wrote: > On 2014-09-05 18:35, Juan Christian wrote: > >> I made this code just for fun and learning, it's working, but would this >> be a good approach? Thanks. >> >> import sys >> >> >> def prime_checker(start = 1, stop = 1): >> > > In Python, the standard is to use a half-open range. > > for number in range(start, stop + 1): >> divisors = [(number % x) for x in range(1, number + 1)] >> print("{n} prime? {r}".format(n = number, r = >> (divisors.count(0) == 2))) >> >> You want to know only whether it's prime, so why continue looking after > finding a factor? > >> >> if __name__ == '__main__': >> prime_checker(int(sys.argv[1]), int(sys.argv[2])) >> >> [snip] > > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Fri Sep 5 15:54:31 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 05 Sep 2014 20:54:31 +0100 Subject: My backwards logic In-Reply-To: References: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> <5409EE02.7030308@stoneleaf.us> <540A0582.1010403@mrabarnett.plus.com> Message-ID: On 05/09/2014 20:34, Juan Christian wrote: > What's [snip] ?? > As in cut out or chopped out such that some of the original text has been removed. And please don't top post here, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From no.email at nospam.invalid Fri Sep 5 16:07:41 2014 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 05 Sep 2014 13:07:41 -0700 Subject: My backwards logic References: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> <5409EE02.7030308@stoneleaf.us> <540A0582.1010403@mrabarnett.plus.com> Message-ID: <7x38c5u8z6.fsf@ruckus.brouhaha.com> Juan Christian writes: > I made this code just for fun and learning, it's working, but would > this be a good approach? Thanks. ... > ** ** for number in range(start, stop + 1): > ** ** ** ** divisors = [(number % x) for x in range(1, number + 1)] > ** ** ** ** ** ** print("{n} prime? {r}".format(n = number, r = > (divisors.count(0) == 2))) 1. Mathematically it's better to stop checking once you've gone past the square root of the number, since if n = p*q and is composite, then at least one of p,q will be <= sqrt(n). 2. As a program design matter, it's generally preferable for functions like this to not print the answer. They should just return a value, in this case a bool indicating whether the number is prime. That makes it easier to re-use the function, to wrap it in a unit test framework, etc. If you want to print the result, then call the function and have the caller print the returned value. 3. As a simple optimization, once you have checked that the number is not divisible by 2, you don't have to check for other even divisors. So just check for 2, then the odd numbers 3,5,7... This is a little bit fancy but I like to use itertools for these sorts of problems: from itertools import chain, takewhile, count def is_prime(n): if n < 2: return False candidates = chain([2], count(3,2)) return all(n%d!=0 for d in takewhile(lambda d: d*d<=n, candidates)) If you're not familiar with those functions, "chain" concatenates two sequences, and "count(n,i)" gives an increasing sequence starting with n and incrementing by i. So chain([2], count(3,2)) gives the unending sequence [2, 3, 5, 7, 9, ...] which is the numbers you want to check against. Then the takewhile expression chops that sequence once it gets past sqrt(n), and "all" returns true iff all of the candidate divisors fail to divide the number. From kurt.alfred.mueller at gmail.com Fri Sep 5 16:41:16 2014 From: kurt.alfred.mueller at gmail.com (Kurt Mueller) Date: Fri, 5 Sep 2014 22:41:16 +0200 Subject: How to turn a string into a list of integers? In-Reply-To: References: <1amjdb-p3n.ln1@chris.zbmc.eu> <1k9odb-1qs.ln1@chris.zbmc.eu> Message-ID: <69800CFD-102C-4AA9-B6B2-9B0848E633E5@gmail.com> Am 05.09.2014 um 21:16 schrieb Kurt Mueller : > Am 05.09.2014 um 20:25 schrieb Chris ?Kwpolska? Warrick : >> On Sep 5, 2014 7:57 PM, "Kurt Mueller" wrote: >>> Could someone please explain the following behavior to me: >>> Python 2.7.7, MacOS 10.9 Mavericks >>> >>>>>> import sys >>>>>> sys.getdefaultencoding() >>> 'ascii' >>>>>> [ord(c) for c in 'A?'] >>> [65, 195, 132] >>>>>> [ord(c) for c in u'A?'] >>> [65, 196] >>> >>> My obviously wrong understanding: >>> ?A?? in ?ascii? are two characters >>> one with ord A=65 and >>> one with ord ?=196 ISO8859-1 >>> ?-> why [65, 195, 132] >>> u?A?? is an Unicode string >>> ?-> why [65, 196] >>> >>> It is just the other way round as I would expect. >> >> Basically, the first string is just a bunch of bytes, as provided by your terminal ? which sounds like UTF-8 (perfectly logical in 2014). The second one is converted into a real Unicode representation. The codepoint for ? is U+00C4 (196 decimal). It's just a coincidence that it also matches latin1 aka ISO 8859-1 as Unicode starts with all 256 latin1 codepoints. Please kindly forget encodings other than UTF-8. > > So: > ?A?? is an UTF-8 string represented by 3 bytes: > A -> 41 -> 65 first byte decimal > ? -> c384 -> 195 and 132 second and third byte decimal > > u?A?? is an Unicode string represented by 2 bytes?: > A -> U+0041 -> 65 first byte decimal, 00 is omitted or not yielded by ord()? > ? -> U+00C4 -> 196 second byte decimal, 00 is ommited or not yielded by ord()? After reading the ord() manual: The second case should read: u?A?? is an Unicode string represented by 2 unicode characters: If Python was built with UCS2 Unicode, then the character?s code point must be in the range [0..65535, 16 bits, U-0000..U-FFFF] A -> U+0041 -> 65 first character decimal (code point) ? -> U+00C4 -> 196 second character decimal (code point) Am I right now? -- Kurt Mueller, kurt.alfred.mueller at gmail.com From ned at nedbatchelder.com Fri Sep 5 16:50:47 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 05 Sep 2014 16:50:47 -0400 Subject: Storing instances using jsonpickle In-Reply-To: <87bnquj64j.fsf@elektro.pacujo.net> References: <46e782a5-b087-4f95-aadb-26e233bf5419@googlegroups.com> <5407A69B.3030707@mrabarnett.plus.com> <87fvg6j8dq.fsf@elektro.pacujo.net> <87bnquj64j.fsf@elektro.pacujo.net> Message-ID: On 9/5/14 2:04 PM, Marko Rauhamaa wrote: > Ned Batchelder : > >> I don't understand how JSON has flopped? The parser may be a bit more >> complex (but not much, it isn't hard to examine the first few bytes), >> but you're using off-the-shelf parsers anyway, so why are you >> concerned by this? > > There are occasions where you need to take shortcuts. Say you need to > glean information from JSON with bash, grep, awk or straight C. If JSON > was fixed to UTF-8, that would be quite feasible. Being as it is, you > are bound to 3rd-party libraries. > > That alone invites ad-hoc encodings. For example, I have run into > "asterisked" JSON, libraries that limit themselves to UTF-8. > > Compare that with HTTP, SMTP, or even XML(!). They fix the encoding to > the bit. No need for completely unnecessary options. I see what you mean about JSON, but you are mistaken about HTTP and XML. Neither of them dictates the encoding of the data, and both of them offer ways to declare the encoding. This means XML parsers must be prepared for many different encodings. > > > Marko > -- Ned Batchelder, http://nedbatchelder.com From marko at pacujo.net Fri Sep 5 16:57:02 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 05 Sep 2014 23:57:02 +0300 Subject: Storing instances using jsonpickle References: <46e782a5-b087-4f95-aadb-26e233bf5419@googlegroups.com> <5407A69B.3030707@mrabarnett.plus.com> <87fvg6j8dq.fsf@elektro.pacujo.net> <87bnquj64j.fsf@elektro.pacujo.net> Message-ID: <87mwadiy5d.fsf@elektro.pacujo.net> Ned Batchelder : > I see what you mean about JSON, but you are mistaken about HTTP and > XML. Neither of them dictates the encoding of the data, and both of > them offer ways to declare the encoding. This means XML parsers must > be prepared for many different encodings. You can rest assured that the line GET / HTTP/1.1 is strictly 8-bit ASCII. I was intentionally exaggerating about XML, but I have yet to encounter non-UTF-8 XML in the wild. Marko From ian.g.kelly at gmail.com Fri Sep 5 17:04:03 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 5 Sep 2014 15:04:03 -0600 Subject: My backwards logic In-Reply-To: References: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> Message-ID: On Fri, Sep 5, 2014 at 11:44 AM, Seymore4Head wrote: > BTW since I am getting no grade, I much prefer the answer than a hint. > The best hint IMO is to tell me how you would do it. from math import ceil, sqrt def is_prime(n): if n < 2: return False if n % 2 == 0: return n == 2 return all(n % x != 0 for x in range(3, int(sqrt(n)) + 1, 2)) while True: n = int(input("Enter a number: ")) if is_prime(n): print("{} is prime.".format(n)) else: print("{} is not prime.".format(n)) From Seymore4Head at Hotmail.invalid Fri Sep 5 17:49:36 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Fri, 05 Sep 2014 17:49:36 -0400 Subject: My backwards logic References: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> Message-ID: <6ebk0a95ia9llot967jf7hpmidhh6hl4fd@4ax.com> On Fri, 05 Sep 2014 12:48:56 -0400, Seymore4Head wrote: >I'm still doing practice problems. I haven't heard from the library >on any of the books I have requested. > >http://www.practicepython.org/exercise/2014/04/16/11-check-primality-functions.html > >This is not a hard problem, but it got me to thinking a little. A >prime number will divide by one and itself. When setting up this >loop, if I start at 2 instead of 1, that automatically excludes one of >the factors. Then, by default, Python goes "to" the chosen count and >not "through" the count, so just the syntax causes Python to rule out >the other factor (the number itself). > >So this works: >while True: > a=random.randrange(1,8) > print (a) > for x in range(2,a): > if a%x==0: > print ("Number is not prime") > break > wait = input (" "*40 + "Wait") > >But, what this instructions want printed is "This is a prime number" >So how to I use this code logic NOT print (not prime) and have the >logic print "This number is prime" I am sure this has already been done, but after it was pointed out that you don't need to test for any number that multiplies by 2 it made me think again. If you start with the list [3,5,7] and step through the list of all remaining odd numbers (step 2), and start appending numbers that won't divide by numbers already appended in the list, that would seem like a pretty efficient way to find all prime numbers. From julian at julianvidal.com Fri Sep 5 17:52:07 2014 From: julian at julianvidal.com (julian at julianvidal.com) Date: Fri, 5 Sep 2014 14:52:07 -0700 (PDT) Subject: O'Reilly Python Certification In-Reply-To: References: Message-ID: <6657943d-4924-4f8f-8894-8e7541a9d5a5@googlegroups.com> On Wednesday, September 3, 2014 5:53:12 PM UTC-4, jaron... at gmail.com wrote: > Ethan, Steve, Tim, and others: > > > > I'm thinking of taking the program. How long, in hours, does it take to complete all four Python courses? I'm currently taking the first out of four modules. I have extensive PHP knowledge and I also have a certification by Zend so programming is not new to me. I've never done anything at all with Python. I've already completed 12 out of the 16 lessons and so far the reading has taken me from 15 to 30 minutes and the code assignments no more than 10. There was one exception that took me 30 minutes as I wasn't sure what the hell they were asking (it was a very obscure and useless algorithm which hasn't been the case on any of the other assignments). On top of that you have to answer 2 quizzes and each quiz usually has 2 questions (no more than 5). Those usually take 1 to 3 minutes max as they are mostly syntax or concepts but not coding. As I said, this is only true for the first module as I haven't taken the others yet. But if you already know programming and have a few years of coding experience you will breeze through the first module in probably 3 days (assuming you only do that). The syllabus for the other modules suggests (to me) that going so fast would not be that easy. From ckaynor at zindagigames.com Fri Sep 5 18:14:41 2014 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Fri, 5 Sep 2014 15:14:41 -0700 Subject: My backwards logic In-Reply-To: <6ebk0a95ia9llot967jf7hpmidhh6hl4fd@4ax.com> References: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> <6ebk0a95ia9llot967jf7hpmidhh6hl4fd@4ax.com> Message-ID: On Fri, Sep 5, 2014 at 2:49 PM, Seymore4Head wrote: > On Fri, 05 Sep 2014 12:48:56 -0400, Seymore4Head > wrote: > > >I'm still doing practice problems. I haven't heard from the library > >on any of the books I have requested. > > > > > http://www.practicepython.org/exercise/2014/04/16/11-check-primality-functions.html > > > >This is not a hard problem, but it got me to thinking a little. A > >prime number will divide by one and itself. When setting up this > >loop, if I start at 2 instead of 1, that automatically excludes one of > >the factors. Then, by default, Python goes "to" the chosen count and > >not "through" the count, so just the syntax causes Python to rule out > >the other factor (the number itself). > > > >So this works: > >while True: > > a=random.randrange(1,8) > > print (a) > > for x in range(2,a): > > if a%x==0: > > print ("Number is not prime") > > break > > wait = input (" "*40 + "Wait") > > > >But, what this instructions want printed is "This is a prime number" > >So how to I use this code logic NOT print (not prime) and have the > >logic print "This number is prime" > > I am sure this has already been done, but after it was pointed out > that you don't need to test for any number that multiplies by 2 it > made me think again. > > If you start with the list [3,5,7] and step through the list of all > remaining odd numbers (step 2), and start appending numbers that won't > divide by numbers already appended in the list, that would seem like a > pretty efficient way to find all prime numbers. > To be correct, you only need to check for n being divisible by primes less than sqrt(n). For example, the following code will produce a list of primes from 2 to 1000 (the result will be in the "primes" list): import math primes = [2] for i in range(3, 1000): end = math.sqrt(i) for x in primes: if x > end: # Once x is larger than the sqrt(i), we know it must be prime, so we can early exit. #print(i, "is a prime number") primes.append(i) break if (i % x) == 0: #print(i, "is a composite number") break -------------- next part -------------- An HTML attachment was scrubbed... URL: From irmen.NOSPAM at xs4all.nl Fri Sep 5 18:18:33 2014 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sat, 06 Sep 2014 00:18:33 +0200 Subject: Storing instances using jsonpickle In-Reply-To: <87fvg6j8dq.fsf@elektro.pacujo.net> References: <46e782a5-b087-4f95-aadb-26e233bf5419@googlegroups.com> <5407A69B.3030707@mrabarnett.plus.com> <87fvg6j8dq.fsf@elektro.pacujo.net> Message-ID: <540a36bc$0$2935$e4fe514c@news.xs4all.nl> On 5-9-2014 19:16, Marko Rauhamaa wrote: > Thus, ast.literal_eval() is superior to anything JSON has to offer. Incidentally, I've made a serialization library based on Python's literal expressions. It uses ast.literal_eval() to deserialize, and a bit of custom code to serialize Python objects: https://pypi.python.org/pypi/serpent Irmen From ian.g.kelly at gmail.com Fri Sep 5 18:35:18 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 5 Sep 2014 16:35:18 -0600 Subject: My backwards logic In-Reply-To: <6ebk0a95ia9llot967jf7hpmidhh6hl4fd@4ax.com> References: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> <6ebk0a95ia9llot967jf7hpmidhh6hl4fd@4ax.com> Message-ID: On Fri, Sep 5, 2014 at 3:49 PM, Seymore4Head wrote: > I am sure this has already been done, but after it was pointed out > that you don't need to test for any number that multiplies by 2 it > made me think again. > > If you start with the list [3,5,7] and step through the list of all > remaining odd numbers (step 2), and start appending numbers that won't > divide by numbers already appended in the list, that would seem like a > pretty efficient way to find all prime numbers. Indeed, this type of algorithm is known as a sieve. For a (literally) classical example, see http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes It's a nice way to find all the prime numbers up to a given limit, or it can be modified to run indefinitely high, but it's not very efficient for determining the primality of a single number. From Seymore4Head at Hotmail.invalid Fri Sep 5 18:36:59 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Fri, 05 Sep 2014 18:36:59 -0400 Subject: My backwards logic References: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> <6ebk0a95ia9llot967jf7hpmidhh6hl4fd@4ax.com> Message-ID: <2oek0ahilju7qjvgl2ougm2gto1f0mrhrg@4ax.com> On Fri, 5 Sep 2014 15:14:41 -0700, Chris Kaynor wrote: >On Fri, Sep 5, 2014 at 2:49 PM, Seymore4Head >wrote: > >> On Fri, 05 Sep 2014 12:48:56 -0400, Seymore4Head >> wrote: >> >> >I'm still doing practice problems. I haven't heard from the library >> >on any of the books I have requested. >> > >> > >> http://www.practicepython.org/exercise/2014/04/16/11-check-primality-functions.html >> > >> >This is not a hard problem, but it got me to thinking a little. A >> >prime number will divide by one and itself. When setting up this >> >loop, if I start at 2 instead of 1, that automatically excludes one of >> >the factors. Then, by default, Python goes "to" the chosen count and >> >not "through" the count, so just the syntax causes Python to rule out >> >the other factor (the number itself). >> > >> >So this works: >> >while True: >> > a=random.randrange(1,8) >> > print (a) >> > for x in range(2,a): >> > if a%x==0: >> > print ("Number is not prime") >> > break >> > wait = input (" "*40 + "Wait") >> > >> >But, what this instructions want printed is "This is a prime number" >> >So how to I use this code logic NOT print (not prime) and have the >> >logic print "This number is prime" >> >> I am sure this has already been done, but after it was pointed out >> that you don't need to test for any number that multiplies by 2 it >> made me think again. >> >> If you start with the list [3,5,7] and step through the list of all >> remaining odd numbers (step 2), and start appending numbers that won't >> divide by numbers already appended in the list, that would seem like a >> pretty efficient way to find all prime numbers. >> > >To be correct, you only need to check for n being divisible by primes less >than sqrt(n). For example, the following code will produce a list of primes >from 2 to 1000 (the result will be in the "primes" list): > >import math >primes = [2] >for i in range(3, 1000): > end = math.sqrt(i) > for x in primes: > if x > end: # Once x is larger than the sqrt(i), we know it must be >prime, so we can early exit. > #print(i, "is a prime number") > primes.append(i) > break > if (i % x) == 0: > #print(i, "is a composite number") > break Thanks From Seymore4Head at Hotmail.invalid Fri Sep 5 19:05:08 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Fri, 05 Sep 2014 19:05:08 -0400 Subject: My backwards logic References: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> <6ebk0a95ia9llot967jf7hpmidhh6hl4fd@4ax.com> Message-ID: On Fri, 5 Sep 2014 16:35:18 -0600, Ian Kelly wrote: >On Fri, Sep 5, 2014 at 3:49 PM, Seymore4Head > wrote: >> I am sure this has already been done, but after it was pointed out >> that you don't need to test for any number that multiplies by 2 it >> made me think again. >> >> If you start with the list [3,5,7] and step through the list of all >> remaining odd numbers (step 2), and start appending numbers that won't >> divide by numbers already appended in the list, that would seem like a >> pretty efficient way to find all prime numbers. > >Indeed, this type of algorithm is known as a sieve. For a (literally) >classical example, see >http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes > >It's a nice way to find all the prime numbers up to a given limit, or >it can be modified to run indefinitely high, but it's not very >efficient for determining the primality of a single number. That is a pretty nice example. Thanks From rosuav at gmail.com Fri Sep 5 19:44:48 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 6 Sep 2014 09:44:48 +1000 Subject: My backwards logic In-Reply-To: References: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> Message-ID: On Sat, Sep 6, 2014 at 3:44 AM, Seymore4Head wrote: > BTW since I am getting no grade, I much prefer the answer than a hint. > The best hint IMO is to tell me how you would do it. But for your own learning, it's still better for you to do things yourself. Giving you the answer doesn't teach you nearly as effectively as giving you a hint and having you work out the answer yourself. But telling you how we'd do it can be useful too, especially when we get down to the detaily bits where there are lots of ways to do things. For instance, there's been a suggestion made a few times to break the primality test out into a function... but compare these two: def isprime(n): """Return True iff n is prime""" def find_factor(n): """Return a factor of n, or None if n is prime""" Aside from inverting the truth value, these are both tests of primality - you can write "if isprime(n):" or "if find_factor(n):" and they'll both work. (The latter is actually "iscomposite".) But the second function is giving you a bit more information - it tells you what factor it found. As a general rule, try to avoid throwing information away. To prove that n is composite, your function found a factor. Returning that, rather than a boolean value, might make your function more useful; and it's zero cost, because you know that factors of a number will never be zero. ChrisA From rosuav at gmail.com Fri Sep 5 20:20:07 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 6 Sep 2014 10:20:07 +1000 Subject: Storing instances using jsonpickle In-Reply-To: <5409ED0B.2030902@mrabarnett.plus.com> References: <46e782a5-b087-4f95-aadb-26e233bf5419@googlegroups.com> <5407A69B.3030707@mrabarnett.plus.com> <5409ED0B.2030902@mrabarnett.plus.com> Message-ID: On Sat, Sep 6, 2014 at 3:04 AM, MRAB wrote: > JSON has 'true' and 'false'. > > Python has 'True' and 'False'. > > Therefore, if you want it to be able to drop it into Python's REPL, it > won't be compatible with JSON anyway! (Well, not unless you define > 'true' and 'false' first.) This is a new spec, so I guess the question is whether it's primarily "JSON with some more features" or "subset of Python syntax in the same way that JSON is a subset of JS". If it's the former, then yes, it'd use "true" and "false", and you'd have to define them; but if the latter, the spec would simply use "True" and "False". But being able to guarantee that JSON decodes correctly with this parser (ie make it a guaranteed superset of JSON) would be of value. ChrisA From rustompmody at gmail.com Fri Sep 5 21:24:06 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 5 Sep 2014 18:24:06 -0700 (PDT) Subject: My backwards logic In-Reply-To: <7x38c5u8z6.fsf@ruckus.brouhaha.com> References: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> <5409EE02.7030308@stoneleaf.us> <540A0582.1010403@mrabarnett.plus.com> <7x38c5u8z6.fsf@ruckus.brouhaha.com> Message-ID: <06b5d0e1-4e8c-44f7-bcd2-976b14004695@googlegroups.com> On Saturday, September 6, 2014 1:37:57 AM UTC+5:30, Paul Rubin wrote: > Juan Christian writes: > > I made this code just for fun and learning, it's working, but would > > this be a good approach? Thanks. ... > > ** ** for number in range(start, stop + 1): > > ** ** ** ** divisors = [(number % x) for x in range(1, number + 1)] > > ** ** ** ** ** ** print("{n} prime? {r}".format(n = number, r = > > (divisors.count(0) == 2))) > 1. Mathematically it's better to stop checking once you've gone past > the square root of the number, since if n = p*q and is composite, > then at least one of p,q will be <= sqrt(n). > 2. As a program design matter, it's generally preferable for functions > like this to not print the answer. They should just return a value, in > this case a bool indicating whether the number is prime. That makes it > easier to re-use the function, to wrap it in a unit test framework, etc. > If you want to print the result, then call the function and have the > caller print the returned value. Hoo boy! And we come full circle > 3. As a simple optimization, once you have checked that the number is > not divisible by 2, you don't have to check for other even divisors. > So just check for 2, then the odd numbers 3,5,7... > This is a little bit fancy but I like to use itertools for these > sorts of problems: > from itertools import chain, takewhile, count > def is_prime(n): > if n < 2: return False > candidates = chain([2], count(3,2)) > return all(n%d!=0 for d in takewhile(lambda d: d*d<=n, candidates)) Paul's suggestions without the fancy -- no sqrt stop, no generators, no itertools etc -- (all to be learnt at their time of course!) First of all I make for myself a closed range >>> def crange(a,b) : return range(a,b+1) Check it >>> crange(1,10) [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Now for divisors of a number >>> def divisors(n): return [fact for fact in crange(1,n) if n%fact == 0] Check it >>> divisors(4) [1,2,4] >>> divisors(7) [1, 7] So now a prime is a number n whose divisors are only 1 and n >>> def is_prime(n): return divisors(n) == [1,n] >>> is_prime(2) True >>> is_prime(3) True >>> is_prime(4) False >>> is_prime(5) True >>> is_prime(6) False >>> is_prime(7) True So collecting the code together >>> def crange(a,b): return range(a,b+1) >>> def divisors(n): return [fact for fact in crange(1,n) if n%fact == 0] >>> def is_prime(n): return divisors(n) == [1,n] From juan0christian at gmail.com Fri Sep 5 21:54:17 2014 From: juan0christian at gmail.com (Juan Christian) Date: Fri, 5 Sep 2014 22:54:17 -0300 Subject: My backwards logic In-Reply-To: References: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> <5409EE02.7030308@stoneleaf.us> <540A0582.1010403@mrabarnett.plus.com> Message-ID: @Mark Lawrence: Sorry to ask, but what do you mean by "don't top post here, thanks.", I'm not familiar with mailing lists, so I may be doing something wrong and I don't know. On Fri, Sep 5, 2014 at 4:54 PM, Mark Lawrence wrote: > On 05/09/2014 20:34, Juan Christian wrote: > >> What's [snip] ?? >> >> > As in cut out or chopped out such that some of the original text has been > removed. And please don't top post here, thanks. > > -- > My fellow Pythonistas, ask not what our language can do for you, ask > what you can do for our language. > > Mark Lawrence > > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rustompmody at gmail.com Fri Sep 5 21:58:59 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 5 Sep 2014 18:58:59 -0700 (PDT) Subject: My backwards logic In-Reply-To: References: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> <5409EE02.7030308@stoneleaf.us> <540A0582.1010403@mrabarnett.plus.com> Message-ID: <021c7ac4-3434-47d8-a3a0-49cd8476299a@googlegroups.com> On Saturday, September 6, 2014 7:25:10 AM UTC+5:30, Juan Christian wrote: > @Mark Lawrence: Sorry to ask, but what do you mean by "don't top post here, thanks.", I'm not familiar with mailing lists, so I may be doing something wrong and I don't know. Maybe better to say use this http://en.wikipedia.org/wiki/Posting_style#Interleaved_style rather than to say dont use http://en.wikipedia.org/wiki/Posting_style#Top-posting Also read https://wiki.python.org/moin/GoogleGroupsPython From ben+python at benfinney.id.au Fri Sep 5 22:37:21 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 06 Sep 2014 12:37:21 +1000 Subject: Posting style: interleaved responses (was: My backwards logic) References: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> <5409EE02.7030308@stoneleaf.us> <540A0582.1010403@mrabarnett.plus.com> Message-ID: <85y4txwk2m.fsf_-_@benfinney.id.au> Juan Christian writes: > @Mark Lawrence: Sorry to ask, but what do you mean by "don't top post > here, thanks.", I'm not familiar with mailing lists, so I may be doing > something wrong and I don't know. Please post your responses interleaved with the quoted material to which you're responding. See the article on ?interleaved style? . And trim any quoted material to which you're not responding, so your message only contains relevant material. -- \ ?Human reason is snatching everything to itself, leaving | `\ nothing for faith.? ?Bernard of Clairvaux, 1090?1153 CE | _o__) | Ben Finney From juan0christian at gmail.com Fri Sep 5 23:06:27 2014 From: juan0christian at gmail.com (Juan Christian) Date: Sat, 6 Sep 2014 00:06:27 -0300 Subject: Posting style: interleaved responses (was: My backwards logic) In-Reply-To: <85y4txwk2m.fsf_-_@benfinney.id.au> References: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> <5409EE02.7030308@stoneleaf.us> <540A0582.1010403@mrabarnett.plus.com> <85y4txwk2m.fsf_-_@benfinney.id.au> Message-ID: On Fri, Sep 5, 2014 at 11:37 PM, Ben Finney wrote: > Juan Christian writes: > > > @Mark Lawrence: Sorry to ask, but what do you mean by "don't top post > > here, thanks.", I'm not familiar with mailing lists, so I may be doing > > something wrong and I don't know. > > Please post your responses interleaved with the quoted material to > which you're responding. See the article on ?interleaved style? > . And > trim any quoted material to which you're not responding, so your message > only contains relevant material. > > -- > \ ?Human reason is snatching everything to itself, leaving | > `\ nothing for faith.? ?Bernard of Clairvaux, 1090?1153 CE | > _o__) | > Ben Finney > > -- > https://mail.python.org/mailman/listinfo/python-list Like that? I'm using gmail so it automatically put the text in the [...] icon. -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at davea.name Fri Sep 5 23:10:40 2014 From: davea at davea.name (Dave Angel) Date: Fri, 5 Sep 2014 23:10:40 -0400 (EDT) Subject: My backwards logic References: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> <6ebk0a95ia9llot967jf7hpmidhh6hl4fd@4ax.com> Message-ID: Seymore4Head Wrote in message: > On Fri, 05 Sep 2014 12:48:56 -0400, Seymore4Head > wrote: > > > If you start with the list [3,5,7] and step through the list of all > remaining odd numbers (step 2), and start appending numbers that won't > divide by numbers already appended in the list, that would seem like a > pretty efficient way to find all prime numbers. > > Yes, that's a well known optimization. In addition, you can stop once you reach the square root of the target. No point in dividing by the higher numbers in the list, since if the result comes out even, you'd have already exited the loop. -- DaveA From zachary.ware+pylist at gmail.com Sat Sep 6 00:04:33 2014 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Fri, 5 Sep 2014 23:04:33 -0500 Subject: Posting style: interleaved responses (was: My backwards logic) In-Reply-To: References: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> <5409EE02.7030308@stoneleaf.us> <540A0582.1010403@mrabarnett.plus.com> <85y4txwk2m.fsf_-_@benfinney.id.au> Message-ID: On Fri, Sep 5, 2014 at 10:06 PM, Juan Christian wrote: > On Fri, Sep 5, 2014 at 11:37 PM, Ben Finney > wrote: >> >> Juan Christian writes: >> >> > @Mark Lawrence: Sorry to ask, but what do you mean by "don't top post >> > here, thanks.", I'm not familiar with mailing lists, so I may be doing >> > something wrong and I don't know. >> >> Please post your responses interleaved with the quoted material to >> which you're responding. See the article on ?interleaved style? >> . And >> trim any quoted material to which you're not responding, so your message >> only contains relevant material. >> >> -- >> \ ?Human reason is snatching everything to itself, leaving | >> `\ nothing for faith.? ?Bernard of Clairvaux, 1090?1153 CE | >> _o__) | >> Ben Finney >> >> -- >> https://mail.python.org/mailman/listinfo/python-list > > > Like that? Almost. I left your entire message intact up to this point so you can see what you sent, though you may need to click the [...] to expand it [1]. (Normally, I would edit out everything but the actual message I'm replying to ("Like that?") and some context from Ben's message.) > I'm using gmail so it automatically put the text in the [...] > icon. Gmail (which I also use) requires a little bit of extra effort to abide by proper mailing list etiquette; in particular, you should always expand the [...]-hidden text and edit out what you don't need to send such as signatures and footers from the message you're replying to. Then add your replies immediately after the text you're actually responding to, like I've done with this paragraph and my previous one. It's also best to choose "plain text mode" from the little menu at lower-right (choose that before you actually edit the message at all, though, or set it as the default. Changing it mid-message causes havoc with the formatting). It's at least a step up from a certain other Google interface to this list, and I think I speak for everyone in saying "thank you for being willing to learn proper etiquette" :) -- Zach [1] Or look here: https://mail.python.org/pipermail/python-list/2014-September/678058.html From steve+comp.lang.python at pearwood.info Sat Sep 6 00:27:05 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 06 Sep 2014 14:27:05 +1000 Subject: How to turn a string into a list of integers? References: <1amjdb-p3n.ln1@chris.zbmc.eu> Message-ID: <540a8d1a$0$29972$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > On Fri, Sep 5, 2014 at 12:09 PM, Ian Kelly wrote: >> On Thu, Sep 4, 2014 at 6:12 PM, Chris Angelico wrote: >>> If it's a Unicode string (which is the default in Python 3), all >>> Unicode characters will work correctly. >> >> Assuming the library that needs this is expecting codepoints and will >> accept integers greater than 255. > > They're still valid integers. It's just that someone might not know > how to work with them. Everyone has limits - I don't think repr() > would like to be fed Graham's Number, for instance, but we still say > that it accepts integers :) If you can fit Graham's Number into memory, repr() will happily deal with it. Although, it might take a while to print out... [...] > I just don't like people talking about "Unicode characters" being > somehow different from "normal text" or something, and being something > that you need to be careful of. It's not that there are some > characters that behave nicely, and then other ones ("Unicode" ones) > that don't. "Behave nicely" depends on what behaviour you're expecting. There is a sense in which Unicode is different from ASCII text. ASCII is a 7 bit character set. In principle, you could have different implementations of ASCII but in practice it's been so long since any machine you're likely to come across uses anything but exactly a single 8-bit byte for each ASCII character that we might as well say that ASCII has a single implementation: * 1 byte code units, fixed width characters That is, every character takes exactly one 8-bit byte. (Reminder: "byte" does not necessarily mean 8 bits.) Unicode, on the other hand, has *at least* nine different implementations which you are *likely* to come across: * UTF-8 has 1-byte code units, variable width characters: every character takes between 1 and 4 bytes; * UTF-8 with a so-called "Byte Order Mark" at the beginning of the file; * UTF-16-BE has 2-byte code units, variable width characters: every character takes either 2 or 4 bytes; * UTF-16-LE is the same, but the bytes are in opposite order; * UTF-16 with a Byte Order Mark at the beginning of the file; * UTF-32-BE has 4-byte code units, fixed width characters; every character takes exactly 4 bytes; * UTF-32-LE is the same, but the bytes are in opposite order; * UTF-32 with a Byte Order Mark at the beginning of the file; * UCS-2 is a subset of Unicode with 2-byte code units, fixed width characters; every character takes exactly 2 bytes (UCS-2 is effectively UTF-16-BE for characters in the Basic Multilingual Plane). Plus various more obscure or exotic encodings. So, while it is not *strictly* correct to say that ASCII character 'A' is always the eight bits 01000001, the exceptions are so rare that there might as well not be any. But the Unicode character 'A' could be: 01000001 01000001 00000000 00000000 01000001 01000001 00000000 00000000 00000000 00000000 00000000 00000000 01000001 and possibly more. -- Steven From steve+comp.lang.python at pearwood.info Sat Sep 6 01:47:45 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 06 Sep 2014 15:47:45 +1000 Subject: How to turn a string into a list of integers? References: <1amjdb-p3n.ln1@chris.zbmc.eu> <1k9odb-1qs.ln1@chris.zbmc.eu> Message-ID: <540aa002$0$29968$c3e8da3$5496439d@news.astraweb.com> Kurt Mueller wrote: > Could someone please explain the following behavior to me: > Python 2.7.7, MacOS 10.9 Mavericks > >>>> import sys >>>> sys.getdefaultencoding() > 'ascii' That's technically known as a "lie", since if it were *really* ASCII it would refuse to deal with characters with the high-bit set. But it doesn't, it treats them in an unpredictable and implementation-dependent manner. >>>> [ord(c) for c in 'A?'] > [65, 195, 132] In this case, it looks like your terminal is using UTF-8, so the character ? is represented in memory by bytes 195, 132: py> u'?'.encode('utf-8') '\xc3\x84' py> for c in u'?'.encode('utf-8'): ... print ord(c) ... 195 132 If your terminal was set to use a different encoding, you probably would have got different results. When you type whatever key combination you used to get ?, your terminal receives the bytes 195, 132, and displays ?. But when Python processes those bytes, it's not expecting arbitrary Unicode characters, it's expecting ASCII-ish bytes, and so treats it as two bytes rather than a single character: py> 'A?' 'A\xc3\x84' That's not *really* ASCII, because ASCII doesn't include anything above 127, but we can pretend that "ASCII plus arbitrary bytes between 128 and 256" is just called ASCII. The important thing here is that although your terminal is interpreting those two bytes \xc3\x84 (decimal 195, 132) as the character ?, it isn't anything of the sort. It's just two arbitrary bytes. >>>> [ord(c) for c in u'A?'] > [65, 196] Here, you have a proper Unicode string, so Python is expecting to receive arbitrary Unicode characters and can treat the two bytes 195, 132 as ?, and that character has ordinal value 196: py> ord(u"?") 196 > My obviously wrong understanding: > ?A?? in ?ascii? are two characters > one with ord A=65 and > one with ord ?=196 ISO8859-1 As soon as you start talking about code tables, *it isn't ASCII anymore*. (Technically, ASCII *is* a code table, but it's one that only covers 127 different characters.) When you type A? on your keyboard, or paste them, or however they were entered, the *actual bytes* the terminal receives will vary, but regardless of how they vary, the terminal *almost certainly* will interpret the first byte (or possibly more than one byte, who knows?) as the ASCII character A. (Most, but not all, code pages agree that byte 65 is A, 66 is B, and so on.) The second (third? fifth?) byte, and possibly subsequent bytes, will *probably* be displayed by the terminal as ?, but Python only sees the raw bytes. The important thing here is that unless you have some bizarre and broken configuration, Python can correctly interpret the A as A, but what you get for the ? depends on the interaction of keyboard, OS, terminal and the phase of the moon. > ?-> why [65, 195, 132] Since Python is expecting to interpret those bytes as an ASCII-ish byte string, it grabs the raw bytes and ends up (in your case) with 65, 195, 132, or 'A\xc3\x84', even though your terminal displays it as A?. This does not happen with Unicode strings. > u?A?? is an Unicode string > ?-> why [65, 196] In this case, Python knows that you are dealing with a Unicode string, and ? is a valid character in Unicode. Python deals with the internal details of converting from whatever-damn-bytes your terminal sends it, and ends up with a string of characters A followed by ?. If you could peer under the hood, and see what implementation Python uses to store that string, you would see something version dependent. In Python 2.7, you would see an object more or less something vaguely like this: [object header containing various fields] [length = 2] [array of bytes = 0x0041 0x00C4] That's for a so-called "narrow build" of Python. If you have a "wide build", it will something like this: [object header containing various fields] [length = 2] [array of bytes = 0x00000041 0x000000C4] In Python 3.3, "narrow builds" and "wide builds" are gone, and you'll have something conceptually like this: [object header containing various fields] [length = 2] [tag = one byte per character] [array of bytes = 0x41 0xC4] Some other implementations of Python could use UTF-8 internally: [object header containing various fields] [length = 2] [array of bytes = 0x41 0xC3 0x84] or even something more complex. But the important thing is, regardless of the internal implementation, Python guarantees that a Unicode string is treated as a fixed array of code points. Each code point has a value between 0 and, not 127, not 255, not 65535, but 1114111. -- Steven From dieter at handshake.de Sat Sep 6 01:54:08 2014 From: dieter at handshake.de (dieter) Date: Sat, 06 Sep 2014 07:54:08 +0200 Subject: Run an http server on Apache without wsgi? References: Message-ID: <87iol1uwe7.fsf@handshake.de> "Frank Millman" writes: > My AccInABox project runs an http server. Previously I used the cherry.py > wsgiserver, but I have now switched to asyncio. > > I tried to use the wsgi interface, but I have a particular requirement and > found that wsgi got in the way, so I dropped it and now handle all requests > directly. > > Now the question arises, what if someone wants to run my program under > Apache or nginx? There are various ways to interface Apache and Python: among others "cgi", "fcgi", "wsgi". There also used to be "mod_python" which allowed to run Python directly inside an Apache process - however, this module is no longer supported. From dieter at handshake.de Sat Sep 6 02:09:09 2014 From: dieter at handshake.de (dieter) Date: Sat, 06 Sep 2014 08:09:09 +0200 Subject: Anyway to reduce size of pdf using python script. References: <034629a4-a045-4509-9b30-dcd6aea9c3e8@googlegroups.com> Message-ID: <87egvpuvp6.fsf@handshake.de> kekeje at gmail.com writes: > On Friday, February 1, 2013 8:03:41 PM UTC-5, access... at gmail.com wrote: >> I have a batch file that exports ArcGIS pdf maps to a directory. I would like to include a step in the script where the pdf file is reduced in size instead of manually opening each file in Acrobat X Pro after the script has run and doing it there. >> >> Can this be done using python scripting or does the automation stop at exporting the map? > > Have you found the solution? I am having exactly the same problem and happen to see your post here. Please let me know how you did it, thanks! Python is a (mostly) general purpose programming language. To optimize "PDF" specialized PDF knowledge is requires - which Python, by itself, lacks. You may check whether "Acrobat X Pro" is scriptable (can be controlled externally). Windows programs sometimes expose a COM interface for such external control (also called "automation"). If "Acrobat" supports automation via COM interfaces, the you can use Python to "drive the automation" (some Python versions for Windows come with COM support). The required PDF knowledge may also come from special (Python extension) packages. "reportlab" provides Python extensions to handle PDF. I do not know whether this includes optimizing "PDF" (I use a "reportlab" package to generate PDF from Python scripts). I expect that the optimization you observe results from compressing the images included in the PDF. If this is the case, you could in principle write your own package to do this in Python. You would need to learn PDF internals for this. From breamoreboy at yahoo.co.uk Sat Sep 6 03:45:43 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 06 Sep 2014 08:45:43 +0100 Subject: My backwards logic In-Reply-To: References: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> <5409EE02.7030308@stoneleaf.us> <540A0582.1010403@mrabarnett.plus.com> Message-ID: This is top posted and makes it extremely difficult to follow long threads with many replies. This is heavily frowned upon here. On 06/09/2014 02:54, Juan Christian wrote: > @Mark Lawrence: Sorry to ask, but what do you mean by "don't top post > here, thanks.", I'm not familiar with mailing lists, so I may be doing > something wrong and I don't know. > > > On Fri, Sep 5, 2014 at 4:54 PM, Mark Lawrence > wrote: > > On 05/09/2014 20:34, Juan Christian wrote: > > What's [snip] ?? > > > As in cut out or chopped out such that some of the original text has > been removed. And please don't top post here, thanks. This is an interleaved reply that I'm putting here as an example. This is the preferred way of replying, especially on the longer threads. > > -- > My fellow Pythonistas, ask not what our language can do for you, ask > what you can do for our language. > > Mark Lawrence > > -- This in bottom posted. Perfectly acceptable but usually only for the shorter messages. -- 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 Sat Sep 6 03:49:49 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Sat, 6 Sep 2014 07:49:49 +0000 (UTC) Subject: My backwards logic References: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> Message-ID: On Fri, 05 Sep 2014 12:48:56 -0400, Seymore4Head wrote: > But, what this instructions want printed is "This is a prime number" > So how to I use this code logic NOT print (not prime) and have the logic > print "This number is prime" This is an algorithmic question, not a python question, so the answer is to write out the steps you would follow to determine that a number is prime, and then write that code. Note also that when searching for factors of a number n, and starting at 2, you can generally stop at somewhere around n/3, as the only possible factor of n greater than n/2 is n, and 2 is probably the first value you tested. This can speed things up. -- Denis McMahon, denismfmcmahon at gmail.com From breamoreboy at yahoo.co.uk Sat Sep 6 03:46:41 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 06 Sep 2014 08:46:41 +0100 Subject: Posting style: interleaved responses In-Reply-To: References: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> <5409EE02.7030308@stoneleaf.us> <540A0582.1010403@mrabarnett.plus.com> <85y4txwk2m.fsf_-_@benfinney.id.au> Message-ID: On 06/09/2014 05:04, Zachary Ware wrote: > > It's at least a step up from a certain other Google interface to this > list, and I think I speak for everyone in saying "thank you for being > willing to learn proper etiquette" :) > +1 :) -- 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 Sep 6 03:56:10 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 06 Sep 2014 08:56:10 +0100 Subject: [OT?]cpython pull from hg Message-ID: The following doesn't make any sense to me as I've very limited knowledge of Mercurial so can someone explain why it says "added 12 changesets with 26 changes to 22 files" but then "3 files updated, 0 files merged, 0 files removed, 0 files unresolved". I'd expect to see 22 files updated. The output is cut and pasted directly from the TortoiseHg Sync screen. % hg pull --verbose --update --config ui.merge=internal:merge http://hg.python.org/cpython pulling from http://hg.python.org/cpython searching for changes all local heads known remotely adding changesets adding manifests adding file changes added 12 changesets with 26 changes to 22 files resolving manifests getting Doc/library/asyncio.rst getting Doc/reference/expressions.rst getting Mac/BuildScript/build-installer.py 3 files updated, 0 files merged, 0 files removed, 0 files unresolved [command completed successfully Sat Sep 06 08:34:18 2014] -- 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 Sat Sep 6 04:22:30 2014 From: __peter__ at web.de (Peter Otten) Date: Sat, 06 Sep 2014 10:22:30 +0200 Subject: How to turn a string into a list of integers? References: <1amjdb-p3n.ln1@chris.zbmc.eu> <1k9odb-1qs.ln1@chris.zbmc.eu> <540aa002$0$29968$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: >>>>> import sys >>>>> sys.getdefaultencoding() >> 'ascii' > > That's technically known as a "lie", since if it were *really* ASCII it > would refuse to deal with characters with the high-bit set. But it > doesn't, it treats them in an unpredictable and implementation-dependent > manner. It's not a lie, it just doesn't control the unicode-to-bytes conversion when printing: $ python Python 2.7.6 (default, Mar 22 2014, 22:59:56) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.getdefaultencoding() 'ascii' >>> print u"???" ??? >>> str(u"???") Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128) >>> reload(sys) >>> sys.setdefaultencoding("latin1") >>> print u"???" ??? >>> str(u"???") '\xe4\xf6\xfc' >>> sys.setdefaultencoding("utf-8") >>> print u"???" ??? >>> str(u"???") '\xc3\xa4\xc3\xb6\xc3\xbc' You can enforce ascii-only printing: $ LANG=C python Python 2.7.6 (default, Mar 22 2014, 22:59:56) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> print unichr(228) Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in position 0: ordinal not in range(128) To find out the encoding that is used: $ python -c 'import locale; print locale.getpreferredencoding()' UTF-8 $ LANG=C python -c 'import locale; print locale.getpreferredencoding()' ANSI_X3.4-1968 """ Help on function getpreferredencoding in module locale: getpreferredencoding(do_setlocale=True) Return the charset that the user is likely using, according to the system configuration. """ From __peter__ at web.de Sat Sep 6 04:42:50 2014 From: __peter__ at web.de (Peter Otten) Date: Sat, 06 Sep 2014 10:42:50 +0200 Subject: [OT?]cpython pull from hg References: Message-ID: Mark Lawrence wrote: > The following doesn't make any sense to me as I've very limited > knowledge of Mercurial so can someone explain why it says "added 12 > changesets with 26 changes to 22 files" but then "3 files updated, 0 > files merged, 0 files removed, 0 files unresolved". I'd expect to see > 22 files updated. The output is cut and pasted directly from the > TortoiseHg Sync screen. I'm no expert either, but I would guess that the other modified files exist only in another branch. > % hg pull --verbose --update --config ui.merge=internal:merge > http://hg.python.org/cpython > pulling from http://hg.python.org/cpython > searching for changes > all local heads known remotely > adding changesets > adding manifests > adding file changes > added 12 changesets with 26 changes to 22 files > resolving manifests > getting Doc/library/asyncio.rst > getting Doc/reference/expressions.rst > getting Mac/BuildScript/build-installer.py > 3 files updated, 0 files merged, 0 files removed, 0 files unresolved > [command completed successfully Sat Sep 06 08:34:18 2014] > From nikos.gr33k at gmail.com Sat Sep 6 03:18:26 2014 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?1v7t9OHyIMvh5O/w8eHq/PDv9evv8g==?=) Date: Sat, 6 Sep 2014 00:18:26 -0700 (PDT) Subject: Python 3.41 and web3py framework Message-ID: <98587cee-a129-47e2-bffd-a8e23db3b6b7@googlegroups.com> Hello, i'm trying to install and work with web3py as i have Python 3.4.1 installed. [/code] [nikos at dell web3py-master]$ ls apps contrib gluon Makefile runme.py TODO vars web3py [nikos at dell web3py-master]$ python -V Python 3.4.1 [nikos at dell web3py-master]$ python runme.py Traceback (most recent call last): File "runme.py", line 2, in from web3py import run File "/home/nikos/web3py-master/web3py/__init__.py", line 1, in from .wsgi import run File "/home/nikos/web3py-master/web3py/wsgi.py", line 10, in from .fancy_pickle import dumps File "/home/nikos/web3py-master/web3py/fancy_pickle.py", line 50, in check() File "/home/nikos/web3py-master/web3py/fancy_pickle.py", line 46, in check s = dumps(a) File "/home/nikos/web3py-master/web3py/fancy_pickle.py", line 33, in dumps dump(data,stream) File "/home/nikos/web3py-master/web3py/fancy_pickle.py", line 29, in dump p.dump(data) TypeError: string argument expected, got 'bytes' [nikos at dell web3py-master]$ [/code] Does someone know why python3 failing to start the framework and how i will get it working? From tjreedy at udel.edu Sat Sep 6 06:06:11 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 06 Sep 2014 06:06:11 -0400 Subject: [OT?]cpython pull from hg In-Reply-To: References: Message-ID: On 9/6/2014 4:42 AM, Peter Otten wrote: > Mark Lawrence wrote: > >> The following doesn't make any sense to me as I've very limited >> knowledge of Mercurial so can someone explain why it says "added 12 >> changesets with 26 changes to 22 files" but then "3 files updated, 0 >> files merged, 0 files removed, 0 files unresolved". I'd expect to see >> 22 files updated. The output is cut and pasted directly from the >> TortoiseHg Sync screen. > > I'm no expert either, but I would guess that the other modified files exist > only in another branch. The other files mostly, perhaps all, exist in default but were only modified for 2.7. I just pulled and updated my separate working directories for 2.7, 3.4, and 3.5. In particular, 32 files changed for 2.7, 4 for 3.4, and 8 for 3.5, 37 files total changed in some version. This is a very unusual distribution. I know that there was one patch that modified about 10 test files to ignore valid py3 warnings when the tests are run with py3 deprecation warnings turned on. This is something we just got around to doing on a regular basis. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Sat Sep 6 06:38:55 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 06 Sep 2014 20:38:55 +1000 Subject: Prime testing [was Re: My backwards logic] References: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> Message-ID: <540ae440$0$29995$c3e8da3$5496439d@news.astraweb.com> Denis McMahon wrote: > Note also that when searching for factors of a number n, and starting at > 2, you can generally stop at somewhere around n/3, The largest factor of N you actually need to check is sqrt(n). Every factor of n below the square root has a corresponding factor above it, e.g. if n equals 100, then factor 2 (below 10) corresponds to factor 50 (above 10), so there's no need to test with numbers above the square root since you would have already detected their partner. (No need to check whether 50 is a factor, since you've already checked 2.) Stopping at n/2, or n/3, does a lot more work than necessary. E.g. for n equal to one million, we have: py> n = 10**6 py> n/2, n/3, n**0.5 (500000.0, 333333.3333333333, 1000.0) Even there, we can improve matters by only dividing by primes: 3, 5, 7, 9 is a waste of time, 11, 13, 15 is a waste of time, ... If n is divisible by 9, it is also divisible by 3; likewise if n is divisible by 15, it is also divisible by both 3 and 5. There are only 78,498 primes below one million, compared to 499,999 odd numbers excluding 1, so if you can find away to only test against primes, you'll save a lot of time. But even that's not how the specialists do it. If you want to check whether (say) 2**3000+1 is prime, you don't want to use trial division at all... -- Steven From rosuav at gmail.com Sat Sep 6 06:42:58 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 6 Sep 2014 20:42:58 +1000 Subject: Prime testing [was Re: My backwards logic] In-Reply-To: <540ae440$0$29995$c3e8da3$5496439d@news.astraweb.com> References: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> <540ae440$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Sep 6, 2014 at 8:38 PM, Steven D'Aprano wrote: > 3, 5, 7, 9 is a waste of time, 11, 13, 15 is a waste of time, ... I love this sequence. ChrisA From steve+comp.lang.python at pearwood.info Sat Sep 6 07:17:43 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 06 Sep 2014 21:17:43 +1000 Subject: How to turn a string into a list of integers? References: <1amjdb-p3n.ln1@chris.zbmc.eu> <1k9odb-1qs.ln1@chris.zbmc.eu> <540aa002$0$29968$c3e8da3$5496439d@news.astraweb.com> Message-ID: <540aed58$0$29985$c3e8da3$5496439d@news.astraweb.com> Peter Otten wrote: > Steven D'Aprano wrote: > >>>>>> import sys >>>>>> sys.getdefaultencoding() >>> 'ascii' >> >> That's technically known as a "lie", since if it were *really* ASCII it >> would refuse to deal with characters with the high-bit set. But it >> doesn't, it treats them in an unpredictable and implementation-dependent >> manner. > > It's not a lie, it just doesn't control the unicode-to-bytes conversion > when printing: That's not what I'm referring to. I'm referring to this: py> s '\xff' There is no such ASCII character (or code point, to steal terminology from Unicode). ASCII is a 7-bit encoding, and includes 128 characters, with ordinal values 0 through 127. Once you accept arbitrary bytes 128 through 255, it's no longer ASCII, it's ASCII plus undefined stuff. (Historical note: the committee that designed ASCII *explicitly* rejected making it an 8-bit code. They also considered, but rejected, using a 6-bit code with a "shift" function.) -- Steven From kurt.alfred.mueller at gmail.com Sat Sep 6 08:15:26 2014 From: kurt.alfred.mueller at gmail.com (Kurt Mueller) Date: Sat, 6 Sep 2014 14:15:26 +0200 Subject: How to turn a string into a list of integers? In-Reply-To: <540aa002$0$29968$c3e8da3$5496439d@news.astraweb.com> References: <1amjdb-p3n.ln1@chris.zbmc.eu> <1k9odb-1qs.ln1@chris.zbmc.eu> <540aa002$0$29968$c3e8da3$5496439d@news.astraweb.com> Message-ID: <200C8328-DBB2-4DE1-9419-4A0A53599C08@gmail.com> Am 06.09.2014 um 07:47 schrieb Steven D'Aprano : > Kurt Mueller wrote: >> Could someone please explain the following behavior to me: >> Python 2.7.7, MacOS 10.9 Mavericks [snip] Thanks for the detailed explanation. I think I understand a bit better now. Now the part of the two Python builds is still somewhat unclear to me. > If you could peer under the hood, and see what implementation Python uses to > store that string, you would see something version dependent. In Python > 2.7, you would see an object more or less something vaguely like this: > > [object header containing various fields] > [length = 2] > [array of bytes = 0x0041 0x00C4] > > > That's for a so-called "narrow build" of Python. If you have a "wide build", > it will something like this: > > [object header containing various fields] > [length = 2] > [array of bytes = 0x00000041 0x000000C4] > > In Python 3.3, "narrow builds" and "wide builds" are gone, and you'll have > something conceptually like this: > > [object header containing various fields] > [length = 2] > [tag = one byte per character] > [array of bytes = 0x41 0xC4] > > Some other implementations of Python could use UTF-8 internally: > > [object header containing various fields] > [length = 2] > [array of bytes = 0x41 0xC3 0x84] > > > or even something more complex. But the important thing is, regardless of > the internal implementation, Python guarantees that a Unicode string is > treated as a fixed array of code points. Each code point has a value > between 0 and, not 127, not 255, not 65535, but 1114111. In Python 2.7: As I learned from the ord() manual: If a unicode argument is given and Python was built with UCS2 Unicode, (I suppose this is the narrow build in your terms), then the character?s code point must be in the range [0..65535] inclusive; I understand: In a UCS2 build each character of a Unicode string uses 16 Bits and can represent code points from U-0000..U-FFFF. From the unichr(i) manual I learn: The valid range for the argument depends how Python was configured ? it may be either UCS2 [0..0xFFFF] or UCS4 [0..0x10FFFF]. I understand: narrow build is UCS2, wide build is UCS4 - In a UCS2 build each character of an Unicode string uses 16 Bits and has code points from U-0000..U-FFFF (0..65535) - In a UCS4 build each character of an Unicode string uses 32 Bits and has code points from U-00000000..U-0010FFFF (0..1114111) Am I right? -- Kurt Mueller, kurt.alfred.mueller at gmail.com From rosuav at gmail.com Sat Sep 6 08:23:20 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 6 Sep 2014 22:23:20 +1000 Subject: How to turn a string into a list of integers? In-Reply-To: <200C8328-DBB2-4DE1-9419-4A0A53599C08@gmail.com> References: <1amjdb-p3n.ln1@chris.zbmc.eu> <1k9odb-1qs.ln1@chris.zbmc.eu> <540aa002$0$29968$c3e8da3$5496439d@news.astraweb.com> <200C8328-DBB2-4DE1-9419-4A0A53599C08@gmail.com> Message-ID: On Sat, Sep 6, 2014 at 10:15 PM, Kurt Mueller wrote: > I understand: narrow build is UCS2, wide build is UCS4 > - In a UCS2 build each character of an Unicode string uses 16 Bits and has > code points from U-0000..U-FFFF (0..65535) > - In a UCS4 build each character of an Unicode string uses 32 Bits and has > code points from U-00000000..U-0010FFFF (0..1114111) Pretty much. Narrow builds are buggy, so as much as possible, you want to avoid using them. Ideally, use Python 3.3 or newer, where the distinction doesn't exist - all builds are functionally like wide builds, with memory usage even better than narrow builds (they'll use 8 bits per character if it's possible). As a general rule, precompiled Python for Windows is usually a narrow build, and Python distributions for Linux are usually wide builds. (I don't know about Mac OS builds.) You can test any Python by checking out sys.maxunicode - it'll be 65535 on a narrow build, or 1114111 on wide builds (because that's the maximum codepoint defined by Unicode - U+10FFFF - as it's the highest number that can be represented in UTF-16). ChrisA From daniel.e.rossy at gmail.com Sat Sep 6 08:31:38 2014 From: daniel.e.rossy at gmail.com (daniel.e.rossy at gmail.com) Date: Sat, 6 Sep 2014 05:31:38 -0700 (PDT) Subject: comparing alternatives to py2exe In-Reply-To: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> References: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> Message-ID: I found this: https://pypi.python.org/pypi/py2exe/0.9.2.0 Also, thanks for the spreadsheet, it's very useful. From isenntp at gmail.com Sat Sep 6 12:13:07 2014 From: isenntp at gmail.com (ISE Development) Date: Sat, 06 Sep 2014 18:13:07 +0200 Subject: __qualname__ in python 3.3 Message-ID: <540b3293$0$2056$426a74cc@news.free.fr> Hi, When a class is defined within a function, the class generation function's '__qualname__' attrbute is not qualified a name. For instance: def test(): class T: def method(self): pass t = T() t.method() When tracing a call to 'test()' using 'sys.settrace()', extracting the 'code' object from the frames of 'call' events and matching it to a 'function' object (using 'gc.get_referrers()') results in the following: 'code' object 'function' object ---------------- ------------------------------------ co_name: test __qualname__: test co_name: T __qualname__: T co_name: method __qualname__: test..T.method The second call corresponds to the class definition and not the call to the constructor (which is in fact a call to 'object.__init__', a C function hence not traced as a 'call' event - I checked this by disassembling the code object). I would expect the second call's '__qualname__' to be 'test..T'. Can this be considered a bug? If so, I'll open one. -- isedev From python at mrabarnett.plus.com Sat Sep 6 12:32:01 2014 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 06 Sep 2014 17:32:01 +0100 Subject: Storing instances using jsonpickle In-Reply-To: References: <46e782a5-b087-4f95-aadb-26e233bf5419@googlegroups.com> <5407A69B.3030707@mrabarnett.plus.com> <5409ED0B.2030902@mrabarnett.plus.com> Message-ID: <540B3701.5020007@mrabarnett.plus.com> On 2014-09-06 01:20, Chris Angelico wrote: > On Sat, Sep 6, 2014 at 3:04 AM, MRAB > wrote: >> JSON has 'true' and 'false'. >> >> Python has 'True' and 'False'. >> >> Therefore, if you want it to be able to drop it into Python's REPL, >> it won't be compatible with JSON anyway! (Well, not unless you >> define 'true' and 'false' first.) > > This is a new spec, so I guess the question is whether it's > primarily "JSON with some more features" or "subset of Python syntax > in the same way that JSON is a subset of JS". If it's the former, > then yes, it'd use "true" and "false", and you'd have to define them; > but if the latter, the spec would simply use "True" and "False". But > being able to guarantee that JSON decodes correctly with this parser > (ie make it a guaranteed superset of JSON) would be of value. > I've found that there's another issue with JSON: string escapes include \u, but not \U: >>> json.dumps('\U0010FFFF') '"\\udbff\\udfff"' Yes, it uses surrogate escapes! Also: >>> json.dumps('\uDBFF\uDFFF') '"\\udbff\\udfff"' so it won't round-trip. On the other hand, you probably won't be using pairs of surrogate escapes in Python 3.3+. From __peter__ at web.de Sat Sep 6 12:47:44 2014 From: __peter__ at web.de (Peter Otten) Date: Sat, 06 Sep 2014 18:47:44 +0200 Subject: __qualname__ in python 3.3 References: <540b3293$0$2056$426a74cc@news.free.fr> Message-ID: ISE Development wrote: > Hi, > > When a class is defined within a function, the class generation function's > '__qualname__' attrbute is not qualified a name. > > For instance: > > def test(): > class T: > def method(self): > pass > t = T() > t.method() > > When tracing a call to 'test()' using 'sys.settrace()', extracting the > 'code' object from the frames of 'call' events and matching it to a > 'function' object (using 'gc.get_referrers()') results in the following: > > 'code' object 'function' object > ---------------- ------------------------------------ > co_name: test __qualname__: test > co_name: T __qualname__: T > co_name: method __qualname__: test..T.method > > The second call corresponds to the class definition and not the call to > the constructor (which is in fact a call to 'object.__init__', a C > function hence not traced as a 'call' event - I checked this by > disassembling the code object). > > I would expect the second call's '__qualname__' to be 'test..T'. > Can this be considered a bug? If so, I'll open one. I don't understand what you are doing, so I tried to reproduce the unqualified class name in 3.4 with the simpler approach of returning T: Python 3.4.0 (default, Apr 11 2014, 13:05:11) [GCC 4.8.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> def test(): ... class T: ... def method(self): pass ... return T ... >>> T = test() >>> T.__qualname__ 'test..T' >>> T.method.__qualname__ 'test..T.method' If you do it that way with 3.3 (I don't have it handy) do you still see T instead of test..T? From ned at nedbatchelder.com Sat Sep 6 12:56:32 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 06 Sep 2014 12:56:32 -0400 Subject: Storing instances using jsonpickle In-Reply-To: <540B3701.5020007@mrabarnett.plus.com> References: <46e782a5-b087-4f95-aadb-26e233bf5419@googlegroups.com> <5407A69B.3030707@mrabarnett.plus.com> <5409ED0B.2030902@mrabarnett.plus.com> <540B3701.5020007@mrabarnett.plus.com> Message-ID: On 9/6/14 12:32 PM, MRAB wrote: > On 2014-09-06 01:20, Chris Angelico wrote: >> On Sat, Sep 6, 2014 at 3:04 AM, MRAB >> wrote: >>> JSON has 'true' and 'false'. >>> >>> Python has 'True' and 'False'. >>> >>> Therefore, if you want it to be able to drop it into Python's REPL, >>> it won't be compatible with JSON anyway! (Well, not unless you >>> define 'true' and 'false' first.) >> >> This is a new spec, so I guess the question is whether it's >> primarily "JSON with some more features" or "subset of Python syntax >> in the same way that JSON is a subset of JS". If it's the former, >> then yes, it'd use "true" and "false", and you'd have to define them; >> but if the latter, the spec would simply use "True" and "False". But >> being able to guarantee that JSON decodes correctly with this parser >> (ie make it a guaranteed superset of JSON) would be of value. >> > I've found that there's another issue with JSON: string escapes include > \u, but not \U: > > >>> json.dumps('\U0010FFFF') > '"\\udbff\\udfff"' > > Yes, it uses surrogate escapes! > > Also: > > >>> json.dumps('\uDBFF\uDFFF') > '"\\udbff\\udfff"' > > so it won't round-trip. Strings in JavaScript are explicitly defined to be sequences of 16-bit value, so the spec mandates surrogate pairs for codepoints outside the Basic Multilingual Plane, unfortunately. JSON follows suit, also unfortunately. > > On the other hand, you probably won't be using pairs of surrogate > escapes in Python 3.3+. -- Ned Batchelder, http://nedbatchelder.com From isenntp at gmail.com Sat Sep 6 13:09:56 2014 From: isenntp at gmail.com (ISE Development) Date: Sat, 06 Sep 2014 19:09:56 +0200 Subject: __qualname__ in python 3.3 References: <540b3293$0$2056$426a74cc@news.free.fr> Message-ID: <540b3fe4$0$2055$426a74cc@news.free.fr> Peter Otten wrote: > ISE Development wrote: > >> Hi, >> >> When a class is defined within a function, the class generation >> function's '__qualname__' attrbute is not qualified a name. >> >> For instance: >> >> def test(): >> class T: >> def method(self): >> pass >> t = T() >> t.method() >> >> When tracing a call to 'test()' using 'sys.settrace()', extracting the >> 'code' object from the frames of 'call' events and matching it to a >> 'function' object (using 'gc.get_referrers()') results in the following: >> >> 'code' object 'function' object >> ---------------- ------------------------------------ >> co_name: test __qualname__: test >> co_name: T __qualname__: T >> co_name: method __qualname__: test..T.method >> >> The second call corresponds to the class definition and not the call to >> the constructor (which is in fact a call to 'object.__init__', a C >> function hence not traced as a 'call' event - I checked this by >> disassembling the code object). >> >> I would expect the second call's '__qualname__' to be 'test..T'. >> Can this be considered a bug? If so, I'll open one. > > I don't understand what you are doing, so I tried to reproduce the > unqualified class name in 3.4 with the simpler approach of returning T: > > Python 3.4.0 (default, Apr 11 2014, 13:05:11) > [GCC 4.8.2] on linux > Type "help", "copyright", "credits" or "license" for more information. >>>> def test(): > ... class T: > ... def method(self): pass > ... return T > ... >>>> T = test() >>>> T.__qualname__ > 'test..T' >>>> T.method.__qualname__ > 'test..T.method' > > If you do it that way with 3.3 (I don't have it handy) do you still see > T instead of test..T? Python 3.3 behaves in the same way in that case. This following shows the behaviour I am referring to: import gc import sys import inspect def global_trace(frame,event,arg): if event == 'call': code = frame.f_code funcs = [obj for obj in gc.get_referrers(code) if inspect.isfunction(obj)] if len(funcs) == 1: f = funcs[0] print(f.__qualname__) def test(): class C: def method(self): self c = C() c.method() sys.settrace(global_trace) try: test() finally: sys.settrace(None) which produces: test C test..C.method From manolo at austrohungaro.com Sat Sep 6 06:53:16 2014 From: manolo at austrohungaro.com (Manolo =?iso-8859-1?Q?Mart=EDnez?=) Date: Sat, 6 Sep 2014 12:53:16 +0200 Subject: Prime testing [was Re: My backwards logic] In-Reply-To: <540ae440$0$29995$c3e8da3$5496439d@news.astraweb.com> References: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> <540ae440$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20140906105316.GB19733@beagle.localdomain> On 09/06/14 at 08:38pm, Steven D'Aprano wrote: > But even that's not how the specialists do it. If you want to check whether > (say) 2**3000+1 is prime, you don't want to use trial division at all... When I was interested in these things, specialists would use the [number field sieve](https://en.wikipedia.org/wiki/General_number_field_sieve). I coded a Mathematica implementation fifteen years ago or so. It was a lot of work :) Manolo From sumitbu.ray at gmail.com Sat Sep 6 12:24:26 2014 From: sumitbu.ray at gmail.com (Sumit Ray) Date: Sat, 6 Sep 2014 09:24:26 -0700 Subject: urllib2 redirect error In-Reply-To: <87ppfddxnr.fsf@handshake.de> References: <540571b8$0$29876$c3e8da3$5496439d@news.astraweb.com> <87ppfddxnr.fsf@handshake.de> Message-ID: Steven, Thank you! User advice was on point. Sumit On Tue, Sep 2, 2014 at 11:29 PM, dieter wrote: > Steven D'Aprano writes: > > ... > > I'm not an expert, but that sounds like a fault at the server end. I just > > tried it in Chrome, and it worked, and then with wget, and I get the same > > sort of error: > > ... > > Sounds like if the server doesn't recognise the browser, it gets > > confused and ends up in a redirect loop. > > > > You could try setting the user-agent and see if that helps: > > Excellent analysis and advice. > > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Sat Sep 6 14:11:01 2014 From: __peter__ at web.de (Peter Otten) Date: Sat, 06 Sep 2014 20:11:01 +0200 Subject: __qualname__ in python 3.3 References: <540b3293$0$2056$426a74cc@news.free.fr> <540b3fe4$0$2055$426a74cc@news.free.fr> Message-ID: ISE Development wrote: > Peter Otten wrote: > >> ISE Development wrote: >> >>> Hi, >>> >>> When a class is defined within a function, the class generation >>> function's '__qualname__' attrbute is not qualified a name. >>> >>> For instance: >>> >>> def test(): >>> class T: >>> def method(self): >>> pass >>> t = T() >>> t.method() >>> >>> When tracing a call to 'test()' using 'sys.settrace()', extracting the >>> 'code' object from the frames of 'call' events and matching it to a >>> 'function' object (using 'gc.get_referrers()') results in the following: >>> >>> 'code' object 'function' object >>> ---------------- ------------------------------------ >>> co_name: test __qualname__: test >>> co_name: T __qualname__: T >>> co_name: method __qualname__: test..T.method >>> >>> The second call corresponds to the class definition and not the call to >>> the constructor (which is in fact a call to 'object.__init__', a C >>> function hence not traced as a 'call' event - I checked this by >>> disassembling the code object). >>> >>> I would expect the second call's '__qualname__' to be 'test..T'. >>> Can this be considered a bug? If so, I'll open one. >> >> I don't understand what you are doing, so I tried to reproduce the >> unqualified class name in 3.4 with the simpler approach of returning T: >> >> Python 3.4.0 (default, Apr 11 2014, 13:05:11) >> [GCC 4.8.2] on linux >> Type "help", "copyright", "credits" or "license" for more information. >>>>> def test(): >> ... class T: >> ... def method(self): pass >> ... return T >> ... >>>>> T = test() >>>>> T.__qualname__ >> 'test..T' >>>>> T.method.__qualname__ >> 'test..T.method' >> >> If you do it that way with 3.3 (I don't have it handy) do you still see >> T instead of test..T? > > Python 3.3 behaves in the same way in that case. > > This following shows the behaviour I am referring to: > > import gc > import sys > import inspect > > def global_trace(frame,event,arg): > if event == 'call': > code = frame.f_code > funcs = [obj for obj in gc.get_referrers(code) > if inspect.isfunction(obj)] > if len(funcs) == 1: > f = funcs[0] > print(f.__qualname__) > > def test(): > class C: > def method(self): > self > c = C() > c.method() > > sys.settrace(global_trace) > try: > test() > finally: > sys.settrace(None) > > which produces: > > test > C > test..C.method OK, I get the same output in Python 3.4. That C seems to be an internal function that helps build the class test..C, and I have no expectations as to its name. If anything I'd use something completely different, _init_namespace_C, say. I'm sorry I am not familiar enough with Python's internals to answer your question -- but if in doubt, file a report. From steve+comp.lang.python at pearwood.info Sat Sep 6 14:19:52 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 07 Sep 2014 04:19:52 +1000 Subject: How to turn a string into a list of integers? References: <1amjdb-p3n.ln1@chris.zbmc.eu> <1k9odb-1qs.ln1@chris.zbmc.eu> <540aa002$0$29968$c3e8da3$5496439d@news.astraweb.com> Message-ID: <540b504a$0$29974$c3e8da3$5496439d@news.astraweb.com> Kurt Mueller wrote: [...] > Now the part of the two Python builds is still somewhat unclear to me. [...] > In Python 2.7: > > As I learned from the ord() manual: > If a unicode argument is given and Python was built with UCS2 Unicode, Where does the manual mention UCS-2? As far as I know, no version of Python uses that. > (I suppose this is the narrow build in your terms), Mostly right, but not quite. "Narrow build" means that Python uses UTF-16, not UCS-2, although the two are very similar. See below for further details. But to make it more confusing, *parts* of Python (like the unichr function) assume UCS-2, and refuse to accept values over 0xFFFF. > then the character?s code point must be in the range [0..65535] inclusive; Half-right. Unicode code points are always in the range U+0000 to U+10FFFF, or in decimal, [0...1114111]. But, Python "narrow builds" don't quite handle that correctly, and only half-support code points from [65536...1114111]. The reasons are complicated, but see below. UCS-2 is an implementation of an early, obsolete version of Unicode which is limited to just 65536 characters (technically: "code points") instead of the full range of 1114112 characters supported by Unicode. UCS-2 is very similar to UTF-16. Both use a 16-bit "code unit" to represent characters. In UCS-2, each character is represented by precisely 1 code unit, numbered between 0 and 65535 (0x0000 and 0xFFFF in hex). In UTF-16, the most common characters (the Basic Multilingual Plane) are likewise represented by 1 code unit, between 0 and 65535, but there are a range of "characters" (actually code points) which are reserved for use as so-called "surrogate pairs". Using hex: Code points U+0000 to U+D7FF: - represent the same character in UCS-2 and UTF-16; Code points U+D800 to U+DFFF: - represent reserved but undefined characters in UCS-2; - represent surrogates in UTF-16 (see below); Code points U+E000 to U+FFFF: - represent the same character in UCS-2 and UTF-16; Code points U+010000 to U+10FFFF: - impossible to represent in UCS-2; - represented by TWO surrogates in UTF-16. For example, the Unicode code point U+1D11E (MUSICAL SYMBOL G CLEF) cannot be represented at all in UCS-2, because it is past U+FFFF. In UTF-16, it cannot be represented as a single 16-bit code unit, instead it is represented as two code-units, 0xD834 0xDD1E. That is called a "surrogate pair". The problem with Python's narrow builds is that, although characters are variable width (the most common are 1 code unit, 16 bits, the rest are 2 code units), the Python implementation assumes that all characters are a fixed 16 bits. So if your string is a single character like U+1D11E, instead of treating it as a string of length one with ordinal value 0x1D11E, Python will treat it as a string of length *two* with ordinal values 0xD834 and 0xDD1E. (In other words, Python narrow builds fail to deal with surrogate pairs correctly.) Although you cannot create that string using unichr, you can create it using the \U notation: py> unichr(0x1D11E) Traceback (most recent call last): File "", line 1, in ValueError: unichr() arg not in range(0x10000) (narrow Python build) py> u'\U0001D11E' u'\U0001d11e' > I understand: In a UCS2 build each character of a Unicode string uses > 16 Bits and can represent code points from U-0000..U-FFFF. That is correct. So UCS-2 can only represent a small subset of Unicode. > From the unichr(i) manual I learn: > The valid range for the argument depends how Python was configured > ? it may be either UCS2 [0..0xFFFF] or UCS4 [0..0x10FFFF]. > I understand: narrow build is UCS2, wide build is UCS4 UCS-4 is exactly the same as UTF-32, and wide builds use a fixed 32 bits for every code point, so that's correct. > - In a UCS2 build each character of an Unicode string uses 16 Bits and has > code points from U-0000..U-FFFF (0..65535) As I said, it's not strictly correct, Python is actually using UTF-16, but it's a buggy or incomplete UTF-16, with parts of the system assuming UCS-2. > - In a UCS4 build each character of an Unicode string uses 32 Bits and has > code points from U-00000000..U-0010FFFF (0..1114111) Correct. Remember that UCS-4 and UTF-32 are exactly the same: every code point from U+0000 to U+10FFFF is represented by a single 32-bit value. So our earlier example, U+1D11E (MUSICAL SYMBOL G CLEF) would be represented as 0x0001D11E in UTF-32 and UCS-4. Remember, though, these internal representations are (nearly) irrelevant to Python code. In Python code, you just consider that a Unicode string is an array of ordinal values from 0x0 to 0x10FFFF, each representing a single code point U+0000 to U+10FFFF. The only reason I say "nearly" is that narrow builds don't *quite* work right if the string contains surrogate pairs. -- Steven From tjreedy at udel.edu Sat Sep 6 14:27:45 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 06 Sep 2014 14:27:45 -0400 Subject: Storing instances using jsonpickle In-Reply-To: <540B3701.5020007@mrabarnett.plus.com> References: <46e782a5-b087-4f95-aadb-26e233bf5419@googlegroups.com> <5407A69B.3030707@mrabarnett.plus.com> <5409ED0B.2030902@mrabarnett.plus.com> <540B3701.5020007@mrabarnett.plus.com> Message-ID: On 9/6/2014 12:32 PM, MRAB wrote: > On 2014-09-06 01:20, Chris Angelico wrote: >> On Sat, Sep 6, 2014 at 3:04 AM, MRAB >> wrote: >>> JSON has 'true' and 'false'. >>> >>> Python has 'True' and 'False'. >>> >>> Therefore, if you want it to be able to drop it into Python's REPL, >>> it won't be compatible with JSON anyway! (Well, not unless you >>> define 'true' and 'false' first.) >> >> This is a new spec, so I guess the question is whether it's >> primarily "JSON with some more features" or "subset of Python syntax >> in the same way that JSON is a subset of JS". If it's the former, >> then yes, it'd use "true" and "false", and you'd have to define them; >> but if the latter, the spec would simply use "True" and "False". But >> being able to guarantee that JSON decodes correctly with this parser >> (ie make it a guaranteed superset of JSON) would be of value. >> > I've found that there's another issue with JSON: string escapes include > \u, but not \U: > > >>> json.dumps('\U0010FFFF') > '"\\udbff\\udfff"' > > Yes, it uses surrogate escapes! Because Javascript does. It does roundtrip properly (3.4.1) >>> json.loads('"\\udbff\\udfff"') '\U0010ffff' > Also: > > >>> json.dumps('\uDBFF\uDFFF') > '"\\udbff\\udfff"' > > so it won't round-trip. > > On the other hand, you probably won't be using pairs of surrogate > escapes in Python 3.3. The surrogate codepoints are not unicode characters and as I remember from reading the standard, would not be allowed in a strict utf-32 implementation. 3.3+ uses them, when requested, to represent undecodable bytes in a non-standard fashion. and for other occasional practical reasons that most of us can ignore. -- Terry Jan Reedy From timr at probo.com Sat Sep 6 14:34:12 2014 From: timr at probo.com (Tim Roberts) Date: Sat, 06 Sep 2014 11:34:12 -0700 Subject: ANN: binario - simple work with binary files References: <33f920ca-16ce-40ce-ab3a-4479beeeae4e@googlegroups.com> <23onv9dom4ek64m273bfic5n0c2ldnij8b@4ax.com> <68d1665b-5369-43f0-8177-352b8949ab20@googlegroups.com> <85e4a393-c926-44cd-a0dd-1654cfaa6b4d@googlegroups.com> Message-ID: <7ekm0altrkt1q19j0pktm2i3kpk59sgsmb@4ax.com> Rustom Mody wrote: >On Tuesday, September 2, 2014 6:05:19 AM UTC+5:30, Tim Roberts wrote: >> Rustom Mody wrote: > >> >On Tuesday, August 26, 2014 6:58:42 AM UTC+5:30, Tim Roberts wrote: > >> >> To the equivalent code with struct: >> >> import struct >> >> dscrp = "H?fs5B" >> >> f = open('file.dat') >> >> stuff = struct.unpack( dscrp, f.read() ) >> >> print stuff >> >> In both cases, you have to KNOW the format of the data beforehand. If you >> >> do a read_short where you happen to have written a float, disaster ensues. >> >> I don't really see that you've added very much. >> >I thought much the same. >> >However notice your f.read(). Its type is string. >> >What if file.dat is a 1GB wav file? > >> f.seek(512000) >> stuff = struct.unpack( dscrp, f.read(128) ) > >And what if the struct you are (trying to) unpack is greater or less >than 128 bytes? stuff = struct.unpack( dscrp, f.read(struct.calcsize(dscrp)) ) >But its not enough. One can write a generator that yields one char >at a time. How to feed that to struct.unpack?? I think you have lost track of the discussion here, because your question is irrelevant. His binario package couldn't do that, either, since it only accepts filenames. But at least with struct.unpack, I can suck from the generator into a string, and feed that string into struct.unpack. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From kurt.alfred.mueller at gmail.com Sat Sep 6 15:28:14 2014 From: kurt.alfred.mueller at gmail.com (Kurt Mueller) Date: Sat, 6 Sep 2014 21:28:14 +0200 Subject: How to turn a string into a list of integers? In-Reply-To: <540b504a$0$29974$c3e8da3$5496439d@news.astraweb.com> References: <1amjdb-p3n.ln1@chris.zbmc.eu> <1k9odb-1qs.ln1@chris.zbmc.eu> <540aa002$0$29968$c3e8da3$5496439d@news.astraweb.com> <540b504a$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <96C0BBC3-D186-4BBE-9C0E-2549739F84C6@gmail.com> Am 06.09.2014 um 20:19 schrieb Steven D'Aprano : > Kurt Mueller wrote: > [...] >> Now the part of the two Python builds is still somewhat unclear to me. > [...] >> In Python 2.7: >> As I learned from the ord() manual: >> If a unicode argument is given and Python was built with UCS2 Unicode, > Where does the manual mention UCS-2? As far as I know, no version of Python > uses that. https://docs.python.org/2/library/functions.html?highlight=ord#ord [snip] very detailed explanation of narrow/wide build, UCS-2/UCS-4, UTF-16/UTF-32 > Remember, though, these internal representations are (nearly) irrelevant to > Python code. In Python code, you just consider that a Unicode string is an > array of ordinal values from 0x0 to 0x10FFFF, each representing a single > code point U+0000 to U+10FFFF. The only reason I say "nearly" is that > narrow builds don't *quite* work right if the string contains surrogate > pairs. So I can interpret your last section: Processing any Unicode string will work with small and wide python 2.7 builds and also with python >3.3? ( parts of small build python will not work with values over 0xFFFF ) ( strings with surrogate pairs will not work correctly on small build python ) Many thanks for your detailed answer! -- Kurt Mueller, kurt.alfred.mueller at gmail.com From mmanns at gmx.net Sat Sep 6 11:57:38 2014 From: mmanns at gmx.net (Martin Manns) Date: Sat, 6 Sep 2014 17:57:38 +0200 Subject: [ANN] pyspread 0.3.3 Message-ID: ============== pyspread 0.3.3 ============== Pyspread 0.3.3 is released. This is a wxPython 3.x related bugfix release that fixes a segfault when initially creating and choosing GPG keys. About pyspread ============== Pyspread is a non-traditional spreadsheet application that is based on and written in the programming language Python. The goal of pyspread is to be the most pythonic spreadsheet application. Pyspread is free software. It is released under the GPL v3. Project website: http://manns.github.com/pyspread/ Download page: https://pypi.python.org/pypi/pyspread Enjoy Martin From steve+comp.lang.python at pearwood.info Sat Sep 6 21:47:07 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 07 Sep 2014 11:47:07 +1000 Subject: How to turn a string into a list of integers? References: <1amjdb-p3n.ln1@chris.zbmc.eu> <1k9odb-1qs.ln1@chris.zbmc.eu> <540aa002$0$29968$c3e8da3$5496439d@news.astraweb.com> <540b504a$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <540bb91c$0$29969$c3e8da3$5496439d@news.astraweb.com> Kurt Mueller wrote: > Processing any Unicode string will work with small and wide > python 2.7 builds and also with python >3.3? > ( parts of small build python will not work with values over 0xFFFF ) > ( strings with surrogate pairs will not work correctly on small build > python ) If you limit yourself to code points in the Basic Multilingual Plane, U+0000 to U+FFFF, then Python's Unicode handling works fine no matter what version or implementation is used. Since most people use only the BMP, you may not notice any problems. (Of course, there are performance and memory-usage differences from one version to the next, but the functionality works correctly.) If you use characters from the supplementary planes ("astral characters"), then: * wide builds will behave correctly; * narrow builds will wrongly treat astral characters as two independent characters, which means functions like len() and string slicing will do the wrong thing; * Python 3.3 doesn't use narrow and wide builds any more, and also behaves correctly with astral characters. So there are three strategies for correct Unicode support in Python: * avoid astral characters (and trust your users will also avoid them); * use a wide build; * use Python 3.3 or higher. In case you are wondering what Python 3.3 does differently, when it builds a string, it works out the largest code point in the string. If the largest code point is no greater than U+00FF, it stores the string in Latin 1 using 8 bits per character; if the largest code point is no greater than U+FFFF, then it uses UTF-16 (or UCS-2, since with the BMP they are functionally the same); if the string contains any astral characters, then it uses UTF-32. So regardless of the string, each character uses a single code unit. Only the size of the code unit varies. -- Steven From zxcvbm4 at gmail.com Sun Sep 7 01:08:11 2014 From: zxcvbm4 at gmail.com (=?TIS-620?B?x8PDs76nyewgwNG3t9TC5L662Q==?= =?TIS-620?B?xcLs?=) Date: Sat, 6 Sep 2014 22:08:11 -0700 (PDT) Subject: pip install PyOpenGL have problem Message-ID: <374bcd83-e0f8-4a2e-a088-30cc036a1e93@googlegroups.com> I using Windows 8.1 64 Bit. Python 3.4.1 32 Bit. I want to install the PyOpenGL. By http://pyopengl.sourceforge.net/. pip install PyOpenGL have problem I using pip but have problem. pip Log https://gist.github.com/wannaphongcom/aa037e92368b61495be6 From zxcvbm4 at gmail.com Sun Sep 7 01:15:38 2014 From: zxcvbm4 at gmail.com (=?TIS-620?B?x8PDs76nyewgwNG3t9TC5L662Q==?= =?TIS-620?B?xcLs?=) Date: Sat, 6 Sep 2014 22:15:38 -0700 (PDT) Subject: pip install PyOpenGL have problem In-Reply-To: <374bcd83-e0f8-4a2e-a088-30cc036a1e93@googlegroups.com> References: <374bcd83-e0f8-4a2e-a088-30cc036a1e93@googlegroups.com> Message-ID: <1802a6c9-9098-416d-98b5-97c7f8a48b1f@googlegroups.com> ????? ????????????? 7 ??????? ?.?. 2014, 12 ?????? 8 ???? 34 ?????? UTC+7, ???????? ????????????? ????????: > I using Windows 8.1 64 Bit. Python 3.4.1 32 Bit. > > I want to install the PyOpenGL. By http://pyopengl.sourceforge.net/. > > > > pip install PyOpenGL have problem > > > > I using pip but have problem. > > pip Log > > https://gist.github.com/wannaphongcom/aa037e92368b61495be6 pip install -U PyOpenGL PyOpenGL_accelerate :( From bfb at riseup.net Sun Sep 7 02:42:11 2014 From: bfb at riseup.net (kjs) Date: Sun, 07 Sep 2014 06:42:11 +0000 Subject: weakref, memory management and execution slow down in PyQt4 Message-ID: <540BFE43.5030006@riseup.net> I built a small application using PyQt4 and pyqtgraph to visualize some data. The app has 32 graphs that plot deques of size 512. The plots are updated when 200 ints are cycled through each deque. The plotting slows down in a linear manner with respect to time. In other words after cycling through 100,000 data points the time between calls to process events is much longer than it was at T0. I have done a little memory profiling. Watching the process on top, it's clear that there is some memory leak. I also tried invoking objgraph.show_most_common_types(). This test reveals that the number of objects being created plateaus, except for weakref objects, which keep growing and growing. I have come to believe that the growing number of weakrefs is slowing down execution. Is my analysis misguided? How can I introspect further? If the slowdown can be attributed to weakref escalation, what are some next steps? Thanks, Kevin -------------- next part -------------- A non-text attachment was scrubbed... Name: 0x8A61431E.asc Type: application/pgp-keys Size: 11239 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 801 bytes Desc: OpenPGP digital signature URL: From antoine at python.org Sun Sep 7 09:03:04 2014 From: antoine at python.org (Antoine Pitrou) Date: Sun, 7 Sep 2014 13:03:04 +0000 (UTC) Subject: =?utf-8?b?X19xdWFsbmFtZV9f?= in python 3.3 References: <540b3293$0$2056$426a74cc@news.free.fr> Message-ID: Hi, ISE Development gmail.com> writes: > 'code' object 'function' object > ---------------- ------------------------------------ > co_name: test __qualname__: test > co_name: T __qualname__: T > co_name: method __qualname__: test..T.method > > The second call corresponds to the class definition and not the call to the > constructor (which is in fact a call to 'object.__init__', a C function > hence not traced as a 'call' event - I checked this by disassembling the > code object). There's nothing wrong here. That's just the way things are implemented internally. This may change in the future without prior notice, so you shouldn't rely on it. If you want to dig more, you have to look at how the hidden function ("T") works: >>> def f(): ... class T: pass ... >>> f.__code__.co_consts (None, ", line 2>, 'T') >>> dis.dis(f.__code__.co_consts[1]) 2 0 LOAD_NAME 0 (__name__) 3 STORE_NAME 1 (__module__) 6 LOAD_CONST 0 ('f..T') 9 STORE_NAME 2 (__qualname__) 12 LOAD_CONST 1 (None) 15 RETURN_VALUE Regards Antoine. From antoine at python.org Sun Sep 7 09:28:56 2014 From: antoine at python.org (Antoine Pitrou) Date: Sun, 7 Sep 2014 13:28:56 +0000 (UTC) Subject: weakref, memory management and execution slow down in PyQt4 References: <540BFE43.5030006@riseup.net> Message-ID: kjs riseup.net> writes: > > I have come to believe that the growing number of weakrefs is slowing > down execution. Is my analysis misguided? How can I introspect further? > If the slowdown can be attributed to weakref escalation, what are some > next steps? The way to analyze this is to build some gradually smaller subsets of your application until you can isolate what is causing the growth in number of objects (if any). I would suggest first remove the GUI and replace it with some dummy functions, to stress your core logic. Note that "top" isn't a very reliable tool, as memory fragmentation and other factors can cause your process' visible size to grow even though Python's memory consumption may be stable. There are dedicated Python tools for finer analysis, such as tracemalloc, which is standard on 3.4 and available as a backport for older versions: https://docs.python.org/3/library/tracemalloc.html http://pytracemalloc.readthedocs.org/ But regardless of such tools, the approach above (try to decompose your workload into separate parts until your find the culprit) is highly recommended. Regards Antoine. From python at mrabarnett.plus.com Sun Sep 7 10:52:28 2014 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 07 Sep 2014 15:52:28 +0100 Subject: How to turn a string into a list of integers? In-Reply-To: <540bb91c$0$29969$c3e8da3$5496439d@news.astraweb.com> References: <1amjdb-p3n.ln1@chris.zbmc.eu> <1k9odb-1qs.ln1@chris.zbmc.eu> <540aa002$0$29968$c3e8da3$5496439d@news.astraweb.com> <540b504a$0$29974$c3e8da3$5496439d@news.astraweb.com> <540bb91c$0$29969$c3e8da3$5496439d@news.astraweb.com> Message-ID: <540C712C.8000806@mrabarnett.plus.com> On 2014-09-07 02:47, Steven D'Aprano wrote: > Kurt Mueller wrote: > >> Processing any Unicode string will work with small and wide >> python 2.7 builds and also with python >3.3? >> ( parts of small build python will not work with values over 0xFFFF ) >> ( strings with surrogate pairs will not work correctly on small build >> python ) > > > If you limit yourself to code points in the Basic Multilingual Plane, U+0000 > to U+FFFF, then Python's Unicode handling works fine no matter what version > or implementation is used. Since most people use only the BMP, you may not > notice any problems. > > (Of course, there are performance and memory-usage differences from one > version to the next, but the functionality works correctly.) > > If you use characters from the supplementary planes ("astral characters"), > then: > > * wide builds will behave correctly; > * narrow builds will wrongly treat astral characters as two > independent characters, which means functions like len() > and string slicing will do the wrong thing; > * Python 3.3 doesn't use narrow and wide builds any more, > and also behaves correctly with astral characters. > > > So there are three strategies for correct Unicode support in Python: > > * avoid astral characters (and trust your users will also avoid them); > > * use a wide build; > > * use Python 3.3 or higher. > > > In case you are wondering what Python 3.3 does differently, when it builds a > string, it works out the largest code point in the string. If the largest > code point is no greater than U+00FF, it stores the string in Latin 1 using > 8 bits per character; if the largest code point is no greater than U+FFFF, > then it uses UTF-16 (or UCS-2, since with the BMP they are functionally the > same); if the string contains any astral characters, then it uses UTF-32. > So regardless of the string, each character uses a single code unit. Only > the size of the code unit varies. > I don't think you should be saying that it stores the string in Latin-1 or UTF-16 because that might suggest that they are encoded. They aren't. From rosuav at gmail.com Sun Sep 7 11:04:34 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 8 Sep 2014 01:04:34 +1000 Subject: How to turn a string into a list of integers? In-Reply-To: <540C712C.8000806@mrabarnett.plus.com> References: <1amjdb-p3n.ln1@chris.zbmc.eu> <1k9odb-1qs.ln1@chris.zbmc.eu> <540aa002$0$29968$c3e8da3$5496439d@news.astraweb.com> <540b504a$0$29974$c3e8da3$5496439d@news.astraweb.com> <540bb91c$0$29969$c3e8da3$5496439d@news.astraweb.com> <540C712C.8000806@mrabarnett.plus.com> Message-ID: On Mon, Sep 8, 2014 at 12:52 AM, MRAB wrote: > I don't think you should be saying that it stores the string in Latin-1 > or UTF-16 because that might suggest that they are encoded. They aren't. Except that they are. RAM stores bytes [1], so by definition everything that's in memory is encoded. You can't store a list in memory; what you store is a set of bits which represent some metadata and a bunch of pointers. You can't store a non-integer in memory, so you use some kind of efficient packed system like IEEE 754. You can't even store an integer without using some kind of encoding, most likely by packing it into some number of bytes and laying those bytes out either smallest first or largest first. So yes, CPython 3.3 stores strings encoded Latin-1, UCS-2 [2], or UCS-4. The Python string *is* a sequence of characters, but it's *stored* as a sequence of bytes in one of those encodings. (And other Pythons may not use the same encodings. MicroPython uses UTF-8 internally, which gives it *very* different indexing performance.) ChrisA [1] On modern systems it stores larger units, probably 64-bit or 128-bit hunks, but whatever. Same difference. [2] As Steven says, UTF-16 or UCS-2. I prefer the latter name here; as it (like Latin-1) is restricted in character set rather than variable in length. But same thing. From roy at panix.com Sun Sep 7 11:40:57 2014 From: roy at panix.com (Roy Smith) Date: Sun, 07 Sep 2014 11:40:57 -0400 Subject: How to turn a string into a list of integers? References: <1amjdb-p3n.ln1@chris.zbmc.eu> <1k9odb-1qs.ln1@chris.zbmc.eu> <540aa002$0$29968$c3e8da3$5496439d@news.astraweb.com> <540b504a$0$29974$c3e8da3$5496439d@news.astraweb.com> <540bb91c$0$29969$c3e8da3$5496439d@news.astraweb.com> <540C712C.8000806@mrabarnett.plus.com> Message-ID: In article , Chris Angelico wrote: > You can't store a list in memory; what you store is a set of bits > which represent some metadata and a bunch of pointers. Well, technically, what you store is something which has the right behavior. If I wrote: my_huffman_coded_list = [0] * 1000000 I don't know of anything which requires Python to actually generate a million 0's and store them somewhere (even ignoring interning of integers). As long as it generated an object (perhaps a subclass of list) which responded to all of list's methods the same way a real list would, it could certainly build a more compact representation. From steve+comp.lang.python at pearwood.info Sun Sep 7 13:02:59 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 08 Sep 2014 03:02:59 +1000 Subject: How to turn a string into a list of integers? References: <1amjdb-p3n.ln1@chris.zbmc.eu> <1k9odb-1qs.ln1@chris.zbmc.eu> <540aa002$0$29968$c3e8da3$5496439d@news.astraweb.com> <540b504a$0$29974$c3e8da3$5496439d@news.astraweb.com> <540bb91c$0$29969$c3e8da3$5496439d@news.astraweb.com> Message-ID: <540c8fc4$0$29973$c3e8da3$5496439d@news.astraweb.com> MRAB wrote: > I don't think you should be saying that it stores the string in Latin-1 > or UTF-16 because that might suggest that they are encoded. They aren't. Of course they are encoded. Memory consists of bytes, not Unicode code points, which are abstract numbers representing characters (and other things). You can't store "?" (U+03BE) in memory, you can only store a particular representation of that "?" in bytes, and that representation is called an encoding. Of course you can create whatever representation you like, or you can use an established encoding rather than re-invent the wheel. Here are four established encodings which support that code point, and the bytes that are used: py> u'?'.encode('iso-8859-7') '\xee' py> u'?'.encode('utf-8') '\xce\xbe' py> u'?'.encode('utf-16be') '\x03\xbe' py> u'?'.encode('utf-32be') '\x00\x00\x03\xbe' -- Steven From rustompmody at gmail.com Sun Sep 7 13:53:33 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 7 Sep 2014 10:53:33 -0700 (PDT) Subject: How to turn a string into a list of integers? In-Reply-To: <540c8fc4$0$29973$c3e8da3$5496439d@news.astraweb.com> References: <1amjdb-p3n.ln1@chris.zbmc.eu> <1k9odb-1qs.ln1@chris.zbmc.eu> <540aa002$0$29968$c3e8da3$5496439d@news.astraweb.com> <540b504a$0$29974$c3e8da3$5496439d@news.astraweb.com> <540bb91c$0$29969$c3e8da3$5496439d@news.astraweb.com> <540c8fc4$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8b80fe39-4aea-4a17-a1a6-a44f0b42fb7b@googlegroups.com> On Sunday, September 7, 2014 10:33:26 PM UTC+5:30, Steven D'Aprano wrote: > MRAB wrote: > > I don't think you should be saying that it stores the string in Latin-1 > > or UTF-16 because that might suggest that they are encoded. They aren't. > Of course they are encoded. Memory consists of bytes, not Unicode code > points, which are abstract numbers representing characters (and other > things). You can't store "?" (U+03BE) in memory, you can only store a > particular representation of that "?" in bytes, and that representation is > called an encoding. Of course you can create whatever representation you > like, or you can use an established encoding rather than re-invent the > wheel. Here are four established encodings which support that code point, > and the bytes that are used: > py> u'?'.encode('iso-8859-7') > '\xee' > py> u'?'.encode('utf-8') > '\xce\xbe' > py> u'?'.encode('utf-16be') > '\x03\xbe' > py> u'?'.encode('utf-32be') > '\x00\x00\x03\xbe' Dunno about philosophical questions -- especially unicode :-) What I can see (python 3) which is I guess what MRAB was pointing out: >>> "".encode >>> "".decode Traceback (most recent call last): File "", line 1, in AttributeError: 'str' object has no attribute 'decode' >>> b"".decode >>> b"".encode Traceback (most recent call last): File "", line 1, in AttributeError: 'bytes' object has no attribute 'encode' >>> From steve+comp.lang.python at pearwood.info Sun Sep 7 14:00:32 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 08 Sep 2014 04:00:32 +1000 Subject: How to turn a string into a list of integers? References: <1amjdb-p3n.ln1@chris.zbmc.eu> <1k9odb-1qs.ln1@chris.zbmc.eu> <540aa002$0$29968$c3e8da3$5496439d@news.astraweb.com> <540b504a$0$29974$c3e8da3$5496439d@news.astraweb.com> <540bb91c$0$29969$c3e8da3$5496439d@news.astraweb.com> <540C712C.8000806@mrabarnett.plus.com> Message-ID: <540c9d41$0$24963$c3e8da3$5496439d@news.astraweb.com> Roy Smith wrote: > In article , > Chris Angelico wrote: > >> You can't store a list in memory; what you store is a set of bits >> which represent some metadata and a bunch of pointers. > > > Well, technically, what you store is something which has the right > behavior. If I wrote: No. Chris is right: what you store is bits, because that is how memory in modern hardware works. Some old Soviet era mainframes used trits, trinary digits, instead of bits, but that's just a footnote in the history of computing. We're talking implementation here, not interface. The implementation of a list in memory is bits, not trits, nor holograms, fragments of DNA, or nanometre-sized carbon rods. Some day there may be computers with implementations not based on bits, but this is not that day. [Aside: technically, very few if any modern memory chips support direct access to individual bits, only to words, which these days are usually 8-bit bytes. At the hardware level, the bits may not even be implemented as individual on/off two-state switches. So technically we should be talking about bytes rather than bits, since that's the interface which the memory chip provides. What it does internally is up to the chip designer.] > my_huffman_coded_list = [0] * 1000000 > > I don't know of anything which requires Python to actually generate a > million 0's and store them somewhere (even ignoring interning of > integers). That's a tricky question. There's not a lot of wiggle-room for what a compliant implementation of Python can do here, but there is some. The language requires that: - the expression must generate a genuine built-in list of length exactly one million; - even if you monkey-patch builtins and replace list with something else, you still get a genuine list, not the monkey-patched version; - all million items must refer to the same instance; - regardless of whether that instance is cached (like 0) or not; - reading and writing to any index must be O(1); - although I guess it would be acceptable if that was O(1) amortised. (Not all of these requirements are documented per se, some are taken from the reference implementation, CPython, and some from comments made by Guido, e.g. he has stated that he would consider it unacceptable for a Python implementation to use a linked list instead of an array for lists, because of the performance implementations.) Beyond that, an implementation could do anything it likes. If the implementer can come up with some clever way to have [0]*1000000 use less memory while not compromising the above, they can do so. > As long as it generated an object (perhaps a subclass of > list) which responded to all of list's methods the same way a real list > would, it could certainly build a more compact representation. However a subclass of list would not be acceptable. -- Steven From steve+comp.lang.python at pearwood.info Sun Sep 7 14:08:24 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 08 Sep 2014 04:08:24 +1000 Subject: How to turn a string into a list of integers? References: <1amjdb-p3n.ln1@chris.zbmc.eu> <1k9odb-1qs.ln1@chris.zbmc.eu> <540aa002$0$29968$c3e8da3$5496439d@news.astraweb.com> <540b504a$0$29974$c3e8da3$5496439d@news.astraweb.com> <540bb91c$0$29969$c3e8da3$5496439d@news.astraweb.com> <540c8fc4$0$29973$c3e8da3$5496439d@news.astraweb.com> <8b80fe39-4aea-4a17-a1a6-a44f0b42fb7b@googlegroups.com> Message-ID: <540c9f19$0$29999$c3e8da3$5496439d@news.astraweb.com> Rustom Mody wrote: > On Sunday, September 7, 2014 10:33:26 PM UTC+5:30, Steven D'Aprano wrote: >> MRAB wrote: > >> > I don't think you should be saying that it stores the string in Latin-1 >> > or UTF-16 because that might suggest that they are encoded. They >> > aren't. > >> Of course they are encoded. Memory consists of bytes, not Unicode code >> points, [...] > Dunno about philosophical questions -- especially unicode :-) > What I can see (python 3) which is I guess what MRAB was pointing out: > >>>> "".encode > > >>>> "".decode > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'str' object has no attribute 'decode' What's your point? I'm talking about the implementation of how strings are stored in memory, not what methods the str class provides. -- Steven From rustompmody at gmail.com Sun Sep 7 14:34:22 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 7 Sep 2014 11:34:22 -0700 (PDT) Subject: How to turn a string into a list of integers? In-Reply-To: <540c9f19$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <1amjdb-p3n.ln1@chris.zbmc.eu> <1k9odb-1qs.ln1@chris.zbmc.eu> <540aa002$0$29968$c3e8da3$5496439d@news.astraweb.com> <540b504a$0$29974$c3e8da3$5496439d@news.astraweb.com> <540bb91c$0$29969$c3e8da3$5496439d@news.astraweb.com> <540c8fc4$0$29973$c3e8da3$5496439d@news.astraweb.com> <8b80fe39-4aea-4a17-a1a6-a44f0b42fb7b@googlegroups.com> <540c9f19$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sunday, September 7, 2014 11:38:41 PM UTC+5:30, Steven D'Aprano wrote: > Rustom Mody wrote: > > On Sunday, September 7, 2014 10:33:26 PM UTC+5:30, Steven D'Aprano wrote: > >> MRAB wrote: > >> > I don't think you should be saying that it stores the string in Latin-1 > >> > or UTF-16 because that might suggest that they are encoded. They > >> > aren't. > >> Of course they are encoded. Memory consists of bytes, not Unicode code > >> points, [...] > > Dunno about philosophical questions -- especially unicode :-) > > What I can see (python 3) which is I guess what MRAB was pointing out: > >>>> "".encode > >>>> "".decode > > Traceback (most recent call last): > > AttributeError: 'str' object has no attribute 'decode' > What's your point? I'm talking about the implementation of how strings are > stored in memory, not what methods the str class provides. The methods (un)available reflect what're the (in)valid operations on the type: Strings The items of a string object are Unicode code units. Conversion from and to other encodings are possible through the string method encode(). Bytes A bytes object is an immutable array. The items are 8-bit bytes, represented by integers in the range 0 <= x < 256. Bytes literals (like b'abc' and the built-in function bytes() can be used to construct bytes objects. Also, bytes objects can be decoded to strings via the decode() method. >From https://docs.python.org/3.1/reference/datamodel.html#the-standard-type-hierarchy IOW I interpret MRAB's statement that strings should not be thought of as encoded because they consist of abstract code-points, seems to me (a unicode-ignoramus!) a reasonable outlook From pkpearson at nowhere.invalid Sun Sep 7 14:53:06 2014 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 7 Sep 2014 18:53:06 GMT Subject: Prime testing [was Re: My backwards logic] References: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> <540ae440$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, 6 Sep 2014 12:53:16 +0200, Manolo Mart?nez wrote: > On 09/06/14 at 08:38pm, Steven D'Aprano wrote: >> But even that's not how the specialists do it. If you want to check whether >> (say) 2**3000+1 is prime, you don't want to use trial division at all... > > When I was interested in these things, specialists would use the [number > field sieve](https://en.wikipedia.org/wiki/General_number_field_sieve). No, one uses the number field sieve to *factor* large numbers. To test for primality, one uses simple tests like Fermat's test (x**(n-1)%n == 1, for many different x) or the slightly more complex Miller-Rabin test. These probabilistic primality tests can prove that a number is composite, but they can't actually *prove* that a number is prime. For that, you need a more complex test that is beyond my ken as a cryptologist. -- To email me, substitute nowhere->runbox, invalid->com. From bfb at riseup.net Sun Sep 7 15:11:25 2014 From: bfb at riseup.net (kjs) Date: Sun, 07 Sep 2014 19:11:25 +0000 Subject: weakref, memory management and execution slow down in PyQt4 In-Reply-To: References: <540BFE43.5030006@riseup.net> Message-ID: <540CADDD.3050501@riseup.net> Antoine Pitrou: > kjs riseup.net> writes: >> >> I have come to believe that the growing number of weakrefs is slowing >> down execution. Is my analysis misguided? How can I introspect further? >> If the slowdown can be attributed to weakref escalation, what are some >> next steps? > > The way to analyze this is to build some gradually smaller subsets of your > application until you can isolate what is causing the growth in number of > objects (if any). I would suggest first remove the GUI and replace it with > some dummy functions, to stress your core logic. Thanks for the advice. I commented out the graph generation and PyQt call >>> self.app.processEvents() where in the class __init__ >>> self.app = QtGui.QApplication(sys.argv) This stopped the weakref proliferation. All other objects grow and shrink in number as expected. > > Note that "top" isn't a very reliable tool, as memory fragmentation and > other factors can cause your process' visible size to grow even though > Python's memory consumption may be stable. There are dedicated Python tools > for finer analysis, such as tracemalloc, which is standard on 3.4 and available > as a backport for older versions: > > https://docs.python.org/3/library/tracemalloc.html > http://pytracemalloc.readthedocs.org/ > > But regardless of such tools, the approach above (try to decompose your > workload into separate parts until your find the culprit) is highly recommended. > > Regards > > Antoine. > > -------------- next part -------------- A non-text attachment was scrubbed... Name: 0x8A61431E.asc Type: application/pgp-keys Size: 11239 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 801 bytes Desc: OpenPGP digital signature URL: From manolo at austrohungaro.com Sun Sep 7 15:09:51 2014 From: manolo at austrohungaro.com (Manolo =?iso-8859-1?Q?Mart=EDnez?=) Date: Sun, 7 Sep 2014 21:09:51 +0200 Subject: Prime testing [was Re: My backwards logic] In-Reply-To: References: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> <540ae440$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20140907190951.GB671@beagle.localdomain> On 09/07/14 at 06:53pm, Peter Pearson wrote: > On Sat, 6 Sep 2014 12:53:16 +0200, Manolo Mart?nez wrote: > > On 09/06/14 at 08:38pm, Steven D'Aprano wrote: > >> But even that's not how the specialists do it. If you want to check whether > >> (say) 2**3000+1 is prime, you don't want to use trial division at all... > > > > When I was interested in these things, specialists would use the [number > > field sieve](https://en.wikipedia.org/wiki/General_number_field_sieve). > > No, one uses the number field sieve to *factor* large numbers. - Ugh. That's what I meant, of course :/ From torriem at gmail.com Sun Sep 7 15:26:20 2014 From: torriem at gmail.com (Michael Torrie) Date: Sun, 07 Sep 2014 13:26:20 -0600 Subject: weakref, memory management and execution slow down in PyQt4 In-Reply-To: <540CADDD.3050501@riseup.net> References: <540BFE43.5030006@riseup.net> <540CADDD.3050501@riseup.net> Message-ID: <540CB15C.2060008@gmail.com> On 09/07/2014 01:11 PM, kjs wrote: > Thanks for the advice. I commented out the graph generation and PyQt call > >>>> self.app.processEvents() > > where in the class __init__ > >>>> self.app = QtGui.QApplication(sys.argv) > > This stopped the weakref proliferation. All other objects grow and > shrink in number as expected. Can you make an absolute minimal example with no widgets save the graph itself? You could then go to the PyQt folks with that. Could be a bug, or could be an improper use of something by your code. This is one of the problems with using Qt in other languages: it's not a perfect fit for Python's object model as it is C++-based. So you have to think like a C++ programmer, and you might have to manage some resources manually, unlike normal Python objects which for the most part take care of themselves. Also you could try a minimal example using PySide instead of PyQt and see if that also manifests the leak. If so, then the problem could be in Qt itself. Though I suspect the problem is some kind of impedance mismatch between C++ and Python. From python at mrabarnett.plus.com Sun Sep 7 17:55:28 2014 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 07 Sep 2014 22:55:28 +0100 Subject: "We made from water every living thing"... In-Reply-To: <540cd120$0$51276$c3e8da3$de690749@news.astraweb.com> References: <540cd120$0$51276$c3e8da3$de690749@news.astraweb.com> Message-ID: <540CD450.8000005@mrabarnett.plus.com> On 2014-09-07 22:41, Tony the Tiger wrote: [snip] As it says here: https://www.python.org/community/lists/ """Rudeness and personal attacks, even in reaction to blatant flamebait, are strongly frowned upon. People may strongly disagree on an issue, but usually discussion remains civil. In case of an actual flamebait posting, you can ignore it, quietly plonk the offending poster in your killfile or mail filters, or write a sharp but still- polite response, but at all costs resist the urge to flame back.""" From isenntp at gmail.com Sun Sep 7 18:25:18 2014 From: isenntp at gmail.com (ISE Development) Date: Mon, 08 Sep 2014 00:25:18 +0200 Subject: __qualname__ in python 3.3 References: <540b3293$0$2056$426a74cc@news.free.fr> Message-ID: <540cdb4f$0$2926$426a74cc@news.free.fr> Antoine Pitrou wrote: > Hi, > > ISE Development gmail.com> writes: >> 'code' object 'function' object >> ---------------- ------------------------------------ >> co_name: test __qualname__: test >> co_name: T __qualname__: T >> co_name: method __qualname__: test..T.method >> >> The second call corresponds to the class definition and not the call to >> the constructor (which is in fact a call to 'object.__init__', a C >> function hence not traced as a 'call' event - I checked this by >> disassembling the code object). > > There's nothing wrong here. That's just the way things are implemented > internally. This may change in the future without prior notice, so > you shouldn't rely on it. > > If you want to dig more, you have to look at how the hidden function ("T") > works: > >>>> def f(): > ... class T: pass > ... >>>> f.__code__.co_consts > (None, ", line 2>, 'T') >>>> dis.dis(f.__code__.co_consts[1]) > 2 0 LOAD_NAME 0 (__name__) > 3 STORE_NAME 1 (__module__) > 6 LOAD_CONST 0 ('f..T') > 9 STORE_NAME 2 (__qualname__) > 12 LOAD_CONST 1 (None) > 15 RETURN_VALUE > > Regards > > Antoine. Ok, I accept it's implementation specific. That's fair enough. Yet wouldn't it make more sense to have the 'T' function '__qualname__' attribute refer to the defining context, i.e. in the present case, 'test..T' (much along the lines of the actual method qualified names, e.g. 'test..T.__init__', and identical to the qualified name of the actual object if returned by the defining function - see Peter Otten reply)? The rationale is that a properly qualified name is easier to interpret than the current unqualified one. To properly identify the 'T' function if a 'class T' is defined in more than enclosing function requires some additional complex (and hence error prone) logic as things stand: one has to examine the previous stack frame. Effectively, I am not saying the current behaviour is wrong, simply that it is inconsistent and could be improved. In that context, is it worth an enhancement request? -- isedev From ned at nedbatchelder.com Sun Sep 7 18:35:33 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sun, 07 Sep 2014 18:35:33 -0400 Subject: "We made from water every living thing"... In-Reply-To: <540cd120$0$51276$c3e8da3$de690749@news.astraweb.com> References: <540cd120$0$51276$c3e8da3$de690749@news.astraweb.com> Message-ID: On 9/7/14 5:41 PM, Tony the Tiger wrote: > > Now, kindly get the fuck outta here, you fucking retard! > > > /Grrr > That was unnecessary, ineffective, and totally outside the bounds of this community's norms: http://www.python.org/psf/codeofconduct Behave. -- Ned Batchelder, http://nedbatchelder.com From rosuav at gmail.com Sun Sep 7 20:12:13 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 8 Sep 2014 10:12:13 +1000 Subject: How to turn a string into a list of integers? In-Reply-To: References: <1amjdb-p3n.ln1@chris.zbmc.eu> <1k9odb-1qs.ln1@chris.zbmc.eu> <540aa002$0$29968$c3e8da3$5496439d@news.astraweb.com> <540b504a$0$29974$c3e8da3$5496439d@news.astraweb.com> <540bb91c$0$29969$c3e8da3$5496439d@news.astraweb.com> <540C712C.8000806@mrabarnett.plus.com> Message-ID: On Mon, Sep 8, 2014 at 1:40 AM, Roy Smith wrote: > Well, technically, what you store is something which has the right > behavior. If I wrote: > > my_huffman_coded_list = [0] * 1000000 > > I don't know of anything which requires Python to actually generate a > million 0's and store them somewhere (even ignoring interning of > integers). As long as it generated an object (perhaps a subclass of > list) which responded to all of list's methods the same way a real list > would, it could certainly build a more compact representation. Steven hinted at it, but I'll say one thing more explicitly here: There's actually something that requires Python to *not* generate a million 0 integers. What you get is a million references to the *same* zero. >>> another_list = [object()] * 1000000 >>> sum(id(x) for x in another_list) 140287290433648000000 >>> id(another_list[0]) * len(another_list) 140287290433648000000 The two figures are guaranteed to be the same, these are all the same object. But what you're talking about here is an alternative encoding. And it's definitely possible for different Pythons to encode strings differently; uPy uses UTF-8 internally, which gives different performance metrics, but guarantees the same semantics; I could imagine someone implementing a Python interpreter in Pike, and using the Pike string type to store Python strings (the semantics will all be correct, as it's a Unicode string; the most notable difference is that Pike strings are guaranteed to be interned, so all equality comparisons are identity checks); if you wanted to, I'm sure you could build a Python that uses a dictionary of words (added to every time you create a string, of course), and actually represents entire words as short integers, which would mean individual characters aren't necessarily represented directly. But somehow, you have to turn the concept of "sequence of Unicode characters" into some well-defined sequence of bytes, and that's an encoding. ChrisA From rosuav at gmail.com Sun Sep 7 20:14:29 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 8 Sep 2014 10:14:29 +1000 Subject: How to turn a string into a list of integers? In-Reply-To: References: <1amjdb-p3n.ln1@chris.zbmc.eu> <1k9odb-1qs.ln1@chris.zbmc.eu> <540aa002$0$29968$c3e8da3$5496439d@news.astraweb.com> <540b504a$0$29974$c3e8da3$5496439d@news.astraweb.com> <540bb91c$0$29969$c3e8da3$5496439d@news.astraweb.com> <540c8fc4$0$29973$c3e8da3$5496439d@news.astraweb.com> <8b80fe39-4aea-4a17-a1a6-a44f0b42fb7b@googlegroups.com> <540c9f19$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Sep 8, 2014 at 4:34 AM, Rustom Mody wrote: > IOW I interpret MRAB's statement that strings should not be thought > of as encoded because they consist of abstract code-points, seems to me (a unicode-ignoramus!) a reasonable outlook The original question was regarding storage - how PEP 393 says that strings will be encoded in memory in any of three ways (Latin-1, UCS-2/UTF-16, or UCS-4/UTF-32). But even in our world, that is not what a string *is*, but only what it is made of. ChrisA From drsalists at gmail.com Sun Sep 7 23:23:30 2014 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 7 Sep 2014 20:23:30 -0700 Subject: Prime testing [was Re: My backwards logic] In-Reply-To: References: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> <540ae440$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Sep 7, 2014 at 11:53 AM, Peter Pearson wrote: > On Sat, 6 Sep 2014 12:53:16 +0200, Manolo Mart?nez wrote: >> On 09/06/14 at 08:38pm, Steven D'Aprano wrote: >>> But even that's not how the specialists do it. If you want to check whether >>> (say) 2**3000+1 is prime, you don't want to use trial division at all... >> >> When I was interested in these things, specialists would use the [number >> field sieve](https://en.wikipedia.org/wiki/General_number_field_sieve). > > No, one uses the number field sieve to *factor* large numbers. To > test for primality, one uses simple tests like Fermat's test (x**(n-1)%n == 1, > for many different x) or the slightly more complex Miller-Rabin test. Usually you'd preceed a Miller-Rabin test with trial division by some small primes, as division by small primes identifies a lot of composites more quickly than Miller-Rabin. > These probabilistic primality tests can prove that a number is composite, > but they can't actually *prove* that a number is prime. For that, you > need a more complex test that is beyond my ken as a cryptologist. Actually, smallish numbers are always correctly identified as prime or composite by Miller-Rabin. It's the big ones that aren't. For a deterministic primality test that works on large numbers, check out the AKS algorithm. From marko at pacujo.net Mon Sep 8 01:44:06 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 08 Sep 2014 08:44:06 +0300 Subject: How to turn a string into a list of integers? References: <1amjdb-p3n.ln1@chris.zbmc.eu> <1k9odb-1qs.ln1@chris.zbmc.eu> <540aa002$0$29968$c3e8da3$5496439d@news.astraweb.com> <540b504a$0$29974$c3e8da3$5496439d@news.astraweb.com> <540bb91c$0$29969$c3e8da3$5496439d@news.astraweb.com> <540c8fc4$0$29973$c3e8da3$5496439d@news.astraweb.com> <8b80fe39-4aea-4a17-a1a6-a44f0b42fb7b@googlegroups.com> <540c9f19$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8738c2ekex.fsf@elektro.pacujo.net> Chris Angelico : > The original question was regarding storage - how PEP 393 says that > strings will be encoded in memory in any of three ways (Latin-1, > UCS-2/UTF-16, or UCS-4/UTF-32). But even in our world, that is not > what a string *is*, but only what it is made of. I'm a bit surprised that kind of CPython implementation detail would go into a PEP. I had thought PEPs codified Python independently of CPython. But maybe CPython is to Python what England is to the UK: even the government is having a hard time making a distinction. Marko From rosuav at gmail.com Mon Sep 8 01:53:05 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 8 Sep 2014 15:53:05 +1000 Subject: How to turn a string into a list of integers? In-Reply-To: <8738c2ekex.fsf@elektro.pacujo.net> References: <1amjdb-p3n.ln1@chris.zbmc.eu> <1k9odb-1qs.ln1@chris.zbmc.eu> <540aa002$0$29968$c3e8da3$5496439d@news.astraweb.com> <540b504a$0$29974$c3e8da3$5496439d@news.astraweb.com> <540bb91c$0$29969$c3e8da3$5496439d@news.astraweb.com> <540c8fc4$0$29973$c3e8da3$5496439d@news.astraweb.com> <8b80fe39-4aea-4a17-a1a6-a44f0b42fb7b@googlegroups.com> <540c9f19$0$29999$c3e8da3$5496439d@news.astraweb.com> <8738c2ekex.fsf@elektro.pacujo.net> Message-ID: On Mon, Sep 8, 2014 at 3:44 PM, Marko Rauhamaa wrote: > Chris Angelico : > >> The original question was regarding storage - how PEP 393 says that >> strings will be encoded in memory in any of three ways (Latin-1, >> UCS-2/UTF-16, or UCS-4/UTF-32). But even in our world, that is not >> what a string *is*, but only what it is made of. > > I'm a bit surprised that kind of CPython implementation detail would go > into a PEP. I had thought PEPs codified Python independently of CPython. > > But maybe CPython is to Python what England is to the UK: even the > government is having a hard time making a distinction. It is a bit of a tricky one. The PEP governs things about the API that CPython offers to extensions, so it's part of the public face of the language - it's not "purely an implementation detail" like, say, the exact algorithm for expanding a list's capacity as elements get appended to it. ChrisA From bfb at riseup.net Sun Sep 7 16:39:20 2014 From: bfb at riseup.net (kjs) Date: Sun, 07 Sep 2014 20:39:20 +0000 Subject: weakref, memory management and execution slow down in PyQt4 In-Reply-To: <540CB15C.2060008@gmail.com> References: <540BFE43.5030006@riseup.net> <540CADDD.3050501@riseup.net> <540CB15C.2060008@gmail.com> Message-ID: <540CC278.4050106@riseup.net> Michael Torrie: > On 09/07/2014 01:11 PM, kjs wrote: >> Thanks for the advice. I commented out the graph generation and PyQt call >> >>>>> self.app.processEvents() >> >> where in the class __init__ >> >>>>> self.app = QtGui.QApplication(sys.argv) >> >> This stopped the weakref proliferation. All other objects grow and >> shrink in number as expected. > > Can you make an absolute minimal example with no widgets save the graph > itself? You could then go to the PyQt folks with that. Could be a bug, > or could be an improper use of something by your code. This is one of > the problems with using Qt in other languages: it's not a perfect fit > for Python's object model as it is C++-based. So you have to think like > a C++ programmer, and you might have to manage some resources manually, > unlike normal Python objects which for the most part take care of > themselves. > The code is minimal[0]. The only other widgets are a start button that fires off the plotting and a stop button that calls sys.exit(). Lines 112-114 appear to be causing the weakref proliferation. I do not doubt that I could be using PyQt4 incorrectly. I'll send a message to the pyqt mailing list as well. > Also you could try a minimal example using PySide instead of PyQt and > see if that also manifests the leak. If so, then the problem could be > in Qt itself. Though I suspect the problem is some kind of impedance > mismatch between C++ and Python. > Thanks much, Kevin [0] https://github.com/kevinjos/kaggle-aes-seizure-prediction/blob/master/explore.py -------------- next part -------------- A non-text attachment was scrubbed... Name: 0x8A61431E.asc Type: application/pgp-keys Size: 11239 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 801 bytes Desc: OpenPGP digital signature URL: From tjreedy at udel.edu Mon Sep 8 03:41:31 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 08 Sep 2014 03:41:31 -0400 Subject: How to turn a string into a list of integers? In-Reply-To: <8738c2ekex.fsf@elektro.pacujo.net> References: <1amjdb-p3n.ln1@chris.zbmc.eu> <1k9odb-1qs.ln1@chris.zbmc.eu> <540aa002$0$29968$c3e8da3$5496439d@news.astraweb.com> <540b504a$0$29974$c3e8da3$5496439d@news.astraweb.com> <540bb91c$0$29969$c3e8da3$5496439d@news.astraweb.com> <540c8fc4$0$29973$c3e8da3$5496439d@news.astraweb.com> <8b80fe39-4aea-4a17-a1a6-a44f0b42fb7b@googlegroups.com> <540c9f19$0$29999$c3e8da3$5496439d@news.astraweb.com> <8738c2ekex.fsf@elektro.pacujo.net> Message-ID: On 9/8/2014 1:44 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> The original question was regarding storage - how PEP 393 says that >> strings will be encoded in memory in any of three ways (Latin-1, >> UCS-2/UTF-16, or UCS-4/UTF-32). But even in our world, that is not >> what a string *is*, but only what it is made of. > > I'm a bit surprised that kind of CPython implementation detail would go > into a PEP. I had thought PEPs codified Python independently of CPython. There are multiple PEP that are not strictly about Python the language: meta-peps, informational peps, and others about the cpython api, implementation, and distribution issues. 393 is followed by 397 Python launcher for Windows Hammond, v. L?wis http://legacy.python.org/dev/peps/ The PEP process is a tool for the core development team and the product is documentation of decisions and actions thereby > But maybe CPython is to Python what England is to the UK: even the > government is having a hard time making a distinction. We don't. -- Terry Jan Reedy From DLipman~nospam~ at Verizon.Net Mon Sep 8 07:54:17 2014 From: DLipman~nospam~ at Verizon.Net (David H. Lipman) Date: Mon, 8 Sep 2014 07:54:17 -0400 Subject: "We made from water every living thing"... In-Reply-To: References: <540cd120$0$51276$c3e8da3$de690749@news.astraweb.com> Message-ID: From: "Ned Batchelder" > On 9/7/14 5:41 PM, Tony the Tiger wrote: > >> Now, kindly get the fuck outta here, you fucking retard! >> >> /Grrr >> > That was unnecessary, ineffective, and totally outside the bounds of this > community's norms: http://www.python.org/psf/codeofconduct > > Behave. > He posted via Astraweb to Usenet. He is not using GMane or a listserver. The Python.Org CoC does not extend to Usenet unless a FAQ is properly published for news:comp.lang.python You need to filter out Google Groupers who are the cause of spam and abuse. -- Dave Multi-AV Scanning Tool - http://multi-av.thespykiller.co.uk http://www.pctipp.ch/downloads/dl/35905.asp From joshua at landau.ws Mon Sep 8 08:41:39 2014 From: joshua at landau.ws (Joshua Landau) Date: Mon, 8 Sep 2014 13:41:39 +0100 Subject: "We made from water every living thing"... In-Reply-To: References: <540cd120$0$51276$c3e8da3$de690749@news.astraweb.com> Message-ID: On 8 September 2014 12:54, David H. Lipman wrote: > From: "Ned Batchelder" >> On 9/7/14 5:41 PM, Tony the Tiger wrote: >> >>> Now, kindly get the fuck outta here, you fucking retard! >>> >> That was unnecessary, ineffective, and totally outside the bounds of this >> community's norms: http://www.python.org/psf/codeofconduct > > The Python.Org CoC does not extend to Usenet unless a FAQ is properly > published for news:comp.lang.python I don't think allowing people to be disrespectful because they accessed the forum in a different way is a good idea. I'd rather we all just be nice. From rosuav at gmail.com Mon Sep 8 09:06:46 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 8 Sep 2014 23:06:46 +1000 Subject: "We made from water every living thing"... In-Reply-To: References: <540cd120$0$51276$c3e8da3$de690749@news.astraweb.com> Message-ID: On Mon, Sep 8, 2014 at 10:41 PM, Joshua Landau wrote: > I don't think allowing people to be disrespectful because they > accessed the forum in a different way is a good idea. I'd rather we > all just be nice. May I just point out that lots of us didn't even see the original post? If "Tony the Tiger" hadn't bothered to quote it, it would quietly have dropped into oblivion. Let's let this thread finish and have done with the whole matter. ChrisA From breamoreboy at yahoo.co.uk Mon Sep 8 09:09:37 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 08 Sep 2014 14:09:37 +0100 Subject: "We made from water every living thing"... In-Reply-To: References: <540cd120$0$51276$c3e8da3$de690749@news.astraweb.com> Message-ID: On 08/09/2014 14:06, Chris Angelico wrote: > On Mon, Sep 8, 2014 at 10:41 PM, Joshua Landau wrote: >> I don't think allowing people to be disrespectful because they >> accessed the forum in a different way is a good idea. I'd rather we >> all just be nice. > > May I just point out that lots of us didn't even see the original > post? If "Tony the Tiger" hadn't bothered to quote it, it would > quietly have dropped into oblivion. Let's let this thread finish and > have done with the whole matter. > > ChrisA > +1 -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From gheskett at wdtv.com Mon Sep 8 11:28:46 2014 From: gheskett at wdtv.com (Gene Heskett) Date: Mon, 8 Sep 2014 11:28:46 -0400 Subject: "We made from water every living thing"... In-Reply-To: References: Message-ID: <201409081128.46862.gheskett@wdtv.com> On Monday 08 September 2014 09:06:46 Chris Angelico did opine And Gene did reply: > On Mon, Sep 8, 2014 at 10:41 PM, Joshua Landau wrote: > > I don't think allowing people to be disrespectful because they > > accessed the forum in a different way is a good idea. I'd rather we > > all just be nice. > > May I just point out that lots of us didn't even see the original > post? If "Tony the Tiger" hadn't bothered to quote it, it would > quietly have dropped into oblivion. Let's let this thread finish and > have done with the whole matter. > > ChrisA I am with you on that Chris, nothing with googlegroups in a header last long enough to even be seen by fetchmail, its in a mailfilter rule and gets nuked on the server. And life is much simpler. Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page US V Castleman, SCOTUS, Mar 2014 is grounds for Impeaching SCOTUS From invalid at invalid.invalid Mon Sep 8 12:41:01 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 8 Sep 2014 16:41:01 +0000 (UTC) Subject: "We made from water every living thing"... References: Message-ID: On 2014-09-08, Gene Heskett wrote: > On Monday 08 September 2014 09:06:46 Chris Angelico did opine > And Gene did reply: >> On Mon, Sep 8, 2014 at 10:41 PM, Joshua Landau wrote: >> >> > I don't think allowing people to be disrespectful because they >> > accessed the forum in a different way is a good idea. I'd rather we >> > all just be nice. >> >> May I just point out that lots of us didn't even see the original >> post? If "Tony the Tiger" hadn't bothered to quote it, it would >> quietly have dropped into oblivion. Let's let this thread finish and >> have done with the whole matter. > > I am with you on that Chris, nothing with googlegroups in a header last > long enough to even be seen by fetchmail, its in a mailfilter rule and > gets nuked on the server. And life is much simpler. I plonked everything coming from Google Groups years ago. I never regretted it for a second, and can recommend doing so without reservation. All you have to do is toss anything with a Message-ID ending in googlegroups.com. For the benefit of anybody using slrn to read the Usenet group (or presumably reading the mailing list via gmane), here's the .score file rule: [*] Score:: =-9999 Message-ID: .*googlegroups.com -- Grant Edwards grant.b.edwards Yow! Now KEN and BARBIE at are PERMANENTLY ADDICTED to gmail.com MIND-ALTERING DRUGS ... From DLipman~nospam~ at Verizon.Net Mon Sep 8 14:51:21 2014 From: DLipman~nospam~ at Verizon.Net (David H. Lipman) Date: Mon, 8 Sep 2014 14:51:21 -0400 Subject: "We made from water every living thing"... In-Reply-To: References: <540cd120$0$51276$c3e8da3$de690749@news.astraweb.com> Message-ID: From: "Chris Angelico" > On Mon, Sep 8, 2014 at 10:41 PM, Joshua Landau wrote: >> I don't think allowing people to be disrespectful because they >> accessed the forum in a different way is a good idea. I'd rather we >> all just be nice. > > May I just point out that lots of us didn't even see the original > post? If "Tony the Tiger" hadn't bothered to quote it, it would > quietly have dropped into oblivion. Let's let this thread finish and > have done with the whole matter. > > ChrisA That true. One should *never* quote spam. -- Dave Multi-AV Scanning Tool - http://multi-av.thespykiller.co.uk http://www.pctipp.ch/downloads/dl/35905.asp From travisgriggs at gmail.com Mon Sep 8 15:04:26 2014 From: travisgriggs at gmail.com (Travis Griggs) Date: Mon, 8 Sep 2014 12:04:26 -0700 Subject: Newer Debian versions of python on older Debian distros? Message-ID: <5D152EC0-CDBB-4AC9-B074-B648074CE372@gmail.com> (I realize that this may be seen as off topic for as a general python question, but given my historical experience with the Debian community?s predilection to answer all questions with a grumpy ?go read the very very very very large and ever shifting fine manual?, I?m hoping for better luck here.) Does anyone have experience with using newer versions of python debian packages (in particular, python3 and python3-bson-ext from ?testing?) on older stable versions (?wheezy? in this case)? If someone?s figured out how to do this easily, I?d love to hear the recipe! TIA From forma105 at mail.chapman.edu Mon Sep 8 18:03:23 2014 From: forma105 at mail.chapman.edu (Ashley Forman) Date: Mon, 8 Sep 2014 15:03:23 -0700 Subject: Installing Python 3 Message-ID: Hello, My name is Ashley Forman, and I am emailing because I cannot install python onto my Mac laptop! I have installed Active-TCl 8.5 along with Python 3.3 and tried with 3.4, and couldn't figure out a solution to my problem. When I click on IDLE to open, it does not open at all. Therefore, if you have any information that could help me, then I would really appreciate it! Thank you! Best, Ashley Forman -------------- next part -------------- An HTML attachment was scrubbed... URL: From torriem at gmail.com Mon Sep 8 19:51:25 2014 From: torriem at gmail.com (Michael Torrie) Date: Mon, 08 Sep 2014 17:51:25 -0600 Subject: weakref, memory management and execution slow down in PyQt4 In-Reply-To: <540CC278.4050106@riseup.net> References: <540BFE43.5030006@riseup.net> <540CADDD.3050501@riseup.net> <540CB15C.2060008@gmail.com> <540CC278.4050106@riseup.net> Message-ID: <540E40FD.8030706@gmail.com> On 09/07/2014 02:39 PM, kjs wrote: > The code is minimal[0]. The only other widgets are a start button that > fires off the plotting and a stop button that calls sys.exit(). Unfortunately there are no data files in your git repository so I can't run it. > > Lines 112-114 appear to be causing the weakref proliferation. Is there a reason you are using setattr and getattr instead of a proper data structure? both of those calls are rather expensive. Would probably be cheaper to use some kind of array, dictionary, or other purpose-built data structure? From rosuav at gmail.com Mon Sep 8 20:06:39 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 9 Sep 2014 10:06:39 +1000 Subject: Newer Debian versions of python on older Debian distros? In-Reply-To: <5D152EC0-CDBB-4AC9-B074-B648074CE372@gmail.com> References: <5D152EC0-CDBB-4AC9-B074-B648074CE372@gmail.com> Message-ID: On Tue, Sep 9, 2014 at 5:04 AM, Travis Griggs wrote: > Does anyone have experience with using newer versions of python debian packages (in particular, python3 and python3-bson-ext from ?testing?) on older stable versions (?wheezy? in this case)? If someone?s figured out how to do this easily, I?d love to hear the recipe! > I don't know about grabbing from testing, because that's fraught with peril... but there's a pretty easy way to get a newer Python: build from source. Basically, the standard incantation: $ sudo apt-get build-dep python3 $ hg clone http://hg.python.org/cpython $ cd cpython $ ./configure && make && sudo make install (I like to separate the last three steps, but putting them together works too.) Alternatively, you could just run Debian Jessie. I have a few Jessie systems on the network, with a Python 3.4 IIRC, and there've been no stability problems lately. Both options are pretty easy. ChrisA From torriem at gmail.com Mon Sep 8 22:18:42 2014 From: torriem at gmail.com (Michael Torrie) Date: Mon, 08 Sep 2014 20:18:42 -0600 Subject: pip install PyOpenGL have problem In-Reply-To: <1802a6c9-9098-416d-98b5-97c7f8a48b1f@googlegroups.com> References: <374bcd83-e0f8-4a2e-a088-30cc036a1e93@googlegroups.com> <1802a6c9-9098-416d-98b5-97c7f8a48b1f@googlegroups.com> Message-ID: <540E6382.4000209@gmail.com> On 09/06/2014 11:15 PM, ???????? ????????????? wrote: > pip install -U PyOpenGL PyOpenGL_accelerate > :( I don't recognize that particular error message... If you require assistance you need to copy and paste the output from the command so people can know exactly what failed. From nad at acm.org Mon Sep 8 22:23:20 2014 From: nad at acm.org (Ned Deily) Date: Mon, 08 Sep 2014 19:23:20 -0700 Subject: Installing Python 3 References: Message-ID: In article , Ashley Forman wrote: > My name is Ashley Forman, and I am emailing because I cannot install > python onto my Mac laptop! I have installed Active-TCl 8.5 along with > Python 3.3 and tried with 3.4, and couldn't figure out a solution to my > problem. When I click on IDLE to open, it does not open at all. Therefore, > if you have any information that could help me, then I would really > appreciate it! Thank you! Clicking on the IDLE icon is fine - unless it is doesn't work, in which case error messages associated with the failure may end up in a system log rather than being display directly to you. It's easier to debug problems like this by launching IDLE from a terminal session than by double-clicking on it. Assuming you installed Python 3.4 (3.4.1 is current) from one of the python.org installers, open a terminal shell window, for example by using the Terminal.app (found in /Applications/Utilities). Then, in the shell window, try typing: /usr/local/bin/idle3.4 If IDLE fails, there should be some sort of error message in the terminal window. If it is not clear what the problem is, copy and paste them to the group here. You can also just try launching Python itself and verify that it works without IDLE: /usr/local/bin/python3.4 Good luck! -- Ned Deily, nad at acm.org From bfb at riseup.net Mon Sep 8 22:45:03 2014 From: bfb at riseup.net (kjs) Date: Tue, 09 Sep 2014 02:45:03 +0000 Subject: weakref, memory management and execution slow down in PyQt4 In-Reply-To: <540E40FD.8030706@gmail.com> References: <540BFE43.5030006@riseup.net> <540CADDD.3050501@riseup.net> <540CB15C.2060008@gmail.com> <540CC278.4050106@riseup.net> <540E40FD.8030706@gmail.com> Message-ID: <540E69AF.5040309@riseup.net> Thanks for the consideration Michael. If you do get the data, and are able to run the code, let me know if you notice anything interesting. Michael Torrie: > On 09/07/2014 02:39 PM, kjs wrote: >> The code is minimal[0]. The only other widgets are a start button that >> fires off the plotting and a stop button that calls sys.exit(). > > Unfortunately there are no data files in your git repository so I can't > run it. The data is available from the internet[0] in the form of 3+GB gziped blobs. In case you don't want to register an account with Kaggle and download 3GB to execute the code, I have uploaded a sample file to a Tahoe LAFS grid accessible via tor. If you're interested in downloading the data, please let me know and I'll share the read capability with you. Additionally, I should write some tests the use mock data. I'll let you know if I get around to this. > >> >> Lines 112-114 appear to be causing the weakref proliferation. > > Is there a reason you are using setattr and getattr instead of a proper > data structure? both of those calls are rather expensive. Would > probably be cheaper to use some kind of array, dictionary, or other > purpose-built data structure? > You're right, a dictionary can do everything I need and more. This happened to be the first thing I thought of, and I didn't imagine it would be very expensive. I figured it was simply a different way of defining and retrieving a class variable. IE setattr(self, foo, True) == self.foo = True. Thanks, Kevin [0] http://www.kaggle.com/c/seizure-prediction/data -------------- next part -------------- A non-text attachment was scrubbed... Name: 0x8A61431E.asc Type: application/pgp-keys Size: 11239 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 801 bytes Desc: OpenPGP digital signature URL: From torriem at gmail.com Tue Sep 9 01:46:15 2014 From: torriem at gmail.com (Michael Torrie) Date: Mon, 08 Sep 2014 23:46:15 -0600 Subject: pip install PyOpenGL have problem In-Reply-To: <540E6382.4000209@gmail.com> References: <374bcd83-e0f8-4a2e-a088-30cc036a1e93@googlegroups.com> <1802a6c9-9098-416d-98b5-97c7f8a48b1f@googlegroups.com> <540E6382.4000209@gmail.com> Message-ID: <540E9427.6070707@gmail.com> On 09/08/2014 08:18 PM, Michael Torrie wrote: > On 09/06/2014 11:15 PM, ???????? ????????????? wrote: >> pip install -U PyOpenGL PyOpenGL_accelerate >> :( > > I don't recognize that particular error message... > > If you require assistance you need to copy and paste the output from the > command so people can know exactly what failed. You might try googling as well: https://www.google.ca/search?q=python3+pip+windows There seems to be a number of pages that talk about installing pip if it's not there (using easy_install if I recall correctly). From jeanbigboute at gmail.com Tue Sep 9 01:50:29 2014 From: jeanbigboute at gmail.com (JBB) Date: Tue, 9 Sep 2014 05:50:29 +0000 (UTC) Subject: Passing a list into a list .append() method Message-ID: I have a list with a fixed number of elements which I need to grow; ie. add rows of a fixed number of elements, some of which will be blank. e.g. [['a','b','c','d'], ['A','B','C','D'], ['', 'aa', 'inky', ''], ['', 'bb', 'binky', ''], ... ] This is a reduced representation of a larger list-of-lists problem that had me running in circles today. I think I figured out _how_ to get what I want but I am looking to understand why one approach works and another doesn't. 1) What does NOT work as desired: proc_file = [] proc_file = [['a','b','c','d']] proc_file.append(['A','B','C','D']) blank_r = ['','','',''] qq = ['aa','bb','cc','dd'] rr = ['inky', 'binky', 'pinky', 'clyde'] for i,j in enumerate(zip(qq,rr)): proc_file.append((blank_r)) # Add a row of blanks proc_file[i+2][1] = j[0] proc_file[i+2][2] = j[1] print len(proc_file), blank_r, proc_file print print proc_file 3 ['', 'aa', 'inky', ''] [['a', 'b', 'c', 'd'], ['A', 'B', 'C', 'D'], ['', 'aa', 'inky', '']] 4 ['', 'bb', 'binky', ''] [['a', 'b', 'c', 'd'], ['A', 'B', 'C', 'D'], ['', 'bb', 'binky', ''], ['', 'bb', 'binky', '']] 5 ['', 'cc', 'pinky', ''] [['a', 'b', 'c', 'd'], ['A', 'B', 'C', 'D'], ['', 'cc', 'pinky', ''], ['', 'cc', 'pinky', ''], ['', 'cc', 'pinky', '']] 6 ['', 'dd', 'clyde', ''] [['a', 'b', 'c', 'd'], ['A', 'B', 'C', 'D'], ['', 'dd', 'clyde', ''], ['', 'dd', 'clyde', ''], ['', 'dd', 'clyde', ''], ['', 'dd', 'clyde', '']] Out[82]: [['a', 'b', 'c', 'd'], ['A', 'B', 'C', 'D'], ['', 'dd', 'clyde', ''], ['', 'dd', 'clyde', ''], ['', 'dd', 'clyde', ''], ['', 'dd', 'clyde', '']] 2) What works as desired: proc_file = [] proc_file = [['a','b','c','d']] proc_file.append(['A','B','C','D']) blank_r = ['','','',''] qq = ['aa','bb','cc','dd'] rr = ['inky', 'binky', 'pinky', 'clyde'] for i,j in enumerate(zip(qq,rr)): proc_file.append(list(blank_r)) # Change it to list(blank_r) and it works proc_file[i+2][1] = j[0] proc_file[i+2][2] = j[1] print len(proc_file), blank_r, proc_file print print proc_file 3 ['', '', '', ''] [['a', 'b', 'c', 'd'], ['A', 'B', 'C', 'D'], ['', 'aa', 'inky', '']] 4 ['', '', '', ''] [['a', 'b', 'c', 'd'], ['A', 'B', 'C', 'D'], ['', 'aa', 'inky', ''], ['', 'bb', 'binky', '']] 5 ['', '', '', ''] [['a', 'b', 'c', 'd'], ['A', 'B', 'C', 'D'], ['', 'aa', 'inky', ''], ['', 'bb', 'binky', ''], ['', 'cc', 'pinky', '']] 6 ['', '', '', ''] [['a', 'b', 'c', 'd'], ['A', 'B', 'C', 'D'], ['', 'aa', 'inky', ''], ['', 'bb', 'binky', ''], ['', 'cc', 'pinky', ''], ['', 'dd', 'clyde', '']] Out[83]: [['a', 'b', 'c', 'd'], ['A', 'B', 'C', 'D'], ['', 'aa', 'inky', ''], ['', 'bb', 'binky', ''], ['', 'cc', 'pinky', ''], ['', 'dd', 'clyde', '']] ==== Due diligence I've read extensively on how arguments are passed to functions but I don't think they are completely applicable here (though interesting nevertheless) http://www.jeffknupp.com/blog/2012/11/13/is-python-callbyvalue-or-callbyreference-neither/ https://www.udacity.com/wiki/common-python-pitfalls and others. It looks like .append binds blank_r to proc_file in 1). I change proc_file and blank_r changes along with it. Should I expect this? I understand lists are mutable but I didn't expect that they could be associated/bound in this manner. I first tried "protecting" blank_r by passing it as a tuple. That caused an expected mismatch error. Next, I tried passing it as list(tuple(blank_r)) which worked. Then, I finally settled on 2) where I dispensed with the tuple conversion. From frank at chagford.com Tue Sep 9 02:53:20 2014 From: frank at chagford.com (Frank Millman) Date: Tue, 9 Sep 2014 08:53:20 +0200 Subject: Passing a list into a list .append() method References: Message-ID: "JBB" wrote in message news:loom.20140909T073428-713 at post.gmane.org... >I have a list with a fixed number of elements which I need to grow; ie. add > rows of a fixed number of elements, some of which will be blank. > > e.g. [['a','b','c','d'], ['A','B','C','D'], ['', 'aa', 'inky', ''], ['', > 'bb', 'binky', ''], ... ] > > This is a reduced representation of a larger list-of-lists problem that > had > me running in circles today. > > I think I figured out _how_ to get what I want but I am looking to > understand why one approach works and another doesn't. > [...] > > Next, I tried passing it as list(tuple(blank_r)) which worked. Then, I > finally settled on 2) where I dispensed with the tuple conversion. > I am sure that someone will give you a comprehensive answer, but here is a quick clue which may be all you need. >>> x = [1, 2, 3] >>> id(x) 16973256 >>> y = x >>> id(y) 16973256 >>> z = list(x) >>> id(z) 17004864 Wrapping a list with 'list()' has the effect of making a copy of it. This is from the docs (3.4.1) - """ Lists may be constructed in several ways: - Using a pair of square brackets to denote the empty list: [] - Using square brackets, separating items with commas: [a], [a, b, c] - Using a list comprehension: [x for x in iterable] - Using the type constructor: list() or list(iterable) The constructor builds a list whose items are the same and in the same order as iterable's items. iterable may be either a sequence, a container that supports iteration, or an iterator object. If iterable is already a list, a copy is made and returned, similar to iterable[:]. [*] For example, list('abc') returns ['a', 'b', 'c'] and list( (1, 2, 3) ) returns [1, 2, 3]. If no argument is given, the constructor creates a new empty list, []. """ I marked the relevant line with [*] HTH Frank Millman From jeanbigboute at gmail.com Tue Sep 9 03:08:57 2014 From: jeanbigboute at gmail.com (JBB) Date: Tue, 9 Sep 2014 07:08:57 +0000 (UTC) Subject: Passing a list into a list .append() method References: Message-ID: Frank Millman chagford.com> writes: > > > "JBB" gmail.com> wrote in message > news:loom.20140909T073428-713 post.gmane.org... > >I have a list with a fixed number of elements which I need to grow; ie. add > > rows of a fixed number of elements, some of which will be blank. ... > I am sure that someone will give you a comprehensive answer, but here is a > quick clue which may be all you need. >... [ Deletia per gmane's requirements ] > Wrapping a list with 'list()' has the effect of making a copy of it. > > This is from the docs (3.4.1) - > > """ > Lists may be constructed in several ways: > > - Using a pair of square brackets to denote the empty list: [] > - Using square brackets, separating items with commas: [a], [a, b, c] > - Using a list comprehension: [x for x in iterable] > - Using the type constructor: list() or list(iterable) > > The constructor builds a list whose items are the same and in the same order > as iterable's items. > iterable may be either a sequence, a container that supports iteration, or > an iterator object. > If iterable is already a list, a copy is made and returned, similar to > iterable[:]. [*] > For example, list('abc') returns ['a', 'b', 'c'] and list( (1, 2, 3) ) > returns [1, 2, 3]. > If no argument is given, the constructor creates a new empty list, []. > """ > > I marked the relevant line with [*] > > HTH > > Frank Millman Ok, this does clear up why the list() construction worked in this context - I wasn't aware that it would create a copy. I'm still a little confused by why passing the list as an argument causes the list to change. But, I was not aware of the id() method to see what's equivalent to what. I'll experiment with this and you've given me some good ideas on other docs I need to read. Thank you for the quick reply. JBB From __peter__ at web.de Tue Sep 9 03:13:16 2014 From: __peter__ at web.de (Peter Otten) Date: Tue, 09 Sep 2014 09:13:16 +0200 Subject: Passing a list into a list .append() method References: Message-ID: JBB wrote: > I have a list with a fixed number of elements which I need to grow; ie. > add rows of a fixed number of elements, some of which will be blank. > > e.g. [['a','b','c','d'], ['A','B','C','D'], ['', 'aa', 'inky', ''], ['', > 'bb', 'binky', ''], ... ] > > This is a reduced representation of a larger list-of-lists problem that > had me running in circles today. > > I think I figured out _how_ to get what I want but I am looking to > understand why one approach works and another doesn't. The actual problem is that you are appending the same list multiple times. In nuce: >>> inner = [1, 2, 3] >>> outer = [inner, inner, inner] Remember that outer[0] is inner just like the two other items of the outer list: >>> outer[0] is inner True >>> outer[1] is inner True >>> outer[2] is inner True So >>> outer[0][0] = 42 effectively changes inner >>> inner [42, 2, 3] which is reflected in the following output: >>> outer [[42, 2, 3], [42, 2, 3], [42, 2, 3]] With list(inner) you create a (shallow) copy of inner >>> inner = [1, 2, 3] >>> outer = [list(inner), list(inner), list(inner)] >>> outer[0] is inner False and a subsequent assignment changes only that specific copy of inner: >>> outer[0][0] = 42 >>> outer [[42, 2, 3], [1, 2, 3], [1, 2, 3]] So the key to the solution is that you create a new list on every iteration of the loop. With that in mind I'd write for a, b, in zip(qq, rr): proc_file.append(["", a, b, ""]) or alternatively if the actual inner list is more complex template = ["", "", "", ""] for p in zip(qq, rr): inner = list(template) inner[1:3] = p proc_file.append(inner) > 1) What does NOT work as desired: > proc_file.append((blank_r)) # Add a row of blanks > proc_file[i+2][1] = j[0] > proc_file[i+2][2] = j[1] > 2) What works as desired: > proc_file.append(list(blank_r)) # Change it to list(blank_r) and it > works > proc_file[i+2][1] = j[0] > proc_file[i+2][2] = j[1] > print len(proc_file), blank_r, proc_file From news at prz-wugen.com Tue Sep 9 03:12:49 2014 From: news at prz-wugen.com (Paul Kroeger) Date: Tue, 09 Sep 2014 09:12:49 +0200 Subject: Passing a list into a list .append() method In-Reply-To: References: Message-ID: <1410246769.28830.23.camel@pcom01.wugen> Hello, I'm myself still learning Python, so others may please correct me, if I'm wrong. Consider the following sentence of your link "jeffknupp.com/...": "some_guy and first_names[0] both refer to the same object" This is what is going on here. Am Dienstag, den 09.09.2014, 05:50 +0000 schrieb JBB: > [...] > > for i,j in enumerate(zip(qq,rr)): > proc_file.append((blank_r)) # Add a row of blanks At this point, the last "row" of "proc_file" and the variable "blank_r" both refer to the list object [blank_r]. > proc_file[i+2][1] = j[0] > proc_file[i+2][2] = j[1] The object under "proc_file[...]" is changed now. This object is the list object [blank_r]! So "proc_file[-1]" and "blank_r" both refer to [blank_r] = ["", j[0], j[1], ""], which is added do the list object [proc_file] at the beginning of the next iteration. Thus, all entries of [proc_file] with index greater 1 are bound to [blank_r], which is itself modified in each iteration to the corresponding j: proc_file[0] -> ["a", "b,", "c", "d"] proc_file[1] -> ["A", "B,", "C", "D"] proc_file[2] -> [blank_r] proc_file[3] -> [blank_r] proc_file[4] -> [blank_r] proc_file[5] -> [blank_r] ... Thus, printing proc_file will always print the values of the last j for all rows greater than 1. Maybe, this will help (although I think you got it already: proc_file = [] proc_file = [['a','b','c','d']] proc_file.append(['A','B','C','D']) blank_r = ['','','',''] qq = ['aa','bb','cc','dd'] rr = ['inky', 'binky', 'pinky', 'clyde'] for i,j in enumerate(zip(qq,rr)): proc_file.append((blank_r)) # Add a row of blanks print "proc_file at loop entry:", proc_file print "current blank_r:", blank_r proc_file[i+2][1] = j[0] proc_file[i+2][2] = j[1] print "proc_file at loop end:", proc_file, "\n\n" And maybe thinking of lists as objects and of variables "containing" lists (somehow) as "pointers" may also help. > [...] 2) What works as desired: > proc_file.append(list(blank_r)) # Change it to list(blank_r) and it works The list() function returns a copy of [blank_r]. So with this code, "proc_file[-1]" refers not the same list object as "blank_r". This leads to the desired behaviour of your program. > It looks like .append binds blank_r to proc_file in 1). I change proc_file > and blank_r changes along with it. Should I expect this? [...] I hope, the above helps to understand why this behaviour.is to be expected. So long, Paul From jeanbigboute at gmail.com Tue Sep 9 03:37:34 2014 From: jeanbigboute at gmail.com (JBB) Date: Tue, 9 Sep 2014 07:37:34 +0000 (UTC) Subject: Passing a list into a list .append() method References: <1410246769.28830.23.camel@pcom01.wugen> Message-ID: Paul Kroeger prz-wugen.com> writes: > > Hello, > > I'm myself still learning Python, so others may please correct me, if > I'm wrong. ... > I hope, the above helps to understand why this behaviour.is to be > expected. > To Peter Otten and Paul Kroeger: Thank you both, very much. I think I now get why the binding works as it does in addition to why the list() approach worked. JBB From breamoreboy at yahoo.co.uk Tue Sep 9 03:43:29 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 09 Sep 2014 08:43:29 +0100 Subject: weakref, memory management and execution slow down in PyQt4 In-Reply-To: <540E69AF.5040309@riseup.net> References: <540BFE43.5030006@riseup.net> <540CADDD.3050501@riseup.net> <540CB15C.2060008@gmail.com> <540CC278.4050106@riseup.net> <540E40FD.8030706@gmail.com> <540E69AF.5040309@riseup.net> Message-ID: On 09/09/2014 03:45, kjs wrote: > > You're right, a dictionary can do everything I need and more. This > happened to be the first thing I thought of, and I didn't imagine it > would be very expensive. I figured it was simply a different way of > defining and retrieving a class variable. IE setattr(self, foo, True) == > self.foo = True. > My rule of thumb for making a judgement on Python performance is never assume anything, ever. In using Python for well over 10 years my gut instinct has never been correct on this matter. The only thing to do is profile your code and then seek the answers online, as you can guarantee someone else has already been there, seen it, done it and got the t-shirt :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rustompmody at gmail.com Tue Sep 9 04:09:29 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 9 Sep 2014 01:09:29 -0700 (PDT) Subject: Newer Debian versions of python on older Debian distros? In-Reply-To: References: Message-ID: <437cfb6d-283f-4151-a1af-68b61a5f099c@googlegroups.com> On Tuesday, September 9, 2014 12:35:27 AM UTC+5:30, Travis Griggs wrote: > (I realize that this may be seen as off topic for as a general > python question, but given my historical experience with the Debian > community's predilection to answer all questions with a grumpy "go > read the very very very very large and ever shifting fine manual", > I'm hoping for better luck here.) > Does anyone have experience with using newer versions of python > debian packages (in particular, python3 and python3-bson-ext from > 'testing') on older stable versions ('wheezy' in this case)? If > someone's figured out how to do this easily, I'd love to hear the > recipe! Wheezy appears to have a python3 (though not the latest) https://packages.debian.org/wheezy/python3 Chris said: > Alternatively, you could just run Debian Jessie. I have a few Jessie > systems on the network, with a Python 3.4 IIRC, and there've been no > stability problems lately. Both options are pretty easy. I'm not so sure. There's quite a brawl going on right now on debian users over systemd. [I am running testing myself] From jeanbigboute at gmail.com Tue Sep 9 03:53:14 2014 From: jeanbigboute at gmail.com (JBB) Date: Tue, 9 Sep 2014 07:53:14 +0000 (UTC) Subject: Passing a list into a list .append() method References: Message-ID: Peter Otten <__peter__ web.de> writes: [Deletia] To Peter Otten and Paul Kroeger: Thank you both, very much. I think I now get why the binding works as it does in addition to why the list() approach worked. (Third attempt - priors not going through, please excuse any repetition) JBB From vimal.rughani at gmail.com Tue Sep 9 04:25:05 2014 From: vimal.rughani at gmail.com (Vimal Rughani) Date: Tue, 9 Sep 2014 01:25:05 -0700 (PDT) Subject: How to create python web framework for ERP Message-ID: Hi All, Greetings ! I am bit familiar with Django and Python. I want to create ERP on python. Initially I feel Django will be good option for My Own ERP, but after working bit on that I feel it doesn't fit with my requirement. So I decided to create my own python based web framework for ERP. Can you please suggest me better book / video / resources / content which help me to build proper web framework for ERP. Thanks From stephane at wirtel.be Tue Sep 9 04:33:21 2014 From: stephane at wirtel.be (=?utf-8?q?St=C3=A9phane?= Wirtel) Date: Tue, 09 Sep 2014 10:33:21 +0200 Subject: How to create python web framework for ERP In-Reply-To: References: Message-ID: <64CBE55B-ED4C-478E-804E-F7611A6BDE0C@wirtel.be> On 9 Sep 2014, at 10:25, Vimal Rughani wrote: > Hi All, > > Greetings ! > > I am bit familiar with Django and Python. I want to create ERP on > python. Initially I feel Django will be good option for My Own ERP, > but after working bit on that I feel it doesn't fit with my > requirement. So I decided to create my own python based web framework > for ERP. Can you please suggest me better book / video / resources / > content which help me to build proper web framework for ERP. > > Thanks > -- > https://mail.python.org/mailman/listinfo/python-list Use Odoo. -- St?phane Wirtel - http://wirtel.be - @matrixise From rosuav at gmail.com Tue Sep 9 05:17:54 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 9 Sep 2014 19:17:54 +1000 Subject: Newer Debian versions of python on older Debian distros? In-Reply-To: <437cfb6d-283f-4151-a1af-68b61a5f099c@googlegroups.com> References: <437cfb6d-283f-4151-a1af-68b61a5f099c@googlegroups.com> Message-ID: On Tue, Sep 9, 2014 at 6:09 PM, Rustom Mody wrote: >> Does anyone have experience with using newer versions of python >> debian packages (in particular, python3 and python3-bson-ext from >> 'testing') on older stable versions ('wheezy' in this case)? If >> someone's figured out how to do this easily, I'd love to hear the >> recipe! > > Wheezy appears to have a python3 (though not the latest) > https://packages.debian.org/wheezy/python3 I think the point of "python3 from testing" is because the python3 package in Wheezy is 3.2.3. (And if he hadn't explicitly told us he's using Wheezy, it could have been Squeeze, which went out of primary support just a few months ago, and is still in Long-Term Support for a couple of years. Squeeze ships Python 3.1.) All my Wheezy systems have a locally-compiled Python. But then, I've been installing quite a few Jessie (testing) systems, for various reasons (support for our network scanner being one of them), and the one really important Wheezy system here is my personal dev system where I worked on the PEP 463 branch, so compiling CPython from source was absolutely necessary. :) > Chris said: >> Alternatively, you could just run Debian Jessie. I have a few Jessie >> systems on the network, with a Python 3.4 IIRC, and there've been no >> stability problems lately. Both options are pretty easy. > > I'm not so sure. > There's quite a brawl going on right now on debian users over > systemd. > [I am running testing myself] Sadly, yes. I wish these things could be resolved on technical grounds rather than political. I'm certain that systemd is superior to sysvinit; I'm fairly sure it's superior to Upstart, and others I don't have experience with. The technical downsides are few - it's Linux-only (or was last I checked - this stuff can change), and it's fairly invasive, needing kernel support. Most of the issues are political ("how much power will Red Hat have?") and I have no interest in arguing those. But frankly, that's not really much different from the OpenOffice vs Libre Office battles. Most people just don't care. I mean, let's face it, there are a lot of people who wouldn't care (and maybe wouldn't even notice) if you just go in and rename all the menu items to "Microsoft Excel" and "Microsoft Word" and so on, and claim it's a port of MS Office! If the average user doesn't care about an application that's right in the face, why will s/he care about an init system? "This one means the system boots faster." "Fine! Good enough for me." ChrisA From vimal.rughani at gmail.com Tue Sep 9 06:06:50 2014 From: vimal.rughani at gmail.com (Vimal Rughani) Date: Tue, 9 Sep 2014 03:06:50 -0700 (PDT) Subject: How to create python web framework for ERP In-Reply-To: References: Message-ID: On Tuesday, 9 September 2014 14:09:48 UTC+5:30, St?phane Wirtel wrote: > On 9 Sep 2014, at 10:25, Vimal Rughani wrote: > > > > > Hi All, > > > > > > Greetings ! > > > > > > I am bit familiar with Django and Python. I want to create ERP on > > > python. Initially I feel Django will be good option for My Own ERP, > > > but after working bit on that I feel it doesn't fit with my > > > requirement. So I decided to create my own python based web framework > > > for ERP. Can you please suggest me better book / video / resources / > > > content which help me to build proper web framework for ERP. > > > > > > Thanks > > > -- > > > https://mail.python.org/mailman/listinfo/python-list > > Use Odoo. > > > > -- > > St?phane Wirtel - http://wirtel.be - @matrixise Thanks St?phane, for your suggestion. I know about Odoo and Odoo is good choice for domain related to Business. I am developing solution for Education / schools / colleges. Requirements are bit complex so I want to have own framework. From adam at nespurek.com Tue Sep 9 06:19:13 2014 From: adam at nespurek.com (=?UTF-8?B?QWRhbSBOZcWhcMWvcmVr?=) Date: Tue, 9 Sep 2014 12:19:13 +0200 Subject: How to create python web framework for ERP In-Reply-To: References: Message-ID: I would say you can still use Django. See django-oscar for instance, it is 'ecommerce framework', based od Django. I would highly recommend to stick around Django, because of its huge ecosystem. You can still add/write some missing parts yourself. Can you be more specific, why Django does not suit your needs? 2014-09-09 12:06 GMT+02:00 Vimal Rughani : > On Tuesday, 9 September 2014 14:09:48 UTC+5:30, St?phane Wirtel wrote: > > On 9 Sep 2014, at 10:25, Vimal Rughani wrote: > > > > > > > > > Hi All, > > > > > > > > > > Greetings ! > > > > > > > > > > I am bit familiar with Django and Python. I want to create ERP on > > > > > python. Initially I feel Django will be good option for My Own ERP, > > > > > but after working bit on that I feel it doesn't fit with my > > > > > requirement. So I decided to create my own python based web framework > > > > > for ERP. Can you please suggest me better book / video / resources / > > > > > content which help me to build proper web framework for ERP. > > > > > > > > > > Thanks > > > > > -- > > > > > https://mail.python.org/mailman/listinfo/python-list > > > > Use Odoo. > > > > > > > > -- > > > > St?phane Wirtel - http://wirtel.be - @matrixise > > Thanks St?phane, for your suggestion. I know about Odoo and Odoo is good > choice for domain related to Business. I am developing solution for > Education / schools / colleges. Requirements are bit complex so I want to > have own framework. > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rustompmody at gmail.com Tue Sep 9 08:07:54 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 9 Sep 2014 05:07:54 -0700 (PDT) Subject: Passing a list into a list .append() method In-Reply-To: References: Message-ID: <6426e4b9-5d55-4901-99a4-027b8352d229@googlegroups.com> On Tuesday, September 9, 2014 11:25:29 AM UTC+5:30, JBB wrote: > I have a list with a fixed number of elements which I need to grow; ie. add > rows of a fixed number of elements, some of which will be blank. > e.g. [['a','b','c','d'], ['A','B','C','D'], ['', 'aa', 'inky', ''], ['', > 'bb', 'binky', ''], ... ] > This is a reduced representation of a larger list-of-lists problem that had > me running in circles today. > I think I figured out _how_ to get what I want but I am looking to > understand why one approach works and another doesn't. > 1) What does NOT work as desired: > proc_file = [] > proc_file = [['a','b','c','d']] > proc_file.append(['A','B','C','D']) > blank_r = ['','','',''] > qq = ['aa','bb','cc','dd'] > rr = ['inky', 'binky', 'pinky', 'clyde'] > for i,j in enumerate(zip(qq,rr)): > proc_file.append((blank_r)) # Add a row of blanks > proc_file[i+2][1] = j[0] > proc_file[i+2][2] = j[1] > print len(proc_file), blank_r, proc_file > print > print > proc_file > 3 ['', 'aa', 'inky', ''] [['a', 'b', 'c', 'd'], ['A', 'B', 'C', 'D'], ['', > 'aa', 'inky', '']] > 4 ['', 'bb', 'binky', ''] [['a', 'b', 'c', 'd'], ['A', 'B', 'C', 'D'], ['', > 'bb', 'binky', ''], ['', 'bb', 'binky', '']] > 5 ['', 'cc', 'pinky', ''] [['a', 'b', 'c', 'd'], ['A', 'B', 'C', 'D'], ['', > 'cc', 'pinky', ''], ['', 'cc', 'pinky', ''], ['', 'cc', 'pinky', '']] > 6 ['', 'dd', 'clyde', ''] [['a', 'b', 'c', 'd'], ['A', 'B', 'C', 'D'], ['', > 'dd', 'clyde', ''], ['', 'dd', 'clyde', ''], ['', 'dd', 'clyde', ''], ['', > 'dd', 'clyde', '']] > Out[82]: > [['a', 'b', 'c', 'd'], > ['A', 'B', 'C', 'D'], > ['', 'dd', 'clyde', ''], > ['', 'dd', 'clyde', ''], > ['', 'dd', 'clyde', ''], > ['', 'dd', 'clyde', '']] > 2) What works as desired: > proc_file = [] > proc_file = [['a','b','c','d']] > proc_file.append(['A','B','C','D']) > blank_r = ['','','',''] > qq = ['aa','bb','cc','dd'] > rr = ['inky', 'binky', 'pinky', 'clyde'] > for i,j in enumerate(zip(qq,rr)): > proc_file.append(list(blank_r)) # Change it to list(blank_r) and it works > proc_file[i+2][1] = j[0] > proc_file[i+2][2] = j[1] > print len(proc_file), blank_r, proc_file > print > print > proc_file > 3 ['', '', '', ''] [['a', 'b', 'c', 'd'], ['A', 'B', 'C', 'D'], ['', 'aa', > 'inky', '']] > 4 ['', '', '', ''] [['a', 'b', 'c', 'd'], ['A', 'B', 'C', 'D'], ['', 'aa', > 'inky', ''], ['', 'bb', 'binky', '']] > 5 ['', '', '', ''] [['a', 'b', 'c', 'd'], ['A', 'B', 'C', 'D'], ['', 'aa', > 'inky', ''], ['', 'bb', 'binky', ''], ['', 'cc', 'pinky', '']] > 6 ['', '', '', ''] [['a', 'b', 'c', 'd'], ['A', 'B', 'C', 'D'], ['', 'aa', > 'inky', ''], ['', 'bb', 'binky', ''], ['', 'cc', 'pinky', ''], ['', 'dd', > 'clyde', '']] > Out[83]: > [['a', 'b', 'c', 'd'], > ['A', 'B', 'C', 'D'], > ['', 'aa', 'inky', ''], > ['', 'bb', 'binky', ''], > ['', 'cc', 'pinky', ''], > ['', 'dd', 'clyde', '']] Dont quite know what you are trying to do. Does this serve your purpose? >>> proc_file = [['a','b','c','d']] >>> proc_file.append(['A','B','C','D']) >>> blank_r = ['','','',''] >>> [[i,j0,j1, ""] for (i, (j0, j1)) in enumerate(zip(qq,rr))] [[0, 'aa', 'inky', ''], [1, 'bb', 'binky', ''], [2, 'cc', 'pinky', ''], [3, 'dd', 'clyde', '']] Or if you prefer: >>> proc_file + [[i,j0,j1, ""] for (i, (j0, j1)) in enumerate(zip(qq,rr))] [['a', 'b', 'c', 'd'], [0, 'aa', 'inky', ''], [1, 'bb', 'binky', ''], [2, 'cc', 'pinky', ''], [3, 'dd', 'clyde', '']] From matteo.boscolo at boscolini.eu Tue Sep 9 08:12:38 2014 From: matteo.boscolo at boscolini.eu (Matteo Boscolo) Date: Tue, 09 Sep 2014 14:12:38 +0200 Subject: How to create python web framework for ERP In-Reply-To: References: Message-ID: <540EEEB6.7040905@boscolini.eu> Use the only odoo framework.. without addons .. will be the best choice .. do not reinvent the whell if you do not need web interface, you can have a look at http://www.tryton.org/ otherwise you could have flask for the top of flexibility regards, Matteo Il 09/09/2014 12:06, Vimal Rughani ha scritto: > On Tuesday, 9 September 2014 14:09:48 UTC+5:30, St?phane Wirtel wrote: >> On 9 Sep 2014, at 10:25, Vimal Rughani wrote: >> >> >> >>> Hi All, >>> Greetings ! >>> I am bit familiar with Django and Python. I want to create ERP on >>> python. Initially I feel Django will be good option for My Own ERP, >>> but after working bit on that I feel it doesn't fit with my >>> requirement. So I decided to create my own python based web framework >>> for ERP. Can you please suggest me better book / video / resources / >>> content which help me to build proper web framework for ERP. >>> Thanks >>> -- >>> https://mail.python.org/mailman/listinfo/python-list >> Use Odoo. >> >> >> >> -- >> >> St?phane Wirtel - http://wirtel.be - @matrixise > Thanks St?phane, for your suggestion. I know about Odoo and Odoo is good choice for domain related to Business. I am developing solution for Education / schools / colleges. Requirements are bit complex so I want to have own framework. From thequietcenter at gmail.com Tue Sep 9 09:55:34 2014 From: thequietcenter at gmail.com (thequietcenter at gmail.com) Date: Tue, 9 Sep 2014 06:55:34 -0700 (PDT) Subject: exit code of a script that raises an Exception? Message-ID: Hello, after looking at the docs for Exception: https://docs.python.org/2/library/exceptions.html I do not see any information on the guaranteed exit code a script that exits because Python threw an exception. I wonder if all exceptions throw the exact same non-zero exit code, or whether a specific exit code is assigned to each exception uniquely. Or whether the exit code behavior is undefined (especially since it appears to be undocumented). Thanks, Terrence From thequietcenter at gmail.com Tue Sep 9 09:57:44 2014 From: thequietcenter at gmail.com (thequietcenter at gmail.com) Date: Tue, 9 Sep 2014 06:57:44 -0700 (PDT) Subject: How to create python web framework for ERP In-Reply-To: References: Message-ID: On Tuesday, September 9, 2014 6:53:37 AM UTC-4, Adam Ne?p?rek wrote: > I would highly recommend to stick around Django, because of its huge ecosystem. Django's ORM layer does not perform intelligent object creation does it? It naively creates two instances for the same row and does not handle commits gracefully, often resulting in stale object errors? it's been awhile since I used it. But I think SQLAlchemy has solved all the problems the Django ORM has not and can't solve? From gerd.niemetz at gmail.com Tue Sep 9 10:18:30 2014 From: gerd.niemetz at gmail.com (Gerd Niemetz) Date: Tue, 9 Sep 2014 07:18:30 -0700 (PDT) Subject: How to create python web framework for ERP In-Reply-To: References: Message-ID: <86e47213-c87d-4557-9c05-177788f391dc@googlegroups.com> Am Dienstag, 9. September 2014 10:25:24 UTC+2 schrieb Vimal Rughani: > Hi All, > > > > Greetings ! > > > > I am bit familiar with Django and Python. I want to create ERP on python. Initially I feel Django will be good option for My Own ERP, but after working bit on that I feel it doesn't fit with my requirement. So I decided to create my own python based web framework for ERP. Can you please suggest me better book / video / resources / content which help me to build proper web framework for ERP. > > > > Thanks Take a look at www.web2py.com Actively developed and a great community here at google groups -> https://groups.google.com/forum/#!forum/web2py best regards Gerd From clint.tecnologia at gmail.com Tue Sep 9 10:18:53 2014 From: clint.tecnologia at gmail.com (Andre Duarte) Date: Tue, 9 Sep 2014 07:18:53 -0700 (PDT) Subject: How to create python web framework for ERP In-Reply-To: References: Message-ID: <50484d9b-7dfb-41c6-bbaa-5ca07d2e23a2@googlegroups.com> Vimal, Django is a more generic framework(was built initialy for content management). Odoo is a valid sugestion but take some time to see Frappe.io. ERPNext was built on top of this framework and is a great application for small bussiness. []'s Andr? From thequietcenter at gmail.com Tue Sep 9 10:36:51 2014 From: thequietcenter at gmail.com (thequietcenter at gmail.com) Date: Tue, 9 Sep 2014 07:36:51 -0700 (PDT) Subject: [ANN] pathlib 1.0.1 In-Reply-To: References: Message-ID: <99ada096-77c0-4030-a09c-ef53b05b58c8@googlegroups.com> On Wednesday, September 3, 2014 11:58:47 AM UTC-4, Antoine Pitrou wrote: > > pathlib offers a set of classes to handle filesystem paths. How does it differ from path.py? From thequietcenter at gmail.com Tue Sep 9 10:41:54 2014 From: thequietcenter at gmail.com (thequietcenter at gmail.com) Date: Tue, 9 Sep 2014 07:41:54 -0700 (PDT) Subject: exit code of a script that raises an Exception? In-Reply-To: References: Message-ID: On Tuesday, September 9, 2014 9:56:04 AM UTC-4, thequie... at gmail.com wrote: > I wonder if all exceptions throw the exact same non-zero exit code, or whether a specific exit code is assigned to each exception uniquely. Or whether the exit code behavior is undefined (especially since it appears to be undocumented). > Just found sys.excepthook. I see that there is no sys.exit() call in its documented behavior: https://docs.python.org/2/library/sys.html sys.excepthook(type, value, traceback) This function prints out a given traceback and exception to sys.stderr. When an exception is raised and uncaught, the interpreter calls sys.excepthook with three arguments, the exception class, exception instance, and a traceback object. In an interactive session this happens just before control is returned to the prompt; in a Python program this happens just before the program exits. The handling of such top-level exceptions can be customized by assigning another three-argument function to sys.excepthook. From gandalf at shopzeus.com Tue Sep 9 09:36:20 2014 From: gandalf at shopzeus.com (=?ISO-8859-2?Q?Nagy_L=E1szl=F3_Zsolt?=) Date: Tue, 09 Sep 2014 15:36:20 +0200 Subject: cx_freeze and architecture Message-ID: <540F0254.8030908@shopzeus.com> Is it possible to create executeable for different architectures on the same windows OS? What I mean is that I can install Python 3 amd64 and then create 64 bit executeables with cx_freeze. But I cannot create 32bit x86 executeables. It would be great to install Python 3 x86 on the same system but it does not seem to be possible. Then what should I do? Is there a way around this other than installing a completely new OS and synchronizing source files between them? Thanks From gandalf at shopzeus.com Tue Sep 9 10:45:11 2014 From: gandalf at shopzeus.com (=?ISO-8859-2?Q?Nagy_L=E1szl=F3_Zsolt?=) Date: Tue, 09 Sep 2014 16:45:11 +0200 Subject: pycrypto 3.4 binaries for windows x86 Message-ID: <540F1277.3090405@shopzeus.com> Where can I find compiled installer for pycrypto for python 3.4 windows 32bit? Voidspace does not have compiled installers for 3.4, only 3.3. pip cannot install it because it wants to compile it from source. (I need a binary installer, and I don't have MSVC.) It is not present at Gholke's website either ( http://www.lfd.uci.edu/~gohlke/pythonlibs/ ). So where? Thanks From ned at nedbatchelder.com Tue Sep 9 11:22:05 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 09 Sep 2014 11:22:05 -0400 Subject: exit code of a script that raises an Exception? In-Reply-To: References: Message-ID: On 9/9/14 9:55 AM, thequietcenter at gmail.com wrote: > Hello, after looking at the docs for Exception: > https://docs.python.org/2/library/exceptions.html > > I do not see any information on the guaranteed exit code a script that exits because Python threw an exception. > > I wonder if all exceptions throw the exact same non-zero exit code, or whether a specific exit code is assigned to each exception uniquely. Or whether the exit code behavior is undefined (especially since it appears to be undocumented). > > Thanks, > Terrence > A quick check demonstrates that exceptions do not get distinct status codes. BTW: how could they?, you can create new exception types, there is not a bounded number of them. On my Mac, Python 2.7 exited with a status code of 1 for ZeroDivisionError, NameError, SyntaxError, IndexError, and KeyError. -- Ned Batchelder, http://nedbatchelder.com From rustompmody at gmail.com Tue Sep 9 11:23:02 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 9 Sep 2014 08:23:02 -0700 (PDT) Subject: Newer Debian versions of python on older Debian distros? In-Reply-To: References: <437cfb6d-283f-4151-a1af-68b61a5f099c@googlegroups.com> Message-ID: On Tuesday, September 9, 2014 2:53:53 PM UTC+5:30, Chris Angelico wrote: > On Tue, Sep 9, 2014 at 6:09 PM, Rustom Mody wrote: > >> Does anyone have experience with using newer versions of python > >> debian packages (in particular, python3 and python3-bson-ext from > >> 'testing') on older stable versions ('wheezy' in this case)? If > >> someone's figured out how to do this easily, I'd love to hear the > >> recipe! > > Wheezy appears to have a python3 (though not the latest) > > https://packages.debian.org/wheezy/python3 > I think the point of "python3 from testing" is because the python3 > package in Wheezy is 3.2.3. (And if he hadn't explicitly told us he's > using Wheezy, it could have been Squeeze, which went out of primary > support just a few months ago, and is still in Long-Term Support for a > couple of years. Squeeze ships Python 3.1.) > All my Wheezy systems have a locally-compiled Python. But then, I've > been installing quite a few Jessie (testing) systems, for various > reasons (support for our network scanner being one of them), and the > one really important Wheezy system here is my personal dev system > where I worked on the PEP 463 branch, so compiling CPython from source > was absolutely necessary. :) > > Chris said: > >> Alternatively, you could just run Debian Jessie. I have a few Jessie > >> systems on the network, with a Python 3.4 IIRC, and there've been no > >> stability problems lately. Both options are pretty easy. > > I'm not so sure. > > There's quite a brawl going on right now on debian users over > > systemd. > > [I am running testing myself] > Sadly, yes. I wish these things could be resolved on technical grounds > rather than political. I'm certain that systemd is superior to > sysvinit; I'm fairly sure it's superior to Upstart, and others I don't > have experience with. The technical downsides are few - it's > Linux-only (or was last I checked - this stuff can change), and it's > fairly invasive, needing kernel support. Most of the issues are > political ("how much power will Red Hat have?") and I have no interest > in arguing those. > But frankly, that's not really much different from the OpenOffice vs > Libre Office battles. Most people just don't care. I mean, let's face > it, there are a lot of people who wouldn't care (and maybe wouldn't > even notice) if you just go in and rename all the menu items to > "Microsoft Excel" and "Microsoft Word" and so on, and claim it's a > port of MS Office! If the average user doesn't care about an > application that's right in the face, why will s/he care about an init > system? "This one means the system boots faster." "Fine! Good enough > for me." I thought so too viz that the problems were teething troubles. However the rants on debian-dev seem to be following from extensive breakage from systemd. Also there is this thread in which systemd broke the standard kernel debugging options -- ok bugs happen. And then the systemd devs refuse to admit to their bug. I find this alarming. From rosuav at gmail.com Tue Sep 9 11:27:53 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 10 Sep 2014 01:27:53 +1000 Subject: Newer Debian versions of python on older Debian distros? In-Reply-To: References: <437cfb6d-283f-4151-a1af-68b61a5f099c@googlegroups.com> Message-ID: On Wed, Sep 10, 2014 at 1:23 AM, Rustom Mody wrote: > I thought so too viz that the problems were teething troubles. > However the rants on debian-dev seem to be following from extensive breakage > from systemd. > > Also there is this thread in which systemd broke the standard > kernel debugging options -- ok bugs happen. > And then the systemd devs refuse to admit to their bug. I find this alarming. Well, I'm just going to point out that this is off-topic for python-list, because I *really* don't want to get caught in the vortex of a discussion like this :) I'm so glad I'm not subscribed to debian-dev. ChrisA From christian at python.org Tue Sep 9 11:31:52 2014 From: christian at python.org (Christian Heimes) Date: Tue, 09 Sep 2014 17:31:52 +0200 Subject: pycrypto 3.4 binaries for windows x86 In-Reply-To: <540F1277.3090405@shopzeus.com> References: <540F1277.3090405@shopzeus.com> Message-ID: On 09.09.2014 16:45, Nagy L?szl? Zsolt wrote: > Where can I find compiled installer for pycrypto for python 3.4 windows > 32bit? Voidspace does not have compiled installers for 3.4, only 3.3. > pip cannot install it because it wants to compile it from source. (I > need a binary installer, and I don't have MSVC.) It is not present at > Gholke's website either ( http://www.lfd.uci.edu/~gohlke/pythonlibs/ ). Michael Ford hasn't had the time to upload my binaries yet. Usually I provide compiled versions of PyCrypto for Windows people. You can grab a full bundle with MSI, EXE and wheels for Python 2.6 to 3.4 from my dropbox: https://www.dropbox.com/s/n6rckn0k6u4nqke/pycrypto-2.6.1.zip?dl=0 Christian From torriem at gmail.com Tue Sep 9 11:32:19 2014 From: torriem at gmail.com (Michael Torrie) Date: Tue, 09 Sep 2014 09:32:19 -0600 Subject: weakref, memory management and execution slow down in PyQt4 In-Reply-To: <540E69AF.5040309@riseup.net> References: <540BFE43.5030006@riseup.net> <540CADDD.3050501@riseup.net> <540CB15C.2060008@gmail.com> <540CC278.4050106@riseup.net> <540E40FD.8030706@gmail.com> <540E69AF.5040309@riseup.net> Message-ID: <540F1D83.1010602@gmail.com> Reposting to list, instead of directly to kjs On 09/08/2014 08:45 PM, kjs wrote: > Thanks for the consideration Michael. If you do get the data, and are > able to run the code, let me know if you notice anything interesting. Yeah I don't think I'll be able to have the time to download a 3 GB file. >> Is there a reason you are using setattr and getattr instead of a proper >> data structure? both of those calls are rather expensive. Would >> probably be cheaper to use some kind of array, dictionary, or other >> purpose-built data structure? >> > > You're right, a dictionary can do everything I need and more. This > happened to be the first thing I thought of, and I didn't imagine it > would be very expensive. I figured it was simply a different way of > defining and retrieving a class variable. IE setattr(self, foo, True) == > self.foo = True. Yes you're correct. It is the equivalent. But it always involves lookup in the object's dictionary, which is big O order O(n log n) complexity for each and every access. A list would be far faster, essentially O(1) (I think?) after the single name lookup, since you can access the elements by number. Indexing into a list doesn't involve doing name lookups; you just specify an offset. No idea how much faster, but significantly so. If a list is too slow, there are other array-like classes you can use (like numpy arrays) that do offer true O(1) lookups. Besides that, it's not typical use of setattr and getattr in python. From torriem at gmail.com Tue Sep 9 11:34:46 2014 From: torriem at gmail.com (Michael Torrie) Date: Tue, 09 Sep 2014 09:34:46 -0600 Subject: weakref, memory management and execution slow down in PyQt4 In-Reply-To: <540E69AF.5040309@riseup.net> References: <540BFE43.5030006@riseup.net> <540CADDD.3050501@riseup.net> <540CB15C.2060008@gmail.com> <540CC278.4050106@riseup.net> <540E40FD.8030706@gmail.com> <540E69AF.5040309@riseup.net> Message-ID: <540F1E16.5060003@gmail.com> On 09/08/2014 08:45 PM, kjs wrote: > You're right, a dictionary can do everything I need and more. Actually I am wrong in suggesting a dictionary. A list or an array would probably be more appropriate. Thinking about it this morning, one additional reason why getattr and setattr aren't appropriate for this task is that they are not just a dictionary lookup under the hood, they are an additional layer. One more function call that would be unnecessary if you used a data structure directly. From rosuav at gmail.com Tue Sep 9 11:37:01 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 10 Sep 2014 01:37:01 +1000 Subject: weakref, memory management and execution slow down in PyQt4 In-Reply-To: <540F1D83.1010602@gmail.com> References: <540BFE43.5030006@riseup.net> <540CADDD.3050501@riseup.net> <540CB15C.2060008@gmail.com> <540CC278.4050106@riseup.net> <540E40FD.8030706@gmail.com> <540E69AF.5040309@riseup.net> <540F1D83.1010602@gmail.com> Message-ID: On Wed, Sep 10, 2014 at 1:32 AM, Michael Torrie wrote: > Yes you're correct. It is the equivalent. But it always involves > lookup in the object's dictionary, which is big O order O(n log n) > complexity for each and every access. Where do you get that figure from? A CPython dictionary is implemented as a hashtable, so algorithmic complexity of lookups ought to be O(1). ChrisA From python at mrabarnett.plus.com Tue Sep 9 11:51:51 2014 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 09 Sep 2014 16:51:51 +0100 Subject: cx_freeze and architecture In-Reply-To: <540F0254.8030908@shopzeus.com> References: <540F0254.8030908@shopzeus.com> Message-ID: <540F2217.1090000@mrabarnett.plus.com> On 2014-09-09 14:36, Nagy L?szl? Zsolt wrote: > Is it possible to create executeable for different architectures on > the same windows OS? What I mean is that I can install Python 3 amd64 > and then create 64 bit executeables with cx_freeze. But I cannot > create 32bit x86 executeables. It would be great to install Python 3 > x86 on the same system but it does not seem to be possible. > > Then what should I do? Is there a way around this other than > installing a completely new OS and synchronizing source files between > them? > It _is_ possible to install you 32-bit and 64-bit Python on a 64-bit Windows. Just install them in different folders. From guido at python.org Tue Sep 9 11:56:52 2014 From: guido at python.org (Guido van Rossum) Date: Tue, 9 Sep 2014 08:56:52 -0700 Subject: installing python 3 In-Reply-To: References: Message-ID: Dear Ashley, Try describing your problem on StackOverflow.com. I'm sure someone there will help you. Good luck! --Guido On Sep 9, 2014 2:27 AM, "Ashley Forman" wrote: > Hello, > My name is Ashley Forman, and I am emailing because I cannot install > python onto my Mac laptop! I have installed Active-TCl 8.5 along with > Python 3.3 and tried with 3.4, and couldn't figure out a solution to my > problem. When I click on IDLE to open, it does not open at all. Therefore, > if you have any information that could help me, then I would really > appreciate it! Thank you! > Best, > Ashley Forman > -- > https://mail.python.org/mailman/listinfo/python-announce-list > > Support the Python Software Foundation: > http://www.python.org/psf/donations/ > -------------- next part -------------- An HTML attachment was scrubbed... URL: From torriem at gmail.com Tue Sep 9 11:57:02 2014 From: torriem at gmail.com (Michael Torrie) Date: Tue, 09 Sep 2014 09:57:02 -0600 Subject: weakref, memory management and execution slow down in PyQt4 In-Reply-To: References: <540BFE43.5030006@riseup.net> <540CADDD.3050501@riseup.net> <540CB15C.2060008@gmail.com> <540CC278.4050106@riseup.net> <540E40FD.8030706@gmail.com> <540E69AF.5040309@riseup.net> <540F1D83.1010602@gmail.com> Message-ID: <540F234E.1080901@gmail.com> On 09/09/2014 09:37 AM, Chris Angelico wrote: > On Wed, Sep 10, 2014 at 1:32 AM, Michael Torrie wrote: >> Yes you're correct. It is the equivalent. But it always involves >> lookup in the object's dictionary, which is big O order O(n log n) >> complexity for each and every access. > > Where do you get that figure from? A CPython dictionary is implemented > as a hashtable, so algorithmic complexity of lookups ought to be O(1). You're right, it is. My mistake. Guess the main issue is the overhead of an additional function call. A dict directly or a list directly may me faster. Anyway, I guess we're wandering in the weeds a bit as the original issue is probably not related to his unorthodox choice of metaprogramming as a data model. From bfb at riseup.net Tue Sep 9 13:28:50 2014 From: bfb at riseup.net (kjs) Date: Tue, 09 Sep 2014 10:28:50 -0700 Subject: weakref, memory management and execution slow down in PyQt4 In-Reply-To: <540F234E.1080901@gmail.com> References: <540BFE43.5030006@riseup.net> <540CADDD.3050501@riseup.net> <540CB15C.2060008@gmail.com> <540CC278.4050106@riseup.net> <540E40FD.8030706@gmail.com> <540E69AF.5040309@riseup.net> <540F1D83.1010602@gmail.com> <540F234E.1080901@gmail.com> Message-ID: <4b50e542-74f0-4154-a7db-bc04b42f657a@email.android.com> On September 9, 2014 8:57:02 AM PDT, Michael Torrie wrote: >On 09/09/2014 09:37 AM, Chris Angelico wrote: >> On Wed, Sep 10, 2014 at 1:32 AM, Michael Torrie >wrote: >>> Yes you're correct. It is the equivalent. But it always involves >>> lookup in the object's dictionary, which is big O order O(n log n) >>> complexity for each and every access. >> >> Where do you get that figure from? A CPython dictionary is >implemented >> as a hashtable, so algorithmic complexity of lookups ought to be >O(1). > >You're right, it is. My mistake. Guess the main issue is the overhead >of an additional function call. A dict directly or a list directly may >me faster. > >Anyway, I guess we're wandering in the weeds a bit as the original >issue >is probably not related to his unorthodox choice of metaprogramming as >a >data model. I agree. I believe I have isolated the issue to be either my user of pyqtgraph, or is implementation. I lean towards the my use, because I know how little effort I put into understanding the library. If I figure on a solution, I'll be sure to come back in. I'm also curious why the weakrefs are not being garbage collected. And how many (~20,000) tiny little things can bring processing to a halt after only a couple minutes of runtime. From bumens at dingens.org Tue Sep 9 13:03:13 2014 From: bumens at dingens.org (Volker Birk) Date: Tue, 9 Sep 2014 17:03:13 +0000 (UTC) Subject: installing python 3 References: Message-ID: Ashley Forman wrote: > My name is Ashley Forman, and I am emailing because I cannot install > python onto my Mac laptop! I have installed Active-TCl 8.5 along with > Python 3.3 and tried with 3.4, and couldn't figure out a solution to my > problem. When I click on IDLE to open, it does not open at all. Therefore, > if you have any information that could help me, then I would really > appreciate it! Thank you! Python best is being installed using MacPorts or Homebrew: So what did you install? This one? Yours, VB. -- ?Vor Snowden war das ein Blog mit Verschw?rungstheorien. Nach Snowden ist das ein Security-Newsticker. Bei unver?ndertem Inhalt...? Marc Stibane ?ber Fefes Blog From andy.zhang at gmail.com Tue Sep 9 13:57:10 2014 From: andy.zhang at gmail.com (Andy Zhang) Date: Tue, 9 Sep 2014 13:57:10 -0400 Subject: How to exit from embedded IPython shell? Message-ID: Hi, I am embedding IPython inside a c application, by running PYTHONSTARTUP file which is: import IPython IPython.embed() Then the application interact with user input via stdin. After the user is done, she would type EOF. The program should exit, but keep all the python objects in memory, and the user can re-enter python by calling the function again. Because of the embedded IPython, the user needs to enter EOF twice (First EOF exit IPython, second exit outter Python). I wonder whether it is possible to exit the outer Shell in my C code so that user can type one EOF and exit IPython and Python? char *startup = Py_GETENV("PYTHONSTARTUP"); if (startup != NULL && startup[0] != '\0') { FILE *fp = fopen(startup, "r"); if (fp != NULL) { (void) PyRun_SimpleFile(fp, startup); PyErr_Clear(); fclose(fp); } } retval = PyRun_AnyFile(stdin, (const char *) ""); Many thanks, -------------- next part -------------- An HTML attachment was scrubbed... URL: From noone at nowhere.net Tue Sep 9 16:20:28 2014 From: noone at nowhere.net (blindanagram) Date: Tue, 09 Sep 2014 21:20:28 +0100 Subject: Bad comment on Enigmatic Code Message-ID: <0IWdnR_lob-R_JLJnZ2dnUVZ8mednZ2d@brightview.co.uk> Hi Jim, When you get a moment, can you please remove the wrongly formatted Python comment I made on your site? Thanks Brian From tjreedy at udel.edu Tue Sep 9 22:15:15 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 09 Sep 2014 22:15:15 -0400 Subject: weakref, memory management and execution slow down in PyQt4 In-Reply-To: <540F1E16.5060003@gmail.com> References: <540BFE43.5030006@riseup.net> <540CADDD.3050501@riseup.net> <540CB15C.2060008@gmail.com> <540CC278.4050106@riseup.net> <540E40FD.8030706@gmail.com> <540E69AF.5040309@riseup.net> <540F1E16.5060003@gmail.com> Message-ID: On 9/9/2014 11:34 AM, Michael Torrie wrote: > On 09/08/2014 08:45 PM, kjs wrote: >> You're right, a dictionary can do everything I need and more. > > Actually I am wrong in suggesting a dictionary. A list or an array > would probably be more appropriate. > > Thinking about it this morning, one additional reason why getattr and > setattr aren't appropriate for this task is that they are not just a > dictionary lookup under the hood, they are an additional layer. One > more function call that would be unnecessary if you used a data > structure directly. The extra function call for getattr at least doubles the lookup time >>> repeat("C.a", "class C: a=1") [0.06093001107618079, 0.042186288111423664, 0.04218598069616064] >>> repeat("getattr(C, 'a')", "class C: a=1") [0.13152054655972734, 0.1100451316336688, 0.11021882125309901] -- Terry Jan Reedy From gandalf at shopzeus.com Wed Sep 10 01:17:06 2014 From: gandalf at shopzeus.com (=?UTF-8?B?TmFneSBMw6FzemzDsyBac29sdA==?=) Date: Wed, 10 Sep 2014 07:17:06 +0200 Subject: cx_freeze and architecture In-Reply-To: <540F2217.1090000@mrabarnett.plus.com> References: <540F0254.8030908@shopzeus.com> <540F2217.1090000@mrabarnett.plus.com> Message-ID: <540FDED2.8060100@shopzeus.com> >> Then what should I do? Is there a way around this other than >> installing a completely new OS and synchronizing source files between >> them? >> > It _is_ possible to install you 32-bit and 64-bit Python on a 64-bit > Windows. Just install them in different folders. And then how should I select the one from setup.py? Or do I have to start setup.py with the 32 bit version, and that's all? -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. From steve+comp.lang.python at pearwood.info Wed Sep 10 02:05:23 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 10 Sep 2014 16:05:23 +1000 Subject: Bad comment on Enigmatic Code References: <0IWdnR_lob-R_JLJnZ2dnUVZ8mednZ2d@brightview.co.uk> Message-ID: <540fea24$0$29992$c3e8da3$5496439d@news.astraweb.com> blindanagram wrote: > Hi Jim, > > When you get a moment, can you please remove the wrongly formatted > Python comment I made on your site? > > Thanks > > Brian Who is Jim, and what comment are you talking about? Perhaps you have sent this message to the wrong address? -- Steven From noone at nowhere.net Wed Sep 10 05:02:01 2014 From: noone at nowhere.net (blindanagram) Date: Wed, 10 Sep 2014 10:02:01 +0100 Subject: Bad comment on Enigmatic Code In-Reply-To: <540fea24$0$29992$c3e8da3$5496439d@news.astraweb.com> References: <0IWdnR_lob-R_JLJnZ2dnUVZ8mednZ2d@brightview.co.uk> <540fea24$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 10/09/2014 07:05, Steven D'Aprano wrote: > blindanagram wrote: > >> Hi Jim, >> >> When you get a moment, can you please remove the wrongly formatted >> Python comment I made on your site? >> >> Thanks >> >> Brian > > Who is Jim, and what comment are you talking about? > > Perhaps you have sent this message to the wrong address? > My apologies for this unintended message to this newsgroup. Brian From d.moorcroft at turvgng.bham.sch.uk Wed Sep 10 07:14:25 2014 From: d.moorcroft at turvgng.bham.sch.uk (D Moorcroft) Date: Wed, 10 Sep 2014 12:14:25 +0100 (BST) Subject: Python 3.3.2 help In-Reply-To: <54101B2E.8050100@timgolden.me.uk> References: <1951135237.5067937.1410341316898.JavaMail.zimbra@turvgng.bham.sch.uk> <54101B2E.8050100@timgolden.me.uk> Message-ID: <2004281172.5099238.1410347665048.JavaMail.zimbra@turvgng.bham.sch.uk> > Hi, > > We are running Python 3.3.2 but pupils are unable to print as they > cannot use the command prompt. > > An error comes up saying printing failed (exit status Oxff). > > Is there any way that we can get users who can't see the command > prompt to be able to print? > > Thank you, > > David Moorcroft ICT Operations Manager & Website Manager Turves Green > Girls' School > > > > ************************************************************* This > email and any files transmitted with it are confidential and intended > solely for the use of the individual or entity to whom they are > addressed. If you have received this email in error please notify > postmaster at bgfl.org > > The views expressed within this email are those of the individual, > and not necessarily those of the organisation > ************************************************************* > ************************************************************* This message has been checked for viruses by the Birmingham Grid for Learning. For guidance on good e-mail practice, e-mail viruses and hoaxes please visit: http://www.bgfl.org/emailaup ************************************************************* ************************************************************* This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify postmaster at bgfl.org The views expressed within this email are those of the individual, and not necessarily those of the organisation ************************************************************* From steve+comp.lang.python at pearwood.info Wed Sep 10 08:15:49 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 10 Sep 2014 22:15:49 +1000 Subject: Python 3.3.2 help References: <1951135237.5067937.1410341316898.JavaMail.zimbra@turvgng.bham.sch.uk> <54101B2E.8050100@timgolden.me.uk> Message-ID: <541040f6$0$29978$c3e8da3$5496439d@news.astraweb.com> Hello, My response is below, interleaved with your comments. D Moorcroft wrote: >> Hi, >> >> We are running Python 3.3.2 but pupils are unable to print as they >> cannot use the command prompt. What operating system are you using? Windows, Linux, Mac? Something else? Is it ALL pupils who are unable to print or just some of them? Which command prompt are they using? Can you reproduce the failure to print? If so, please tell us the detailed steps you (and the pupils) go through. E.g. something like this: "On Windows XP, choose Run from the Start Menu. Type cmd.exe and press Enter. When the terminal window opens, type print 'Hello World' and Enter." It will help if you can tell us whether your pupils are using IDLE, IPython, or the default Python interactive interpreter. If you can answer these questions, which should have a better chance of diagnosing the problem. Further responses below. >> An error comes up saying printing failed (exit status Oxff). Based on this, my guess is that your students are accidentally running the DOS "print" command at the DOS prompt, not Python at all. Perhaps they are forgetting to run the "python" command first to launch the Python interpreter, and are running directly in the DOS prompt? You can check this by reading the command prompt. If it looks like three greater-than signs >>> then you are running in Python's default interpreter. If it looks something like this: C:\Documents and Settings\user\> or perhaps like this: C:\> then you are still inside the DOS command prompt. Unfortunately, I am not very experienced with Windows, so I cannot tell you the right method to start Python. I would expect there to be a Start menu command, perhaps called "IDLE", or "Python", but I'm not sure. >> Is there any way that we can get users who can't see the command >> prompt to be able to print? I'm not entirely sure I understand this question. Can you explain in more detail? By the way, as you know there are two meanings of "print" in computing. There is printing to the screen, and printing to sheets of paper with an actual printer. Which are you intending? Regards, -- Steven From steve+comp.lang.python at pearwood.info Wed Sep 10 08:20:28 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 10 Sep 2014 22:20:28 +1000 Subject: Why Python has moved to a multilingual Unicode model Message-ID: <5410420c$0$29978$c3e8da3$5496439d@news.astraweb.com> Many Python 2 users (mostly English speakers, but also a few Europeans) are frustrated with the move of Python 3 to Unicode strings instead of ASCII strings. One of the core Python developers, Nick Coghlan of Red Hat, has written an article for the Red Hat Developer Blog explaining why the core devs have made that major paradigm shift of text-as-ASCII-plus-bytes to text-as-Unicode: http://developerblog.redhat.com/2014/09/09/transition-to-multilingual-programming-python/ -- Steven From michael at stroeder.com Wed Sep 10 08:20:33 2014 From: michael at stroeder.com (=?ISO-8859-1?Q?Michael_Str=F6der?=) Date: Wed, 10 Sep 2014 14:20:33 +0200 Subject: ANN: python-ldap 2.4.16 Message-ID: Find a new release of python-ldap: http://pypi.python.org/pypi/python-ldap/2.4.16 python-ldap provides an object-oriented API to access LDAP directory servers from Python programs. It mainly wraps the OpenLDAP 2.x libs for that purpose. Additionally it contains modules for other LDAP-related stuff (e.g. processing LDIF, LDAP URLs and LDAPv3 schema). Project's web site: http://www.python-ldap.org/ Ciao, Michael. ---------------------------------------------------------------- Released 2.4.16 2014-09-10 Changes since 2.4.15: Lib/ * New convenience function ldap.dn.is_dn() * New convenience function ldap.escape_str() * New convenience methods LDAPObject.read_s() and LDAPObject.find_unique_entry() * Fixed invoking start_tls_s() in ReconnectLDAPObject.reconnect() (thanks to Philipp Hahn) From mike at madhappy.com Wed Sep 10 09:24:13 2014 From: mike at madhappy.com (Mike Kilmer) Date: Wed, 10 Sep 2014 08:24:13 -0500 Subject: streaming dynamically appended music tracks Message-ID: <9813A53A-D3E5-4E33-9F7C-FA0007AD2529@madhappy.com> Hi Python list admins, I didn't see a page on etiquette at the info page, so inquiring of you: Is the Python list an appropriate place to seek a mentor for hire? I'm new to Python and have been working with Echonest's Remix "music synthesizer" package. I may be out of my league with the large amount of data required by the Numpy arrays, which will require some combination of streaming, threading, lazy loading, etc. I've found some promising leads in ForeverFM, but my background in php (css, html, etc) does not include extensive or advanced programming. Thanks and peace. Michael Kilmer Media Zoo Music, Theater, Multimedia and Web Development info at mzoo.org 201-679-4168 http://www.mZoo.org www.madhappy.com www.explorepensacolahistory.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From wxjmfauth at gmail.com Wed Sep 10 09:27:51 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 10 Sep 2014 06:27:51 -0700 (PDT) Subject: Why Python has moved to a multilingual Unicode model In-Reply-To: <5410420c$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <5410420c$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: Le mercredi 10 septembre 2014 14:20:42 UTC+2, Steven D'Aprano a ?crit?: > Many Python 2 users (mostly English speakers, but also a few Europeans) are > > frustrated with the move of Python 3 to Unicode strings instead of ASCII > > strings. > > > > One of the core Python developers, Nick Coghlan of Red Hat, has written an > > article for the Red Hat Developer Blog explaining why the core devs have > > made that major paradigm shift of text-as-ASCII-plus-bytes to > > text-as-Unicode: > > > > > > http://developerblog.redhat.com/2014/09/09/transition-to-multilingual-programming-python/ > > A "multilingual Unicode model" has not too much sense. The Unicode Standard encodes [1] *characters* on a per script basis. The "multilingualism" is only a consequence. [1] Via a *unique* encoding mechanism. A *single* operator, on a *single* set of elements (a repertoire of characters). There is no other way to do it (mathematics). --- Python 2.7 and the characters repertoire of the cp1252 coding scheme works very well. It follows the rule given in [1]. jmf From magda.brylska at gmail.com Wed Sep 10 09:28:51 2014 From: magda.brylska at gmail.com (magda.brylska at gmail.com) Date: Wed, 10 Sep 2014 06:28:51 -0700 (PDT) Subject: =?ISO-8859-2?Q?Poszukiwany_Programista_Python_=2D_Warszawa_=2F_Gda=F1sk_?= =?ISO-8859-2?Q?=2F_Krak=F3w?= Message-ID: <54686936-b0fe-48aa-92a7-8fd71410c098@googlegroups.com> Witam, Aktulanie prowadz? kilka bardzo ciekawych projekt?w rekrutacyjnych, w zwi?zku z czym poszukuj? kilkunastu developer?w Python, chc?cych pracowa? w Warszawie, Krakowie b?d? Gda?sku. Je?li masz minimum 3 letnie do?wiaczenie w programowaniu w j?zyku Python LUB do?wiadczenie w programowaniu w innym j?zyku (np. PHP, Ruby, C#, Java) i chesz si? przekwalifikowa? na programist? Python to zach?cam do wys?ania CV na adres mbrylska at devonshire.pl Oferujemy wsp??prac? w oparciu o dowoln? form? wsp??pracy. Umowa o prac?: od 10.000 brutto do 15.000 brutto B2B: od 10.000 netto do 15.000 netto +vat Dla najlepszych mo?liwo?? negocjacji stawek U?miech Zainteresowane osoby zapraszam do kontaktu (mbrylska at devonshire.pl lub 797 021 610), z ch?ci? odpowiem na wszelkie pytania o wide?ki, stanowisko oraz samego klienta :) Pozdrawiam, Magdalena Brylska IT/Telco Recruitment Consultant Devonshire Sp. z o.o. From rosuav at gmail.com Wed Sep 10 09:38:13 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 10 Sep 2014 23:38:13 +1000 Subject: streaming dynamically appended music tracks In-Reply-To: <9813A53A-D3E5-4E33-9F7C-FA0007AD2529@madhappy.com> References: <9813A53A-D3E5-4E33-9F7C-FA0007AD2529@madhappy.com> Message-ID: On Wed, Sep 10, 2014 at 11:24 PM, Mike Kilmer wrote: > I didn't see a page on etiquette at the info page, so inquiring of you: > > Is the Python list an appropriate place to seek a mentor for hire? An interesting question. Normally I'd point you to the Python Job Board, but I believe it's down at the moment. I'm really not sure what the best place to post this sort of thing is. You could try http://careers.stackoverflow.com/ but I've never used it and can't advise either way. ChrisA From chris at simplistix.co.uk Wed Sep 10 11:47:35 2014 From: chris at simplistix.co.uk (Chris Withers) Date: Wed, 10 Sep 2014 16:47:35 +0100 Subject: testfixtures 4.0.2 Released! Message-ID: <54107297.4060106@simplistix.co.uk> Hi All, I'm pleased to announce the release of testfixtures 4.0.2. This is a bugfix release that fixes the following: - Fix "maximum recursion depth exceeded" when comparing a string with bytes that did not contain the same character. 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 none at mailinator.com Wed Sep 10 13:57:56 2014 From: none at mailinator.com (mm0fmf) Date: Wed, 10 Sep 2014 18:57:56 +0100 Subject: Why Python has moved to a multilingual Unicode model (OT) In-Reply-To: References: <5410420c$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 10/09/2014 14:27, wxjmfauth at gmail.com wrote: > A "multilingual Unicode model" has not too much sense. You are Pavlov's Dog AICMFP ;-) From mjkantowski at gmail.com Wed Sep 10 14:18:49 2014 From: mjkantowski at gmail.com (mjkantowski at gmail.com) Date: Wed, 10 Sep 2014 11:18:49 -0700 (PDT) Subject: O'Reilly Python Certification In-Reply-To: <6657943d-4924-4f8f-8894-8e7541a9d5a5@googlegroups.com> References: <6657943d-4924-4f8f-8894-8e7541a9d5a5@googlegroups.com> Message-ID: <9e5d10eb-9111-4843-a106-6d1c4610472c@googlegroups.com> I just completed all four modules and Kirby was my instructor. I really enjoyed the class and got a lot out of it. I am not a developer, so common concepts like objects were new to me, whereas standard data structures like lists, dicts, etc. were already known. It definitely allowed me to increase my overall understanding of common programming concepts while I learned the pythonic way to implement them. I recommend the class. It's a bit pricey, so best if your employer can foot the bill. From tjreedy at udel.edu Wed Sep 10 14:26:38 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 10 Sep 2014 14:26:38 -0400 Subject: Why Python has moved to a multilingual Unicode model (OT) In-Reply-To: References: <5410420c$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 9/10/2014 1:57 PM, mm0fmf wrote: > On 10/09/2014 14:27, wxjmfauth at gmail.com wrote: >> [quoted trollpost deleted] By quoting spam and trolls, you become a spam/troll distributor yourself, and thrust same before people who missed (or blocked) the original. Please don't do this. Best to completely ignore such. > [insulting response deleted] Insults are also not wanted. They have more of a negative effect on bystanders than the intended target. Again, you are aiding the troll poster you purport to oppose. Our intention is for python-list to be a polite, mutually respectful discussion for discussion of Python and how to use it well. -- Terry Jan Reedy, python-list moderator From jazeltq at 163.com Thu Sep 11 00:00:03 2014 From: jazeltq at 163.com (Li Tianqing) Date: Thu, 11 Sep 2014 12:00:03 +0800 (CST) Subject: recursive closure Message-ID: Hello, Can someone explain me why gc(CPython) can not collect recursive closure's cycle reference? There is no __del__ there, why gc can not collect? After many times gc collect, i also see objects like below in gc.garbage. So i ask why gc can not collect them? Thanks a lot. (, ), , , [1], , (, ), , , [1], , (, ), , , [1], , (, ), , , [1], , (, ), , , [1], , (, ), , , [1], , (, ), , The test program is below. #!/usr/bin/env python import ipdb import gc gc.set_debug(gc.DEBUG_LEAK) def A(): N = [1] def aa(n): if n in N: return 1 else: return n * aa(n-1) x = 33 + aa(10) #ipdb.set_trace() print x if __name__ == '__main__': while xrange(1000): A() -- Best Li Tianqing -------------- next part -------------- An HTML attachment was scrubbed... URL: From vinirma2008 at yahoo.com Thu Sep 11 01:58:10 2014 From: vinirma2008 at yahoo.com (vinirma2008 at yahoo.com) Date: Wed, 10 Sep 2014 22:58:10 -0700 (PDT) Subject: Enterprise Data Warehouse Business Analyst in Banking domain Required for Qatar Message-ID: VAM SYSTEMS is a Business Consulting, IT Technology Solutions and Services company with operations in UAE, Qatar, Bahrain, USA, Australia, Singapore &India. VAM SYSTEMS is currently looking for Enterprise Data Warehouse Business Analyst for our Qatar operations with the following skill set and terms and conditions: Skill Set required: * 3-8 years in data warehousing environment * Should have experience in Business Analyst. * Banking experience is mandatory. * Knowledge of the design and implementation of the data warehouse life cycle * Experience in ETL design and Implementation * Good knowledge of data quality and data analysis * Exposed to IBM datastage tool * Used Data Modeller tool * Exposed to Oracle, MS SQL, ERWIN * Exposed to BI tools (Cognos BI 8.4 or 10.2) Tasks * Design or Works with IBM data modeler representative on developing the Banking Data warehouse System of Record (SoR) and Data Marts (Analysis area). * Analyzes operational source systems, business processes, data files and data files structure to determine source systems and source files to be extracted and map accordingly source to target * Analyzes data gaps and impact on deliverables * Team player * Excellent communication skills * Handle all the documentation related to EDW from mapping to design documents. Responsibility: * Issues and assess Risk, Error and Change requests in respective Forms * Develops deliverables; Business requirements documents, Mapping documents, business transformations rules documents, Data mart dimensions and facts, Reports dimensions and measures matrixes documents * Develops test strategy, plan, and test phases Domain: Bank Terms and conditions: Joining time frame: 2 weeks (maximum 1 month). The selected candidates shall join VAM SYSTEMS - Qatar and shall be deputed to one of the leading Banks in Qatar. Should you be interested in this opportunity, please send your latest resume in MS Word format at the earliest at ambili.krishnan at vamsystems.com or call us +91 476 2681150. From wxjmfauth at gmail.com Thu Sep 11 02:20:48 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 10 Sep 2014 23:20:48 -0700 (PDT) Subject: Why Python has moved to a multilingual Unicode model (OT) In-Reply-To: References: <5410420c$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <6e9947a6-d8d9-4ff0-89fc-617aa0bc3ac8@googlegroups.com> Le mercredi 10 septembre 2014 20:27:21 UTC+2, Terry Reedy a ?crit?: > On 9/10/2014 1:57 PM, mm0fmf wrote: > > > On 10/09/2014 14:27, wxjmfauth at gmail.com wrote: > > >> [quoted trollpost deleted] > > > A troll? I'm only reproducing what the Unicode doc says. I extended it to the general "coding of characters" problem. ascii, iso-*, Unicode (the utf's), cp*, ... All coding schemes work and are based on the same principles. jmf From ian.g.kelly at gmail.com Thu Sep 11 02:37:49 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 11 Sep 2014 00:37:49 -0600 Subject: recursive closure In-Reply-To: References: Message-ID: On Wed, Sep 10, 2014 at 10:00 PM, Li Tianqing wrote: > gc.set_debug(gc.DEBUG_LEAK) The DEBUG_LEAK flag implies the DEBUG_SAVEALL flag, which causes all unreachable objects to be appended to gc.garbage rather than freed. https://docs.python.org/3/library/gc.html#gc.DEBUG_SAVEALL Try not setting the flag, and I think you will find that gc.garbage no longer accumulates. From info at wingware.com Thu Sep 11 09:04:15 2014 From: info at wingware.com (Wingware) Date: Thu, 11 Sep 2014 09:04:15 -0400 Subject: ANN: Wing IDE 5.0.9 released Message-ID: <54119DCF.1050403@wingware.com> Hi, Wingware has released version 5.0.9 of Wing IDE, our cross-platform integrated development environment for the Python programming language. Wing IDE includes a professional quality code editor with vi, emacs, visual studio, and other key bindings, auto-completion, call tips, goto-definition, find uses, refactoring, context-aware auto-editing, a powerful graphical debugger, version control, unit testing, search, and many other features. For details see http://wingware.com/ Changes in this minor release include: Ability to mark a range of code in the editor for easy reevaluation in the Python Shell or Debug Probe Optimized multi-file searching Improved goto-definition in the Python Shell and Debug Probe Preliminary support for OS X 10.10 (Yosemite) Several VI mode fixes Improved visit history Fixed crashing on some mako files Recursively copy directories dragged and dropped in the Project tool Fix problems with typing into block selections About 24 other improvements; see the change log for details For details see http://wingware.com/pub/wingide/5.0.9/CHANGELOG.txt A summary of new features in Wing 5: Native GUI on OS X and better overall OS-native look and feel Draggable tools and editors Configurable toolbar and editor & project context menus Lockable editor splits and mode to open different files in each split Sharable color palettes and syntax highlighting configurations Auto-editing is on by default (except some operations that have a learning curve) Optional Python Turbo completion (context-appropriate completion on all non-symbol keys) Improved Source Assistant with PEP 287 docstring rendering and return types Move debug program counter Named file sets New Project dialog Sharable launch configurations and named entry points Asynchronous I/O in Debug Probe and Python Shell More control over unit testing environment Initial preferences dialog for new users Support for Python 3.4 and Stackless Python 2.7 and 3.3 Support for Django 1.6 Support for matplotlib on Anaconda and with MacOSX backend Support for Maya 2015, MotionBuilder 2015, Nuke 8, and Source Filmmaker Improved integrated and PDF documentation Expanded and rewritten tutorial Multiple selections Debug stepping by physical line, statement, and block Mark active range in editor for Python Shell and Debug Probe For more information on what's new in Wing 5, see http://wingware.com/wingide/whatsnew Free trial: http://wingware.com/wingide/trial Downloads: http://wingware.com/downloads Feature list: http://wingware.com/wingide/features Sales: http://wingware.com/store/purchase Upgrades: https://wingware.com/store/upgrade Questions? Don't hesitate to email us at support at wingware.com. Thanks, -- Stephan Deibel Wingware | Python IDE The Intelligent Development Environment for Python Programmers wingware.com From travisgriggs at gmail.com Thu Sep 11 11:30:19 2014 From: travisgriggs at gmail.com (Travis Griggs) Date: Thu, 11 Sep 2014 08:30:19 -0700 Subject: Newer Debian versions of python on older Debian distros? In-Reply-To: References: <5D152EC0-CDBB-4AC9-B074-B648074CE372@gmail.com> Message-ID: On Sep 8, 2014, at 5:06 PM, Chris Angelico wrote: > Alternatively, you could just run Debian Jessie. I have a few Jessie > systems on the network, with a Python 3.4 IIRC, and there've been no > stability problems lately. Both options are pretty easy. In the end, we were able to get jessie running on this little board (it?s an Atmel Xplained SAMA5D3 which boasts one of the lowest linux power consumptions). And that solved our problems. From travisgriggs at gmail.com Thu Sep 11 13:48:07 2014 From: travisgriggs at gmail.com (Travis Griggs) Date: Thu, 11 Sep 2014 10:48:07 -0700 Subject: Example of python service running under systemd? Message-ID: I?ve been reading lots of systemd docs. And blogs. Etc. At this point, I think I would benefit from learning by example? Does anyone have an example .service file that they use to launch a long running service written as a python program? If there is any example of what you changed to your python program itself, that to would be really instructional for me. From kwpolska at gmail.com Thu Sep 11 14:18:55 2014 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Thu, 11 Sep 2014 20:18:55 +0200 Subject: Example of python service running under systemd? In-Reply-To: References: Message-ID: On Thu, Sep 11, 2014 at 7:48 PM, Travis Griggs wrote: > I?ve been reading lots of systemd docs. And blogs. Etc. At this point, I think I would benefit from learning by example? > > Does anyone have an example .service file that they use to launch a long running service written as a python program? > > If there is any example of what you changed to your python program itself, that to would be really instructional for me. > -- > https://mail.python.org/mailman/listinfo/python-list Depends what you want. If you are running a Python web app, you can use uWSGI Emperor, which plugs into systemd nicely and provides a .service file in the docs (which also ships with the Arch Linux package). Otherwise, there are various ways, and this all depends on how you structure this and your needs. Use Type=simple and you won?t need any changes to your program, or use one of the more magical methods and implement them. Describe your needs to get more details. -- Chris ?Kwpolska? Warrick PGP: 5EAAEA16 stop html mail | always bottom-post | only UTF-8 makes sense From vimal.rughani at gmail.com Thu Sep 11 15:20:33 2014 From: vimal.rughani at gmail.com (Vimal Rughani) Date: Thu, 11 Sep 2014 12:20:33 -0700 (PDT) Subject: How to create python web framework for ERP In-Reply-To: References: Message-ID: On Tuesday, 9 September 2014 13:55:24 UTC+5:30, Vimal Rughani wrote: > Hi All, > > > > Greetings ! > > > > I am bit familiar with Django and Python. I want to create ERP on python. Initially I feel Django will be good option for My Own ERP, but after working bit on that I feel it doesn't fit with my requirement. So I decided to create my own python based web framework for ERP. Can you please suggest me better book / video / resources / content which help me to build proper web framework for ERP. > > > > Thanks Thanks to all for your kind support. I looking into different suggestions given by you. Thanks again for your time From airween at gmail.com Thu Sep 11 15:30:18 2014 From: airween at gmail.com (Ervin =?utf-8?Q?Heged=C3=BCs?=) Date: Thu, 11 Sep 2014 21:30:18 +0200 Subject: Thread-ID - how much could be? Message-ID: <20140911193018.GA24416@arxnet.hu> Hello, I've made a long-time running daemon, which uses threads. Looks like that works perfectly, now I'm looking at the exceptions :). In the log, I found an interesting message: Exception in thread Thread-82: ... The main function allows 2 thread to run simultaniously, and if the thread finished, then it joined with th.join(), where the "th" is the thread item, derived from threading.Thread class. My question is: how much thread ID could be totally? Is there any maximum number? And if the thread reached that, what will be done? Overlflowed? Couting from 0 again? Thanks, a. -- I ? UTF-8 From oselaji at yahoo.com Thu Sep 11 15:31:38 2014 From: oselaji at yahoo.com (osemen tosin) Date: Thu, 11 Sep 2014 12:31:38 -0700 Subject: Problem Installing Python Message-ID: <1410463898.85725.YahooMailNeo@web161503.mail.bf1.yahoo.com> Hi there, I tried installing Python and I could not continue without getting this error. "There is a problem with this installer package. A DLL required for this install to complete could not be run. Contact your support personnel or vendor package." Please I need your help. -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Thu Sep 11 15:48:18 2014 From: __peter__ at web.de (Peter Otten) Date: Thu, 11 Sep 2014 21:48:18 +0200 Subject: Thread-ID - how much could be? References: <20140911193018.GA24416@arxnet.hu> Message-ID: Ervin Heged?s wrote: > I've made a long-time running daemon, which uses threads. Looks > like that works perfectly, now I'm looking at the exceptions :). > > In the log, I found an interesting message: > > Exception in thread Thread-82: > ... > > The main function allows 2 thread to run simultaniously, and if > the thread finished, then it joined with th.join(), where the > "th" is the thread item, derived from threading.Thread class. > > My question is: how much thread ID could be totally? Is there any > maximum number? And if the thread reached that, what will be > done? Overlflowed? Couting from 0 again? A quick peak into threading.py reveals # Helper to generate new thread names _counter = 0 def _newname(template="Thread-%d"): global _counter _counter += 1 return template % _counter class Thread: ... def __init__(self, group=None, target=None, name=None, args=(), kwargs=None, *, daemon=None): ... self._name = str(name or _newname()) There is no upper limit to the thread name other than that you will eventually run out of memory ;) From travisgriggs at gmail.com Thu Sep 11 17:06:48 2014 From: travisgriggs at gmail.com (Travis Griggs) Date: Thu, 11 Sep 2014 14:06:48 -0700 Subject: Example of python service running under systemd? In-Reply-To: References: Message-ID: <6B97B7A5-0816-401E-9BDD-A23FFC646985@gmail.com> On Sep 11, 2014, at 11:18 AM, Chris ?Kwpolska? Warrick wrote: > Depends what you want. Mine is not a web service. My main.py looks like this: #!/usr/bin/env python3 import cycle import pushTelemetry from threading import Thread def main(): Thread(target=pushTelemetry.udpLoop).start() Thread(target=cycle.cycleLoop).start() if __name__ == '__main__': main() It basically creates two threads, one which does some local processing and control, the other which periodically does reporting via udp packets. I use the dual threads because they both work with a shared serial port at times, so I have to synchronize access through that. What I want is to have this startup, after my board has it?s networking layer up and running (and hopefully a valid ip address by then), and to just keep running forever From airween at gmail.com Thu Sep 11 17:29:21 2014 From: airween at gmail.com (Ervin =?utf-8?Q?Heged=C3=BCs?=) Date: Thu, 11 Sep 2014 23:29:21 +0200 Subject: Example of python service running under systemd? In-Reply-To: <6B97B7A5-0816-401E-9BDD-A23FFC646985@gmail.com> References: <6B97B7A5-0816-401E-9BDD-A23FFC646985@gmail.com> Message-ID: <20140911212921.GB26465@arxnet.hu> Hi Travis, On Thu, Sep 11, 2014 at 02:06:48PM -0700, Travis Griggs wrote: > > On Sep 11, 2014, at 11:18 AM, Chris ?Kwpolska? Warrick wrote: > > > Depends what you want. > > Mine is not a web service. My main.py looks like this: > > #!/usr/bin/env python3 > > import cycle > import pushTelemetry > from threading import Thread > > def main(): > Thread(target=pushTelemetry.udpLoop).start() > Thread(target=cycle.cycleLoop).start() > > if __name__ == '__main__': > main() > > It basically creates two threads, one which does some local processing and control, the other which periodically does reporting via udp packets. I use the dual threads because they both work with a shared serial port at times, so I have to synchronize access through that. > > What I want is to have this startup, after my board has it?s networking layer up and running (and hopefully a valid ip address by then), and to just keep running forever may be you think about the fork(), eg: if __name__ == "__main__": ...other codes, eg. drop root privileges, ... ...check arguments... try: pid = os.fork() if pid > 0: #print "Daemon started (pid: %d)" % (pid) sys.exit(0) except OSError, e: print >>sys.stderr, "fork #1 failed: %d (%s)" % (e.errno, e.strerror) sys.exit(1) os.chdir("/") os.setsid() os.umask(0) # do second fork try: pid = os.fork() if pid > 0: #print "Daemon started (pid: %d)" % (pid) sys.exit(0) except OSError, e: print >>sys.stderr, "fork #2 failed: %d (%s)" % (e.errno, e.strerror) sys.exit(1) main() regards, a. -- I ? UTF-8 From airween at gmail.com Thu Sep 11 17:32:29 2014 From: airween at gmail.com (Ervin =?utf-8?Q?Heged=C3=BCs?=) Date: Thu, 11 Sep 2014 23:32:29 +0200 Subject: Thread-ID - how much could be? In-Reply-To: References: <20140911193018.GA24416@arxnet.hu> Message-ID: <20140911213229.GC26465@arxnet.hu> Hi Peter, thanks for the reply, On Thu, Sep 11, 2014 at 09:48:18PM +0200, Peter Otten wrote: > Ervin Heged?s wrote: > > > Exception in thread Thread-82: > > ... > > My question is: how much thread ID could be totally? Is there any > > maximum number? And if the thread reached that, what will be > > done? Overlflowed? Couting from 0 again? > > A quick peak into threading.py reveals > > # Helper to generate new thread names > _counter = 0 > def _newname(template="Thread-%d"): > global _counter > _counter += 1 > return template % _counter > > class Thread: > ... > def __init__(self, group=None, target=None, name=None, > args=(), kwargs=None, *, daemon=None): > ... > self._name = str(name or _newname()) > > > There is no upper limit to the thread name other than that you will > eventually run out of memory ;) thanks - I hope that the memory will not run out by these threads... :) Anyway, that means, on my system: >>> import sys >>> print sys.maxint 9223372036854775807 the couter could be 9223372036854775807? And after? :) Thanks, a. -- I ? UTF-8 From __peter__ at web.de Thu Sep 11 18:02:50 2014 From: __peter__ at web.de (Peter Otten) Date: Fri, 12 Sep 2014 00:02:50 +0200 Subject: Thread-ID - how much could be? References: <20140911193018.GA24416@arxnet.hu> <20140911213229.GC26465@arxnet.hu> Message-ID: Ervin Heged?s wrote: > Hi Peter, > > thanks for the reply, > > On Thu, Sep 11, 2014 at 09:48:18PM +0200, Peter Otten wrote: >> Ervin Heged?s wrote: >> >> > Exception in thread Thread-82: >> > ... >> > My question is: how much thread ID could be totally? Is there any >> > maximum number? And if the thread reached that, what will be >> > done? Overlflowed? Couting from 0 again? >> >> A quick peak into threading.py reveals >> >> # Helper to generate new thread names >> _counter = 0 >> def _newname(template="Thread-%d"): >> global _counter >> _counter += 1 >> return template % _counter >> >> class Thread: >> ... >> def __init__(self, group=None, target=None, name=None, >> args=(), kwargs=None, *, daemon=None): >> ... >> self._name = str(name or _newname()) >> >> >> There is no upper limit to the thread name other than that you will >> eventually run out of memory ;) > > thanks - I hope that the memory will not run out by these > threads... :) > > Anyway, that means, on my system: > >>>> import sys >>>> print sys.maxint > 9223372036854775807 > > the couter could be 9223372036854775807? > > And after? :) Try it! >>> print sys.maxint + 1 9223372036854775808 When you start one thread per second >>> sys.maxint / (60*60 * 24 * 365.25) 292271023045.3132 after less than 300 billion years the only thing that will change is the type: >>> type(sys.maxint) >>> type(sys.maxint + 1) From emile at fenx.com Thu Sep 11 19:02:50 2014 From: emile at fenx.com (Emile van Sebille) Date: Thu, 11 Sep 2014 16:02:50 -0700 Subject: Problem Installing Python In-Reply-To: <1410463898.85725.YahooMailNeo@web161503.mail.bf1.yahoo.com> References: <1410463898.85725.YahooMailNeo@web161503.mail.bf1.yahoo.com> Message-ID: On 9/11/2014 12:31 PM, osemen tosin wrote: > Hi there, > > I tried installing Python and I could not continue without getting this > error. > > "There is a problem with this installer package. A DLL required for this > install to complete could not be run. Contact your support personnel or > vendor package." > > Please I need your help. Well, I suspect you're on windows, so I'd recommend you download and install the appropriate activestate distribution of python. See http://www.activestate.com/activepython/downloads Emile From tjreedy at udel.edu Thu Sep 11 19:11:43 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 11 Sep 2014 19:11:43 -0400 Subject: Problem Installing Python In-Reply-To: <1410463898.85725.YahooMailNeo@web161503.mail.bf1.yahoo.com> References: <1410463898.85725.YahooMailNeo@web161503.mail.bf1.yahoo.com> Message-ID: On 9/11/2014 3:31 PM, osemen tosin wrote: > Hi there, > > I tried installing Python and I could not continue without getting this > error. > > "There is a problem with this installer package. A DLL required for this > install to complete could not be run. Contact your support personnel or > vendor package." Which version of Windows? Which version of Python? Did you try re-downloading? Are any versions already installed? Do they run? What *exactly* did you do? What happened before the error occurred? Did you run as admin or get the permission box? -- Terry Jan Reedy From travisgriggs at gmail.com Thu Sep 11 19:45:56 2014 From: travisgriggs at gmail.com (Travis Griggs) Date: Thu, 11 Sep 2014 16:45:56 -0700 Subject: Example of python service running under systemd? In-Reply-To: <20140911212921.GB26465@arxnet.hu> References: <6B97B7A5-0816-401E-9BDD-A23FFC646985@gmail.com> <20140911212921.GB26465@arxnet.hu> Message-ID: <6AAD5ED8-32C9-42BA-A532-C4C1C27BB01A@gmail.com> On Sep 11, 2014, at 2:29 PM, Ervin Heged?s wrote: > Hi Travis, > > On Thu, Sep 11, 2014 at 02:06:48PM -0700, Travis Griggs wrote: >> >> On Sep 11, 2014, at 11:18 AM, Chris ?Kwpolska? Warrick wrote: >> >>> Depends what you want. >> >> Mine is not a web service. My main.py looks like this: >> >> #!/usr/bin/env python3 >> >> import cycle >> import pushTelemetry >> from threading import Thread >> >> def main(): >> Thread(target=pushTelemetry.udpLoop).start() >> Thread(target=cycle.cycleLoop).start() >> >> if __name__ == '__main__': >> main() >> >> It basically creates two threads, one which does some local processing and control, the other which periodically does reporting via udp packets. I use the dual threads because they both work with a shared serial port at times, so I have to synchronize access through that. >> >> What I want is to have this startup, after my board has it?s networking layer up and running (and hopefully a valid ip address by then), and to just keep running forever > > may be you think about the fork(), eg: > > if __name__ == "__main__": > ...other codes, eg. drop root privileges, ... > ...check arguments... > try: > pid = os.fork() > if pid > 0: > #print "Daemon started (pid: %d)" % (pid) > sys.exit(0) > except OSError, e: > print >>sys.stderr, "fork #1 failed: %d (%s)" % (e.errno, e.strerror) > sys.exit(1) > > os.chdir("/") > os.setsid() > os.umask(0) > > # do second fork > try: > pid = os.fork() > if pid > 0: > #print "Daemon started (pid: %d)" % (pid) > sys.exit(0) > except OSError, e: > print >>sys.stderr, "fork #2 failed: %d (%s)" % (e.errno, e.strerror) > sys.exit(1) > > main() OK, I?m probably going to show my naivety about something simple here? I thought a ?fork? essentially created a memory copy of the original process and let it go off running. The problem is, in the bowels of the code executing in those loops, I access a single instance of a threading.RLock, so that I can avoid both threads trying to do transactions with a single serial port at the same time. If I end up with two copies of the base process, unhooked from their parent, does that RLock still remain valid between the two? I thought since they were complete different copies of the same memory, they would no longer be coordinated. Is this a day where I discover something new? From rosuav at gmail.com Thu Sep 11 20:06:59 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 12 Sep 2014 10:06:59 +1000 Subject: Example of python service running under systemd? In-Reply-To: References: Message-ID: On Fri, Sep 12, 2014 at 3:48 AM, Travis Griggs wrote: > I?ve been reading lots of systemd docs. And blogs. Etc. At this point, I think I would benefit from learning by example? > > Does anyone have an example .service file that they use to launch a long running service written as a python program? > > If there is any example of what you changed to your python program itself, that to would be really instructional for me. Yeah, I did that for the Yosemite Project: https://github.com/Rosuav/Yosemite The main program is Python, but all the systemd code comes from a Pike script that creates a bash script that creates the systemd file. Yes, that's a little convoluted... Here's the relevant shell script part, in case you don't want to dig it out of auth.pike: #!/bin/bash [ "$1" = "install" ] && [ -d /etc/systemd/system ] && { echo "[Unit] Description=Yosemite Project [Service] # The user, path, and X display are derived at installation time # from the attributes of the yos script. Reinstall to reset them. Environment=DISPLAY=$DISPLAY User=`stat -c %u $0` ExecStart=`readlink -e $0` # If the network isn't available yet, restart until it is. Restart=on-failure RestartSec=10 [Install] WantedBy=multi-user.target " >/etc/systemd/system/yos.service # Note that some of this will fail if systemd is installed # but isn't the default init system. In that case, well, you # can't use this method of autostarting. TODO: Provide some # other ways to autostart (eg for Upstart and/or sysvinit). systemctl --system daemon-reload systemctl enable yos.service echo Installed as yos.service. systemctl start yos.service exit } # ... blah blah various setup python Yosemite.py This has some complications that you probably don't need, like that the owner of the script should become the user that runs it (chances are you can hard-code this, or run it as root and have it drop privileges itself, or something), and it needs to restart on failure, as it has to establish an sshfs mount before starting the main program. But it's a start. Note the three commands just before the script exits. Unlike sysvinit and upstart, systemd needs to be told to reload service files, and then you need to enable the service before it'll run on startup (and I like to start it immediately, to see that it's working properly). Took me a few hang-ups to figure that part out. Fortunately systemd can notice and give a warning if you change files and don't daemon-reload it; I'm not sure why it can't simply reload automatically (AIUI Upstart uses inotify on /etc/init - no idea why systemd can't do the same). ChrisA From steve+comp.lang.python at pearwood.info Thu Sep 11 21:29:56 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 12 Sep 2014 11:29:56 +1000 Subject: Thread-ID - how much could be? References: <20140911193018.GA24416@arxnet.hu> Message-ID: <54124c95$0$29991$c3e8da3$5496439d@news.astraweb.com> Ervin Heged?s wrote: [...] >> > My question is: how much thread ID could be totally? Is there any >> > maximum number? And if the thread reached that, what will be >> > done? Overlflowed? Couting from 0 again? [...] >> There is no upper limit to the thread name other than that you will >> eventually run out of memory ;) > > thanks - I hope that the memory will not run out by these > threads... :) > > Anyway, that means, on my system: > >>>> import sys >>>> print sys.maxint > 9223372036854775807 > > the couter could be 9223372036854775807? > > And after? :) Suppose you somehow managed to create 9223372036854775807 threads. If your computer has 16 GB of RAM available, that means that at most each thread can use: py> 16*1024*1024*1024/9223372036854775807 1.862645149230957e-09 bytes. That's not allowing any memory for the rest of your program, the Python interpreter, other processes, or the operating system. That is less than a single bit and clearly is impossible. You will run out of memory *long* before reaching 9223372036854775807 threads running at once. Suppose you don't have all the threads running at once, but you create and destroy the threads as quickly as possible, so there is never more than one thread alive at a time (plus the main interpreter thread). Suppose you have an extremely fast computer that can create and destroy a billion threads per second, one thread per nanosecond. Then your program would need to run for: py> 9223372036854775807*1e-9/60/60/24/365 292.471208677536 years non-stop before reaching a count of sys.maxint. I know that some Linux systems can have an uptime over a year, perhaps even two years, but I think that nearly 300 years is asking a bit much. Your hardware probably won't keep working that long. -- Steven From skip at pobox.com Thu Sep 11 21:38:52 2014 From: skip at pobox.com (Skip Montanaro) Date: Thu, 11 Sep 2014 20:38:52 -0500 Subject: Thread-ID - how much could be? In-Reply-To: <54124c95$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <20140911193018.GA24416@arxnet.hu> <54124c95$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Sep 11, 2014 at 8:29 PM, Steven D'Aprano wrote: > Suppose you somehow managed to create 9223372036854775807 threads. If your > computer has 16 GB of RAM available, that means that at most each thread > can use: > > py> 16*1024*1024*1024/9223372036854775807 > 1.862645149230957e-09 > > bytes. Doesn't that calculation assume that they all have to be alive at the same time? (Maybe I missed it in earlier posts, but I don't think the OP indicated they'd have to all be active.) That said, I think the OP should probably be worrying about other ways his program could fail besides overflowing some nonexistent max thread id. :-) Skip From rosuav at gmail.com Thu Sep 11 21:49:07 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 12 Sep 2014 11:49:07 +1000 Subject: Thread-ID - how much could be? In-Reply-To: <54124c95$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <20140911193018.GA24416@arxnet.hu> <54124c95$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Sep 12, 2014 at 11:29 AM, Steven D'Aprano wrote: > I know that some Linux > systems can have an uptime over a year, perhaps even two years, but I think > that nearly 300 years is asking a bit much. Your hardware probably won't > keep working that long. I've had over two years of uptime. Currently looking at 85 wk 4d 02:11:28 since the UPS and power failed simultaneously, but before that, over two years. But what about a 32-bit build? You could blow 1<<31 in about a month of milliseconds, and I just tried, and on this 32-bit Windows box I have here, I can start 10K threads in under a second: >>> def test(n): def f(): pass start=time.time() for i in range(n): t=threading.Thread(target=f) return (time.time()-start)/n >>> test(10000) 6.562459468841553e-05 >>> test(100000) 6.906198978424073e-05 So if it's 7e-5 seconds per thread (65-69 microseconds), that'd be less than two days to blow a 32-bit maxint. You could probably keep even a Win 98 computer running that long! ChrisA From torriem at gmail.com Thu Sep 11 22:03:54 2014 From: torriem at gmail.com (Michael Torrie) Date: Thu, 11 Sep 2014 20:03:54 -0600 Subject: Example of python service running under systemd? In-Reply-To: <20140911212921.GB26465@arxnet.hu> References: <6B97B7A5-0816-401E-9BDD-A23FFC646985@gmail.com> <20140911212921.GB26465@arxnet.hu> Message-ID: <5412548A.1090507@gmail.com> On 09/11/2014 03:29 PM, Ervin Heged?s wrote: >> It basically creates two threads, one which does some local processing and control, the other which periodically does reporting via udp packets. I use the dual threads because they both work with a shared serial port at times, so I have to synchronize access through that. >> >> What I want is to have this startup, after my board has it?s networking layer up and running (and hopefully a valid ip address by then), and to just keep running forever > > may be you think about the fork(), eg: No, you you don't need to do this. Systemd can handle all of that for you. Read up on the docs on creating systemd services. Here's a little blog post that has some good examples, both a non-daemonizing service and a daemonizing service: http://patrakov.blogspot.com/2011/01/writing-systemd-service-files.html Any executable file can be turned into a daemon service with systemd (whether or not it forks itself into the background). Thus any python script can easily be run from systemd. From rosuav at gmail.com Thu Sep 11 22:29:27 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 12 Sep 2014 12:29:27 +1000 Subject: Example of python service running under systemd? In-Reply-To: <5412548A.1090507@gmail.com> References: <6B97B7A5-0816-401E-9BDD-A23FFC646985@gmail.com> <20140911212921.GB26465@arxnet.hu> <5412548A.1090507@gmail.com> Message-ID: On Fri, Sep 12, 2014 at 12:03 PM, Michael Torrie wrote: > No, you you don't need to do this. Systemd can handle all of that for > you. Read up on the docs on creating systemd services. Here's a little > blog post that has some good examples, both a non-daemonizing service > and a daemonizing service: > > http://patrakov.blogspot.com/2011/01/writing-systemd-service-files.html > > Any executable file can be turned into a daemon service with systemd > (whether or not it forks itself into the background). Thus any python > script can easily be run from systemd. I strongly recommend making a non-daemonizing service. It's so much easier to debug - there's one mode of operation, the script just runs. You can then run that directly in a terminal, or via tmux, or via systemd - and I've done all three with Yosemite. In fact, I think I have instances here on the LAN that are doing all three, right now! ChrisA From torriem at gmail.com Thu Sep 11 23:09:47 2014 From: torriem at gmail.com (Michael Torrie) Date: Thu, 11 Sep 2014 21:09:47 -0600 Subject: Example of python service running under systemd? In-Reply-To: References: <6B97B7A5-0816-401E-9BDD-A23FFC646985@gmail.com> <20140911212921.GB26465@arxnet.hu> <5412548A.1090507@gmail.com> Message-ID: <541263FB.8060001@gmail.com> On 09/11/2014 08:29 PM, Chris Angelico wrote: > On Fri, Sep 12, 2014 at 12:03 PM, Michael Torrie wrote: >> No, you you don't need to do this. Systemd can handle all of that for >> you. Read up on the docs on creating systemd services. Here's a little >> blog post that has some good examples, both a non-daemonizing service >> and a daemonizing service: >> >> http://patrakov.blogspot.com/2011/01/writing-systemd-service-files.html >> >> Any executable file can be turned into a daemon service with systemd >> (whether or not it forks itself into the background). Thus any python >> script can easily be run from systemd. > > I strongly recommend making a non-daemonizing service. It's so much > easier to debug - there's one mode of operation, the script just runs. > You can then run that directly in a terminal, or via tmux, or via > systemd - and I've done all three with Yosemite. In fact, I think I > have instances here on the LAN that are doing all three, right now! Agreed 100%. If you want to run on a system without systemd, I recommend using supervisord[1] for turning your program into a daemon. It also does not require the app to fork. [1] http://supervisord.org/ From vhnguyenn at yahoo.com Fri Sep 12 01:15:31 2014 From: vhnguyenn at yahoo.com (Viet Nguyen) Date: Thu, 11 Sep 2014 22:15:31 -0700 (PDT) Subject: Why command os.popen works in python interactive mode but not in script debugger mode? Message-ID: Can anyone give me hint or reason why same command behaves differently in debugger mode from interactive mode: >From interactive mode: >>> import os >>> p = os.popen('date') >>> p.read() 'Thu Sep 11 11:18:07 PDT 2014\n' But from debugger mode in a script: >>> import os (Pdb) p = os.popen('date') *** SyntaxError: SyntaxError('invalid syntax', ('', 1, 1, "= os.popen('date')")) Can anyone help me why there is syntax here? Thanks, Viet From rosuav at gmail.com Fri Sep 12 01:26:04 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 12 Sep 2014 15:26:04 +1000 Subject: Why command os.popen works in python interactive mode but not in script debugger mode? In-Reply-To: References: Message-ID: On Fri, Sep 12, 2014 at 3:15 PM, Viet Nguyen wrote: > But from debugger mode in a script: >>>> import os > (Pdb) p = os.popen('date') > *** SyntaxError: SyntaxError('invalid syntax', ('', 1, 1, "= os.popen('date')")) > > > Can anyone help me why there is syntax here? > This is actually a command to the debugger. You say "p some_expression" and it prints out the value of some_expression. https://docs.python.org/2/library/pdb.html#debugger-commands """" Commands that the debugger doesn?t recognize are assumed to be Python statements and are executed in the context of the program being debugged. Python statements can also be prefixed with an exclamation point (!). """ So try this: !p = os.popen('date') ChrisA From cs at zip.com.au Thu Sep 11 23:41:00 2014 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 12 Sep 2014 13:41:00 +1000 Subject: Thread-ID - how much could be? In-Reply-To: <54124c95$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <54124c95$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20140912034100.GA14188@cskk.homeip.net> On 12Sep2014 11:29, Steven D'Aprano wrote: >[...]maxint. I know that some Linux >systems can have an uptime over a year, perhaps even two years, but I think >that nearly 300 years is asking a bit much. 2 years is nothing. Unless they have a particularly buggy kernel, most UNIX systems, Linux included, will stay up almost indefinitely. We've definitely had systems up for well over 2 years. >Your hardware probably won't >keep working that long. 300 years? Probably not. Regrettably. Cheers, Cameron Simpson We need a taxonomy for 'printing-that-is-no-longer-printing.' - overhead by WIRED at the Intelligent Printing conference Oct2006 From rosuav at gmail.com Fri Sep 12 01:41:51 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 12 Sep 2014 15:41:51 +1000 Subject: Thread-ID - how much could be? In-Reply-To: <20140912034100.GA14188@cskk.homeip.net> References: <54124c95$0$29991$c3e8da3$5496439d@news.astraweb.com> <20140912034100.GA14188@cskk.homeip.net> Message-ID: On Fri, Sep 12, 2014 at 1:41 PM, Cameron Simpson wrote: > On 12Sep2014 11:29, Steven D'Aprano > wrote: >> >> [...]maxint. I know that some Linux >> systems can have an uptime over a year, perhaps even two years, but I >> think >> that nearly 300 years is asking a bit much. > > > 2 years is nothing. Unless they have a particularly buggy kernel, most UNIX > systems, Linux included, will stay up almost indefinitely. We've definitely > had systems up for well over 2 years. > >> Your hardware probably won't >> keep working that long. > > > 300 years? Probably not. Regrettably. Once you get into the counting of years (rather than days), it's all down to hardware. How long before that hardware needs an upgrade? Does your incoming power have fail-overs? I don't currently have any servers with multiple power supplies, so if anything like that goes bung, my server's down. Doesn't matter how quickly I can bring up an equivalent on a different hunk of hardware, the uptime's gone. But yeah. 300 years? Good luck. I don't think anyone's ever going to hit that. ChrisA From rahuldbhagat at gmail.com Fri Sep 12 01:48:00 2014 From: rahuldbhagat at gmail.com (rahuldbhagat at gmail.com) Date: Thu, 11 Sep 2014 22:48:00 -0700 (PDT) Subject: pythonw.exe has stopped working Message-ID: Hello Folks, I'm using RIDE -- Robot Framework Test Data Editor RIDE 1.3 running on Python 2.7.6. When I click on some of my test case the RIDE GUI hangs and gives bellow error message. [Window Title] pythonw.exe [Main Instruction] pythonw.exe has stopped working [Content] A problem caused the program to stop working correctly. Windows will close the program and notify you if a solution is available. [Close program] It's strange that while it's able to open other test cases but fails on one particular test case. The distinguishing fact about the test case is that it is a big one using lots of keywords. I know it might work if I split my test case but have any of you encountered this problem and knows how to fix it ? some fix like providing more memory or specifying some parameter when pythonw.exe starts? Thank you very much in advance. Cheers, Rahul. From airween at gmail.com Fri Sep 12 02:06:51 2014 From: airween at gmail.com (Ervin =?utf-8?Q?Heged=C3=BCs?=) Date: Fri, 12 Sep 2014 08:06:51 +0200 Subject: Example of python service running under systemd? In-Reply-To: <5412548A.1090507@gmail.com> References: <6B97B7A5-0816-401E-9BDD-A23FFC646985@gmail.com> <20140911212921.GB26465@arxnet.hu> <5412548A.1090507@gmail.com> Message-ID: <20140912060651.GA3333@arxnet.hu> Hi Michael, On Thu, Sep 11, 2014 at 08:03:54PM -0600, Michael Torrie wrote: > >> What I want is to have this startup, after my board has it?s networking layer up and running (and hopefully a valid ip address by then), and to just keep running forever > > > > may be you think about the fork(), eg: > > No, you you don't need to do this. Systemd can handle all of that for > you. Read up on the docs on creating systemd services. Here's a little > blog post that has some good examples, both a non-daemonizing service > and a daemonizing service: > > http://patrakov.blogspot.com/2011/01/writing-systemd-service-files.html > > Any executable file can be turned into a daemon service with systemd > (whether or not it forks itself into the background). Thus any python > script can easily be run from systemd. thanks a lot, I didn't hear about that feature. Cheers, Ervin From airween at gmail.com Fri Sep 12 02:18:06 2014 From: airween at gmail.com (Ervin =?utf-8?Q?Heged=C3=BCs?=) Date: Fri, 12 Sep 2014 08:18:06 +0200 Subject: Example of python service running under systemd? In-Reply-To: References: <6B97B7A5-0816-401E-9BDD-A23FFC646985@gmail.com> <20140911212921.GB26465@arxnet.hu> <5412548A.1090507@gmail.com> Message-ID: <20140912061806.GB3333@arxnet.hu> Hi Chris, On Fri, Sep 12, 2014 at 12:29:27PM +1000, Chris Angelico wrote: > On Fri, Sep 12, 2014 at 12:03 PM, Michael Torrie wrote: > > > > Any executable file can be turned into a daemon service with systemd > > (whether or not it forks itself into the background). Thus any python > > script can easily be run from systemd. > > I strongly recommend making a non-daemonizing service. It's so much > easier to debug - there's one mode of operation, the script just runs. > You can then run that directly in a terminal, or via tmux, or via > systemd - and I've done all three with Yosemite. In fact, I think I > have instances here on the LAN that are doing all three, right now! is there any other reason outside the debugging? Of course, I've handled that in a simple way: parser = optparse.OptionParser() parser.add_option("-d", "--debug", action="count", dest="debug_mode", help="Start process in debug mode, not forking.") (options, args) = parser.parse_args() debug_mode = True if options.debug_mode is None: debug_mode = False try: pid = os.fork() if pid > 0: .... And of course, I've handled the signals, logfiles and so on... So, now I can run my app with -d, then it will not do the fork(), I'll see all messages and feedbacks. Elsewhere, the process will run in background. Anyway, thanks all comments from others. May be the life is easier with systemd, but that was my "5-minutes-finger-exercise" :) Thanks again, a. From airween at gmail.com Fri Sep 12 02:30:41 2014 From: airween at gmail.com (Ervin =?utf-8?Q?Heged=C3=BCs?=) Date: Fri, 12 Sep 2014 08:30:41 +0200 Subject: Thread-ID - how much could be? In-Reply-To: <54124c95$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <20140911193018.GA24416@arxnet.hu> <54124c95$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20140912063041.GC3333@arxnet.hu> Hi Steven, On Fri, Sep 12, 2014 at 11:29:56AM +1000, Steven D'Aprano wrote: > >>>> import sys > >>>> print sys.maxint > > 9223372036854775807 > > > > the couter could be 9223372036854775807? > > > > And after? :) > > Suppose you somehow managed to create 9223372036854775807 threads. If your > computer has 16 GB of RAM available, that means that at most each thread > can use: so, thanks for your and others answers - this was just a _theoretical_ question. What is the practice - that's an another thread. :) I just simply interested about this theory, not more. I don't care with-how-many-memories-needs-and-how-many-years-to-overflow that counter, but many people calculates that - thanks :) Cheers, a. From rosuav at gmail.com Fri Sep 12 04:15:00 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 12 Sep 2014 18:15:00 +1000 Subject: Example of python service running under systemd? In-Reply-To: <20140912061806.GB3333@arxnet.hu> References: <6B97B7A5-0816-401E-9BDD-A23FFC646985@gmail.com> <20140911212921.GB26465@arxnet.hu> <5412548A.1090507@gmail.com> <20140912061806.GB3333@arxnet.hu> Message-ID: On Fri, Sep 12, 2014 at 4:18 PM, Ervin Heged?s wrote: > is there any other reason outside the debugging? > > Of course, I've handled that in a simple way: > > parser = optparse.OptionParser() > > parser.add_option("-d", > "--debug", > action="count", > dest="debug_mode", > help="Start process in debug mode, not forking.") > > (options, args) = parser.parse_args() > > debug_mode = True > if options.debug_mode is None: > > debug_mode = False > try: > pid = os.fork() > if pid > 0: > .... > > And of course, I've handled the signals, logfiles and so on... 1) You don't need all of the above code. 2) You don't need to test all of that code. And that code is significantly abbreviated. In reality it's quite a bit longer. Having less code branches is itself an advantage. If I can accomplish everything with simple top-down code, why go for a -d option and then an alternative method that forks, forks again, handles signals, etc, etc, etc? (Although handling signals may still be important, if I want some kind of more orderly shutdown on SIGTERM, or if I want SIGHUP to do some sort of reload - not usually in Python, but my Pike code generally takes SIGHUP to mean "reload your code from the disk".) The simpler, the better. Less code => less bugs. ChrisA From rahuldbhagat at gmail.com Fri Sep 12 04:57:21 2014 From: rahuldbhagat at gmail.com (Rahul Bhagat) Date: Fri, 12 Sep 2014 01:57:21 -0700 (PDT) Subject: pythonw.exe has stopped working In-Reply-To: References: Message-ID: <45201191-331a-44a8-aa83-d49186aa3742@googlegroups.com> On Friday, 12 September 2014 11:18:25 UTC+5:30, Rahul Bhagat wrote: > Hello Folks, > > > > I'm using RIDE -- Robot Framework Test Data Editor > > RIDE 1.3 running on Python 2.7.6. > > > > When I click on some of my test case the RIDE GUI hangs and gives bellow error message. > > > > > > [Window Title] > > pythonw.exe > > > > [Main Instruction] > > pythonw.exe has stopped working > > > > [Content] > > A problem caused the program to stop working correctly. Windows will close the program and notify you if a solution is available. > > > > [Close program] > > > > > > It's strange that while it's able to open other test cases but fails on one particular test case. The distinguishing fact about the test case is that it is a big one using lots of keywords. > > > > I know it might work if I split my test case but have any of you encountered this problem and knows how to fix it ? some fix like providing more memory or specifying some parameter when pythonw.exe starts? > > > > > > Thank you very much in advance. > > > > Cheers, > > > > Rahul. UPDATE: Additional Windows Log Problem signature: Problem Event Name: APPCRASH Application Name: pythonw.exe Application Version: 0.0.0.0 Application Timestamp: 527fcf67 Fault Module Name: wxmsw28uh_core_vc.dll Fault Module Version: 2.8.12.1 Fault Module Timestamp: 4e21188a Exception Code: c0000005 Exception Offset: 000000000002516e OS Version: 6.1.7601.2.1.0.256.48 Locale ID: 1033 Additional Information 1: af6f Additional Information 2: af6f3f0509d68fb0a703e2e9a01d8095 Additional Information 3: 14ba Additional Information 4: 14ba7bfab2274826d4d9f81374905fca Read our privacy statement online: http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0409 If the online privacy statement is not available, please read our privacy statement offline: C:\Windows\system32\en-US\erofflps.txt From steve+comp.lang.python at pearwood.info Fri Sep 12 06:14:20 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 12 Sep 2014 20:14:20 +1000 Subject: pythonw.exe has stopped working References: Message-ID: <5412c77d$0$29974$c3e8da3$5496439d@news.astraweb.com> rahuldbhagat at gmail.com wrote: > It's strange that while it's able to open other test cases but fails on > one particular test case. The distinguishing ?fact about the test case is > that it is a big one using lots of keywords. Sounds like you've run out of memory, and Windows has killed the process. > I know it might work if I split my test case but have any of you > encountered this problem and knows how to fix it ? some fix like providing > more memory or specifying some parameter when pythonw.exe starts? Install more memory? It might help if you show us the code that crashes. -- Steven From serge.guelton at enst-bretagne.fr Fri Sep 12 03:45:32 2014 From: serge.guelton at enst-bretagne.fr (serge Guelton) Date: Fri, 12 Sep 2014 09:45:32 +0200 Subject: Pyston 0.2 released In-Reply-To: References: Message-ID: <20140912074532.GA4801@lakota> On Thu, Sep 11, 2014 at 12:52:15PM -0700, Kevin Modzelewski wrote: > > Hi all, we're excited to announce the existence of Pyston 0.2, a > much-improved version of our new Python JIT. The new > version features greatly improved language support, basic native C API > support, and an experimental GIL-free mode. Pyston is now in alpha, and is > still not ready for general use, but we have hit a significant milestone of > being able to run a number of existing benchmarks and standard libraries. > Hi Kevin, Great work! I wonder if (in an undetermined future) the following scenario could stand to optimize calls to native libraries, like numpy: - compile numpy into LLVM bytecode - when meeting a function with a bunch of numpy call, instead of using the CAPI, directly call functions from the numpy bytecode and optimize evertyhing as a whole? Keep up the good work! From marko at pacujo.net Fri Sep 12 07:33:17 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 12 Sep 2014 14:33:17 +0300 Subject: pythonw.exe has stopped working References: <5412c77d$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <877g199ipu.fsf@elektro.pacujo.net> Steven D'Aprano : > rahuldbhagat at gmail.com wrote: >> encountered this problem and knows how to fix it ? some fix like >> providing more memory or specifying some parameter when pythonw.exe >> starts? > > Install more memory? > > It might help if you show us the code that crashes. Reminds me of a Q&A column from my university's CS student newsletter in the 80's. It went something like this: Q. I finally managed to save enough money to buy a home computer. I read the user manual and wrote my first BASIC program as follows: 20 GOTO 20 I started the program with the RUN command, and it has been running since. What do I do now? I am new to computers, so no tech jargon, please. A. You can't expect shorter latencies in a computer in this price range. What we suggest, at a bare minimum, is a RAM upgrade to at least 64 kilobytes. The CPU might need to be replaced with the recently released 8 MHz model as well. [...] Marko From nomail at invalid.com Fri Sep 12 09:19:01 2014 From: nomail at invalid.com (ast) Date: Fri, 12 Sep 2014 15:19:01 +0200 Subject: =?iso-8859-1?Q?Changer_le_path_pour_l'acc=E8s_aux_modules?= Message-ID: <5412f2cb$0$2069$426a34cc@news.free.fr> bonjour Mon path est: >>> sys.path [' ', 'C:\\Python33\\Lib\\idlelib', 'C:\\Windows\\system32\\python33.zip', 'C:\\Python33\\DLLs', 'C:\\Python33\\lib', 'C:\\Python33', 'C:\\Python33\\lib\\site-packages', 'mypath'] Tout d'abord ? quoi correspond le ' ' vide au tout d?but ? Pourquoi y a t'il deux backslashs \\ entre les r?pertoires ? (sous windows normalement c'est un seul) Ensuite j'aimerais ajouter un r?pertoire de fa?on d?finitive, donc pas en utilisant sys.path.append(... apr?s chaque ouverture d'un shell. J'ai lu qu'il fallait changer une variable $PYTHONFILE mais ou exactement ? Je suis sous Windows Vista. Merci From nomail at invalid.com Fri Sep 12 09:20:52 2014 From: nomail at invalid.com (ast) Date: Fri, 12 Sep 2014 15:20:52 +0200 Subject: =?iso-8859-1?Q?Re:_Changer_le_path_pour_l'acc=E8s_aux_modules?= In-Reply-To: <5412f2cb$0$2069$426a34cc@news.free.fr> References: <5412f2cb$0$2069$426a34cc@news.free.fr> Message-ID: <5412f33b$0$2383$426a34cc@news.free.fr> "ast" a ?crit dans le message de news:5412f2cb$0$2069$426a34cc at news.free.fr... > bonjour > > Mon path est: > >>>> sys.path > [' ', 'C:\\Python33\\Lib\\idlelib', 'C:\\Windows\\system32\\python33.zip', > 'C:\\Python33\\DLLs', 'C:\\Python33\\lib', 'C:\\Python33', > 'C:\\Python33\\lib\\site-packages', 'mypath'] > > Tout d'abord ? quoi correspond le ' ' vide au tout d?but ? > Pourquoi y a t'il deux backslashs \\ entre les r?pertoires ? > (sous windows normalement c'est un seul) > > Ensuite j'aimerais ajouter un r?pertoire de fa?on d?finitive, > donc pas en utilisant sys.path.append(... apr?s chaque ouverture > d'un shell. > > J'ai lu qu'il fallait changer une variable $PYTHONFILE > mais ou exactement ? Je suis sous Windows Vista. > > Merci > Sorry I sent this message in the wrong forum. I intended to send it to fr.comp.lang.python From rosuav at gmail.com Fri Sep 12 09:34:47 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 12 Sep 2014 23:34:47 +1000 Subject: =?UTF-8?Q?Re=3A_Changer_le_path_pour_l=27acc=C3=A8s_aux_modules?= In-Reply-To: <5412f2cb$0$2069$426a34cc@news.free.fr> References: <5412f2cb$0$2069$426a34cc@news.free.fr> Message-ID: 2014-09-12 23:19 GMT+10:00 ast : > Tout d'abord ? quoi correspond le ' ' vide au tout d?but ? > Pourquoi y a t'il deux backslashs \\ entre les r?pertoires ? > (sous windows normalement c'est un seul) Hi! I'm afraid my French isn't very good, but Google Translate suggests you're asking about why there are two backslashes rather than one. I hope your English is good enough to comprehend my response; otherwise, you may find more help on a dedicated French language forum - sorry! The backslash has special meaning to Python strings. When they're displayed in a list, like that, strings get special characters marked. For instance, quotes and apostrophes will have backslashes in front of them. That means that the backslash has to be marked too - so it'll be shown with a second backslash. Try this instead: for path in sys.path: print(path) That'll show them with only one backslash, one per line. ChrisA From rosuav at gmail.com Fri Sep 12 09:36:05 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 12 Sep 2014 23:36:05 +1000 Subject: =?UTF-8?Q?Re=3A_Changer_le_path_pour_l=27acc=C3=A8s_aux_modules?= In-Reply-To: <5412f33b$0$2383$426a34cc@news.free.fr> References: <5412f2cb$0$2069$426a34cc@news.free.fr> <5412f33b$0$2383$426a34cc@news.free.fr> Message-ID: 2014-09-12 23:20 GMT+10:00 ast : > Sorry I sent this message in the wrong forum. > I intended to send it to fr.comp.lang.python Ah! Okay. That works too :) ChrisA From vhnguyenn at yahoo.com Fri Sep 12 09:39:22 2014 From: vhnguyenn at yahoo.com (Viet Nguyen) Date: Fri, 12 Sep 2014 06:39:22 -0700 (PDT) Subject: Why command os.popen works in python interactive mode but not in script debugger mode? In-Reply-To: References: Message-ID: <1cc97a34-b21a-4681-b361-117dd4a352fc@googlegroups.com> On Thursday, September 11, 2014 10:15:57 PM UTC-7, Viet Nguyen wrote: > Can anyone give me hint or reason why same command behaves differently in debugger mode from interactive mode: > > > > From interactive mode: > > > > >>> import os > > >>> p = os.popen('date') > > >>> p.read() > > 'Thu Sep 11 11:18:07 PDT 2014\n' > > > > But from debugger mode in a script: > > >>> import os > > (Pdb) p = os.popen('date') > > *** SyntaxError: SyntaxError('invalid syntax', ('', 1, 1, "= os.popen('date')")) > > > > > > Can anyone help me why there is syntax here? > > > > Thanks, > > Viet Thank you for your help. That resolved the issue. From skip at pobox.com Fri Sep 12 11:52:15 2014 From: skip at pobox.com (Skip Montanaro) Date: Fri, 12 Sep 2014 10:52:15 -0500 Subject: pylint for cython? Message-ID: I have slowly been converting some Python source to Cython. I'm pretty conservative in what changes I make, mostly sprinkling a few "cdef", "float" and "int" declarations around the pyx file. Still, conservative or not, it's enough to choke pylint. Rather than have to maintain a pure Python version of my code, it would be nice if pylint had a flag or if there was a "cylint" tool available. A few Google and PyPi searches failed to reveal anything. Is there something out there? Thanks, Skip -------------- next part -------------- An HTML attachment was scrubbed... URL: From gandalf at shopzeus.com Fri Sep 12 12:35:32 2014 From: gandalf at shopzeus.com (=?ISO-8859-2?Q?Nagy_L=E1szl=F3_Zsolt?=) Date: Fri, 12 Sep 2014 18:35:32 +0200 Subject: very lightweight gui for win32 + python 3.4 Message-ID: <541320D4.5030800@shopzeus.com> I wrote a small program that copies some files between directories. This is a special utility program for a particular customer. I could compile the program into a portable exe with cx_freeze, and the total size is below 10MB. This customer wants to use this utility on many computers. He wants me to display a dialog with a progress bar and possibly a label with some messages while files are copied, and also let the user answer a question by clicking a button instead of typing in "yes" or "no" into the console. So I need to create a GUI mode version of my program. That the customer should be able to see a progress bar. What kind of GUI toolkit should I use for this? I would like this to be lightweight, preferably under 5MB with a very easy API for simple things like create a dialog, put some labels and a progress bar on it, and finally close the dialog when the program is finished. (And of course, needs to work with cx Freeze.) I do not need a full featured cross platform GUI toolkit. What are my options? I have been looking at this: https://wiki.python.org/moin/GuiProgramming The only Windows specific lightweight frameworks are venster and Ocean but they have not been updated since ages. I know that I can do this using the win32 API, but I don't really want to learn how to build a dialog using win32 API calls and then process window message queues.... wxPython and Qt are well known but they are not exactly lightweight. What are my best options? Thanks, Laszlo -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. From rosuav at gmail.com Fri Sep 12 12:38:54 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 13 Sep 2014 02:38:54 +1000 Subject: very lightweight gui for win32 + python 3.4 In-Reply-To: <541320D4.5030800@shopzeus.com> References: <541320D4.5030800@shopzeus.com> Message-ID: On Sat, Sep 13, 2014 at 2:35 AM, Nagy L?szl? Zsolt wrote: > So I need to create a GUI mode version of my program. That the customer > should be able to see a progress bar. What kind of GUI toolkit should I use > for this? I would like this to be lightweight, preferably under 5MB with a > very easy API for simple things like create a dialog, put some labels and a > progress bar on it, and finally close the dialog when the program is > finished. (And of course, needs to work with cx Freeze.) > > I do not need a full featured cross platform GUI toolkit. What are my > options? > > I have been looking at this: > > https://wiki.python.org/moin/GuiProgramming > > The only Windows specific lightweight frameworks are venster and Ocean but > they have not been updated since ages. I know that I can do this using the > win32 API, but I don't really want to learn how to build a dialog using > win32 API calls and then process window message queues.... wxPython and Qt > are well known but they are not exactly lightweight. There's absolutely no reason to go Windows-specific. Use Tkinter - it's pretty light-weight. Comes with most Python distros. See how it goes in terms of code size - if it's unsuitable, then look at others, but start with the obvious option. ChrisA From stefan_ml at behnel.de Fri Sep 12 12:42:15 2014 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 12 Sep 2014 18:42:15 +0200 Subject: pylint for cython? In-Reply-To: References: Message-ID: Skip Montanaro schrieb am 12.09.2014 um 17:52: > I have slowly been converting some Python source to Cython. I'm pretty > conservative in what changes I make, mostly sprinkling a few "cdef", > "float" and "int" declarations around the pyx file. Still, conservative or > not, it's enough to choke pylint. Rather than have to maintain a pure > Python version of my code, it would be nice if pylint had a flag or if > there was a "cylint" tool available. If you really just do things like "cdef int x", I recommend using pure Python syntax for it (in a .py file). That way, you can just run pylint over it as before. http://docs.cython.org/src/tutorial/pure.html#static-typing Specifically, the "@cython.locals()" decorator might be all you need, or maybe some of the other things like "@cython.cfunc". Stefan From nmz787 at gmail.com Fri Sep 12 12:33:09 2014 From: nmz787 at gmail.com (Nathan McCorkle) Date: Fri, 12 Sep 2014 09:33:09 -0700 (PDT) Subject: Marco's atexit issue was: Re: ANN: wxPython 3.0.1.1 In-Reply-To: <180ac253-7f29-4157-aed6-38f929e00674@googlegroups.com> References: <5411246B.8060700@alldunn.com> <180ac253-7f29-4157-aed6-38f929e00674@googlegroups.com> Message-ID: <29a07ca1-990c-432a-9693-3dbc5f89f6f4@googlegroups.com> On Friday, September 12, 2014 1:14:41 AM UTC-7, Marco Prosperi wrote: > > > I'm trying to pass my application from wxpython2.9.4 to 3.0.1 but there > seems to be still some of the problems that made me skip wxpy2.9.5: when I > close the main window of my application (windows7-64bit, python 2.7) I get > exceptions like this below (none with wxpy2.9.4). How can I avoid that my > users get this? this happens after my OnExit function is completed > > Marco > > Error in atexit._run_exitfuncs: > Traceback (most recent call last): > File "C:\Programmi\Python27\lib\atexit.py", line 24, in _run_exitfuncs > func(*targs, **kargs) > PyAssertionError: C++ assertion "GetEventHandler() == this" failed at > ..\..\src\ > common\wincmn.cpp(478) in wxWindowBase::~wxWindowBase(): any pushed event > handle > rs must have been removed > Error in sys.exitfunc: > Traceback (most recent call last): > File "C:\Programmi\Python27\lib\atexit.py", line 24, in _run_exitfuncs > func(*targs, **kargs) > wx._core.PyAssertionError: C++ assertion "GetEventHandler() == this" > failed > at . > .\..\src\common\wincmn.cpp(478) in wxWindowBase::~wxWindowBase(): any > pushed eve > nt handlers must have been removed > Post some code? Sounds like you're trying to interact with a wxPython object in a function using atexit.register(AtExit)... which likely is always going to happen after the wx Destroy method is all done. -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Fri Sep 12 13:08:18 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 12 Sep 2014 18:08:18 +0100 Subject: very lightweight gui for win32 + python 3.4 In-Reply-To: References: <541320D4.5030800@shopzeus.com> Message-ID: On 12/09/2014 17:38, Chris Angelico wrote: > On Sat, Sep 13, 2014 at 2:35 AM, Nagy L?szl? Zsolt wrote: >> So I need to create a GUI mode version of my program. That the customer >> should be able to see a progress bar. What kind of GUI toolkit should I use >> for this? I would like this to be lightweight, preferably under 5MB with a >> very easy API for simple things like create a dialog, put some labels and a >> progress bar on it, and finally close the dialog when the program is >> finished. (And of course, needs to work with cx Freeze.) >> >> I do not need a full featured cross platform GUI toolkit. What are my >> options? >> >> I have been looking at this: >> >> https://wiki.python.org/moin/GuiProgramming >> >> The only Windows specific lightweight frameworks are venster and Ocean but >> they have not been updated since ages. I know that I can do this using the >> win32 API, but I don't really want to learn how to build a dialog using >> win32 API calls and then process window message queues.... wxPython and Qt >> are well known but they are not exactly lightweight. > > There's absolutely no reason to go Windows-specific. Use Tkinter - > it's pretty light-weight. Comes with most Python distros. See how it > goes in terms of code size - if it's unsuitable, then look at others, > but start with the obvious option. > > ChrisA > As IDLE comes with all Python distros shouldn't the same apply to tkinter as that's what IDLE is based around? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rosuav at gmail.com Fri Sep 12 13:26:00 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 13 Sep 2014 03:26:00 +1000 Subject: very lightweight gui for win32 + python 3.4 In-Reply-To: References: <541320D4.5030800@shopzeus.com> Message-ID: On Sat, Sep 13, 2014 at 3:08 AM, Mark Lawrence wrote: >> There's absolutely no reason to go Windows-specific. Use Tkinter - >> it's pretty light-weight. Comes with most Python distros. See how it >> goes in terms of code size - if it's unsuitable, then look at others, >> but start with the obvious option. >> >> ChrisA >> > > As IDLE comes with all Python distros shouldn't the same apply to tkinter as > that's what IDLE is based around? It doesn't, though. It comes with most. It's perfectly possible to have a minimal Python with no Tkinter and therefore no Idle; on my Debian systems, there's a separate "python-tk" package on which "idle" depends, but "python" doesn't. rosuav at dewey:~$ python Python 2.7.8 (default, Aug 18 2014, 10:01:58) [GCC 4.9.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import Tkinter Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 42, in raise ImportError, str(msg) + ', please install the python-tk package' ImportError: No module named _tkinter, please install the python-tk package I believe Tkinter and Idle come with all Windows MSI installers downloaded from python.org, but I can't state even that with certainty, so I just kept it to "most" for safety. If I'd said "all", I'm pretty sure something would have proven me wrong, and knowing my luck, it would have been the OP's system :) ChrisA From theller at ctypes.org Fri Sep 12 14:35:37 2014 From: theller at ctypes.org (Thomas Heller) Date: Fri, 12 Sep 2014 20:35:37 +0200 Subject: very lightweight gui for win32 + python 3.4 In-Reply-To: References: <541320D4.5030800@shopzeus.com> Message-ID: Am 12.09.2014 18:38, schrieb Chris Angelico: > On Sat, Sep 13, 2014 at 2:35 AM, Nagy L?szl? Zsolt wrote: >> So I need to create a GUI mode version of my program. That the customer >> should be able to see a progress bar. What kind of GUI toolkit should I use >> for this? I would like this to be lightweight, preferably under 5MB with a >> very easy API for simple things like create a dialog, put some labels and a >> progress bar on it, and finally close the dialog when the program is >> finished. (And of course, needs to work with cx Freeze.) >> >> I do not need a full featured cross platform GUI toolkit. What are my >> options? >> >> I have been looking at this: >> >> https://wiki.python.org/moin/GuiProgramming >> >> The only Windows specific lightweight frameworks are venster and Ocean but >> they have not been updated since ages. I know that I can do this using the >> win32 API, but I don't really want to learn how to build a dialog using >> win32 API calls and then process window message queues.... wxPython and Qt >> are well known but they are not exactly lightweight. > I would recommend to look into Pyglet - it uses the native windows api via ctypes calls (and is cross-platform as well). I have never used it myself, all this info is from the web pages. > There's absolutely no reason to go Windows-specific. Use Tkinter - > it's pretty light-weight. Comes with most Python distros. See how it > goes in terms of code size - if it's unsuitable, then look at others, > but start with the obvious option. Does Tkinter really work well with cx_Freeze? I doubt it (from my experiences with py2exe). From travisgriggs at gmail.com Fri Sep 12 15:05:46 2014 From: travisgriggs at gmail.com (Travis Griggs) Date: Fri, 12 Sep 2014 12:05:46 -0700 Subject: Python stdout goes where under systemd? (Was: Example of python service running under systemd?) In-Reply-To: References: <6B97B7A5-0816-401E-9BDD-A23FFC646985@gmail.com> <20140911212921.GB26465@arxnet.hu> <5412548A.1090507@gmail.com> <20140912061806.GB3333@arxnet.hu> Message-ID: <997C8621-DD83-461C-9F2E-45BB360DAC18@gmail.com> Thanks all for the help/advice. I?m getting there. To experiment/learn, I made a simple python program (/Foo/cyclic.py): #!/usr/bin/env python3 import time while True: time.sleep(5) with open('sound', 'r') as file: currentValue = file.read() otherValue = 'tick' if currentValue == 'tock' else 'tock' with open('sound', 'w') as file: file.write(otherValue) print(currentValue, '->', otherValue) Run from the command line, this tick-tocks nicely, both outputting, as well as updating the ?/Foo/sound? file on a 5 second period. I then created a simple .service file: [Unit] Description=Foo for learning service After=network-online.target [Service] Type=simple ExecStart=/Foo/cyclic.py WorkingDirectory=/Foo StandardOutput=journal [Install] WantedBy=multi-user.target I chose to be ?explicit? with some of the default options (Type and StandardOutput). I finally executed: systemctl --system daemon-reload systemctl enable foo systemctl start foo It seems to work. Almost. The file is being updated regularly (watch cat /Foo/sound shows the change happening). But I can?t seem to find the output from my print() statement. journalctl -f doesn?t show anything. Nor does tail -f /var/log/syslog or any of the others. It just seems to be going nowhere? Is there something I need to do special to get the print() output going somewhere logable? From zachary.ware+pylist at gmail.com Fri Sep 12 15:28:46 2014 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Fri, 12 Sep 2014 14:28:46 -0500 Subject: very lightweight gui for win32 + python 3.4 In-Reply-To: References: <541320D4.5030800@shopzeus.com> Message-ID: On Fri, Sep 12, 2014 at 1:35 PM, Thomas Heller wrote: > Does Tkinter really work well with cx_Freeze? I doubt it (from my > experiences with py2exe). Just to give anecdotal evidence, I have used Tkinter successfully without much headache with both cx_Freeze (with Python 2.7 and 3.1-3.2) and py2exe (with Python 3.4). -- Zach From dihedral88888 at gmail.com Fri Sep 12 16:05:34 2014 From: dihedral88888 at gmail.com (CHIN Dihedral) Date: Fri, 12 Sep 2014 13:05:34 -0700 (PDT) Subject: Example of python service running under systemd? In-Reply-To: References: Message-ID: <15e4e01c-dde1-48f7-bfc1-0468a436897e@googlegroups.com> On Friday, September 12, 2014 1:48:37 AM UTC+8, Travis Griggs wrote: > I've been reading lots of systemd docs. And blogs. Etc. At this point, I think I would benefit from learning by example... > > > > Does anyone have an example .service file that they use to launch a long running service written as a python program? > > > > If there is any example of what you changed to your python program itself, that to would be really instructional for me. Please check the examples in wxpython and boa. From travisgriggs at gmail.com Fri Sep 12 17:45:42 2014 From: travisgriggs at gmail.com (Travis Griggs) Date: Fri, 12 Sep 2014 14:45:42 -0700 Subject: Python stdout goes where under systemd? (Was: Example of python service running under systemd?) In-Reply-To: <997C8621-DD83-461C-9F2E-45BB360DAC18@gmail.com> References: <6B97B7A5-0816-401E-9BDD-A23FFC646985@gmail.com> <20140911212921.GB26465@arxnet.hu> <5412548A.1090507@gmail.com> <20140912061806.GB3333@arxnet.hu> <997C8621-DD83-461C-9F2E-45BB360DAC18@gmail.com> Message-ID: On Sep 12, 2014, at 12:05 PM, Travis Griggs wrote: > Thanks all for the help/advice. I?m getting there. > > To experiment/learn, I made a simple python program (/Foo/cyclic.py): > > #!/usr/bin/env python3 > > import time > > while True: > time.sleep(5) > with open('sound', 'r') as file: > currentValue = file.read() > otherValue = 'tick' if currentValue == 'tock' else 'tock' > with open('sound', 'w') as file: > file.write(otherValue) > print(currentValue, '->', otherValue) > > Run from the command line, this tick-tocks nicely, both outputting, as well as updating the ?/Foo/sound? file on a 5 second period. > > I then created a simple .service file: > > [Unit] > Description=Foo for learning service > After=network-online.target > > [Service] > Type=simple > ExecStart=/Foo/cyclic.py > WorkingDirectory=/Foo > StandardOutput=journal > > [Install] > WantedBy=multi-user.target > > I chose to be ?explicit? with some of the default options (Type and StandardOutput). > I finally executed: > > systemctl --system daemon-reload > systemctl enable foo > systemctl start foo > > It seems to work. Almost. The file is being updated regularly (watch cat /Foo/sound shows the change happening). But I can?t seem to find the output from my print() statement. journalctl -f doesn?t show anything. Nor does tail -f /var/log/syslog or any of the others. It just seems to be going nowhere? Is there something I need to do special to get the print() output going somewhere logable? > Arghhh? I?ll answer my own question here. I wasn?t patient enough, when I checked after lunch, I found I had a mountain of tick/tock entries in journalctl -f. Python print() is buffered, so it wasn?t showing up except in huge blocks. Changed the .service file to start with -u and everything works as expected now. From tjreedy at udel.edu Fri Sep 12 19:16:29 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 12 Sep 2014 19:16:29 -0400 Subject: pythonw.exe has stopped working In-Reply-To: References: Message-ID: On 9/12/2014 1:48 AM, rahuldbhagat at gmail.com wrote: > > > Hello Folks, > > I'm using RIDE -- Robot Framework Test Data Editor RIDE 1.3 running > on Python 2.7.6. > > When I click on some of my test case the RIDE GUI hangs and gives > bellow error message. Run RIDE with python, not pythonw, from a command prompt, and you should be error messages from python. -- Terry Jan Reedy From invalid at invalid.invalid Fri Sep 12 21:19:05 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Sat, 13 Sep 2014 01:19:05 +0000 (UTC) Subject: very lightweight gui for win32 + python 3.4 References: <541320D4.5030800@shopzeus.com> Message-ID: On 2014-09-12, Thomas Heller wrote: > Am 12.09.2014 18:38, schrieb Chris Angelico: > > Does Tkinter really work well with cx_Freeze? I doubt it (from my > experiences with py2exe). I never had any problems with Tkinter and py2exe, but you do get a considerably larger distribution than you do with wxWindows. -- Grant From rosuav at gmail.com Fri Sep 12 21:50:10 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 13 Sep 2014 11:50:10 +1000 Subject: Python stdout goes where under systemd? (Was: Example of python service running under systemd?) In-Reply-To: References: <6B97B7A5-0816-401E-9BDD-A23FFC646985@gmail.com> <20140911212921.GB26465@arxnet.hu> <5412548A.1090507@gmail.com> <20140912061806.GB3333@arxnet.hu> <997C8621-DD83-461C-9F2E-45BB360DAC18@gmail.com> Message-ID: On Sat, Sep 13, 2014 at 7:45 AM, Travis Griggs wrote: > Python print() is buffered, so it wasn?t showing up except in huge blocks. Changed the .service file to start with -u and everything works as expected now. Ah, yes, that'll happen any time stdout isn't connected to a tty. Nothing to do with systemd or journal. ChrisA From torriem at gmail.com Fri Sep 12 22:36:16 2014 From: torriem at gmail.com (Michael Torrie) Date: Fri, 12 Sep 2014 20:36:16 -0600 Subject: Example of python service running under systemd? In-Reply-To: <15e4e01c-dde1-48f7-bfc1-0468a436897e@googlegroups.com> References: <15e4e01c-dde1-48f7-bfc1-0468a436897e@googlegroups.com> Message-ID: <5413ADA0.5070109@gmail.com> On 09/12/2014 02:05 PM, CHIN Dihedral wrote: > Please check the examples in wxpython and boa. Oh funny. Just when I think the bot is ready to pass a turing test we get a regression. From rosuav at gmail.com Fri Sep 12 22:48:23 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 13 Sep 2014 12:48:23 +1000 Subject: Example of python service running under systemd? In-Reply-To: <5413ADA0.5070109@gmail.com> References: <15e4e01c-dde1-48f7-bfc1-0468a436897e@googlegroups.com> <5413ADA0.5070109@gmail.com> Message-ID: On Sat, Sep 13, 2014 at 12:36 PM, Michael Torrie wrote: > Oh funny. Just when I think the bot is ready to pass a turing test we > get a regression. Ah, the Turing test... everyone loves it. I had some really naughty fun with that name a while ago. In my D&D world themed on Wonderland, there are two rival manufacturers who produce a drinkable form of intelligence. One form is drained from real people, stolen from our world (they send them back with empty liquor bottles and nobody notices the difference - or else they just take from middle management, and again, nobody notices), and the other produces an artificial form, which is dangerously addictive. The test of addictiveness is how it "tours", and when eventually a safer form of manufactured stuff was developed, it was hailed as "artificial intelligence that passes the touring test"... Yeah, they listened to rumours in the tavern, and that was their pun-ishment... ChrisA From daoudimca at gmail.com Sat Sep 13 01:47:57 2014 From: daoudimca at gmail.com (daoudimca at gmail.com) Date: Fri, 12 Sep 2014 22:47:57 -0700 (PDT) Subject: find the error Message-ID: <70d7bef7-6393-41e1-b4e0-a5d3a6630063@googlegroups.com> Dear friends when i used import urllib, re, sys symbol = sys.argv[1] >>> this function is show -->> symbol = sys.argv[1] IndexError: list index out of range kindly find the solution of this From rosuav at gmail.com Sat Sep 13 01:53:37 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 13 Sep 2014 15:53:37 +1000 Subject: find the error In-Reply-To: <70d7bef7-6393-41e1-b4e0-a5d3a6630063@googlegroups.com> References: <70d7bef7-6393-41e1-b4e0-a5d3a6630063@googlegroups.com> Message-ID: On Sat, Sep 13, 2014 at 3:47 PM, wrote: > Dear friends when i used > import urllib, re, sys > > symbol = sys.argv[1] >>> this function is show -->> symbol = sys.argv[1] > IndexError: list index out of range > > kindly find the solution of this If you're using sys.argv, you need to provide arguments to your script. You provided no arguments, so the list doesn't have elements for you to find. ChrisA From rosuav at gmail.com Sat Sep 13 02:22:14 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 13 Sep 2014 16:22:14 +1000 Subject: Iterator, modify data in loop body In-Reply-To: References: Message-ID: On Sat, Sep 13, 2014 at 4:09 PM, Michael Welle wrote: > foo = [1,2,3,4] > it = iter(foo) > > for e in it: > if e % 2 == 0: > x.append(e) A better way to do this is with a list comprehension: x = [e for e in foo if e %2 == 0] Modifying something that you're iterating over is unspecified, I believe. Certainly it's not a good idea. ChrisA From anddamNOALPASTICCIODICARNE+gruppi at brapi.net Sat Sep 13 02:43:00 2014 From: anddamNOALPASTICCIODICARNE+gruppi at brapi.net (Andrea D'Amore) Date: Sat, 13 Sep 2014 08:43:00 +0200 Subject: find the error References: <70d7bef7-6393-41e1-b4e0-a5d3a6630063@googlegroups.com> Message-ID: On 2014-09-13 05:53:37 +0000, Chris Angelico said: > If you're using sys.argv, you need to provide arguments to your > script. Or check sys.argv's length ensuring that an element is there before accessing it. -- Andrea From dieter at handshake.de Sat Sep 13 02:56:09 2014 From: dieter at handshake.de (dieter) Date: Sat, 13 Sep 2014 08:56:09 +0200 Subject: Thread-ID - how much could be? References: <20140911193018.GA24416@arxnet.hu> <54124c95$0$29991$c3e8da3$5496439d@news.astraweb.com> <20140912063041.GC3333@arxnet.hu> Message-ID: <87k3582ely.fsf@handshake.de> Ervin Heged?s writes: > ... What is used as thread id is platform dependent. Likely, it depends on the thread support of the underlying C libary (i.e. the operating system thread support). Under Linux, thread ids seem to be addresses - i.e. very large integers. From rosuav at gmail.com Sat Sep 13 03:22:54 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 13 Sep 2014 17:22:54 +1000 Subject: Iterator, modify data in loop body In-Reply-To: <4o6debxojk.ln2@news.c0t0d0s0.de> References: <4o6debxojk.ln2@news.c0t0d0s0.de> Message-ID: On Sat, Sep 13, 2014 at 5:01 PM, Michael Welle wrote: > ideed, this works for the minimal example. In a real application list > comprehension might be a bit unhandy, because there is a lot of code > involved. Sure. Sometimes, cutting something down for posting makes a completely different solution possible, and that doesn't much help. :) > It depends on the use case I think. For some algorithms it feels natural > to just append at the end of the list while consuming elements from the > front. I think a deque supports that as well. In that case, don't iterate over the list at all. Do something like this: while lst: element = lst.pop(0) # work with element lst.append(new_element) There's no mutation-while-iterating here, and it's clear that you'll keep going until there's absolutely nothing left. ChrisA From __peter__ at web.de Sat Sep 13 03:34:43 2014 From: __peter__ at web.de (Peter Otten) Date: Sat, 13 Sep 2014 09:34:43 +0200 Subject: Iterator, modify data in loop body References: Message-ID: Michael Welle wrote: > I want to create an iterator it=iter(list) and control a for-loop with > it. Is it save to append elements to the list in the body of the > for-loop or is the behaviour undefined then? PEP234 notes that once the > iterator has signaled exhaustion, subsequent calls of next() should not > change that state. That suggests that it is possible to modify the list > during the iterator's livetime. It's possible, but usually not a good idea. Especially inserting or deleting elements before the current position of the iterator (you can think of it as an index into the list) gives results that are usually unexpected: >>> items = [1, "remove me", 2, "remove me", "remove me", 3, 4] >>> for item in items: ... if item == "remove me": ... items.remove(item) ... >>> items [1, 2, 'remove me', 3, 4] Pro tip: don't do it even when it's possible. > Ex.: > > foo = [1,2,3,4] > it = iter(foo) > > for e in it: > if e % 2 == 0: > x.append(e) I don't see how the example is related to the question. Did you mean foo.append(e) ? With that modification the loop would run "forever" because you keep appending items that satisfy the condition e % 2 == 0. > it = iter(foo) Normally you would just iterate over foo; the only use-case where you'd create an iterator explicitly is when you want to skip some items: it = iter(items) for e in it: if skip_next(e): next(it) From __peter__ at web.de Sat Sep 13 03:48:05 2014 From: __peter__ at web.de (Peter Otten) Date: Sat, 13 Sep 2014 09:48:05 +0200 Subject: Thread-ID - how much could be? References: <20140911193018.GA24416@arxnet.hu> <54124c95$0$29991$c3e8da3$5496439d@news.astraweb.com> <20140912063041.GC3333@arxnet.hu> <87k3582ely.fsf@handshake.de> Message-ID: dieter wrote: > Ervin Heged?s writes: >> ... > What is used as thread id is platform dependent. Likely, it depends > on the thread support of the underlying C libary (i.e. the > operating system thread support). > > Under Linux, thread ids seem to be addresses - i.e. very large > integers. $ grep "Exception in thread" /usr/lib/python3.4/threading.py _sys.stderr.write("Exception in thread %s:\n%s\n" % "Exception in thread " + self.name + I believe the "Thread-ID"s we are talking about are actually user-specified names attached Python's threading.Thread instances, not something on the OS level. These names default to $ grep -i -A4 -B1 "def _newname" /usr/lib/python3.4/threading.py _counter = 0 def _newname(template="Thread-%d"): global _counter _counter += 1 return template % _counter From HeinzSchmitz at gmx.net Sat Sep 13 04:34:08 2014 From: HeinzSchmitz at gmx.net (Heinz Schmitz) Date: Sat, 13 Sep 2014 10:34:08 +0200 Subject: Pyston 0.2 released References: Message-ID: serge Guelton wrote: >> Hi all, we're excited to announce the existence of Pyston 0.2, a >> much-improved version of our new Python JIT. Every reason to get excited: http://www.pyston.com/ Regards, H. From albert at spenarnc.xs4all.nl Sat Sep 13 05:23:13 2014 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 13 Sep 2014 09:23:13 GMT Subject: Global indent References: <53f8ab8b$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <54140d01$0$6917$e4fe514c@dreader36.news.xs4all.nl> In article , Anders Wegge Keller wrote: >On Sun, 24 Aug 2014 00:56:11 +1000 >Steven D'Aprano wrote: > >> Despite my comments, I don't actually have any objection to people who >> choose to use Emacs, or Vim, or edit their text files by poking the hard >> drive platter with a magnetised needle if they prefer :-) But I do think >> it's silly of them to claim that Emacs has no learning curve, or to fail to >> recognise how unfamiliar and different the UIs are compared to nearly >> everything else a computer user is likely to be familiar with in 2014. > > Really, they don't! At least not for the people, for whom they are >necessary tools. When I started in my present job, "remote access" was >a dial-up modem, that could do 2400 baud, if you were lucky[1]. With such a >shitty connection, a text-only editor is indisputably the right thing. > > Curiously enough, even today the same lousy kind of connections prevail. We >still have a sizeable modem bank at my job. We still do our remote support >over a telnet/ssh session. And we still are unable to reliable get the >connection speeds[2], that would make anything with a GUI remotely >pleasant. > > So emacs and vim still have their niches. Those of us, who are old enough >to have started our first job in a glorified teletype, OR have to support >systems that are only reachable over RFC-1149 quality datalinks, belong >there. The rest of you would probably be better off with something nicer. > >1. Meaning a real switched landline all the way from Denmark to Tokyo. >Ending up with two satellite up/down-links was a killer. > >2. We have an installation in the Philippines, where we ended up installing a > satellite uplink. It feels like we have doubled the connectivity of the > entire Manilla area by doing so. And it's still painfully slow. Right. I remember having a 300 baud dial up line. Edwin's editor (ee), the editor I'm using right now, was optimised for screen access, and I could do cursor based full screen editing, quite passably, doing a vt100 emulation on my Osborne CP/M machine. (I've a non transferable license and ee is not for sale.) > >-- >//Wegge Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From shieldfire at gmail.com Sat Sep 13 06:09:28 2014 From: shieldfire at gmail.com (=?ISO-8859-1?Q?Martin_Skj=F6ldebrand?=) Date: Sat, 13 Sep 2014 12:09:28 +0200 Subject: Thread-ID - how much could be? In-Reply-To: References: <54124c95$0$29991$c3e8da3$5496439d@news.astraweb.com> <20140912034100.GA14188@cskk.homeip.net> Message-ID: Unfortunately we will never know ? Sent from Blue Mail On 12 Sep 2014 07:43, at 07:43, Chris Angelico wrote: >On Fri, Sep 12, 2014 at 1:41 PM, Cameron Simpson wrote: >> On 12Sep2014 11:29, Steven D'Aprano > >> wrote: >>> >>> [...]maxint. I know that some Linux >>> systems can have an uptime over a year, perhaps even two years, but >I >>> think >>> that nearly 300 years is asking a bit much. >> >> >> 2 years is nothing. Unless they have a particularly buggy kernel, >most UNIX >> systems, Linux included, will stay up almost indefinitely. We've >definitely >> had systems up for well over 2 years. >> >>> Your hardware probably won't >>> keep working that long. >> >> >> 300 years? Probably not. Regrettably. > >Once you get into the counting of years (rather than days), it's all >down to hardware. How long before that hardware needs an upgrade? Does >your incoming power have fail-overs? I don't currently have any >servers with multiple power supplies, so if anything like that goes >bung, my server's down. Doesn't matter how quickly I can bring up an >equivalent on a different hunk of hardware, the uptime's gone. > >But yeah. 300 years? Good luck. I don't think anyone's ever going to >hit that. > >ChrisA >-- >https://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From antoine at python.org Sat Sep 13 06:40:10 2014 From: antoine at python.org (Antoine Pitrou) Date: Sat, 13 Sep 2014 10:40:10 +0000 (UTC) Subject: Newer Debian versions of python on older Debian distros? References: <5D152EC0-CDBB-4AC9-B074-B648074CE372@gmail.com> Message-ID: Hi, Chris Angelico gmail.com> writes: > > On Tue, Sep 9, 2014 at 5:04 AM, Travis Griggs gmail.com> wrote: > > Does anyone have experience with using newer versions of python debian packages (in particular, python3 > and python3-bson-ext from ?testing?) on older stable versions (?wheezy? in this case)? If > someone?s figured out how to do this easily, I?d love to hear the recipe! > > > > I don't know about grabbing from testing, because that's fraught with > peril... but there's a pretty easy way to get a newer Python: build > from source. Basically, the standard incantation: [...] I know the OP solved their problem now, but for the record, you can also get binaries of recent Pythons (and other packages) by using conda: http://conda.pydata.org/miniconda.html#miniconda This assumes you don't mind having a local install rather than a system install of Python (something akin to a virtual environment). Regards Antoine. From airween at gmail.com Sat Sep 13 06:32:24 2014 From: airween at gmail.com (Ervin =?utf-8?Q?Heged=C3=BCs?=) Date: Sat, 13 Sep 2014 12:32:24 +0200 Subject: Thread-ID - how much could be? In-Reply-To: References: <54124c95$0$29991$c3e8da3$5496439d@news.astraweb.com> <20140912034100.GA14188@cskk.homeip.net> Message-ID: <20140913103224.GA5389@arxnet.hu> On Sat, Sep 13, 2014 at 12:09:28PM +0200, Martin Skj?ldebrand wrote: > Unfortunately we will never know ? hehe :), joke of the day :) thanks, a. -- I ? UTF-8 From theller at ctypes.org Sat Sep 13 07:31:48 2014 From: theller at ctypes.org (Thomas Heller) Date: Sat, 13 Sep 2014 13:31:48 +0200 Subject: very lightweight gui for win32 + python 3.4 In-Reply-To: References: <541320D4.5030800@shopzeus.com> Message-ID: Am 13.09.2014 03:19, schrieb Grant Edwards: > On 2014-09-12, Thomas Heller wrote: >> Am 12.09.2014 18:38, schrieb Chris Angelico: >> >> Does Tkinter really work well with cx_Freeze? I doubt it (from my >> experiences with py2exe). > > I never had any problems with Tkinter and py2exe, but you do get > a considerably larger distribution than you do with wxWindows. > That was what I meant - sorry for being unclear. Especially you cannot create single-file executables with py2exe, you get a directory full with the tcl/tk files. From ian.g.kelly at gmail.com Sat Sep 13 11:27:23 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 13 Sep 2014 09:27:23 -0600 Subject: Iterator, modify data in loop body In-Reply-To: References: <4o6debxojk.ln2@news.c0t0d0s0.de> Message-ID: On Sat, Sep 13, 2014 at 1:39 AM, Michael Welle wrote: >> In that case, don't iterate over the list at all. Do something like this: >> >> while lst: >> element = lst.pop(0) >> # work with element >> lst.append(new_element) >> >> There's no mutation-while-iterating here, and it's clear that you'll >> keep going until there's absolutely nothing left. > Ah, that looks like a good approach, thank you. Also note that this approach (appending to the end and popping from the front) will be more efficient using a collections.deque than a list. From rosuav at gmail.com Sat Sep 13 11:32:48 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 14 Sep 2014 01:32:48 +1000 Subject: Iterator, modify data in loop body In-Reply-To: References: <4o6debxojk.ln2@news.c0t0d0s0.de> Message-ID: On Sun, Sep 14, 2014 at 1:27 AM, Ian Kelly wrote: > On Sat, Sep 13, 2014 at 1:39 AM, Michael Welle wrote: >>> In that case, don't iterate over the list at all. Do something like this: >>> >>> while lst: >>> element = lst.pop(0) >>> # work with element >>> lst.append(new_element) >>> >>> There's no mutation-while-iterating here, and it's clear that you'll >>> keep going until there's absolutely nothing left. >> Ah, that looks like a good approach, thank you. > > Also note that this approach (appending to the end and popping from > the front) will be more efficient using a collections.deque than a > list. Sure it will - that's kinda the point of a double-ended queue, to avoid all the inefficient movements :) But the concept is still the same: do repeated mutations rather than iteration. Either that, or iterate and build up a new list, either with a comprehension or with something like this: newlst = [] for element in lst: # work with element newlst.append(new_element) ChrisA From denismfmcmahon at gmail.com Sat Sep 13 13:28:19 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Sat, 13 Sep 2014 17:28:19 +0000 (UTC) Subject: find the error References: <70d7bef7-6393-41e1-b4e0-a5d3a6630063@googlegroups.com> Message-ID: On Fri, 12 Sep 2014 22:47:57 -0700, daoudimca wrote: > Dear friends when i used import urllib, re, sys > > symbol = sys.argv[1] >>> this function is show -->> symbol = sys.argv[1] > IndexError: list index out of range > > kindly find the solution of this You are trying to reference more elements than your list contains. -- Denis McMahon, denismfmcmahon at gmail.com From davea at davea.name Sat Sep 13 19:26:36 2014 From: davea at davea.name (Dave Angel) Date: Sat, 13 Sep 2014 19:26:36 -0400 (EDT) Subject: find the error References: <70d7bef7-6393-41e1-b4e0-a5d3a6630063@googlegroups.com> Message-ID: daoudimca at gmail.com Wrote in message: > Dear friends when i used > import urllib, re, sys > > symbol = sys.argv[1] >>> this function is show -->> symbol = sys.argv[1] > IndexError: list index out of range > > kindly find the solution of this > sys.argv is filled in from the command line arguments. Perhaps your script should protect itself by majing sure len (sys.argv) is what's required, in this case at least 2. That way the user gets a friendlier message when he omits the arguments. By the way, you should simply copy/paste the entire stack trace. When you paraphrase, you're likely to have a typo, or omit something useful. -- DaveA From Seymore4Head at Hotmail.invalid Sat Sep 13 19:47:35 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Sat, 13 Sep 2014 19:47:35 -0400 Subject: Shuffle Message-ID: Here is a screenshot of me trying Dave Briccetti's quiz program from the shell and it (the shuffle command) works. https://www.youtube.com/watch?v=VR-yNEpGk3g http://i.imgur.com/vlpVa5i.jpg Two questions If you import random, do you need to "from random import shuffle"? Why does shuffle work from the command line and not when I add it to this program? import random import shuffle nums=list(range(1,11)) shuffle(nums) print (nums) I get: No module named 'shuffle' From rosuav at gmail.com Sat Sep 13 20:28:53 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 14 Sep 2014 10:28:53 +1000 Subject: Shuffle In-Reply-To: References: Message-ID: On Sun, Sep 14, 2014 at 9:47 AM, Seymore4Head wrote: > Two questions > If you import random, do you need to "from random import shuffle"? > > Why does shuffle work from the command line and not when I add it to > this program? > > import random > import shuffle To understand this, you need to understand what the 'from' import does: https://docs.python.org/3/tutorial/modules.html#more-on-modules It's not the same as "import shuffle", but is a variant of "import random". ChrisA From torriem at gmail.com Sat Sep 13 21:32:55 2014 From: torriem at gmail.com (Michael Torrie) Date: Sat, 13 Sep 2014 19:32:55 -0600 Subject: Shuffle In-Reply-To: References: Message-ID: <5414F047.9030809@gmail.com> On 09/13/2014 05:47 PM, Seymore4Head wrote: > Here is a screenshot of me trying Dave Briccetti's quiz program from > the shell and it (the shuffle command) works. > https://www.youtube.com/watch?v=VR-yNEpGk3g > http://i.imgur.com/vlpVa5i.jpg > > Two questions > If you import random, do you need to "from random import shuffle"? > > Why does shuffle work from the command line and not when I add it to > this program? > > import random > import shuffle > nums=list(range(1,11)) > shuffle(nums) > print (nums) > > I get: > No module named 'shuffle' You can do it two ways: Refer to it as random.shuffle() or from random import shuffle I tend to use the first method (random.shuffle). That way it prevents my local namespace from getting polluted with random symbols imported from modules. From Seymore4Head at Hotmail.invalid Sat Sep 13 22:10:08 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Sat, 13 Sep 2014 22:10:08 -0400 Subject: Shuffle References: Message-ID: On Sat, 13 Sep 2014 19:32:55 -0600, Michael Torrie wrote: >On 09/13/2014 05:47 PM, Seymore4Head wrote: >> Here is a screenshot of me trying Dave Briccetti's quiz program from >> the shell and it (the shuffle command) works. >> https://www.youtube.com/watch?v=VR-yNEpGk3g >> http://i.imgur.com/vlpVa5i.jpg >> >> Two questions >> If you import random, do you need to "from random import shuffle"? >> >> Why does shuffle work from the command line and not when I add it to >> this program? >> >> import random >> import shuffle >> nums=list(range(1,11)) >> shuffle(nums) >> print (nums) >> >> I get: >> No module named 'shuffle' > >You can do it two ways: >Refer to it as random.shuffle() > >or > >from random import shuffle > >I tend to use the first method (random.shuffle). That way it prevents >my local namespace from getting polluted with random symbols imported >from modules. Thanks. From bfb at riseup.net Sat Sep 13 22:51:25 2014 From: bfb at riseup.net (kjs) Date: Sun, 14 Sep 2014 02:51:25 +0000 Subject: CSV methodology In-Reply-To: References: Message-ID: <541502AD.90209@riseup.net> jetrn at newsguy.com wrote: > > Hello. Back in the '80s, I wrote a fractal generator, which, over the years, > I've modified/etc to run under Windows. I've been an Assembly Language > programmer for decades. Recently, I decided to learn a new language, > and decided on Python, and I just love it, and the various IDEs. > > Anyway, something I thought would be interesting, would be to export > some data from my fractal program (I call it MXP), and write something > in Python and its various scientific data analysis and plotting modules, > and... well, see what's in there. > > An example of the data: > 1.850358651774470E-0002 > 32 > 22 > 27 > ... (this format repeats) > > So, I wrote a procedure in MXP which converts "the data" and exports > a csv file. So far, here's what I've started with: > > ----------------------------------------------- > import csv > > fname = 'E:/Users/jayte/Documents/Python Scripts/XportTestBlock.csv' > > f = open(fname) > > reader = csv.reader(f) > > for flt in reader: > x = len(flt) > file.close(f) > ----------------------------------------------- The csv.reader(f) object creates an iterable that will create lists from lines in f. The list will have values at indexes based on the commas in the file. EX: my_header_1, my_header_2 111, 0001 101, 1010 100, 1001 The csv.reader will lazily make lists like ['my_header_1', 'my_header_2'], ['111', '0001'], ... and so forth. Your program above will take the length of those lists, and assign that value to x. For every line in the file, f will get rewritten with a new value, the length of list which is derived from the number of commas in the csv. Also note that the csv.reader speaks many dialects, and can do similar work on files with different quote characters and delimiters. Generally, I prefer to read in csv files with the standard readline() method of open files. I do like to use csv.DictWriter, which helps me to keep my csv output tabular. -Kevin > > This will get me an addressable array, as: > > flt[0], flt[1], flt[350], etc... from which values can be assigned to > other variables, converted... > > My question: Is there a better way? Do I need to learn more about > how csv file are organized? Perhaps I know far too little of Python > to be attempting something like this, just yet. > > Advice? > > Jeff > -------------- next part -------------- A non-text attachment was scrubbed... Name: 0x8A61431E.asc Type: application/pgp-keys Size: 11239 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 801 bytes Desc: OpenPGP digital signature URL: From vhnguyenn at yahoo.com Sun Sep 14 01:44:16 2014 From: vhnguyenn at yahoo.com (Viet Nguyen) Date: Sat, 13 Sep 2014 22:44:16 -0700 (PDT) Subject: Why captured match is displayed as part of pexpect ".after" ? Message-ID: <3538df33-b9b3-419e-be37-866819d40728@googlegroups.com> Hi, If any is familiar with pexpect, please help to point out why my script seems to fail to capture the desired text. Here, I want to log into a server 172.27.161.19. Once I see "Username: ", I will type in my userid "admin". The problem here is I have a list of keywords for pexpect to match before returning the matched item for me. The list consists of following list items: expects = ['yes', '.*Username: ', '.*login: |.*Login: ', 'SY-FAR-1>', 'SY-FAR-1#', 'Password: |password: ', '.*Press RETURN to get started'] Here, it seems my script found "Username: " but it got displayed as PART OF _pexpect_session.after (and this is what I don't understand). The ".before" or ".after" data should consist of match before and after the desired keyword only. ============= Manual Execution ======================= telnet 172.27.161.19 Trying 172.27.161.19... Connected to 172.27.161.19. Escape character is '^]'. User Access Verification Username: admin Password: SY-FAR-1>en SY-FAR-1# =============== Python Script Snippet ======================= expects = ['yes', '.*Username: ', '.*login: |.*Login: ', 'SY-FAR-1>', 'SY-FAR-1#', 'Password: |password: ', '.*Press RETURN to get started'] i = -1 # reset its value print "*step 1*before match, i = %s" % i self._pexpect_session.timeout = 80 cmd = "admin" self._log("Executing CLI: '{0}'".format(cmd)) self._pexpect_session.sendline(cmd) i = self._pexpect_session.expect(expects) print "*step 2* found index i = %s" % i print "*step 3* after match, exec_cmd expects (%s) =" % i, expects print "*step 4* exec_cmd match before: '%s'" % self._pexpect_session.before print "*step 5* exec_cmd match after: '%s'" % self._pexpect_session.after =============== Actual Script Output ====================== *step1* before match, i = -1 Executing CLI: 'admin' *step2* found index i = 1 *step3* after match, exec_cmd expects (1) = ['yes', '.*Username: ', '.*login: |.*Login: ', 'SY-FAR-1>', 'SY-FAR-1#', 'Password: |password: ', '.*Press RETURN to get started'] *step4* exec_cmd match before: '' *step5* exec_cmd match after: ' Username: ' Appreciate any input or explanation. Thanks, Viet From Joshua.R.English at gmail.com Sun Sep 14 02:44:40 2014 From: Joshua.R.English at gmail.com (Josh English) Date: Sat, 13 Sep 2014 23:44:40 -0700 (PDT) Subject: protocol.py, brine.py, and compat.py causing trouble Message-ID: I do not know what these three filesare doing, but suddenly they have caught in a loop every time I try to run some code. I grabbed the trace decorator from the python library and this is the last bit of the output: trollvictims.py(129): if self.current_attack: trollvictims.py(130): print "returning", self.current_attack, type(self.current_attack) (532): protocol.py(439): protocol.py(228): protocol.py(229): protocol.py(244): brine.py(366): brine.py(368): brine.py(369): brine.py(369): brine.py(366): brine.py(367): brine.py(369): brine.py(366): brine.py(368): brine.py(369): brine.py(369): brine.py(366): brine.py(367): brine.py(369): brine.py(369): brine.py(366): brine.py(368): brine.py(369): brine.py(369): brine.py(369): protocol.py(245): protocol.py(221): brine.py(339): brine.py(340): brine.py(203): brine.py(181): brine.py(182): brine.py(184): brine.py(186): brine.py(188): brine.py(189): brine.py(196): brine.py(197): brine.py(203): brine.py(108): brine.py(109): brine.py(196): brine.py(197): brine.py(203): brine.py(108): brine.py(109): brine.py(196): brine.py(197): brine.py(203): brine.py(181): brine.py(182): brine.py(184): brine.py(186): brine.py(187): brine.py(196): brine.py(197): brine.py(203): brine.py(108): brine.py(109): brine.py(196): brine.py(197): brine.py(203): brine.py(181): brine.py(182): brine.py(184): brine.py(186): brine.py(187): brine.py(196): brine.py(197): brine.py(203): brine.py(108): brine.py(109): brine.py(196): brine.py(197): brine.py(203): brine.py(181): brine.py(182): brine.py(184): brine.py(186): brine.py(188): brine.py(189): brine.py(196): brine.py(197): brine.py(203): brine.py(108): brine.py(111): compat.py(18): brine.py(112): brine.py(113): brine.py(114): brine.py(196): brine.py(197): brine.py(203): brine.py(181): brine.py(182): brine.py(184): brine.py(185): brine.py(196): brine.py(197): brine.py(203): brine.py(152): brine.py(153): brine.py(155): brine.py(157): brine.py(159): brine.py(161): brine.py(163): brine.py(164): brine.py(196): brine.py(196): brine.py(197): brine.py(203): brine.py(181): brine.py(182): brine.py(183): brine.py(196): brine.py(196): brine.py(196): brine.py(196): brine.py(196): brine.py(341): compat.py(18): protocol.py(222): This is where I managed to send a keybord interrupt. I was working just fine, tweaking a line, running the code, tweaking a line, running the code, until this point. I'm on Windows 7 using Python 2.7.5. I should upgrade, and will do so, but what are these files and why are they suddenly crashing on me? Josh From tjreedy at udel.edu Sun Sep 14 03:02:12 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 14 Sep 2014 03:02:12 -0400 Subject: CSV methodology In-Reply-To: References: Message-ID: On 9/13/2014 9:34 PM, jetrn at newsguy.com wrote: > > Hello. Back in the '80s, I wrote a fractal generator, which, over the years, > I've modified/etc to run under Windows. I've been an Assembly Language > programmer for decades. Recently, I decided to learn a new language, > and decided on Python, and I just love it, and the various IDEs. > > Anyway, something I thought would be interesting, would be to export > some data from my fractal program (I call it MXP), and write something > in Python and its various scientific data analysis and plotting modules, > and... well, see what's in there. First you need to think about (and document) what your numbers mean and how they should be organized for analysis. > An example of the data: > 1.850358651774470E-0002 Why is this so smaller than the next numbers. Are all those digits significant, or are they mostly just noise -- and best dropped by rounding the number to a few significant digits. > 32 > 22 > 27 > ... (this format repeats) After exactly 3 numbers in this range? > So, I wrote a procedure in MXP which converts "the data" and exports > a csv file. Answer the questions above before writing code. .csf is likely not the best format to use. -- Terry Jan Reedy From cs at zip.com.au Sun Sep 14 04:38:41 2014 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 14 Sep 2014 18:38:41 +1000 Subject: CSV methodology In-Reply-To: References: Message-ID: <20140914083841.GA30137@cskk.homeip.net> On 13Sep2014 21:34, jetrn at newsguy.com wrote: >Hello. Back in the '80s, I wrote a fractal generator, [...] >Anyway, something I thought would be interesting, would be to export >some data from my fractal program (I call it MXP), and write something >in Python and its various scientific data analysis and plotting modules, >and... well, see what's in there. > >An example of the data: >1.850358651774470E-0002 >32 >22 >27 >... (this format repeats) > >So, I wrote a procedure in MXP which converts "the data" and exports >a csv file. So far, here's what I've started with: Normally a CSV file will have multiple values per row. Echoing Terry, what shape did you intend your CSV data to be? i.e. what values appear on a row? >import csv >fname = 'E:/Users/jayte/Documents/Python Scripts/XportTestBlock.csv' >f = open(fname) >reader = csv.reader(f) >for flt in reader: > x = len(flt) >file.close(f) > >This will get me an addressable array, as: > >flt[0], flt[1], flt[350], etc... from which values can be assigned to >other variables, converted... > >My question: Is there a better way? Do I need to learn more about >how csv file are organized? Perhaps I know far too little of Python >to be attempting something like this, just yet. If you have a nice regular CSV file, with say 3 values per row, you can go: reader = csv.reader(f) for row in reader: a, b, c - row and proceed with a, b and c directly from there. But of course, that requires your export format to be usable that way. Cheers, Cameron Simpson For a good prime, call: 391581 * 2^216193 -1 From rustompmody at gmail.com Sun Sep 14 04:56:21 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 14 Sep 2014 01:56:21 -0700 (PDT) Subject: CSV methodology In-Reply-To: References: Message-ID: <85cca2f1-47e3-490c-92e8-66c0461cf8ff@googlegroups.com> On Sunday, September 14, 2014 2:09:51 PM UTC+5:30, Cameron Simpson wrote: > If you have a nice regular CSV file, with say 3 values per row, you can go: > reader = csv.reader(f) > for row in reader: > a, b, c - row I guess you meant: a, b, c = row ? Also you will want to do appropriate type conversions up front. eg if the first field is string the second field is int and the third a float something like a,b,c = row[0], int(row[1]), float(row[2]) More generally as Terry said csv is not necessarily a appropriate standard (because there is no standard!!) If inputting outputting to/from a spreadsheet is required thats ok. Else there are dozens of others. My favorite is yml Json is close enough and getting more traction nowadays Then of course there's XML which everyone loves to hate -- for reasons similar to csv it may be required From feliphil at gmx.net Sun Sep 14 09:13:45 2014 From: feliphil at gmx.net (Wolfgang Keller) Date: Sun, 14 Sep 2014 15:13:45 +0200 Subject: very lightweight gui for win32 + python 3.4 References: Message-ID: <20140914151345.4a17399a94aee701b58137e5@gmx.net> > wxPython and Qt are well known but they are not exactly lightweight. wxPython not lightweight? It's just a wrapper of win32. Sincerely, Wolfgang From auriocus at gmx.de Sun Sep 14 11:15:04 2014 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sun, 14 Sep 2014 17:15:04 +0200 Subject: very lightweight gui for win32 + python 3.4 In-Reply-To: References: <541320D4.5030800@shopzeus.com> Message-ID: Am 13.09.14 13:31, schrieb Thomas Heller: > Am 13.09.2014 03:19, schrieb Grant Edwards: >> On 2014-09-12, Thomas Heller wrote: >>> Am 12.09.2014 18:38, schrieb Chris Angelico: >>> >>> Does Tkinter really work well with cx_Freeze? I doubt it (from my >>> experiences with py2exe). >> >> I never had any problems with Tkinter and py2exe, but you do get >> a considerably larger distribution than you do with wxWindows. >> > > That was what I meant - sorry for being unclear. Especially you > cannot create single-file executables with py2exe, you get a directory > full with the tcl/tk files. > which is not the fault of Tcl, BTW - "starpack" technology is the Tcl way to make a single-file executable containing Tcl, Tk, scripts and any number of libraries. Unfortunately, no python interpreter can be included so far. By bridging Tcl_FileSystem with Python's VFS, this restriction could be overcome. Christian From rosuav at gmail.com Sun Sep 14 13:10:07 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 15 Sep 2014 03:10:07 +1000 Subject: CSV methodology In-Reply-To: References: Message-ID: On Mon, Sep 15, 2014 at 2:56 AM, jayte wrote: > Anyway, thanks (everyone) for responding. I'm very anxious to > try some data analysis (what I'm hoping, is to discover some new > approaches / enhancements to coloring, as I'm not convinced we've > seen all there is to see, from The Mandelbrot Set) I agree! For one thing, I'd like to see a Mandelbrot set built out of ice. Spiralling all around... and one thought crystallizes... *goes off humming* But seriously, yes. There's so much to be found in it. Python can probably help you more easily than you think - reading the raw binary isn't too hard. Maybe we can help you get it into a more useful data structure. How's the file laid out? ChrisA From tjreedy at udel.edu Sun Sep 14 13:57:45 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 14 Sep 2014 13:57:45 -0400 Subject: protocol.py, brine.py, and compat.py causing trouble In-Reply-To: References: Message-ID: On 9/14/2014 2:44 AM, Josh English wrote: > I do not know what these three files are doing, To the best of my knowledge, protocol.py, brine.py, compat.py, are not part of the stdlib. What have you installed other than Python? What editor/IDE are you using? Check your lib/site-packages directory. From a google search, brine.py is a pickle replacement in the rpyc and dreampie (and other) packages. The other two names are pretty generic and probably common. -- Terry Jan Reedy From tjreedy at udel.edu Sun Sep 14 14:42:52 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 14 Sep 2014 14:42:52 -0400 Subject: CSV methodology In-Reply-To: References: Message-ID: On 9/14/2014 12:56 PM, jayte wrote: > On Sun, 14 Sep 2014 03:02:12 -0400, Terry Reedy wrote: > >> On 9/13/2014 9:34 PM, jetrn at newsguy.com wrote: > > [...] > >> First you need to think about (and document) what your numbers mean and >> how they should be organized for analysis. >> >>> An example of the data: >>> 1.850358651774470E-0002 >> >> Why is this so smaller than the next numbers. Are all those digits >> significant, or are they mostly just noise -- and best dropped by >> rounding the number to a few significant digits. > > Sorry, I neglected to mention the values' significance. The MXP program > uses the "distance estimate" algorithm in its fractal data generation. The > values are thus, for each point in a 1778 x 1000 image: > > Distance, (an extended double) > Iterations, (a 16 bit int) > zc_x, (a 16 bit int) > zc_y (a 16 bit int) > (Durring the "orbit" calculations, the result of each iteration will be positive > or negative. The "zc" is a "zero crossing" count, or frequency, and is > used in the eventual coloring algorithm. "Distance" can range from zero > to very small.) > >>> 32 >>> 22 >>> 27 If you can output Distance as an 8 byte double in IEEE 754 binary64 format, you could read a binary file with Python using the struct module. https://docs.python.org/3/library/struct.html#module-struct This would be the fastest way for output and subsequent input. If you want a text file either for human readability or because you cannot write a readable binary file, each line would have the 4 fields listed above (with image row/col implied by line number). I strongly suggest a fixed column format with spaces between the fields. It might be easiest to put the float as the end instead of the beginning. Allowing max iterations = 999, your first line would look like 32 22 27 1.850358651774470E-0002 for line in file iternum, zc_x, zc_y, distance = line.split() This will be faster for both you and the machine to read. > Initially, I tried exporting the raw binary (hex) data, 'hex' usually means a hex string representation of the raw binary, so I am not sure what you actually did. > and no matter > what I tried, could not get Python to read it in any useful way (which > I attribute to my lack of knowledge in Python) Again, see struct module. Your mention of 'zooming' implies that you might want to write and read multiple multi-megabyte images in a single session. If so, true binary would be best. Another suggestion is to use the numpy package to read your image files into binary arrays (rather than arrays of Python number objects). This would be much faster (and use less memory). Numpy arrays are 'standard' within Pythonland and can be used by scipy and other programs to display and analyze the arrays. A third idea is to make your generator directly callable from Python. If you can put it in a dll, you could access it with ctypes. If you can wrap it in a C program, you could use cython to make a Python extension modules. Now I have probably given you too much to think about, so time to stop ;-). -- Terry Jan Reedy From cs at zip.com.au Sun Sep 14 19:28:03 2014 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 15 Sep 2014 09:28:03 +1000 Subject: CSV methodology In-Reply-To: <85cca2f1-47e3-490c-92e8-66c0461cf8ff@googlegroups.com> References: <85cca2f1-47e3-490c-92e8-66c0461cf8ff@googlegroups.com> Message-ID: <20140914232803.GA28817@cskk.homeip.net> On 14Sep2014 01:56, rusi wrote: >On Sunday, September 14, 2014 2:09:51 PM UTC+5:30, Cameron Simpson wrote: > >> If you have a nice regular CSV file, with say 3 values per row, you can go: > >> reader = csv.reader(f) >> for row in reader: >> a, b, c - row > >I guess you meant: a, b, c = row >? Yeah :-( Cheers, Cameron Simpson From auriocus at gmx.de Mon Sep 15 02:04:03 2014 From: auriocus at gmx.de (Christian Gollwitzer) Date: Mon, 15 Sep 2014 08:04:03 +0200 Subject: Lists In-Reply-To: <12kc1a5j82lak7tmnatvhk84fh2ne08s24@4ax.com> References: <12kc1a5j82lak7tmnatvhk84fh2ne08s24@4ax.com> Message-ID: Am 15.09.14 04:40, schrieb Seymore4Head: > nums=range(1,11) > print (nums) > I don't understand why the command nums=range(1,11) doesn't work. > I would think that print(nums) should be 1,2,3 ect. > Instead it prints range(1,11) It does work, but in a different way than you might think. range() does not return a list of numbers, but rather a generator - that is an object which produces the values one after another. But you can transform it into a list: print(list(nums)) should give you what you want. Christian From steve+comp.lang.python at pearwood.info Mon Sep 15 02:59:36 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 15 Sep 2014 16:59:36 +1000 Subject: Lists References: <12kc1a5j82lak7tmnatvhk84fh2ne08s24@4ax.com> Message-ID: <54168e59$0$30000$c3e8da3$5496439d@news.astraweb.com> Seymore4Head wrote: > import random > nums=range(1,11) > print (nums) > samp=random.sample(nums,10) > top=nums > newlist=nums[::-1] > tail=newlist > > for x in range(10): > print ("Top {:2d} Tail {:2.0f} Sample {:2d} > ".format(top[x],tail[x],samp[x])) > > I don't understand why the command nums=range(1,11) doesn't work. Of course it works. It does exactly what you told it to do: set the variable "nums" to the result of calling range(1, 11). The only question is, what does range(1, 11) do? > I would think that print(nums) should be 1,2,3 ect. > Instead it prints range(1,11) Did you read the documentation for range? py> help(range) class range(object) | range([start,] stop[, step]) -> range object | | Returns a virtual sequence of numbers from start to stop by step. [...] range in Python 3 does not return a list. It returns a special object which provides a sequence of numbers, but without actually storing them all in a list. > Why does random.sample(nums,10) give me the numbers between 1 and 10. What did you expect it to do? Did you read the documentation? py> import random py> help(random.sample) Help on method sample in module random: sample(self, population, k) method of random.Random instance Chooses k unique random elements from a population sequence or set. [...] To choose a sample in a range of integers, use range as an argument. This is especially fast and space efficient for sampling from a large population: sample(range(10000000), 60) The docs even tell you that (1) sample supports range objects, and (2) using range is more efficient than lists. > I am missing something subtle again. range objects behave *like* lists when you index them: py> nums = range(1, 100) py> nums[0] # First item. 1 py> nums[-1] # Last item. 99 They're even smart enough that you can take a slice, and they give you a new range object: py> nums[1:10] range(2, 11) When you iterate over them, you get each item in turn: py> for i in range(1, 4): ... print(i) ... 1 2 3 range objects are more efficient than lists if the numbers follow the right sort of pattern. While a list can contain any values you like, in any order: py> nums = [1, 33, 5, 222, 4, 6, 0, 8888888, 7] range objects are limited to a linear sequence of: start, start+step, start+2*step, start+3*step, ... up to some end value. The reason range is more efficient is that, unlike lists, it doesn't need to pre-populate all the values required, it can calculate them on the fly when and as required. The reason why lists are more flexible is that the values don't have to be calculated as needed, they can just be stored, ready to use. -- Steven From steve+comp.lang.python at pearwood.info Mon Sep 15 03:09:21 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 15 Sep 2014 17:09:21 +1000 Subject: Lists References: <12kc1a5j82lak7tmnatvhk84fh2ne08s24@4ax.com> Message-ID: <541690a1$0$29966$c3e8da3$5496439d@news.astraweb.com> Christian Gollwitzer wrote: > range() does > not return a list of numbers, but rather a generator Technically, it's not a generator. It's a range object. Generators can return anything, and you have to program them by using yield: def gen(): yield 1 yield 2 if today() is Tuesday: yield 99 yield 3 whereas range() objects are much more specific in what they can do. But otherwise, they behave in a similar fashion. -- Steven From 4kir4.1i at gmail.com Mon Sep 15 03:12:27 2014 From: 4kir4.1i at gmail.com (Akira Li) Date: Mon, 15 Sep 2014 11:12:27 +0400 Subject: CSV methodology References: Message-ID: <87oauhe4ro.fsf@gmail.com> jetrn at newsguy.com writes: > Hello. Back in the '80s, I wrote a fractal generator, which, over the years, > I've modified/etc to run under Windows. I've been an Assembly Language > programmer for decades. Recently, I decided to learn a new language, > and decided on Python, and I just love it, and the various IDEs. > > Anyway, something I thought would be interesting, would be to export > some data from my fractal program (I call it MXP), and write something > in Python and its various scientific data analysis and plotting modules, > and... well, see what's in there. > Tools that are worth mentioning: ipython notebook, pandas For example, http://nbviewer.ipython.org/github/twiecki/financial-analysis-python-tutorial/blob/master/1.%20Pandas%20Basics.ipynb -- Akira From Seymore4Head at Hotmail.invalid Sun Sep 14 22:40:14 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Sun, 14 Sep 2014 22:40:14 -0400 Subject: Lists Message-ID: <12kc1a5j82lak7tmnatvhk84fh2ne08s24@4ax.com> import random nums=range(1,11) print (nums) samp=random.sample(nums,10) top=nums newlist=nums[::-1] tail=newlist for x in range(10): print ("Top {:2d} Tail {:2.0f} Sample {:2d} ".format(top[x],tail[x],samp[x])) I don't understand why the command nums=range(1,11) doesn't work. I would think that print(nums) should be 1,2,3 ect. Instead it prints range(1,11) Why does random.sample(nums,10) give me the numbers between 1 and 10. I am missing something subtle again. From __peter__ at web.de Mon Sep 15 03:29:02 2014 From: __peter__ at web.de (Peter Otten) Date: Mon, 15 Sep 2014 09:29:02 +0200 Subject: CSV methodology References: Message-ID: jayte wrote: > Sorry, I neglected to mention the values' significance. The MXP program > uses the "distance estimate" algorithm in its fractal data generation. > The values are thus, for each point in a 1778 x 1000 image: > > Distance, (an extended double) > Iterations, (a 16 bit int) > zc_x, (a 16 bit int) > zc_y (a 16 bit int) > Probably a bit too early in your "Python career", but you can read raw data with numpy. Something like with open(filename, "rb") as f: a = numpy.fromfile(f, dtype=[ ("distance", "f16"), ("iterations", "i2"), ("zc_x", "i2"), ("zc_y", "i2"), ]).reshape(1778, 1000) might do, assuming "extended double" takes 16 bytes. From __peter__ at web.de Mon Sep 15 03:36:46 2014 From: __peter__ at web.de (Peter Otten) Date: Mon, 15 Sep 2014 09:36:46 +0200 Subject: Lists References: <12kc1a5j82lak7tmnatvhk84fh2ne08s24@4ax.com> Message-ID: Christian Gollwitzer wrote: > Am 15.09.14 04:40, schrieb Seymore4Head: >> nums=range(1,11) >> print (nums) > >> I don't understand why the command nums=range(1,11) doesn't work. >> I would think that print(nums) should be 1,2,3 ect. >> Instead it prints range(1,11) > > It does work, but in a different way than you might think. range() does > not return a list of numbers, but rather a generator - that is an object > which produces the values one after another. But you can transform it > into a list: > > print(list(nums)) > > should give you what you want. > > Christian I'd call range() an iterable. A generator is a specific kind of iterator. The difference between iterable and iterator is that the latter cannot be restarted: >>> def f(): ... yield 1 ... yield 2 ... >>> g = f() >>> list(g) [1, 2] >>> list(g) [] # empty --> g is an iterator >>> r = range(1, 3) >>> list(r) [1, 2] >>> list(r) [1, 2] # same as before --> r is an iterable From gandalf at shopzeus.com Mon Sep 15 05:21:15 2014 From: gandalf at shopzeus.com (=?ISO-8859-2?Q?Nagy_L=E1szl=F3_Zsolt?=) Date: Mon, 15 Sep 2014 11:21:15 +0200 Subject: something like pyfilesystem, fs.zipfs that works on windows Message-ID: <5416AF8B.50106@shopzeus.com> I need something that is similar to zipfs, but it should work on Windows and Unix too. Requirements: * store a complete directory structure and multiple files in a single file * be able to add, replace and delete files and directories * binary write/append to files is NOT a requirement but it would be good * should work with any file-like object that implements read(), write(), seek(), tell(), close(), flush() and truncate() [e.g. no fileno()] * does not need to store the files in compressed form Is there something like this available? Thanks, Laszlo -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. From technews.full at gmail.com Mon Sep 15 08:16:25 2014 From: technews.full at gmail.com (Harish Tech) Date: Mon, 15 Sep 2014 17:46:25 +0530 Subject: List insert at index that is well out of range - behaves like append that too SILENTLY Message-ID: Hi , Let me demonstrate the problem I encountered : I had a list a = [1, 2, 3] when I did a.insert(100, 100) [1, 2, 3, 100] as list was originally of size 4 and I was trying to insert value at index 100 , it behaved like append instead of throwing any errors as I was trying to insert in an index that did not even existed . Should it not throw IndexError: list assignment index out of range exception as it throws when I attempt doing a[100] = 100 Personal Opinion : Lets see how other languages behave in such a situation : 1. Ruby : > a = [1, 2] > a[100] = 100 > a => [1, 2, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 100] The way ruby handles this is pretty clear and sounds meaningful (and this is how I expected to behave and it behaved as per my expectation) at least to me . Here also it was silently handled but the way it fills non existing indexes in between with nil sounded meaningful . 2. Java : When I do such an action in java by using .add(index.value) on may be arraylist or linkedlist I get java.lang.IndexOutOfBoundException Here instead of handling it silently it throws an error . But the python way of handling such a problem by appending to the end sounds more unexpected to me . This in fact flummoxed me in the beginning making me think it could be a bug . Then when I raised it in stackoverflow I got chance to look at source and found that's the way code is written . Question : 1. Any idea Why it has been designed to silently handle this instead of at least informing the user with an exception(as in java) or attaching null values in empty places (as in ruby) ? Thanks Harish -------------- next part -------------- An HTML attachment was scrubbed... URL: From marcoprosperi347 at gmail.com Mon Sep 15 08:19:43 2014 From: marcoprosperi347 at gmail.com (Marco Prosperi) Date: Mon, 15 Sep 2014 05:19:43 -0700 (PDT) Subject: Marco's atexit issue was: Re: ANN: wxPython 3.0.1.1 In-Reply-To: <29a07ca1-990c-432a-9693-3dbc5f89f6f4@googlegroups.com> References: <5411246B.8060700@alldunn.com> <180ac253-7f29-4157-aed6-38f929e00674@googlegroups.com> <29a07ca1-990c-432a-9693-3dbc5f89f6f4@googlegroups.com> Message-ID: <5890038b-4169-4fad-8702-81cdfc53a4fe@googlegroups.com> all the code addressed by the exception is out of my source. I don't have any atexit.register in my code Marco On Friday, September 12, 2014 6:33:09 PM UTC+2, Nathan McCorkle wrote: > > > > On Friday, September 12, 2014 1:14:41 AM UTC-7, Marco Prosperi wrote: >> >> >> I'm trying to pass my application from wxpython2.9.4 to 3.0.1 but there >> seems to be still some of the problems that made me skip wxpy2.9.5: when >> I >> close the main window of my application (windows7-64bit, python 2.7) I >> get >> exceptions like this below (none with wxpy2.9.4). How can I avoid that my >> users get this? this happens after my OnExit function is completed >> >> Marco >> >> Error in atexit._run_exitfuncs: >> Traceback (most recent call last): >> File "C:\Programmi\Python27\lib\atexit.py", line 24, in _run_exitfuncs >> func(*targs, **kargs) >> PyAssertionError: C++ assertion "GetEventHandler() == this" failed at >> ..\..\src\ >> common\wincmn.cpp(478) in wxWindowBase::~wxWindowBase(): any pushed event >> handle >> rs must have been removed >> Error in sys.exitfunc: >> Traceback (most recent call last): >> File "C:\Programmi\Python27\lib\atexit.py", line 24, in _run_exitfuncs >> func(*targs, **kargs) >> wx._core.PyAssertionError: C++ assertion "GetEventHandler() == this" >> failed >> at . >> .\..\src\common\wincmn.cpp(478) in wxWindowBase::~wxWindowBase(): any >> pushed eve >> nt handlers must have been removed >> > > > Post some code? Sounds like you're trying to interact with a wxPython > object in a function using atexit.register(AtExit)... which likely is > always going to happen after the wx Destroy method is all done. > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at davea.name Mon Sep 15 09:05:50 2014 From: davea at davea.name (Dave Angel) Date: Mon, 15 Sep 2014 09:05:50 -0400 (EDT) Subject: Lists References: <12kc1a5j82lak7tmnatvhk84fh2ne08s24@4ax.com> Message-ID: Seymore4Head Wrote in message: > import random > nums=range(1,11) > print (nums) > samp=random.sample(nums,10) > top=nums > newlist=nums[::-1] > tail=newlist > > for x in range(10): > print ("Top {:2d} Tail {:2.0f} Sample {:2d} > ".format(top[x],tail[x],samp[x])) > > I don't understand why the command nums=range(1,11) doesn't work. > I would think that print(nums) should be 1,2,3 ect. > Instead it prints range(1,11) You need to specify that you're using python 3.x In python 2, nums would indeed be a list. And range (5000000) would be a list of 5 million items, taking quite a while and lots of memory to build. So python 3 uses lazy evaluation when it can. In this case it returns a range sequence type, not a list. https://docs.python.org/3/library/stdtypes.html#typesseq-range If you need the ints all at once, simply call list. nums =list (range (1, 11) > > Why does random.sample(nums,10) give me the numbers between 1 and 10. > I am missing something subtle again. > > It doesn't give you the numbers between 1 and 10, it gives you a list composed of those numbers in an arbitrary order, but with no duplicates. Your question is incomplete. It does that because it's defined to. But clearly you're puzzled. So what is confusing? The fact that there are 10? The fact that they're between 1 and 10 inclusive? Or the fact there are no duplicates? Or something else? You might help your confusion by experimenting. Try 7 instead of 10. Or pick different range limits. -- DaveA From davea at davea.name Mon Sep 15 09:12:02 2014 From: davea at davea.name (Dave Angel) Date: Mon, 15 Sep 2014 09:12:02 -0400 (EDT) Subject: protocol.py, brine.py, and compat.py causing trouble References: Message-ID: Josh English Wrote in message: > I do not know what these three filesare doing, but suddenly they have caught in a loop every time I try to run some code. > > I grabbed the trace decorator from the python library and this is the last bit of the output: > > > trollvictims.py(129): if self.current_attack: > trollvictims.py(130): print "returning", self.current_attack, type(self.current_attack) > (532): protocol.py(439): protocol.py(228): protocol.py(229): protocol.py(244): brine.py(366): brine.py(368): brine.py(369): brine.py(369): brine.py(366): brine.py(367): ............. > This is where I managed to send a keybord interrupt. I was working just fine, tweaking a line, running the code, tweaking a line, running the code, until this point. > > I'm on Windows 7 using Python 2.7.5. I should upgrade, and will do so, but what are these files and why are they suddenly crashing on me? > Since they're not part of the stdlib, and you don't remember writing them, you might get a hint by printing import brine print (brine.__brine__) -- DaveA From d.moorcroft at turvgng.bham.sch.uk Mon Sep 15 09:11:39 2014 From: d.moorcroft at turvgng.bham.sch.uk (D Moorcroft) Date: Mon, 15 Sep 2014 14:11:39 +0100 (BST) Subject: Python 3.3.2 help In-Reply-To: <541040f6$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <1951135237.5067937.1410341316898.JavaMail.zimbra@turvgng.bham.sch.uk> <54101B2E.8050100@timgolden.me.uk> <541040f6$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <572119645.5803652.1410786699747.JavaMail.zimbra@turvgng.bham.sch.uk> Hi, We are using windows 7 and it is all pupils as they are more restricted than staff. They are using the python 3.3.2 shell and trying to print from there Thank you, David Moorcroft ICT Operations Manager & Website Manager Turves Green Girls' School ----- Original Message ----- From: "Steven D'Aprano" To: python-list at python.org Sent: Wednesday, 10 September, 2014 1:15:49 PM Subject: Re: Python 3.3.2 help Hello, My response is below, interleaved with your comments. D Moorcroft wrote: >> Hi, >> >> We are running Python 3.3.2 but pupils are unable to print as they >> cannot use the command prompt. What operating system are you using? Windows, Linux, Mac? Something else? Is it ALL pupils who are unable to print or just some of them? Which command prompt are they using? Can you reproduce the failure to print? If so, please tell us the detailed steps you (and the pupils) go through. E.g. something like this: "On Windows XP, choose Run from the Start Menu. Type cmd.exe and press Enter. When the terminal window opens, type print 'Hello World' and Enter." It will help if you can tell us whether your pupils are using IDLE, IPython, or the default Python interactive interpreter. If you can answer these questions, which should have a better chance of diagnosing the problem. Further responses below. >> An error comes up saying printing failed (exit status Oxff). Based on this, my guess is that your students are accidentally running the DOS "print" command at the DOS prompt, not Python at all. Perhaps they are forgetting to run the "python" command first to launch the Python interpreter, and are running directly in the DOS prompt? You can check this by reading the command prompt. If it looks like three greater-than signs >>> then you are running in Python's default interpreter. If it looks something like this: C:\Documents and Settings\user\> or perhaps like this: C:\> then you are still inside the DOS command prompt. Unfortunately, I am not very experienced with Windows, so I cannot tell you the right method to start Python. I would expect there to be a Start menu command, perhaps called "IDLE", or "Python", but I'm not sure. >> Is there any way that we can get users who can't see the command >> prompt to be able to print? I'm not entirely sure I understand this question. Can you explain in more detail? By the way, as you know there are two meanings of "print" in computing. There is printing to the screen, and printing to sheets of paper with an actual printer. Which are you intending? Regards, -- Steven -- https://mail.python.org/mailman/listinfo/python-list ************************************************************* This message has been checked for viruses by the Birmingham Grid for Learning. For guidance on good e-mail practice, e-mail viruses and hoaxes please visit: http://www.bgfl.org/emailaup ************************************************************* ************************************************************* This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify postmaster at bgfl.org The views expressed within this email are those of the individual, and not necessarily those of the organisation ************************************************************* From davea at davea.name Mon Sep 15 09:29:48 2014 From: davea at davea.name (Dave Angel) Date: Mon, 15 Sep 2014 09:29:48 -0400 (EDT) Subject: CSV methodology References: Message-ID: jetrn at newsguy.com Wrote in message: > > Hello. Back in the '80s, I wrote a fractal generator, which, over the years, > I've modified/etc to run under Windows. I've been an Assembly Language > programmer for decades. Recently, I decided to learn a new language, > and decided on Python, and I just love it, and the various IDEs. > > Anyway, something I thought would be interesting, would be to export > some data from my fractal program (I call it MXP), and write something > in Python and its various scientific data analysis and plotting modules, > and... well, see what's in there. > > An example of the data: > 1.850358651774470E-0002 > 32 > 22 > 27 > ... (this format repeats) > > So, I wrote a procedure in MXP which converts "the data" and exports > a csv file. So far, here's what I've started with: > > ----------------------------------------------- > import csv > > fname = 'E:/Users/jayte/Documents/Python Scripts/XportTestBlock.csv' > > f = open(fname) > > reader = csv.reader(f) > > for flt in reader: > x = len(flt) > file.close(f) > ----------------------------------------------- > > This will get me an addressable array, as: > > flt[0], flt[1], flt[350], etc... from which values can be assigned to > other variables, converted... > > My question: Is there a better way? Do I need to learn more about > how csv file are organized? Perhaps I know far too little of Python > to be attempting something like this, just yet. > > Looks to me like your MXP has produced a single line file, with all the values on that single line separated by commas. If the data is really uniform, then it'd be more customary to put one item per line. But your sample seems to imply the data is a float followed by 3 ints. If so, then I'd expect to see a line for each group of 4. The only advantage of a csv is if the data is rectangular. If it's really a single column, it should be one per line, and you'd use readline instead. -- DaveA From davea at davea.name Mon Sep 15 09:35:09 2014 From: davea at davea.name (Dave Angel) Date: Mon, 15 Sep 2014 09:35:09 -0400 (EDT) Subject: protocol.py, brine.py, and compat.py causing trouble References: Message-ID: Dave Angel Wrote in message: > Josh English Wrote in message: >> I do not know what these three filesare doing, but suddenly they have caught in a loop every time I try to run some code. >> >> I grabbed the trace decorator from the python library and this is the last bit of the output: >> >> >> trollvictims.py(129): if self.current_attack: >> trollvictims.py(130): print "returning", self.current_attack, type(self.current_attack) >> (532): protocol.py(439): protocol.py(228): protocol.py(229): protocol.py(244): brine.py(366): brine.py(368): brine.py(369): brine.py(369): brine.py(366): brine.py(367): > > ............. > >> This is where I managed to send a keybord interrupt. I was working just fine, tweaking a line, running the code, tweaking a line, running the code, until this point. >> >> I'm on Windows 7 using Python 2.7.5. I should upgrade, and will do so, but what are these files and why are they suddenly crashing on me? >> > > > Since they're not part of the stdlib, and you don't remember > writing them, you might get a hint by printing > import brine > print (brine.__brine__) > Oops, meant print (brine.__file__) -- DaveA From davea at davea.name Mon Sep 15 09:32:34 2014 From: davea at davea.name (Dave Angel) Date: Mon, 15 Sep 2014 09:32:34 -0400 (EDT) Subject: Shuffle References: <5414F047.9030809@gmail.com> Message-ID: Michael Torrie Wrote in message: > On 09/13/2014 05:47 PM, Seymore4Head wrote: >> Here is a screenshot of me trying Dave Briccetti's quiz program from >> the shell and it (the shuffle command) works. >> https://www.youtube.com/watch?v=VR-yNEpGk3g >> http://i.imgur.com/vlpVa5i.jpg >> >> Two questions >> If you import random, do you need to "from random import shuffle"? >> >> Why does shuffle work from the command line and not when I add it to >> this program? >> >> import random >> import shuffle >> nums=list(range(1,11)) >> shuffle(nums) >> print (nums) >> >> I get: >> No module named 'shuffle' > > You can do it two ways: > Refer to it as random.shuffle() > > or > > from random import shuffle > > I tend to use the first method (random.shuffle). That way it prevents > my local namespace from getting polluted with random symbols imported > from modules. > > Or a third way: import random shuffle = random.shuffle -- DaveA From steve+comp.lang.python at pearwood.info Mon Sep 15 10:02:05 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 16 Sep 2014 00:02:05 +1000 Subject: Shuffle References: <5414F047.9030809@gmail.com> Message-ID: <5416f15e$0$30000$c3e8da3$5496439d@news.astraweb.com> Dave Angel wrote: > Michael Torrie Wrote in message: >> You can do it two ways: >> Refer to it as random.shuffle() >> >> or >> >> from random import shuffle >> >> I tend to use the first method (random.shuffle). That way it prevents >> my local namespace from getting polluted with random symbols imported >> from modules. > > Or a third way: > > import random > shuffle = random.shuffle Our three weapons are: (1) fully qualified names: import random random.shuffle (2) unqualified local imports: from random import shuffle (3) local name binding: import random shuffle = random.shuffle (4) messing about under the hood: shuffle = __import__('random', fromlist=['shuffle']).shuffle (5) and a fanatical devotion to the Pope. A serious question -- what is the point of the fromlist argument to __import__? It doesn't appear to actually do anything. https://docs.python.org/3/library/functions.html#__import__ -- Steven From steve+comp.lang.python at pearwood.info Mon Sep 15 10:08:09 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 16 Sep 2014 00:08:09 +1000 Subject: Python 3.3.2 help References: <1951135237.5067937.1410341316898.JavaMail.zimbra@turvgng.bham.sch.uk> <54101B2E.8050100@timgolden.me.uk> <541040f6$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5416f2ca$0$29991$c3e8da3$5496439d@news.astraweb.com> Hello David, and thanks for replying. More comments below. D Moorcroft wrote: > Hi, > > We are using windows 7 and it is all pupils as they are more restricted > than staff. > > They are using the python 3.3.2 shell and trying to print from there What you are describing does not sound like the sort of error the Python shell will give. Are you able to copy and paste the student's exact input and output, including the complete error message? If not, can you take a screenshot and post that? (As a general rule, we prefer text-based communication rather than pictures. For all we know, there could be blind or other visually-impaired users on this forum who can read text via a screen reader, but cannot contribute when it is a screenshot. But if all else fails, a screenshot is better than nothing.) We would love to help you, but without further information we have no idea what is going on. The more concrete information you can pass on to us, the better. Regards, Steve > > Thank you, > > David Moorcroft > ICT Operations Manager & > Website Manager > Turves Green Girls' School > > ----- Original Message ----- > From: "Steven D'Aprano" > To: python-list at python.org > Sent: Wednesday, 10 September, 2014 1:15:49 PM > Subject: Re: Python 3.3.2 help > > Hello, > > My response is below, interleaved with your comments. > > D Moorcroft wrote: > >>> Hi, >>> >>> We are running Python 3.3.2 but pupils are unable to print as they >>> cannot use the command prompt. > > What operating system are you using? Windows, Linux, Mac? Something else? > > Is it ALL pupils who are unable to print or just some of them? > > Which command prompt are they using? Can you reproduce the failure to > print? If so, please tell us the detailed steps you (and the pupils) go > through. E.g. something like this: > > "On Windows XP, choose Run from the Start Menu. Type cmd.exe and press > Enter. When the terminal window opens, type print 'Hello World' and > Enter." > > It will help if you can tell us whether your pupils are using IDLE, > IPython, or the default Python interactive interpreter. > > If you can answer these questions, which should have a better chance of > diagnosing the problem. > > Further responses below. > > >>> An error comes up saying printing failed (exit status Oxff). > > Based on this, my guess is that your students are accidentally running the > DOS "print" command at the DOS prompt, not Python at all. Perhaps they are > forgetting to run the "python" command first to launch the Python > interpreter, and are running directly in the DOS prompt? > > You can check this by reading the command prompt. If it looks like three > greater-than signs >>> then you are running in Python's default > interpreter. If it looks something like this: > > C:\Documents and Settings\user\> > > or perhaps like this: > > C:\> > > then you are still inside the DOS command prompt. > > Unfortunately, I am not very experienced with Windows, so I cannot tell > you the right method to start Python. I would expect there to be a Start > menu command, perhaps called "IDLE", or "Python", but I'm not sure. > > >>> Is there any way that we can get users who can't see the command >>> prompt to be able to print? > > I'm not entirely sure I understand this question. Can you explain in more > detail? > > By the way, as you know there are two meanings of "print" in computing. > There is printing to the screen, and printing to sheets of paper with an > actual printer. Which are you intending? > > > Regards, > > > -- Steven From i at introo.me Mon Sep 15 10:14:24 2014 From: i at introo.me (Shiyao Ma) Date: Mon, 15 Sep 2014 22:14:24 +0800 Subject: What's the function location that reads the cached .pyc file from disk. Message-ID: Hi. what's the location of the function that reads the .pyc file ? I bet it should lie in somewhere in https://hg.python.org/cpython/file/322ee2f2e922/Lib/importlib But what's the actual location? Btw, why I need it? I want to know the structure of a .pyc file. Of course the function that reads the .pyc must know something about it. (I am aware of the structure of a typical .pyc file from some clicks of google pages, but I am interested in the *source* and the most authoritative answer, aka, the source code). Thanks. -- ????????????????http://introo.me? From __peter__ at web.de Mon Sep 15 10:30:50 2014 From: __peter__ at web.de (Peter Otten) Date: Mon, 15 Sep 2014 16:30:50 +0200 Subject: __import__(name, fromlist=...), was Re: Shuffle References: <5414F047.9030809@gmail.com> <5416f15e$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > A serious question -- what is the point of the fromlist argument to > __import__? It doesn't appear to actually do anything. > > > https://docs.python.org/3/library/functions.html#__import__ It may be for submodules: $ mkdir -p aaa/bbb $ tree . ??? aaa ??? bbb 2 directories, 0 files $ python3 Python 3.4.0 (default, Apr 11 2014, 13:05:11) [GCC 4.8.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> __import__("aaa").bbb Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'bbb' >>> __import__("aaa", fromlist=["bbb"]).bbb From Seymore4Head at Hotmail.invalid Mon Sep 15 11:27:54 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Mon, 15 Sep 2014 11:27:54 -0400 Subject: Lists References: <12kc1a5j82lak7tmnatvhk84fh2ne08s24@4ax.com> <54168e59$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, 15 Sep 2014 16:59:36 +1000, Steven D'Aprano wrote: >Seymore4Head wrote: > >> import random >> nums=range(1,11) >> print (nums) >> samp=random.sample(nums,10) >> top=nums >> newlist=nums[::-1] >> tail=newlist >> >> for x in range(10): >> print ("Top {:2d} Tail {:2.0f} Sample {:2d} >> ".format(top[x],tail[x],samp[x])) >> >> I don't understand why the command nums=range(1,11) doesn't work. > >Of course it works. It does exactly what you told it to do: set the >variable "nums" to the result of calling range(1, 11). The only question >is, what does range(1, 11) do? > > >> I would think that print(nums) should be 1,2,3 ect. >> Instead it prints range(1,11) > >Did you read the documentation for range? > >py> help(range) >class range(object) > | range([start,] stop[, step]) -> range object > | > | Returns a virtual sequence of numbers from start to stop by step. > [...] > >range in Python 3 does not return a list. It returns a special object which >provides a sequence of numbers, but without actually storing them all in a >list. > > >> Why does random.sample(nums,10) give me the numbers between 1 and 10. > >What did you expect it to do? Did you read the documentation? > > >py> import random >py> help(random.sample) >Help on method sample in module random: > >sample(self, population, k) method of random.Random instance > Chooses k unique random elements from a population sequence or set. > [...] > To choose a sample in a range of integers, use range as an argument. > This is especially fast and space efficient for sampling from a > large population: sample(range(10000000), 60) > >The docs even tell you that (1) sample supports range objects, and (2) using >range is more efficient than lists. > > >> I am missing something subtle again. > >range objects behave *like* lists when you index them: > >py> nums = range(1, 100) >py> nums[0] # First item. >1 >py> nums[-1] # Last item. >99 > >They're even smart enough that you can take a slice, and they give you a new >range object: > >py> nums[1:10] >range(2, 11) > >When you iterate over them, you get each item in turn: > >py> for i in range(1, 4): >... print(i) >... >1 >2 >3 > >range objects are more efficient than lists if the numbers follow the right >sort of pattern. While a list can contain any values you like, in any >order: > >py> nums = [1, 33, 5, 222, 4, 6, 0, 8888888, 7] > >range objects are limited to a linear sequence of: > >start, start+step, start+2*step, start+3*step, ... > >up to some end value. The reason range is more efficient is that, unlike >lists, it doesn't need to pre-populate all the values required, it can >calculate them on the fly when and as required. The reason why lists are >more flexible is that the values don't have to be calculated as needed, >they can just be stored, ready to use. I see now Thanks everyone From Seymore4Head at Hotmail.invalid Mon Sep 15 11:28:07 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Mon, 15 Sep 2014 11:28:07 -0400 Subject: Lists References: <12kc1a5j82lak7tmnatvhk84fh2ne08s24@4ax.com> Message-ID: On Mon, 15 Sep 2014 09:05:50 -0400 (EDT), Dave Angel wrote: >Seymore4Head Wrote in message: >> import random >> nums=range(1,11) >> print (nums) >> samp=random.sample(nums,10) >> top=nums >> newlist=nums[::-1] >> tail=newlist >> >> for x in range(10): >> print ("Top {:2d} Tail {:2.0f} Sample {:2d} >> ".format(top[x],tail[x],samp[x])) >> >> I don't understand why the command nums=range(1,11) doesn't work. >> I would think that print(nums) should be 1,2,3 ect. >> Instead it prints range(1,11) > >You need to specify that you're using python 3.x > >In python 2, nums would indeed be a list. And range (5000000) > would be a list of 5 million items, taking quite a while and lots > of memory to build. So python 3 uses lazy evaluation when it > can. In this case it returns a range sequence type, not a > list. > >https://docs.python.org/3/library/stdtypes.html#typesseq-range > >If you need the ints all at once, simply call list. > nums =list (range (1, 11) > >> >> Why does random.sample(nums,10) give me the numbers between 1 and 10. >> I am missing something subtle again. >> >> > >It doesn't give you the numbers between 1 and 10, it gives you a > list composed of those numbers in an arbitrary order, but with no > duplicates. > >Your question is incomplete. It does that because it's defined > to. But clearly you're puzzled. So what is confusing? The fact > that there are 10? The fact that they're between 1 and 10 > inclusive? Or the fact there are no duplicates? Or something > else? > >You might help your confusion by experimenting. Try 7 instead of > 10. Or pick different range limits. Actually I do understand that random.sample(nums,10) does give a sample of the numbers in the list. What was throwing me off was that nums=range(1,11) did not appear to be a list ,but sample was still treating it as a list. But I also figured out what I really needed to do was nums=list(range(1,11) Thanks everyone. From ian.g.kelly at gmail.com Mon Sep 15 11:53:45 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 15 Sep 2014 09:53:45 -0600 Subject: Lists In-Reply-To: References: <12kc1a5j82lak7tmnatvhk84fh2ne08s24@4ax.com> Message-ID: On Mon, Sep 15, 2014 at 1:36 AM, Peter Otten <__peter__ at web.de> wrote: > I'd call range() an iterable. I'd even go so far as to call it a sequence. >>> from collections import Sequence >>> issubclass(range, Sequence) True From __peter__ at web.de Mon Sep 15 12:16:23 2014 From: __peter__ at web.de (Peter Otten) Date: Mon, 15 Sep 2014 18:16:23 +0200 Subject: Lists References: <12kc1a5j82lak7tmnatvhk84fh2ne08s24@4ax.com> Message-ID: Ian Kelly wrote: > On Mon, Sep 15, 2014 at 1:36 AM, Peter Otten <__peter__ at web.de> wrote: >> I'd call range() an iterable. > > I'd even go so far as to call it a sequence. > >>>> from collections import Sequence >>>> issubclass(range, Sequence) > True If you want to be as specific as possible call it a range ;) From emile at fenx.com Mon Sep 15 15:11:25 2014 From: emile at fenx.com (Emile van Sebille) Date: Mon, 15 Sep 2014 12:11:25 -0700 Subject: protocol.py, brine.py, and compat.py causing trouble In-Reply-To: References: Message-ID: On 9/13/2014 11:44 PM, Josh English wrote: > I do not know what these three filesare doing, but suddenly they have caught in a loop every time I try to run some code. > This is where I managed to send a keybord interrupt. I was working just fine, tweaking a line, running the code, tweaking a line, running the code, until this point. That's your clue -- I'd take a close look at the last changes you made a result of which caused this failure and apparent looping. It's easy to lay blame on the (whatever) library and look for a root cause there, but I'd first suspect I did something inappropriate as that's much more likely. Emile From Joshua.R.English at gmail.com Mon Sep 15 15:30:44 2014 From: Joshua.R.English at gmail.com (Josh English) Date: Mon, 15 Sep 2014 12:30:44 -0700 (PDT) Subject: Storing instances using jsonpickle In-Reply-To: References: <46e782a5-b087-4f95-aadb-26e233bf5419@googlegroups.com> Message-ID: On Wednesday, September 3, 2014 7:19:07 PM UTC-7, Ned Batchelder wrote: > Typically, you need to decide explicitly on a serialized representation > for your data. Even if it's JSON, you need to decide what that JSON > looks like. Then you need to write code that converts the JSON-able > data structure (dict of lists, whatever) into your object. Often a > version number is a good idea so that you have some chance of using old > data as your code changes. > Right now my cheap workaround is to define a function that saves the instances __dict__ using json, and to recreate the object, I create a new object using the __init__ method and cycle through the rest of the json keys and apply them to the new object using setattr. It's a quick and dirty hack, but it seems to be working. I do have to make sure that everything that lands in the instance's __dict__ is serializable, but that's not so tough. I need to add a version number, though. Good idea, that. Josh From skip at pobox.com Mon Sep 15 15:44:45 2014 From: skip at pobox.com (Skip Montanaro) Date: Mon, 15 Sep 2014 14:44:45 -0500 Subject: PyCharm refactoring tool? Message-ID: I started up an instance of PyCharm last Friday. It's mostly just been sitting there like a bump on a log. I set things up to use Emacs as my editor. It seems most of its functionality won't be all that useful. Most of my work is on libraries/platforms - stuff which is not runnable in isolation, so the Run menu doesn't look all that useful. I have git, etc integrated into my Emacs environment, so don't need the VCS menu. Most everything else looks fairly genertic. Except the Refactor menu. Before I try to do much/anything with it, I thought I would solicit feedback on its capability. Does it work as intended? I read through the PyCharm help sections on refactoring. It seems to describe a number of code refactorings which aren't available for Python code. For example, I don't see an "invert boolean" refactoring. How useful is PyCharm's refactoring subsystem? Thx, Skip -------------- next part -------------- An HTML attachment was scrubbed... URL: From georger.silva at gmail.com Mon Sep 15 15:49:51 2014 From: georger.silva at gmail.com (George Silva) Date: Mon, 15 Sep 2014 16:49:51 -0300 Subject: PyCharm refactoring tool? In-Reply-To: References: Message-ID: It's pretty useful. I use it for some time now and I very much like it. There are some things that might not be available on Python because of it's duck typing behavior (Pycharm perhaps can't confirm that the type is boolean to suggest it's inversion, for instance). The most powerful for me are the rename refactor and extract. Works like charm (no pun intended). On Mon, Sep 15, 2014 at 4:44 PM, Skip Montanaro wrote: > I started up an instance of PyCharm last Friday. It's mostly just been > sitting there like a bump on a log. I set things up to use Emacs as my > editor. It seems most of its functionality won't be all that useful. Most > of my work is on libraries/platforms - stuff which is not runnable in > isolation, so the Run menu doesn't look all that useful. I have git, etc > integrated into my Emacs environment, so don't need the VCS menu. Most > everything else looks fairly genertic. > > Except the Refactor menu. Before I try to do much/anything with it, I > thought I would solicit feedback on its capability. Does it work as > intended? I read through the PyCharm help sections on refactoring. It seems > to describe a number of code refactorings which aren't available for Python > code. For example, I don't see an "invert boolean" refactoring. > > How useful is PyCharm's refactoring subsystem? > > Thx, > > Skip > > > -- > https://mail.python.org/mailman/listinfo/python-list > > -- George R. C. Silva SIGMA Consultoria ---------------------------- http://www.consultoriasigma.com.br/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Mon Sep 15 16:36:50 2014 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 15 Sep 2014 22:36:50 +0200 Subject: PyCharm refactoring tool? In-Reply-To: References: Message-ID: George Silva schrieb am 15.09.2014 um 21:49: > It's pretty useful. I use it for some time now and I very much like it. > [...] > The most powerful for me are the rename refactor and extract. Works like > charm (no pun intended). Dito. > On Mon, Sep 15, 2014 at 4:44 PM, Skip Montanaro wrote: >> I started up an instance of PyCharm last Friday. It's mostly just been >> sitting there like a bump on a log. I set things up to use Emacs as my >> editor. It seems most of its functionality won't be all that useful. Most >> of my work is on libraries/platforms - stuff which is not runnable in >> isolation, so the Run menu doesn't look all that useful. I also do most exec stuff on the command line - it needs to work there anyway, so the additional config in PyCharm is really something on top that I often don't do. However, running stuff within PyCharm can still be really handy because it integrates very nicely with py.test and other test runners. You get nice visual feedback for your tests, can rerun failing tests with one click, can visually debug problems, get coverage analysis for free, etc. It's all very nicely integrated. Stefan From isenntp at gmail.com Mon Sep 15 19:15:05 2014 From: isenntp at gmail.com (ISE Development) Date: Tue, 16 Sep 2014 01:15:05 +0200 Subject: functools.wraps behaviour Message-ID: <541772fa$0$2078$426a74cc@news.free.fr> The purpose of 'functools.wraps' is to make a decorated function look like the original function, i.e. such that the __name__, __module__, __doc__ attributes are the same as the wrapped function. However, I've noticed inconsistent behaviour. Given the following: import functools def decorator(func): @functools.wraps(func) def wrapper(self): func(self) return wrapper class Klass: @decorator def method(self): raise Exception('boom!') print('Klass.method:',Klass.method) k = Klass() print('k.method',k.method) try: k.method(1) except Exception as e: print('exception:',e) The output (Python 3.3) is: Klass.method: k.method > exception: wrapper() takes 1 positional argument but 2 were given The first two lines are as expected, using the name of the decorated function. However, the exception uses the name of the decorating wrapper function. Is this a bug in functools? Or is this a language feature? If so, is there a valid argument to change this behaviour? -- isedev From nicholascannon1 at gmail.com Mon Sep 15 20:07:57 2014 From: nicholascannon1 at gmail.com (Nicholas Cannon) Date: Mon, 15 Sep 2014 17:07:57 -0700 (PDT) Subject: python script monitor Message-ID: <63a94cb9-171a-4b97-a639-75fec71cae63@googlegroups.com> I have made an app that is not fully stable and I would like to monitor the performance of the app and try and improve the speed of it. I tried to use the activity monitor on the mac but what I want I'm to see how much ram, cup and other stats on what resources that app is using. Is there any apps to specifically monitor a certain app. I am on Mac is so any suggestions that could work with that would be great. From rosuav at gmail.com Mon Sep 15 20:33:58 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 16 Sep 2014 10:33:58 +1000 Subject: python script monitor In-Reply-To: <63a94cb9-171a-4b97-a639-75fec71cae63@googlegroups.com> References: <63a94cb9-171a-4b97-a639-75fec71cae63@googlegroups.com> Message-ID: On Tue, Sep 16, 2014 at 10:07 AM, Nicholas Cannon wrote: > I have made an app that is not fully stable and I would like to monitor the performance of the app and try and improve the speed of it. I tried to use the activity monitor on the mac but what I want I'm to see how much ram, cup and other stats on what resources that app is using. Is there any apps to specifically monitor a certain app. I am on Mac is so any suggestions that could work with that would be great. > If by "not fully stable" you mean that it sometimes isn't working, then playing with performance is a bad idea. Start by getting it correct, then worry about how fast it is. Otherwise, what do you mean by that? What's not stable about your app? ChrisA From rosuav at gmail.com Mon Sep 15 20:46:47 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 16 Sep 2014 10:46:47 +1000 Subject: functools.wraps behaviour In-Reply-To: <541772fa$0$2078$426a74cc@news.free.fr> References: <541772fa$0$2078$426a74cc@news.free.fr> Message-ID: On Tue, Sep 16, 2014 at 9:15 AM, ISE Development wrote: > @functools.wraps(func) > def wrapper(self): > func(self) > return wrapper > > try: > k.method(1) > except Exception as e: > print('exception:',e) > > The output (Python 3.3) is: > > Klass.method: > k.method 0x7f2d7c4570d0>> > exception: wrapper() takes 1 positional argument but 2 were given > > The first two lines are as expected, using the name of the decorated > function. However, the exception uses the name of the decorating wrapper > function. In your wrapper, you're swallowing all arguments. That means you're consciously rejecting them, and passing none on. If you want a wrapper to let the wrapped function decide about arguments, try this: def decorator(func): @functools.wraps(func) def wrapper(self, *args, **kwargs): func(self, args, kwargs) return wrapper With that change, the error message reports that it's method() that's rejecting the args. So yes, I'd say this is a feature; you can either let the wrapped function make the decision, or you can have the wrapping function deal with args. ChrisA From Joshua.R.English at gmail.com Mon Sep 15 21:02:13 2014 From: Joshua.R.English at gmail.com (Josh English) Date: Mon, 15 Sep 2014 18:02:13 -0700 (PDT) Subject: protocol.py, brine.py, and compat.py causing trouble In-Reply-To: References: Message-ID: <97c57b2e-3a80-4b92-adc0-34ba86767de1@googlegroups.com> On Monday, September 15, 2014 12:12:50 PM UTC-7, Emile van Sebille wrote: > > That's your clue -- I'd take a close look at the last changes you made a > result of which caused this failure and apparent looping. > It's easy to lay blame on the (whatever) library and look for a root > cause there, but I'd first suspect I did something inappropriate as > that's much more likely. > > > Emile I deleted the original post because I had figured out what I had changed. The troubleshooting I had done pointed me to those files, which turn out to be part of PyScripter, my IDE. Oddly enough, once I fixed the actual problem (minutes after posting) it still makes no sense... I had a list of things that I processed and returned, but some refactoring left out filling the return list with anything. I'm not sure what happened, except possibly an endless loop. Josh From Joshua.R.English at gmail.com Mon Sep 15 21:05:00 2014 From: Joshua.R.English at gmail.com (Josh English) Date: Mon, 15 Sep 2014 18:05:00 -0700 (PDT) Subject: protocol.py, brine.py, and compat.py causing trouble In-Reply-To: References: Message-ID: On Sunday, September 14, 2014 10:59:07 AM UTC-7, Terry Reedy wrote: > On 9/14/2014 2:44 AM, Josh English wrote: > > > To the best of my knowledge, protocol.py, brine.py, compat.py, are not > part of the stdlib. What have you installed other than Python? What > editor/IDE are you using? Check your lib/site-packages directory. From > a google search, brine.py is a pickle replacement in the rpyc and > dreampie (and other) packages. The other two names are pretty generic > and probably common. > They turned out to be part of PyScripter, my IDE. I think the problem was an enless loop, and eventually a memory error, but I'm not sure. Thanks, Josh From wrw at mac.com Mon Sep 15 21:25:38 2014 From: wrw at mac.com (William Ray Wing) Date: Mon, 15 Sep 2014 21:25:38 -0400 Subject: python script monitor In-Reply-To: <63a94cb9-171a-4b97-a639-75fec71cae63@googlegroups.com> References: <63a94cb9-171a-4b97-a639-75fec71cae63@googlegroups.com> Message-ID: <50A3FA03-3D0F-4F77-900C-F7E73237027A@mac.com> On Sep 15, 2014, at 8:07 PM, Nicholas Cannon wrote: > I have made an app that is not fully stable and I would like to monitor the performance of the app and try and improve the speed of it. I tried to use the activity monitor on the mac but what I want I'm to see how much ram, cup and other stats on what resources that app is using. Is there any apps to specifically monitor a certain app. I am on Mac is so any suggestions that could work with that would be great. > -- > https://mail.python.org/mailman/listinfo/python-list Have you investigated the (long) list of options to the ?top? command? I?ve noticed that most Mac users seem to assume that top won?t show anything that Apple?s Activity Monitor doesn?t show. In fact top is WAY more powerful. It should do pretty much what you want. Bill From rosuav at gmail.com Mon Sep 15 21:39:19 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 16 Sep 2014 11:39:19 +1000 Subject: protocol.py, brine.py, and compat.py causing trouble In-Reply-To: <97c57b2e-3a80-4b92-adc0-34ba86767de1@googlegroups.com> References: <97c57b2e-3a80-4b92-adc0-34ba86767de1@googlegroups.com> Message-ID: On Tue, Sep 16, 2014 at 11:02 AM, Josh English wrote: > I deleted the original post because I had figured out what I had changed. This is primarily a newsgroup and a mailing list. You can't delete posts. The best thing to do is to send a follow-up explaining that you no longer need answers. ChrisA From ian.g.kelly at gmail.com Mon Sep 15 23:39:25 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 15 Sep 2014 21:39:25 -0600 Subject: functools.wraps behaviour In-Reply-To: <541772fa$0$2078$426a74cc@news.free.fr> References: <541772fa$0$2078$426a74cc@news.free.fr> Message-ID: On Mon, Sep 15, 2014 at 5:15 PM, ISE Development wrote: > The first two lines are as expected, using the name of the decorated > function. However, the exception uses the name of the decorating wrapper > function. > > Is this a bug in functools? Or is this a language feature? If so, is there a > valid argument to change this behaviour? I believe this is done in order to have useful stack traces. If it said 'method' in the stack trace, it could mislead the person debugging into thinking that method is actually raising the exception, but here the exception is actually coming from wrapped, and method is not even called. From dieter at handshake.de Tue Sep 16 01:58:03 2014 From: dieter at handshake.de (dieter) Date: Tue, 16 Sep 2014 07:58:03 +0200 Subject: List insert at index that is well out of range - behaves like append that too SILENTLY References: Message-ID: <8738bsds44.fsf@handshake.de> Harish Tech writes: > Let me demonstrate the problem I encountered : > > I had a list > > a = [1, 2, 3] > > when I did > > a.insert(100, 100) > > [1, 2, 3, 100] > > as list was originally of size 4 and I was trying to insert value at index > 100 , it behaved like append instead of throwing any errors as I was trying > to insert in an index that did not even existed . > > > Should it not throw > > IndexError: list assignment index out of range At least the documentation states that what you observe is the intended behaviour. According to the documentation, "a.insert(i, x)" is equivalent to "a[i:i] = x" (i.e. a slice assignment) and if in a slice "a[i:j]" "i" or "j" are larger then "len(a)", then it is replaced by "len(a)". If this is not what you want, derive your own list type and override its "insert" method. From dieter at handshake.de Tue Sep 16 02:04:54 2014 From: dieter at handshake.de (dieter) Date: Tue, 16 Sep 2014 08:04:54 +0200 Subject: What's the function location that reads the cached .pyc file from disk. References: Message-ID: <87y4tkcd89.fsf@handshake.de> Shiyao Ma writes: > what's the location of the function that reads the .pyc file ? > > I bet it should lie in somewhere in > https://hg.python.org/cpython/file/322ee2f2e922/Lib/importlib > > But what's the actual location? Maybe, you look at the "importlib" source? Note: the function you search is likely implemented in C. Finally, you will likely need to look at the C code. > Btw, why I need it? > I want to know the structure of a .pyc file. Of course the function > that reads the .pyc must know something about it. > (I am aware of the structure of a typical .pyc file from some clicks > of google pages, but I am interested in the *source* and the most > authoritative answer, aka, the source code). In documentation relative to the "marshal" module (internally used for ".pyc" files), I have read that the details may vary between Python versions. As "mashal" is used for ".pyc" files, the same likely applies to ".pyc" files as well. Thus, do not depend too closely on the things you may find by code inspection. From frank at chagford.com Tue Sep 16 02:22:03 2014 From: frank at chagford.com (Frank Millman) Date: Tue, 16 Sep 2014 08:22:03 +0200 Subject: [OT] Question about Git branches Message-ID: Hi all I know there some Git experts on this list, so I hope you don't mind me posting this question here. I am slowly getting comfortable with Git, but there is something that confuses me. You are encouraged to make liberal use of 'branches', and if required you can have multiple branches running concurrently. When you commit changes on one branch, those changes are not visible to other branches until you merge, so each branch can be worked on independently. However, if you are working on a branch and make some changes, those changes are visible to *all* branches until you commit. If you run 'git status' from any branch, you can see all files that have been modified or added. It seems to me that this can be confusing. When you are ready to commit changes on one branch, you have to - - check that it is the currently checked-out branch, which is not always obvious - choose which altered files you want to add to the staging area - stage them and then commit This seems error-prone. Am I missing something? Frank Millman From ben+python at benfinney.id.au Tue Sep 16 02:51:24 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 16 Sep 2014 16:51:24 +1000 Subject: [OT] Question about Git branches References: Message-ID: <85egvcvz0z.fsf@benfinney.id.au> "Frank Millman" writes: > I know there some Git experts on this list, so I hope you don't mind > me posting this question here. I do. There may be experts on parquetry flooring in this forum, but a topic is not on-topic merely because some people here may know about it. Please engage with the Git community instead of starting non-Python discussions here. -- \ ?We must become the change we want to see.? ?Mohandas K. Gandhi | `\ | _o__) | Ben Finney From isenntp at gmail.com Tue Sep 16 03:24:19 2014 From: isenntp at gmail.com (ISE Development) Date: Tue, 16 Sep 2014 09:24:19 +0200 Subject: functools.wraps behaviour References: <541772fa$0$2078$426a74cc@news.free.fr> Message-ID: <5417e5a3$0$2143$426a74cc@news.free.fr> Chris Angelico wrote: > On Tue, Sep 16, 2014 at 9:15 AM, ISE Development > wrote: >> @functools.wraps(func) >> def wrapper(self): >> func(self) >> return wrapper >> >> try: >> k.method(1) >> except Exception as e: >> print('exception:',e) >> >> The output (Python 3.3) is: >> >> Klass.method: >> k.method > 0x7f2d7c4570d0>> >> exception: wrapper() takes 1 positional argument but 2 were given >> >> The first two lines are as expected, using the name of the decorated >> function. However, the exception uses the name of the decorating wrapper >> function. > > In your wrapper, you're swallowing all arguments. That means you're > consciously rejecting them, and passing none on. If you want a wrapper > to let the wrapped function decide about arguments, try this: > > def decorator(func): > @functools.wraps(func) > def wrapper(self, *args, **kwargs): > func(self, args, kwargs) > return wrapper > > With that change, the error message reports that it's method() that's > rejecting the args. > > So yes, I'd say this is a feature; you can either let the wrapped > function make the decision, or you can have the wrapping function deal > with args. > > ChrisA Very good point. Hadn't thought about it that way - it makes sense now. Thanks. -- isedev From steve+comp.lang.python at pearwood.info Tue Sep 16 03:37:26 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 16 Sep 2014 17:37:26 +1000 Subject: [OT] Question about Git branches References: Message-ID: <5417e8b7$0$29979$c3e8da3$5496439d@news.astraweb.com> Ben Finney wrote: > "Frank Millman" writes: > >> I know there some Git experts on this list, so I hope you don't mind >> me posting this question here. > > I do. There may be experts on parquetry flooring in this forum, but a > topic is not on-topic merely because some people here may know about it. (1) Frank labelled the post [OT] so that people not interested in off-topic posts can filter it. (2) Parquetry flooring has nothing to do with Python programming, while source control is very relevant. Asking questions about revision control is at least as on-topic as asking what editor one should use for Python programming, a question I note you have been known to respond to :-) In my opinion, objecting to Frank's question is not as friendly or helpful a response as I believe we should aim to provide. A more friendly response would have been to suggest that he would likely get better quality answers by elsewhere, but without the editorialising. It's your right to have a different opinion, of course, and you can continue to agitate for a stricter application of on-topic questions, but I just wanted to say I don't fully agree with your position in this matter. Frank, I am not a git expert, and I don't have an answer for your question, sorry. Ben's advice to ask it elsewhere is sound. -- Steven From fomcl at yahoo.com Tue Sep 16 04:00:50 2014 From: fomcl at yahoo.com (Albert-Jan Roskam) Date: Tue, 16 Sep 2014 01:00:50 -0700 Subject: [OT] Question about Git branches Message-ID: <1410854450.821.BPMail_high_noncarrier@web163801.mail.gq1.yahoo.com> ----------------------------- On Tue, Sep 16, 2014 9:37 AM CEST Steven D'Aprano wrote: >Ben Finney wrote: > >> "Frank Millman" writes: >> >> I know there some Git experts on this list, so I hope you don't mind >> me posting this question here. >> >> I do. There may be experts on parquetry flooring in this forum, but a >> topic is not on-topic merely because some people here may know about it. > >(1) Frank labelled the post [OT] so that people not interested in off-topic >posts can filter it. > >(2) Parquetry flooring has nothing to do with Python programming, while >source control is very relevant. Asking questions about revision control is >at least as on-topic as asking what editor one should use for Python >programming, a question I note you have been known to respond to :-) > >In my opinion, objecting to Frank's question is not as friendly or helpful a >response as I believe we should aim to provide. A more friendly response >would have been to suggest that he would likely get better quality answers >by elsewhere, but without the editorialising. It's your right to have a >different opinion, of course, and you can continue to agitate for a >stricter application of on-topic questions, but I just wanted to say I >don't fully agree with your position in this matter. > >Frank, I am not a git expert, and I don't have an answer for your question, >sorry. Ben's advice to ask it elsewhere is sound. list I entirely agree with Steven. VCS is about good software craftmenship. It is just as on-topic as PEP8 is. Vcs is for code what toothpaste is for teeth. Witout it you get bad breath and code smell :-) Wrt the question: I think you should commit or stash files before switching branches. Also 'add' files to make them known to Git. I always use 'commit -a -m' to automatically stage all changed files. In short your working copy should be clean before switching branches. From marko at pacujo.net Tue Sep 16 04:21:05 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 16 Sep 2014 11:21:05 +0300 Subject: [OT] Question about Git branches References: Message-ID: <878ulk7z7y.fsf@elektro.pacujo.net> "Frank Millman" : > You are encouraged to make liberal use of 'branches', Personally, I only use forks, IOW, "git clone". I encourage that practice. Then, there is little need for "git checkout". Instead, I just cd to a different directory. Branches and clones are highly analogous processwise; I would go so far as to say that they are redundant. Marko From rosuav at gmail.com Tue Sep 16 04:29:20 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 16 Sep 2014 18:29:20 +1000 Subject: [OT] Question about Git branches In-Reply-To: <878ulk7z7y.fsf@elektro.pacujo.net> References: <878ulk7z7y.fsf@elektro.pacujo.net> Message-ID: On Tue, Sep 16, 2014 at 6:21 PM, Marko Rauhamaa wrote: > "Frank Millman" : > >> You are encouraged to make liberal use of 'branches', > > Personally, I only use forks, IOW, "git clone". I encourage that > practice. Then, there is little need for "git checkout". Instead, I just > cd to a different directory. > > Branches and clones are highly analogous processwise; I would go so far > as to say that they are redundant. But rather than listening to, shall we say, *strange* advice like this, Frank, you'll do well to pick up a reliable git tutorial, which should explain branches, commits, the working tree, etc, etc, etc. ChrisA From fomcl at yahoo.com Tue Sep 16 04:39:37 2014 From: fomcl at yahoo.com (Albert-Jan Roskam) Date: Tue, 16 Sep 2014 01:39:37 -0700 Subject: [OT] Question about Git branches Message-ID: <1410856777.99452.BPMail_high_noncarrier@web163805.mail.gq1.yahoo.com> ----------------------------- On Tue, Sep 16, 2014 10:29 AM CEST Chris Angelico wrote: >On Tue, Sep 16, 2014 at 6:21 PM, Marko Rauhamaa wrote: >> "Frank Millman" : >> >> You are encouraged to make liberal use of 'branches', >> >> Personally, I only use forks, IOW, "git clone". I encourage that >> practice. Then, there is little need for "git checkout". Instead, I just >> cd to a different directory. >> >> Branches and clones are highly analogous processwise; I would go so far >> as to say that they are redundant. > >But rather than listening to, shall we say, *strange* advice like >this, Frank, you'll do well to pick up a reliable git tutorial, which >should explain branches, commits, the working tree, etc, etc, etc. list I like "Pragmatic guide to Git". 122 pages, to the point, practical. From frank at chagford.com Tue Sep 16 04:59:34 2014 From: frank at chagford.com (Frank Millman) Date: Tue, 16 Sep 2014 10:59:34 +0200 Subject: [OT] Question about Git branches References: <878ulk7z7y.fsf@elektro.pacujo.net> Message-ID: "Chris Angelico" wrote in message news:CAPTjJmr5gh8=1zPjG_KdTmA2QgT_5jj=kh=jyvRFv1atL1EeKw at mail.gmail.com... > On Tue, Sep 16, 2014 at 6:21 PM, Marko Rauhamaa wrote: >> "Frank Millman" : >> >>> You are encouraged to make liberal use of 'branches', >> >> Personally, I only use forks, IOW, "git clone". I encourage that >> practice. Then, there is little need for "git checkout". Instead, I just >> cd to a different directory. >> >> Branches and clones are highly analogous processwise; I would go so far >> as to say that they are redundant. > > But rather than listening to, shall we say, *strange* advice like > this, Frank, you'll do well to pick up a reliable git tutorial, which > should explain branches, commits, the working tree, etc, etc, etc. > I don't want to turn this into a full-on Git discussion, so briefly - 1. I have read all the 'git' tutorials I can find, but they have not addressed my question. 2. Albert's response 'commit or stash files before switching branches' makes sense, and actually answers my question. 3. I have sympathy for Marko's position of using clones rather than branches. I realise it does not follow the 'git' philosophy, but it does make it more obvious 'where you are', and lessens the chances of shooting yourself in the foot. Frank From nicholascannon1 at gmail.com Tue Sep 16 05:14:07 2014 From: nicholascannon1 at gmail.com (Nicholas Cannon) Date: Tue, 16 Sep 2014 02:14:07 -0700 (PDT) Subject: python script monitor In-Reply-To: <63a94cb9-171a-4b97-a639-75fec71cae63@googlegroups.com> References: <63a94cb9-171a-4b97-a639-75fec71cae63@googlegroups.com> Message-ID: Nah I mean like there is performance issues. It delivers result that I want just mot very conveinetly fast. From frank at chagford.com Tue Sep 16 05:15:31 2014 From: frank at chagford.com (Frank Millman) Date: Tue, 16 Sep 2014 11:15:31 +0200 Subject: [OT] Question about Git branches References: <1410856777.99452.BPMail_high_noncarrier@web163805.mail.gq1.yahoo.com> Message-ID: "Albert-Jan Roskam" wrote in message > > > I like "Pragmatic guide to Git". 122 pages, to the point, practical. > Thanks, Albert-Jan. I have started reading it, and it looks useful. Thanks too for your previous response, which was also 'pragmatic and to the point' :-) Frank From skip.montanaro at gmail.com Tue Sep 16 06:26:35 2014 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Tue, 16 Sep 2014 05:26:35 -0500 Subject: python script monitor In-Reply-To: References: <63a94cb9-171a-4b97-a639-75fec71cae63@googlegroups.com> Message-ID: On Sep 16, 2014 4:17 AM, "Nicholas Cannon" wrote: > > Nah I mean like there is performance issues. It delivers result that I want just mot very conveinetly fast. Take a look at the cProfile module. That's what it's called in Python 2.x. Not sure if it lost its camel case spelling in 3.x or is now called simply "profile." Skip -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Tue Sep 16 07:22:02 2014 From: __peter__ at web.de (Peter Otten) Date: Tue, 16 Sep 2014 13:22:02 +0200 Subject: CSV methodology References: Message-ID: jayte wrote: > On Mon, 15 Sep 2014 09:29:02 +0200, Peter Otten <__peter__ at web.de> wrote: > >>jayte wrote: >> >>> Sorry, I neglected to mention the values' significance. The MXP program >>> uses the "distance estimate" algorithm in its fractal data generation. >>> The values are thus, for each point in a 1778 x 1000 image: >>> >>> Distance, (an extended double) >>> Iterations, (a 16 bit int) >>> zc_x, (a 16 bit int) >>> zc_y (a 16 bit int) >>> >> >>Probably a bit too early in your "Python career", > > Absolutely, just thought it would be interesting to start experimenting, > while learning (plus, can't help but be anxious) > >> but you can read raw data >>with numpy. Something like >> >>with open(filename, "rb") as f: >> a = numpy.fromfile(f, dtype=[ >> ("distance", "f16"), >> ("iterations", "i2"), >> ("zc_x", "i2"), >> ("zc_y", "i2"), >> ]).reshape(1778, 1000) >> >>might do, assuming "extended double" takes 16 bytes. > > Will try. Double extended precision is ten bytes, but I assume > changing the "f16" to "f10" would account for that... Unfortunately it seems that numpy doesn't support "f10" >>> numpy.dtype("f8") dtype('float64') >>> numpy.dtype("f16") dtype('float128') >>> numpy.dtype("f10") dtype('float32') # looks strange to me But you better ask for confirmation (and possible workarounds) in a specialist forum. From d.moorcroft at turvgng.bham.sch.uk Tue Sep 16 07:25:46 2014 From: d.moorcroft at turvgng.bham.sch.uk (D Moorcroft) Date: Tue, 16 Sep 2014 12:25:46 +0100 (BST) Subject: Python 3.3.2 help In-Reply-To: <5416f2ca$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <1951135237.5067937.1410341316898.JavaMail.zimbra@turvgng.bham.sch.uk> <54101B2E.8050100@timgolden.me.uk> <541040f6$0$29978$c3e8da3$5496439d@news.astraweb.com> <5416f2ca$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1400971034.5995258.1410866746075.JavaMail.zimbra@turvgng.bham.sch.uk> Hi, Can i be taken off the list please as i am getting too many e-mails. Thank you, David Moorcroft ICT Operations Manager & Website Manager Turves Green Girls' School ----- Original Message ----- From: "Steven D'Aprano" To: python-list at python.org Sent: Monday, 15 September, 2014 3:08:09 PM Subject: Re: Python 3.3.2 help Hello David, and thanks for replying. More comments below. D Moorcroft wrote: > Hi, > > We are using windows 7 and it is all pupils as they are more restricted > than staff. > > They are using the python 3.3.2 shell and trying to print from there What you are describing does not sound like the sort of error the Python shell will give. Are you able to copy and paste the student's exact input and output, including the complete error message? If not, can you take a screenshot and post that? (As a general rule, we prefer text-based communication rather than pictures. For all we know, there could be blind or other visually-impaired users on this forum who can read text via a screen reader, but cannot contribute when it is a screenshot. But if all else fails, a screenshot is better than nothing.) We would love to help you, but without further information we have no idea what is going on. The more concrete information you can pass on to us, the better. Regards, Steve > > Thank you, > > David Moorcroft > ICT Operations Manager & > Website Manager > Turves Green Girls' School > > ----- Original Message ----- > From: "Steven D'Aprano" > To: python-list at python.org > Sent: Wednesday, 10 September, 2014 1:15:49 PM > Subject: Re: Python 3.3.2 help > > Hello, > > My response is below, interleaved with your comments. > > D Moorcroft wrote: > >>> Hi, >>> >>> We are running Python 3.3.2 but pupils are unable to print as they >>> cannot use the command prompt. > > What operating system are you using? Windows, Linux, Mac? Something else? > > Is it ALL pupils who are unable to print or just some of them? > > Which command prompt are they using? Can you reproduce the failure to > print? If so, please tell us the detailed steps you (and the pupils) go > through. E.g. something like this: > > "On Windows XP, choose Run from the Start Menu. Type cmd.exe and press > Enter. When the terminal window opens, type print 'Hello World' and > Enter." > > It will help if you can tell us whether your pupils are using IDLE, > IPython, or the default Python interactive interpreter. > > If you can answer these questions, which should have a better chance of > diagnosing the problem. > > Further responses below. > > >>> An error comes up saying printing failed (exit status Oxff). > > Based on this, my guess is that your students are accidentally running the > DOS "print" command at the DOS prompt, not Python at all. Perhaps they are > forgetting to run the "python" command first to launch the Python > interpreter, and are running directly in the DOS prompt? > > You can check this by reading the command prompt. If it looks like three > greater-than signs >>> then you are running in Python's default > interpreter. If it looks something like this: > > C:\Documents and Settings\user\> > > or perhaps like this: > > C:\> > > then you are still inside the DOS command prompt. > > Unfortunately, I am not very experienced with Windows, so I cannot tell > you the right method to start Python. I would expect there to be a Start > menu command, perhaps called "IDLE", or "Python", but I'm not sure. > > >>> Is there any way that we can get users who can't see the command >>> prompt to be able to print? > > I'm not entirely sure I understand this question. Can you explain in more > detail? > > By the way, as you know there are two meanings of "print" in computing. > There is printing to the screen, and printing to sheets of paper with an > actual printer. Which are you intending? > > > Regards, > > > -- Steven -- https://mail.python.org/mailman/listinfo/python-list ************************************************************* This message has been checked for viruses by the Birmingham Grid for Learning. For guidance on good e-mail practice, e-mail viruses and hoaxes please visit: http://www.bgfl.org/emailaup ************************************************************* ************************************************************* This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify postmaster at bgfl.org The views expressed within this email are those of the individual, and not necessarily those of the organisation ************************************************************* From python at mrabarnett.plus.com Tue Sep 16 08:04:57 2014 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 16 Sep 2014 13:04:57 +0100 Subject: List insert at index that is well out of range - behaves like append that too SILENTLY In-Reply-To: <8738bsds44.fsf@handshake.de> References: <8738bsds44.fsf@handshake.de> Message-ID: <54182769.7070904@mrabarnett.plus.com> On 2014-09-16 06:58, dieter wrote: > Harish Tech writes: > >> Let me demonstrate the problem I encountered : >> >> I had a list >> >> a = [1, 2, 3] >> >> when I did >> >> a.insert(100, 100) >> >> [1, 2, 3, 100] >> >> as list was originally of size 4 and I was trying to insert value at index >> 100 , it behaved like append instead of throwing any errors as I was trying >> to insert in an index that did not even existed . >> >> >> Should it not throw >> >> IndexError: list assignment index out of range > > At least the documentation states that what you observe is the intended > behaviour. > > According to the documentation, "a.insert(i, x)" is > equivalent to "a[i:i] = x" (i.e. a slice assignment) and > if in a slice "a[i:j]" "i" or "j" are larger then "len(a)", > then it is replaced by "len(a)". > > If this is not what you want, derive your own list type > and override its "insert" method. > It's nice to be able to say a.insert(p, x) even when p == len(a) instead of having a special case: if p == len(a): a.append(x) else: a.insert(p, x) Of course, what to do when p > len(a) is another matter. From python at mrabarnett.plus.com Tue Sep 16 08:17:54 2014 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 16 Sep 2014 13:17:54 +0100 Subject: Python 3.3.2 help In-Reply-To: <1400971034.5995258.1410866746075.JavaMail.zimbra@turvgng.bham.sch.uk> References: <1951135237.5067937.1410341316898.JavaMail.zimbra@turvgng.bham.sch.uk> <54101B2E.8050100@timgolden.me.uk> <541040f6$0$29978$c3e8da3$5496439d@news.astraweb.com> <5416f2ca$0$29991$c3e8da3$5496439d@news.astraweb.com> <1400971034.5995258.1410866746075.JavaMail.zimbra@turvgng.bham.sch.uk> Message-ID: <54182A72.1040508@mrabarnett.plus.com> On 2014-09-16 12:25, D Moorcroft wrote: > Hi, > > Can i be taken off the list please as i am getting too many e-mails. > [snip] It's up to you to unsubscribe from the list. From steve+comp.lang.python at pearwood.info Tue Sep 16 08:14:43 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 16 Sep 2014 22:14:43 +1000 Subject: [OT] Question about Git branches References: <878ulk7z7y.fsf@elektro.pacujo.net> Message-ID: <541829b4$0$29995$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > On Tue, Sep 16, 2014 at 6:21 PM, Marko Rauhamaa wrote: >> "Frank Millman" : >> >>> You are encouraged to make liberal use of 'branches', >> >> Personally, I only use forks, IOW, "git clone". I encourage that >> practice. Then, there is little need for "git checkout". Instead, I just >> cd to a different directory. >> >> Branches and clones are highly analogous processwise; I would go so far >> as to say that they are redundant. > > But rather than listening to, shall we say, *strange* advice like > this, Frank, you'll do well to pick up a reliable git tutorial, which > should explain branches, commits, the working tree, etc, etc, etc. Isn't this "strange advice" standard operating procedure in Mercurial? I'm not an expert on either hg or git, but if I've understood hg correctly, the way to begin an experimental branch is to use hg clone. -- Steven From rosuav at gmail.com Tue Sep 16 08:48:45 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 16 Sep 2014 22:48:45 +1000 Subject: [OT] Question about Git branches In-Reply-To: <541829b4$0$29995$c3e8da3$5496439d@news.astraweb.com> References: <878ulk7z7y.fsf@elektro.pacujo.net> <541829b4$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Sep 16, 2014 at 10:14 PM, Steven D'Aprano wrote: > Chris Angelico wrote: > >> On Tue, Sep 16, 2014 at 6:21 PM, Marko Rauhamaa wrote: >>> "Frank Millman" : >>> >>>> You are encouraged to make liberal use of 'branches', >>> >>> Personally, I only use forks, IOW, "git clone". I encourage that >>> practice. Then, there is little need for "git checkout". Instead, I just >>> cd to a different directory. >>> >>> Branches and clones are highly analogous processwise; I would go so far >>> as to say that they are redundant. >> >> But rather than listening to, shall we say, *strange* advice like >> this, Frank, you'll do well to pick up a reliable git tutorial, which >> should explain branches, commits, the working tree, etc, etc, etc. > > Isn't this "strange advice" standard operating procedure in Mercurial? I'm > not an expert on either hg or git, but if I've understood hg correctly, the > way to begin an experimental branch is to use hg clone. I don't know Mercurial well enough to be able to say, but definitely branching is a very normal thing there, too. And since merging can be done only within a single repo, ultimately you need to end up with branches in one repo (rather than separate repos) if you're going to combine them in any way. So even if you do start some experimental work in a separate clone, you're probably going to need to end up with it as a separate branch in the same repo if you ever publish it, for instance. ChrisA From timothy.c.delaney at gmail.com Tue Sep 16 08:50:19 2014 From: timothy.c.delaney at gmail.com (Tim Delaney) Date: Tue, 16 Sep 2014 22:50:19 +1000 Subject: [OT] Question about Git branches In-Reply-To: <541829b4$0$29995$c3e8da3$5496439d@news.astraweb.com> References: <878ulk7z7y.fsf@elektro.pacujo.net> <541829b4$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 16 September 2014 22:14, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > Chris Angelico wrote: > > > On Tue, Sep 16, 2014 at 6:21 PM, Marko Rauhamaa > wrote: > >> "Frank Millman" : > >> > >>> You are encouraged to make liberal use of 'branches', > >> > >> Personally, I only use forks, IOW, "git clone". I encourage that > >> practice. Then, there is little need for "git checkout". Instead, I just > >> cd to a different directory. > >> > >> Branches and clones are highly analogous processwise; I would go so far > >> as to say that they are redundant. > > > > But rather than listening to, shall we say, *strange* advice like > > this, Frank, you'll do well to pick up a reliable git tutorial, which > > should explain branches, commits, the working tree, etc, etc, etc. > > Isn't this "strange advice" standard operating procedure in Mercurial? I'm > not an expert on either hg or git, but if I've understood hg correctly, the > way to begin an experimental branch is to use hg clone. It depends entirely on how you're comfortable working. I tend to have a clone per feature branch (they all push to the same central repo) and then create a named branch per task (which may be a prototype, bugfix, enhancement, whatever). Makes it very easy to switch between tasks - I just update to a different changeset (normally the tip of a named branch) and force a refresh in my IDE. When I'm happy, I merge into the feature branch, then pull the necessary changesets into other feature branch repos to merge/graft as appropriate. Branches and clones are two different ways of organising, and I find that things work best for me when I use both. Tim Delaney -------------- next part -------------- An HTML attachment was scrubbed... URL: From jason.swails at gmail.com Tue Sep 16 09:19:29 2014 From: jason.swails at gmail.com (Jason Swails) Date: Tue, 16 Sep 2014 09:19:29 -0400 Subject: [OT] Question about Git branches In-Reply-To: References: <878ulk7z7y.fsf@elektro.pacujo.net> Message-ID: <1410873569.16572.5.camel@gmail.com> On Tue, 2014-09-16 at 10:59 +0200, Frank Millman wrote: > "Chris Angelico" wrote in message > news:CAPTjJmr5gh8=1zPjG_KdTmA2QgT_5jj=kh=jyvRFv1atL1EeKw at mail.gmail.com... > > On Tue, Sep 16, 2014 at 6:21 PM, Marko Rauhamaa wrote: > >> "Frank Millman" : > >> > >>> You are encouraged to make liberal use of 'branches', > >> > >> Personally, I only use forks, IOW, "git clone". I encourage that > >> practice. Then, there is little need for "git checkout". Instead, I just > >> cd to a different directory. > >> > >> Branches and clones are highly analogous processwise; I would go so far > >> as to say that they are redundant. > > > > But rather than listening to, shall we say, *strange* advice like > > this, Frank, you'll do well to pick up a reliable git tutorial, which > > should explain branches, commits, the working tree, etc, etc, etc. > > > > I don't want to turn this into a full-on Git discussion, so briefly - > > 1. I have read all the 'git' tutorials I can find, but they have not > addressed my question. > 2. Albert's response 'commit or stash files before switching branches' makes > sense, and actually answers my question. > 3. I have sympathy for Marko's position of using clones rather than > branches. I realise it does not follow the 'git' philosophy, but it does > make it more obvious 'where you are', and lessens the chances of shooting > yourself in the foot. I'm with Chris on this one. I use git extensively (I manage more than just software with it -- I used it as version tracking when I was working on my dissertation, articles I'm writing, script databases, project management, etc.) One of the code git repos I work with every day is ~4 GB for a working repo and ~1.6 GB for a bare one. At any given time, I have ~6 branches I'm working on. To have a separate repo for each branch is madness (especially on a SSD where storage is expensive). A trick I use to avoid ever getting lost inside my git repository is to set up my command-line prompt so it always displays the active branch [1]: swails at batman ~/amber (master) $ git branch amber12-with-patches amber13-with-patches amber14-with-patches amoeba2 amoeba2_diis * master sander-python yorkmaster swails at batman ~/amber (master) $ git checkout sander-python Switched to branch 'sander-python' Your branch is up-to-date with 'origin/sander-python'. swails at batman ~/amber (sander-python) $ Doing everything as branches in the same repository has a number of other advantages as well. Merges don't have to be preceded by a fetch (e.g., a git-pull). You can cherry-pick individual commits between branches. You only have one copy of the git objects. You can use "git diff" or "git difftool" to directly compare specific files or folders between branches or different revisions in diverged history between branches. I wouldn't expect you to know all of this git-magic from the outset, but you will learn it as you need to. Assigning each branch to a new clone severely limits git's capabilities. [2] All the best, Jason [1] See http://jswails.wikidot.com/using-git#toc48 for details of how to do this [2] Technically this isn't true since each repository will know about the branches of the other repositories it pulls from, but cherry-picking, merging, diffing, etc. between a branch and a remote copy of a branch on the same machine is a lot more convoluted than working with everything in the same repo (that and you never accidentally look at an outdated version of a 'local' branch because you forgot to fetch or pull!) From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Tue Sep 16 04:49:22 2014 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Tue, 16 Sep 2014 10:49:22 +0200 Subject: Iterator, modify data in loop body In-Reply-To: References: <4o6debxojk.ln2@news.c0t0d0s0.de> Message-ID: Am 13.09.2014 09:22 schrieb Chris Angelico: > In that case, don't iterate over the list at all. Do something like this: > > while lst: > element = lst.pop(0) > # work with element > lst.append(new_element) And if you don't like that, define a def iter_pop(lst): while lst: yield lst.pop(0) and you can do for element in iter_pop(lst): # work with element lst.append(new_element) Thomas From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Tue Sep 16 04:53:37 2014 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Tue, 16 Sep 2014 10:53:37 +0200 Subject: Thread-ID - how much could be? In-Reply-To: References: <20140911193018.GA24416@arxnet.hu> Message-ID: Am 11.09.2014 23:32 schrieb Ervin Heged?s: >> There is no upper limit to the thread name other than that you will >> eventually run out of memory ;) > > thanks - I hope that the memory will not run out by these > threads... :) > > Anyway, that means, on my system: > >>>> import sys >>>> print sys.maxint > 9223372036854775807 > > the couter could be 9223372036854775807? > > And after? :) After that, the couter magically turns into a long and it goes on. Thomas From rosuav at gmail.com Tue Sep 16 11:19:28 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 17 Sep 2014 01:19:28 +1000 Subject: Iterator, modify data in loop body In-Reply-To: References: <4o6debxojk.ln2@news.c0t0d0s0.de> Message-ID: On Tue, Sep 16, 2014 at 6:49 PM, Thomas Rachel wrote: > Am 13.09.2014 09:22 schrieb Chris Angelico: > >> In that case, don't iterate over the list at all. Do something like this: >> >> while lst: >> element = lst.pop(0) >> # work with element >> lst.append(new_element) > > > And if you don't like that, define a > > def iter_pop(lst): > while lst: > yield lst.pop(0) > > and you can do > > for element in iter_pop(lst): But that's exactly the same thing, with another level of indirection. It certainly isn't the advantage you'd expect from an iterator, namely that it simply stores a marker that gets advanced to the next element. Popping the 0th element is costly, wrapping it into an iterator conceals that. ChrisA From robert.kern at gmail.com Tue Sep 16 12:08:10 2014 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 16 Sep 2014 17:08:10 +0100 Subject: [OT] Question about Git branches In-Reply-To: <541829b4$0$29995$c3e8da3$5496439d@news.astraweb.com> References: <878ulk7z7y.fsf@elektro.pacujo.net> <541829b4$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2014-09-16 13:14, Steven D'Aprano wrote: > Chris Angelico wrote: > >> On Tue, Sep 16, 2014 at 6:21 PM, Marko Rauhamaa wrote: >>> "Frank Millman" : >>> >>>> You are encouraged to make liberal use of 'branches', >>> >>> Personally, I only use forks, IOW, "git clone". I encourage that >>> practice. Then, there is little need for "git checkout". Instead, I just >>> cd to a different directory. >>> >>> Branches and clones are highly analogous processwise; I would go so far >>> as to say that they are redundant. >> >> But rather than listening to, shall we say, *strange* advice like >> this, Frank, you'll do well to pick up a reliable git tutorial, which >> should explain branches, commits, the working tree, etc, etc, etc. > > Isn't this "strange advice" standard operating procedure in Mercurial? I'm > not an expert on either hg or git, but if I've understood hg correctly, the > way to begin an experimental branch is to use hg clone. Yes, but this is due to different design decisions of git and Mercurial. git prioritized the multiple branches in a single clone use case; Mercurial prioritized re-cloning. It's natural to do this kind of branching in git, and more natural to re-clone in Mercurial. -- 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 Tue Sep 16 12:25:58 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 17 Sep 2014 02:25:58 +1000 Subject: [OT] Question about Git branches In-Reply-To: References: <878ulk7z7y.fsf@elektro.pacujo.net> <541829b4$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Sep 17, 2014 at 2:08 AM, Robert Kern wrote: > Yes, but this is due to different design decisions of git and Mercurial. git > prioritized the multiple branches in a single clone use case; Mercurial > prioritized re-cloning. It's natural to do this kind of branching in git, > and more natural to re-clone in Mercurial. Ah, I wasn't aware of that philosophical difference. Does hg use hardlinks or something to minimize disk usage when you clone, or does it actually copy everything? (Or worse, does it make the new directory actually depend on the old one?) ChrisA From tjreedy at udel.edu Tue Sep 16 14:39:26 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 16 Sep 2014 14:39:26 -0400 Subject: [OT] Question about Git branches In-Reply-To: <1410854450.821.BPMail_high_noncarrier@web163801.mail.gq1.yahoo.com> References: <1410854450.821.BPMail_high_noncarrier@web163801.mail.gq1.yahoo.com> Message-ID: On 9/16/2014 4:00 AM, Albert-Jan Roskam wrote > On Tue, Sep 16, 2014 9:37 AM CEST Steven D'Aprano wrote: >> Ben Finney wrote: >>> "Frank Millman" writes: >>>> I know there some Git experts on this list, so I hope you don't mind >>>> me posting this question here >>> I do. There may be experts on parquetry flooring in this forum, but a >>> topic is not on-topic merely because some people here may know about it. I agree. If a post on parquet flooring were held for moderation, I would discard it. Threads that wander off into parquet flooring type topics are best let die. >> (1) Frank labelled the post [OT] so that people not interested in off-topic >> posts can filter it. >> (2) Parquetry flooring has nothing to do with Python programming, while >> source control is very relevant. Asking questions about revision control is >> at least as on-topic as asking what editor one should use for Python >> programming, The proper parallel is revision control for Python versus editor for Python. Since Frank is a known Python user, I presume 'for Python' was part of his question. Revision control for word processing would be a bit far afield for this list. >> a question I note you have been known to respond to :-) git, in particular, is used for both development *of* CPython and development *with* Python. At least one of the git sites has a clone of the cpython hg repository that some have used to develop patches. On the core-mentorship list, there has also been discussion about git branching and how it differs from hg use. > I entirely agree with Steven. VCS is about good software craftmenship. > It is just as on-topic as PEP8 is. I think that is too strong, but Frank did not claim that either. -- Terry Jan Reedy From tjreedy at udel.edu Tue Sep 16 14:50:11 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 16 Sep 2014 14:50:11 -0400 Subject: Too many emails, remove (was Re: Python 3.3.2 help) In-Reply-To: <1400971034.5995258.1410866746075.JavaMail.zimbra@turvgng.bham.sch.uk> References: <1951135237.5067937.1410341316898.JavaMail.zimbra@turvgng.bham.sch.uk> <54101B2E.8050100@timgolden.me.uk> <541040f6$0$29978$c3e8da3$5496439d@news.astraweb.com> <5416f2ca$0$29991$c3e8da3$5496439d@news.astraweb.com> <1400971034.5995258.1410866746075.JavaMail.zimbra@turvgng.bham.sch.uk> Message-ID: <54188663.3060300@udel.edu> On 9/16/2014 7:25 AM, D Moorcroft wrote: > Can i be taken off the list please as i am getting too many e-mails. Go to https://mail.python.org/mailman/listinfo/python-list and at the bottom, enter your email address in the box after "To unsubscribe from Python-list, get a password reminder, or change your subscription options enter your subscription email address: " One can selectively read python-list as a newsgroup at news.gmane.org either through the web interface or by 'subscribing' in a news reader. Most modern email programs, such as Thunderbird, include a news reader. -- Terry Jan Reedy From robert.kern at gmail.com Tue Sep 16 15:11:50 2014 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 16 Sep 2014 20:11:50 +0100 Subject: [OT] Question about Git branches In-Reply-To: References: <878ulk7z7y.fsf@elektro.pacujo.net> <541829b4$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2014-09-16 17:25, Chris Angelico wrote: > On Wed, Sep 17, 2014 at 2:08 AM, Robert Kern wrote: >> Yes, but this is due to different design decisions of git and Mercurial. git >> prioritized the multiple branches in a single clone use case; Mercurial >> prioritized re-cloning. It's natural to do this kind of branching in git, >> and more natural to re-clone in Mercurial. > > Ah, I wasn't aware of that philosophical difference. Does hg use > hardlinks or something to minimize disk usage when you clone, or does > it actually copy everything? (Or worse, does it make the new directory > actually depend on the old one?) I haven't kept up with the internals recently, but at least at one point, hardlinks were the order of the day, yes. -- 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 ben+python at benfinney.id.au Tue Sep 16 15:36:10 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 17 Sep 2014 05:36:10 +1000 Subject: [OT] Question about Git branches References: <1410854450.821.BPMail_high_noncarrier@web163801.mail.gq1.yahoo.com> Message-ID: <85wq93uzmd.fsf@benfinney.id.au> Terry Reedy writes: > I agree. If a post on parquet flooring were held for moderation, I > would discard it. Threads that wander off into parquet flooring type > topics are best let die. I'm glad to know that, thank you. > >> (2) Parquetry flooring has nothing to do with Python programming, > >> while source control is very relevant. Asking questions about > >> revision control is at least as on-topic as asking what editor one > >> should use for Python programming, > > The proper parallel is revision control for Python versus editor for > Python. Right. I'd consider ?how do I use Emacs?? to be inappropriate here, and would want the question directed to a more appropriate forum. When it's ?how do I use Emacs to correctly indent Python code?? the question is appropriate here. I'm of the opinion the original question was of the first, inappropriate, kind. > Since Frank is a known Python user, I presume 'for Python' was > part of his question. Revision control for word processing would be a > bit far afield for this list. I didn't see a good reason to think the question had any particular relevance to Python programming (no more than, say, ?how do I use Emacs correctly??) and responded on that basis. I acknowledge that's a judgement call, made by a participant with no special power here. There is an infinite number of topics we could discuss, and would likely be of interest to many people here. Just because some individuals may be found to talk about a topic doesn't make this forum appropriate for that discussion. That was the explicit reason given for a question acknowledged to be off-topic, and *that's* why I responded firmly: the reason given is invalid. The usefulness of a particular forum is only maintained by maintaining the common explicit topic of interest as the criterion, and redirecting most topics away. -- \ ?I believe our future depends powerfully on how well we | `\ understand this cosmos, in which we float like a mote of dust | _o__) in the morning sky.? ?Carl Sagan, _Cosmos_, 1980 | Ben Finney From prashant.mudgal at accenture.com Tue Sep 16 14:08:39 2014 From: prashant.mudgal at accenture.com (prashant.mudgal at accenture.com) Date: Tue, 16 Sep 2014 18:08:39 +0000 Subject: Problems in python pandas Message-ID: Hi All, I am having some problem in python. I have written the code import pandas as pd import numpy as np from scipy.optimize import minimize pd.set_option('display.mpl_style', 'default') """Read the input file into the dataframe""" """T1 file contains the decision variables, corresponding investments and their upper and lower bounds""" df = pd.DataFrame.from_csv('C:\Users\prashant.mudgal\Downloads\T1.csv') """T2 file contains the parameters for the decision variables, note that there can be 2 or more entries for the same decison variable""" """ Our objective func will be prep from T2 file , it will be of the form sum (all DV in params file) (a*(b + c * DV_name)** power) """ df2 = pd.DataFrame.from_csv('C:\Users\prashant.mudgal\Downloads\T2.csv') """subset of DV""" decisionVars= df2['DV'] """subset for coeff """ coeff = df2['coef'] """subset for power""" power = df2['p'] x0 = df['Hist_Inv'] bnds = df[['LB','UB']].values def objFunc(decisionVars,sign=1.0) : return sign*(sum(coeff.values[0:] *(df2['weight_f'].values[0:] + df2['weight_v'].values[0:] * decisionVars[0:])**power.values[0:])) """bounds for the decision variables have been hardcoded """ """ The bounds have been hardcoded and it will be cumbersome if there are thousands of Decision vars """ """ The bounds have been specified in T1.csv file, we want to ream them via the file """ """ Though we are not using constraints as of now, but is it correct form""" """ How to form the constraints for say x + y < 5 ? """ cons = ({'type': 'ineq', 'fun': lambda x: decisionVars[1] - 2 * decisionVars[1] + 2}, {'type': 'ineq', 'fun': lambda x: -decisionVars[2] - 2 * decisionVars[1] + 6}, {'type': 'ineq', 'fun': lambda x: -decisionVars[0] + 2 * decisionVars[1] + 2}) """ the second parameter is the initial values that needs to be optimized""" """ Now, the number of distinct decision vars in the files are 3 in numbers while the total number of decision vars are 12 in number . if we specify x0 as the dataframe of investment (3 in number in the T1 file) , then it gives error that ::: operands could not be broadcast together with shapes (12,) (3,)""" res = minimize(objFunc, x0,args=(-1.0,),method='SLSQP',bounds = bnds, options={'disp': True}) """Print the results""" print (res) T1.csv is like DV LB UB Hist_Inv X1 0.7 1.3 28462739.43 X2 0.7 1.3 177407.18 X3 0.7 1.3 1423271.12 T2.csv is Count DV weight_f weight_v p coef 1 X1 2.310281831 3.661156016 0.5 1828.105881 2 X1 0.693084549 2.20503016 0.5 1460.686147 3 X1 0.207925365 2.030522789 0.5 1436.277144 4 X1 0 5.248353307 0.8 1050.493355 5 X1 0 1.591805116 0.8 983.9964128 6 X1 0 1.933056056 0.8 459.9371809 7 X2 7.322516444 138 0.5 387.4659072 8 X2 3.661258222 139 0.5 606.8684771 9 X2 1.830629111 176.5 0.5 358.8902965 10 X3 164294.4758 77024 0.2 282.0477107 11 X3 98576.68545 122261.4 0.2 345.9217482 12 X3 59146.01127 166242.84 0.2 364.9587162 I create my obj function using vars in T2, there are a lot of vars which are repeated in T2.csv on running optimization I am getting the error operands could not be broadcast together with shapes (12,) (3,) because it is taking all the variables in T2 as different. How should I avoid this issue? X1, X2 AND X3 are the only three vars here. Please help. I am stuck for past many days on this. Thanks, Prashant Mudgal AI (Accenture Interactive) +1 917 615 3574(Cell) ________________________________ This message is for the designated recipient only and may contain privileged, proprietary, or otherwise confidential information. If you have received it in error, please notify the sender immediately and delete the original. Any other use of the e-mail by you is prohibited. Where allowed by local law, electronic communications with Accenture and its affiliates, including e-mail and instant messaging (including content), may be scanned by our systems for the purposes of information security and assessment of internal compliance with Accenture policy. ______________________________________________________________________________________ www.accenture.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From ram.rachum at gmail.com Tue Sep 16 17:40:18 2014 From: ram.rachum at gmail.com (cool-RR) Date: Tue, 16 Sep 2014 14:40:18 -0700 (PDT) Subject: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` Message-ID: <06397cb3-8baf-4af1-8152-ff7c3f6ceb62@googlegroups.com> While debugging my code I found that the bug was because I assumed that something like `divmod(float('inf'), 1)` would be equal to `(float('inf'), float('nan'))`, while Python returns `(float('nan'), float('nan'))`. Why does Python make the division result be NaN in this case? `float('inf') / 1` is still `float('inf')`. Thanks, Ram. From marko at pacujo.net Tue Sep 16 19:26:24 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 17 Sep 2014 02:26:24 +0300 Subject: [OT] Question about Git branches References: <878ulk7z7y.fsf@elektro.pacujo.net> Message-ID: <87vbon6tb3.fsf@elektro.pacujo.net> Jason Swails : > One of the code git repos I work with every day is ~4 GB for a working > repo and ~1.6 GB for a bare one. At any given time, I have ~6 branches > I'm working on. Well, branches could be seen as a compression technique. I'm trying to keep my git repositories in the < 1 MB range. Marko From jumppanen.jussi at gmail.com Tue Sep 16 20:52:51 2014 From: jumppanen.jussi at gmail.com (jumppanen.jussi at gmail.com) Date: Tue, 16 Sep 2014 17:52:51 -0700 (PDT) Subject: [ANN] Jedi Python Autocomplete in Zeus IDE Message-ID: <0f54bd4e-d7c1-4981-a3ea-db9ea35be74d@googlegroups.com> The latest version of the Zeus IDE adds Python autocomplete using the Jedi package. Details about Jedi can be found here: http://jedi.jedidjah.ch/en/latest/ Details of how the autocomplete works can be found here: http://www.zeusedit.com/zforum/viewtopic.php?t=7200 Details of whats new in this latest Zeus release can be found here: http://www.zeusedit.com/ze397u.html *NOTE:* Zeus is shareware, runs natively on the Windows platform and runs on Linux using Wine. Jussi Jumppanen Author: Zeus IDE From tjreedy at udel.edu Tue Sep 16 21:12:48 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 16 Sep 2014 21:12:48 -0400 Subject: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` In-Reply-To: <06397cb3-8baf-4af1-8152-ff7c3f6ceb62@googlegroups.com> References: <06397cb3-8baf-4af1-8152-ff7c3f6ceb62@googlegroups.com> Message-ID: On 9/16/2014 5:40 PM, cool-RR wrote: > While debugging my code I found that the bug was because I assumed > that something like `divmod(float('inf'), 1)` would be equal to > `(float('inf'), float('nan'))`, while Python returns `(float('nan'), > float('nan'))`. Why does Python make the division result be NaN in > this case? `float('inf') / 1` is still `float('inf')`. For integers, divmod(x, y) is defined as (x // y, x % y) == ((x - x%y) // y, x % y) == ((x - x%y) / y, x % y). For floats, Python is documented as using the third expression. "Help on built-in function divmod in module builtins: divmod(...) divmod(x, y) -> (div, mod) Return the tuple ((x-x%y)/y, x%y). Invariant: div*y + mod == x." It does not really matter, however, as infinity cannot be 'floored' as required for // >>> math.floor(float('inf')) Traceback (most recent call last): File "", line 1, in math.floor(float('inf')) OverflowError: cannot convert float infinity to integer and hence >>> float('inf') // 1.0 nan -- Terry Jan Reedy From timothy.c.delaney at gmail.com Tue Sep 16 21:47:48 2014 From: timothy.c.delaney at gmail.com (Tim Delaney) Date: Wed, 17 Sep 2014 11:47:48 +1000 Subject: [OT] Question about Git branches In-Reply-To: References: <878ulk7z7y.fsf@elektro.pacujo.net> <541829b4$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 17 September 2014 02:25, Chris Angelico wrote: > On Wed, Sep 17, 2014 at 2:08 AM, Robert Kern > wrote: > > Yes, but this is due to different design decisions of git and Mercurial. > git > > prioritized the multiple branches in a single clone use case; Mercurial > > prioritized re-cloning. It's natural to do this kind of branching in git, > > and more natural to re-clone in Mercurial. > I disagree that it's more natural to re-clone in Mercurial. It's just that the preferred workflow of the Mercurial developers is to use clones, anonymous branches and bookmarks (almost the same as git branches) rather than named branches - and so that is the workflow that is most associated with using Mercurial. Mercurial fully supports multiple lines of development by: 1. cloning; 2. anonymous branching (i.e. multiple heads on the same branch) - normally combined with bookmarks; 3. named branching (the branch name is an integral part of the commit); 4. all of the above combined. Eventually if you want to merge between lines of development then you end up with multiple branches (either anonymous or named) in the one repo. > Ah, I wasn't aware of that philosophical difference. Does hg use > hardlinks or something to minimize disk usage when you clone, or does > it actually copy everything? (Or worse, does it make the new directory > actually depend on the old one?) > If you clone a repo to the same filesystem (e.g. the same disk partition) then Mercurial will use hardlinks for the repository files (i.e. things in .hg). This means that clones are quick (although if you don't prevent updating the working directory while cloning that can take some time ...). Hardlinks may be broken any time changesets are added to the repo e.g. via a commit or pull. Only the hardlinks involved in the commit (and the manifest) will be broken. Mercurial provides a standard extension (relink) to re-establish hardlinks between identical storage files. For example, running hg relink in my current feature branch repo: [feature_branch_repo:65179] [feature_branch]> hg relink default relinking d:\home\repos\feature_branch_repo\.hg/store to d:\home\repos\default_repo\.hg/store tip has 22680 files, estimated total number of files: 34020 collected 229184 candidate storage files pruned down to 49838 probably relinkable files relinked 359 files (221 MB reclaimed) Tim Delaney -------------- next part -------------- An HTML attachment was scrubbed... URL: From Seymore4Head at Hotmail.invalid Tue Sep 16 22:17:44 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Tue, 16 Sep 2014 22:17:44 -0400 Subject: the python shell window is already executing a command Message-ID: <4jrh1adtbsvnr9o20r9k3hfe4nkrkps2dk@4ax.com> I have googled for a solution to this problem. None I have tried worked. I have a very short program that runs for a count of 20 and ends. What I do is click on the IDLE window and without making any changes I just hit f5 to rerun the program. Sometimes I get the error "the python shell window is already executing a command" and sometimes not. I am using XP and Python 3.4.1. Is there a way to rerun a program without getting this error? From tjreedy at udel.edu Wed Sep 17 04:02:16 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 17 Sep 2014 04:02:16 -0400 Subject: the python shell window is already executing a command In-Reply-To: <4jrh1adtbsvnr9o20r9k3hfe4nkrkps2dk@4ax.com> References: <4jrh1adtbsvnr9o20r9k3hfe4nkrkps2dk@4ax.com> Message-ID: On 9/16/2014 10:17 PM, Seymore4Head wrote: > I have googled for a solution to this problem. None I have tried > worked. > > I have a very short program that runs for a count of 20 and ends. > What I do is click on the IDLE window and without making any changes I > just hit f5 to rerun the program. Do you mean click on the Idle editor window? > Sometimes I get the error "the python shell window is already > executing a command" and sometimes not. > > I am using XP and Python 3.4.1. > > Is there a way to rerun a program without getting this error? Normally, hitting f5 kills the previous process if it is still running and starts the one in the editor. Please post a minimal program that exhibits the problem. -- Terry Jan Reedy From wolfgang.maier at biologie.uni-freiburg.de Wed Sep 17 04:31:46 2014 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Wed, 17 Sep 2014 10:31:46 +0200 Subject: Python docs not accessible from IDLE Message-ID: Dear all, since a few days, when I select Help -> Python Docs from the IDLE menu, the link to the documentation that it tries to open in my browser isn't working anymore. The URL IDLE uses (copied from the browser address bar) is : docs.python.org/3.4 and you have to add a terminal slash for it to work. Now I don't know why it stopped working (browser update, change on the python docs server, others? I'm running idle-python3.4 on Ubuntu 14.04 and Firefox 32.0), but a possible fix may be to simply make IDLE add the slash. Is there anyone else experiencing the same problem ? Cheers, Wolfgang From __peter__ at web.de Wed Sep 17 05:45:43 2014 From: __peter__ at web.de (Peter Otten) Date: Wed, 17 Sep 2014 11:45:43 +0200 Subject: Python docs not accessible from IDLE References: Message-ID: Wolfgang Maier wrote: > since a few days, when I select Help -> Python Docs from the IDLE menu, > the link to the documentation that it tries to open in my browser isn't > working anymore. > The URL IDLE uses (copied from the browser address bar) is : > docs.python.org/3.4 > and you have to add a terminal slash for it to work. > Now I don't know why it stopped working > (browser update, change on the python docs server, others? > I'm running idle-python3.4 on Ubuntu 14.04 and Firefox 32.0), > but a possible fix may be to simply make IDLE add the slash. > > Is there anyone else experiencing the same problem ? I have a similar configuration (Linux Mint 17 which is based on Ubuntu 14.04) and I cannot reproduce the problem. From sorganov at gmail.com Wed Sep 17 06:16:25 2014 From: sorganov at gmail.com (Sergey Organov) Date: Wed, 17 Sep 2014 14:16:25 +0400 Subject: [OT] Question about Git branches References: <878ulk7z7y.fsf@elektro.pacujo.net> Message-ID: "Frank Millman" writes: > 3. I have sympathy for Marko's position of using clones rather than > branches. I realise it does not follow the 'git' philosophy, IMHO one important thing about git that made it is so popular is the fact that it tries hard not to impose any policy or particular work-flow on you, so if clones work better for you, using them still follows git philosophy. -- Sergey. From wolfgang.maier at biologie.uni-freiburg.de Wed Sep 17 06:36:23 2014 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Wed, 17 Sep 2014 12:36:23 +0200 Subject: Python docs not accessible from IDLE In-Reply-To: References: Message-ID: On 09/17/2014 11:45 AM, Peter Otten wrote: > Wolfgang Maier wrote: > >> since a few days, when I select Help -> Python Docs from the IDLE menu, >> the link to the documentation that it tries to open in my browser isn't >> working anymore. >> The URL IDLE uses (copied from the browser address bar) is : >> docs.python.org/3.4 >> and you have to add a terminal slash for it to work. >> Now I don't know why it stopped working >> (browser update, change on the python docs server, others? >> I'm running idle-python3.4 on Ubuntu 14.04 and Firefox 32.0), >> but a possible fix may be to simply make IDLE add the slash. >> >> Is there anyone else experiencing the same problem ? > > I have a similar configuration (Linux Mint 17 which is based on Ubuntu > 14.04) and I cannot reproduce the problem. > Hmm, what happens if you just copy/paste docs.python.org/3.4 into your browser ? Looks like some browsers (like the Ubuntu standard browser) automatically add the trailing slash and others (like my Firefox 32.0) don't. From __peter__ at web.de Wed Sep 17 07:15:08 2014 From: __peter__ at web.de (Peter Otten) Date: Wed, 17 Sep 2014 13:15:08 +0200 Subject: Python docs not accessible from IDLE References: Message-ID: Wolfgang Maier wrote: > On 09/17/2014 11:45 AM, Peter Otten wrote: >> Wolfgang Maier wrote: >> >>> since a few days, when I select Help -> Python Docs from the IDLE menu, >>> the link to the documentation that it tries to open in my browser isn't >>> working anymore. >>> The URL IDLE uses (copied from the browser address bar) is : >>> docs.python.org/3.4 >>> and you have to add a terminal slash for it to work. >>> Now I don't know why it stopped working >>> (browser update, change on the python docs server, others? >>> I'm running idle-python3.4 on Ubuntu 14.04 and Firefox 32.0), >>> but a possible fix may be to simply make IDLE add the slash. >>> >>> Is there anyone else experiencing the same problem ? >> >> I have a similar configuration (Linux Mint 17 which is based on Ubuntu >> 14.04) and I cannot reproduce the problem. >> > > Hmm, what happens if you just copy/paste > > docs.python.org/3.4 > > into your browser ? Works without problem. > Looks like some browsers (like the Ubuntu standard > browser) automatically add the trailing slash and others (like my > Firefox 32.0) don't. The webpage redirects twice: $ curl --head http://docs.python.org/3.4 HTTP/1.1 301 Moved Permanently ... Location: https://docs.python.org/3.4 ... $ curl --head https://docs.python.org/3.4 HTTP/1.1 301 Moved Permanently ... Location: https://docs.python.org/3.4/ ... $ curl --head https://docs.python.org/3.4/ HTTP/1.1 200 OK ... When in firefox' about:config I set network.http.redirection-limit 1 (the original value is 20 over here) I get an "Umleitungsfehler" (redirection error in german). Maybe you should have a look at this setting. If that's not the cause -- is there any error message that firefox displays when you enter docs.python.org/3.4 ? From steve+comp.lang.python at pearwood.info Wed Sep 17 07:41:31 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 17 Sep 2014 21:41:31 +1000 Subject: [ANN] Jedi Python Autocomplete in Zeus IDE References: <0f54bd4e-d7c1-4981-a3ea-db9ea35be74d@googlegroups.com> Message-ID: <5419736c$0$29998$c3e8da3$5496439d@news.astraweb.com> jumppanen.jussi at gmail.com wrote: > The latest version of the Zeus IDE adds Python autocomplete using > the Jedi package. > > Details about Jedi can be found here: > > http://jedi.jedidjah.ch/en/latest/ Thank you! > Details of how the autocomplete works can be found here: > > http://www.zeusedit.com/zforum/viewtopic.php?t=7200 According to the screen shot there, if you have typed self.balan the autocomplete will offer the list: balance close deposit overdrawn withdraw __class__ plus many more__dunder__ attributes. Why does Zeus suggest "close" when I have typed "balan"? Regards, -- Steven From sorganov at gmail.com Wed Sep 17 08:04:48 2014 From: sorganov at gmail.com (Sergey Organov) Date: Wed, 17 Sep 2014 16:04:48 +0400 Subject: [OT] Question about Git branches References: Message-ID: "Frank Millman" writes: > Hi all > > I know there some Git experts on this list, so I hope you don't mind me > posting this question here. > > I am slowly getting comfortable with Git, but there is something that > confuses me. If you want to be really comfortable with Git, you need to understand basics of its rather simple underlying data model. Find a toutorial that discusses this, and things will start to take their natural places. You need to become aware that from Git point of view, your project history is a DAG of commits, and branches are just pointers to specific nodes of the DAG. It's very essential, so I repeat: "branch" in Git is nothing more than a named pointer to specific commit in the DAG. You should also learn that the files you are changing constitute "working tree", and working tree does not belong to the DAG (and therefore to any branch). Git simply remembers particular commit in the DAG the working tree is checked-out from in the special HEAD pointer (that usually points to the current branch, that in turn points to the commit). > You are encouraged to make liberal use of 'branches', and if required you > can have multiple branches running concurrently. I'm afraid "multiple branches running concurrently" could be rather confusing. Recalling that Git branches are just pointers, they don't "run", they just exist. One needs to clearly understand the difference between Git branch, being a pointer to a commit, and the sequence of commits that lead to the commit at which Git branch points. When we say "branch of development", we usually mean the latter, and when we run "git checkout " we should understand we mean the former. > When you commit changes on one branch, Strictly speaking, when you commit, you don't commit changes, you create commit that contains entire state of your tree, and then this new commit is attached to the DAG where current branch points to. Then current branch is changed to point to this new commit. > those changes are not visible to other branches Exaclty. Any commit in the DAG is either reachable or not from given branch when history is traversed backwards. That's how "visible" is defined in Git. Right after commit is made, it's only reachable from the current branch (if any) indeed. > until you merge, Exactly. When you merge a branch to another branch, all commits reachable from the "branch" become reachable from "another branch" as well. > so each branch can be worked on independently. > > However, if you are working on a branch and make some changes, those changes > are visible to *all* branches until you commit. No, as they are not in the DAG yet, they are not reachable from any branches, so they are not visible to any of them. What you see are changes in your working tree with respect to the commit that is currently checked-out (usually those one to which the current branch points). > If you run 'git status' from any branch, you can see all files that > have been modified or added. You don't run 'git status' on a branch. You run it from within repository/working tree, and then repository (usually) has some specific branch being current at the time of invokation of 'git status' that 'git status' will report as such. > It seems to me that this can be confusing. When you are ready to commit > changes on one branch, you have to - > - check that it is the currently checked-out branch, which is not always > obvious What exactly "it" means in the "it is the currently..." above? Do you mean you need to check that the current branch is those one you want to commit changes into? If so, ask youself why do you do changes to a state of your working tree that was checked out from any other branch in the first place? Usually, you checkout a branch, make changes and commit them. Only if you realize that you was (and still are) on the wrong branch, you need to switch branches, and Git allows you to take your changes along with you, exactly what you need in this case. If what you want is to temporarily stop working on these particular changes and visit (checkout) another branch, you can stash your changes using "git stash" and restore them later, or you can commit the changes (remember that commits are local unless you publish them), and then, after you return to this branch later, use, e.g., "git reset HEAD~1" to continue editing your changes, or you can just edit further and then commit the changes as the new commit, or amend those temporary commit with your new changes ("git commit --amend"). > - choose which altered files you want to add to the staging area > - stage them and then commit You rather usually choose them by adding them to the staging area (unless we talk about some GUI on top of Git), so it rather looks like: - choose which changes you want to commit by adding them to the staging area. - commit. You can often bypass staging by "git commit -a", but anyway, "staging area" or "index" is yet another thing in Git it's better to make yourself familiar with, as you won't be able to ignore it if you ever reabase or merge. > This seems error-prone. Am I missing something? What exactly is error-prone? Are you afraid to commit to a wrong branch? Are you afraid to commit the changes you didn't want to commit? Anyway, if you did a mistake, you should be able to examine situation and fix it rather easily, provided you didn't yet publish your history. HTH, -- Sergey. From wolfgang.maier at biologie.uni-freiburg.de Wed Sep 17 08:33:16 2014 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Wed, 17 Sep 2014 14:33:16 +0200 Subject: Python docs not accessible from IDLE In-Reply-To: References: Message-ID: On 09/17/2014 01:15 PM, Peter Otten wrote: > Wolfgang Maier wrote: > >> On 09/17/2014 11:45 AM, Peter Otten wrote: >>> Wolfgang Maier wrote: >>> >>>> since a few days, when I select Help -> Python Docs from the IDLE menu, >>>> the link to the documentation that it tries to open in my browser isn't >>>> working anymore. >>>> The URL IDLE uses (copied from the browser address bar) is : >>>> docs.python.org/3.4 >>>> and you have to add a terminal slash for it to work. >>>> Now I don't know why it stopped working >>>> (browser update, change on the python docs server, others? >>>> I'm running idle-python3.4 on Ubuntu 14.04 and Firefox 32.0), >>>> but a possible fix may be to simply make IDLE add the slash. >>>> >>>> Is there anyone else experiencing the same problem ? >>> >>> I have a similar configuration (Linux Mint 17 which is based on Ubuntu >>> 14.04) and I cannot reproduce the problem. >>> >> >> Hmm, what happens if you just copy/paste >> >> docs.python.org/3.4 >> >> into your browser ? > > Works without problem. > >> Looks like some browsers (like the Ubuntu standard >> browser) automatically add the trailing slash and others (like my >> Firefox 32.0) don't. > > The webpage redirects twice: > > $ curl --head http://docs.python.org/3.4 > HTTP/1.1 301 Moved Permanently > ... > Location: https://docs.python.org/3.4 > ... > > $ curl --head https://docs.python.org/3.4 > HTTP/1.1 301 Moved Permanently > ... > Location: https://docs.python.org/3.4/ > ... > > $ curl --head https://docs.python.org/3.4/ > HTTP/1.1 200 OK > ... > > When in firefox' about:config I set > > network.http.redirection-limit 1 > > (the original value is 20 over here) I get an "Umleitungsfehler" > (redirection error in german). Maybe you should have a look at this setting. > If that's not the cause -- is there any error message that firefox displays > when you enter docs.python.org/3.4 ? > Ok, I confirmed your curl output, checked my firefox settings and tried other browsers on different platforms. Result: the redirection works fine on every platform/browser combination I could find (i.e., the problem is neither Ubuntu- nor firefox 32.0-specific). network.http.redirection-limit is set to its default of 20. I noticed two things, however: 1) If you wait long enough, firefox finally reports: Unable to connect Firefox can't establish a connection to the server at docs.python.org:9000. So it somehow seems to have picked up a port number during redirection, no idea why. 2) curl shows that the first redirect (from http://docs.python.org/3.4) gives HTTP/1.1 301 Moved Permanently as the first response from the server, but the second redirect (from https://docs.python.org/3.4) gives: HTTP/1.1 200 Connection established HTTP/1.1 301 Moved Permanently which looks a bit weird (but as I said no other browser I've tested seems to have a problem with that). So it looks like this is not really a Python issue though I'd still like to find out how to solve it. Thanks for your help, Wolfgang From jumppanen.jussi at gmail.com Wed Sep 17 09:49:12 2014 From: jumppanen.jussi at gmail.com (jumppanen.jussi at gmail.com) Date: Wed, 17 Sep 2014 06:49:12 -0700 (PDT) Subject: [ANN] Jedi Python Autocomplete in Zeus IDE In-Reply-To: <5419736c$0$29998$c3e8da3$5496439d@news.astraweb.com> References: <0f54bd4e-d7c1-4981-a3ea-db9ea35be74d@googlegroups.com> <5419736c$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: <97219f74-6b3c-4216-8147-f6561f0e7c8f@googlegroups.com> On Wednesday, September 17, 2014 9:42:16 PM UTC+10, Steven D'Aprano wrote: > Thank you! Thanks goes to the creators of Jedi. They've done an amazing job creating that package! > According to the screen shot there, if you have typed > > self.balan > > the autocomplete will offer the list: > > balance > close I'm not seeing that behaviour :? For example using the coding sample from the link, assume I had this code (where | represent the location of the cursor): def withdraw(self, amount): self.balan| If the Jedi Autocomplete macro is run from the Macros panel (on the left hand side) then the only thing that is displayed is a popup list is this one item: balance Now if the code had been like this: def withdraw(self, amount): self.| Then yes, I get a full list of selections. > Why does Zeus suggest "close" when I have typed "balan"? Again I'm not seeing this. Consider again this case: def withdraw(self, amount): self.| What should happen is as you start typing the list will be filtered and non matching items removed. So if you had started with the code above and typed in 'balan' as shown below: def withdraw(self, amount): self.balan| Once againn only one item would be left in the list and that should be the one possible matching value: balance When I do this test that is the behaviour I'm seeing. Can you replicate the issue at will? If you are seeing something different it might be some sort of timing issue? In addition, if you run the same test as above do you get the same result? To run that test all I did was save the code below to the test.py file, opened the file in Zeus and then ran the autocomplete macro. class BankAccount(object): """BankAccount Class. This is the bank account class.""" def __init__(self, initial_balance=0): self.initial_balance = initial_balance def deposit(self, amount): self.balance += amount def withdraw(self, amount): self.balance -= amount self. # << run the test here def overdrawn(self): return self.balance < 0 Cheers Jussi From pierrick.koch at gmail.com Wed Sep 17 10:15:53 2014 From: pierrick.koch at gmail.com (Pierrick Koch) Date: Wed, 17 Sep 2014 16:15:53 +0200 Subject: python-distribute.org down Message-ID: Hello, python-distribute.org server seems down, it was hosting the install script distribute_setup.py ( http://python-distribute.org/distribute_setup.py ) meanwhile, you can find it here: https://gist.github.com/anonymous/947191a4635cd7b7f79a Best, -- Pierrick Koch From kwpolska at gmail.com Wed Sep 17 10:49:09 2014 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Wed, 17 Sep 2014 16:49:09 +0200 Subject: python-distribute.org down In-Reply-To: References: Message-ID: On Wed, Sep 17, 2014 at 4:15 PM, Pierrick Koch wrote: > Hello, > > python-distribute.org server seems down, > it was hosting the install script distribute_setup.py > ( http://python-distribute.org/distribute_setup.py ) > > meanwhile, you can find it here: > https://gist.github.com/anonymous/947191a4635cd7b7f79a distribute is long dead (probably why the website is down). Use setuptools instead: https://pythonhosted.org/setuptools/ https://bootstrap.pypa.io/ez_setup.py -- Chris ?Kwpolska? Warrick PGP: 5EAAEA16 stop html mail | always bottom-post | only UTF-8 makes sense From ram.rachum at gmail.com Wed Sep 17 10:55:32 2014 From: ram.rachum at gmail.com (cool-RR) Date: Wed, 17 Sep 2014 07:55:32 -0700 (PDT) Subject: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` In-Reply-To: References: <06397cb3-8baf-4af1-8152-ff7c3f6ceb62@googlegroups.com> Message-ID: Terry, that doesn't really answer the question "why", it just pushes it back to the documentation. Is there a real answer why? Why return NaN when Inf would make mathematical sense? On Wednesday, September 17, 2014 4:13:38 AM UTC+3, Terry Reedy wrote: > On 9/16/2014 5:40 PM, cool-RR wrote: > > > While debugging my code I found that the bug was because I assumed > > > that something like `divmod(float('inf'), 1)` would be equal to > > > `(float('inf'), float('nan'))`, while Python returns `(float('nan'), > > > float('nan'))`. Why does Python make the division result be NaN in > > > this case? `float('inf') / 1` is still `float('inf')`. > > > > For integers, divmod(x, y) is defined as (x // y, x % y) == ((x - x%y) > > // y, x % y) == ((x - x%y) / y, x % y). > > > > For floats, Python is documented as using the third expression. > > > > "Help on built-in function divmod in module builtins: > > divmod(...) > > divmod(x, y) -> (div, mod) > > Return the tuple ((x-x%y)/y, x%y). Invariant: div*y + mod == x." > > > > It does not really matter, however, as infinity cannot be 'floored' as > > required for // > > > > >>> math.floor(float('inf')) > > Traceback (most recent call last): > > File "", line 1, in > > math.floor(float('inf')) > > OverflowError: cannot convert float infinity to integer > > > > and hence > > > > >>> float('inf') // 1.0 > > nan > > > > -- > > Terry Jan Reedy From rosuav at gmail.com Wed Sep 17 11:10:14 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 18 Sep 2014 01:10:14 +1000 Subject: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` In-Reply-To: References: <06397cb3-8baf-4af1-8152-ff7c3f6ceb62@googlegroups.com> Message-ID: On Thu, Sep 18, 2014 at 12:55 AM, cool-RR wrote: > Terry, that doesn't really answer the question "why", it just pushes it back to the documentation. Is there a real answer why? Why return NaN when Inf would make mathematical sense? > To answer that, we have to first look at what it means to do operations on Inf. The definition of "Infinity + 1" is the limit of "x + 1" as x goes toward positive infinity - which is positive infinity. Same with infinity-1, infinity/1, infinity*1, etc, etc, etc. So far, so good. But as x tends toward positive infinity, the value of "x // 1" (or simply of floor(x)) doesn't simply increase tidily. It goes up in little jumps, every time x reaches a new integer. And while it's conceivable to define that infinity divided by anything is infinity, and infinity modulo anything is zero, that raises serious issues of primality and such; I'm not sure that that would really help anything. So there's no possible value for floor division of infinity, ergo the result is NaN. So. There you have an answer. Now, for your next question, can you please use something better than Google Groups, or at least learn how to use an interleaved posting style and trim out all the excess blank lines? Thanks. ChrisA From ram.rachum at gmail.com Wed Sep 17 11:16:03 2014 From: ram.rachum at gmail.com (cool-RR) Date: Wed, 17 Sep 2014 08:16:03 -0700 (PDT) Subject: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` In-Reply-To: References: <06397cb3-8baf-4af1-8152-ff7c3f6ceb62@googlegroups.com> Message-ID: <151e45ce-444d-441c-b59b-67e2aee3882b@googlegroups.com> On Wednesday, September 17, 2014 6:10:35 PM UTC+3, Chris Angelico wrote: > On Thu, Sep 18, 2014 at 12:55 AM, cool-RR wrote: > > Terry, that doesn't really answer the question "why", it just pushes it back to the documentation. Is there a real answer why? Why return NaN when Inf would make mathematical sense? > > > To answer that, we have to first look at what it means to do > operations on Inf. The definition of "Infinity + 1" is the limit of "x > + 1" as x goes toward positive infinity - which is positive infinity. > Same with infinity-1, infinity/1, infinity*1, etc, etc, etc. So far, > so good. But as x tends toward positive infinity, the value of "x // > 1" (or simply of floor(x)) doesn't simply increase tidily. It goes up > in little jumps, every time x reaches a new integer. Despite the fact it goes up in jump, it still satisfies the mathematical condition needed for a limit. (I won't quote the epsilon-delta thing but I think you can find it.) > And while it's > conceivable to define that infinity divided by anything is infinity, > and infinity modulo anything is zero, that raises serious issues of > primality and such; > I'm not sure that that would really help anything. I didn't ask for the modulo, I agree it should remain NaN. I'm talking about the floor division. I don't see any problems this will cause with primality. "I'm not sure that that would really help anything" is a little bit too vague. Thanks, Ram. From rosuav at gmail.com Wed Sep 17 11:29:22 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 18 Sep 2014 01:29:22 +1000 Subject: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` In-Reply-To: <151e45ce-444d-441c-b59b-67e2aee3882b@googlegroups.com> References: <06397cb3-8baf-4af1-8152-ff7c3f6ceb62@googlegroups.com> <151e45ce-444d-441c-b59b-67e2aee3882b@googlegroups.com> Message-ID: On Thu, Sep 18, 2014 at 1:16 AM, cool-RR wrote: > I didn't ask for the modulo, I agree it should remain NaN. I'm talking about the floor division. > Invariant: div*y + mod == x. If mod is NaN, there is no possible value for div that will make the invariant true, ergo it too has to be NaN. ChrisA From ian.g.kelly at gmail.com Wed Sep 17 11:34:14 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 17 Sep 2014 09:34:14 -0600 Subject: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` In-Reply-To: References: <06397cb3-8baf-4af1-8152-ff7c3f6ceb62@googlegroups.com> <151e45ce-444d-441c-b59b-67e2aee3882b@googlegroups.com> Message-ID: On Wed, Sep 17, 2014 at 9:29 AM, Chris Angelico wrote: > On Thu, Sep 18, 2014 at 1:16 AM, cool-RR wrote: >> I didn't ask for the modulo, I agree it should remain NaN. I'm talking about the floor division. >> > > Invariant: div*y + mod == x. > > If mod is NaN, there is no possible value for div that will make the > invariant true, ergo it too has to be NaN. That still doesn't make the invariant true. By this argument div could be 42, and the invariant would hold equally well (i.e. not at all). From steve+comp.lang.python at pearwood.info Wed Sep 17 11:32:36 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 18 Sep 2014 01:32:36 +1000 Subject: [ANN] Jedi Python Autocomplete in Zeus IDE References: <0f54bd4e-d7c1-4981-a3ea-db9ea35be74d@googlegroups.com> <5419736c$0$29998$c3e8da3$5496439d@news.astraweb.com> <97219f74-6b3c-4216-8147-f6561f0e7c8f@googlegroups.com> Message-ID: <5419a994$0$29976$c3e8da3$5496439d@news.astraweb.com> jumppanen.jussi at gmail.com wrote: > On Wednesday, September 17, 2014 9:42:16 PM UTC+10, Steven D'Aprano wrote: [...] >> According to the screen shot there, if you have typed >> >> self.balan >> >> the autocomplete will offer the list: >> >> balance >> close > > I'm not seeing that behaviour :? Look at the screen shot on the page you linked to: http://www.zeusedit.com/zforum/viewtopic.php?t=7200 Here is the specific image: http://www.zeusedit.com/images/jedi_autocomplete.png > For example using the coding sample from the link, assume I had this > code (where | represent the location of the cursor): > > def withdraw(self, amount): > self.balan| > > If the Jedi Autocomplete macro is run from the Macros panel (on the > left hand side) then the only thing that is displayed is a popup list > is this one item: > > balance That behaviour makes more sense than the behaviour shown in the screen shot. Perhaps the image needs to be updated. -- Steven From ian.g.kelly at gmail.com Wed Sep 17 11:35:54 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 17 Sep 2014 09:35:54 -0600 Subject: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` In-Reply-To: References: <06397cb3-8baf-4af1-8152-ff7c3f6ceb62@googlegroups.com> Message-ID: On Tue, Sep 16, 2014 at 7:12 PM, Terry Reedy wrote: > It does not really matter, however, as infinity cannot be 'floored' as > required for // > >>>> math.floor(float('inf')) > Traceback (most recent call last): > File "", line 1, in > math.floor(float('inf')) > OverflowError: cannot convert float infinity to integer > > and hence > >>>> float('inf') // 1.0 > nan In C, floor(INFINITY) returns infinity (at least in the implementation I just tested). From rosuav at gmail.com Wed Sep 17 11:40:01 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 18 Sep 2014 01:40:01 +1000 Subject: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` In-Reply-To: References: <06397cb3-8baf-4af1-8152-ff7c3f6ceb62@googlegroups.com> <151e45ce-444d-441c-b59b-67e2aee3882b@googlegroups.com> Message-ID: On Thu, Sep 18, 2014 at 1:34 AM, Ian Kelly wrote: > On Wed, Sep 17, 2014 at 9:29 AM, Chris Angelico wrote: >> On Thu, Sep 18, 2014 at 1:16 AM, cool-RR wrote: >>> I didn't ask for the modulo, I agree it should remain NaN. I'm talking about the floor division. >>> >> >> Invariant: div*y + mod == x. >> >> If mod is NaN, there is no possible value for div that will make the >> invariant true, ergo it too has to be NaN. > > That still doesn't make the invariant true. By this argument div could > be 42, and the invariant would hold equally well (i.e. not at all). Nothing can possibly make it true, so there are only two possibilities: return NaN, or raise an exception. ChrisA From frank at chagford.com Wed Sep 17 11:52:40 2014 From: frank at chagford.com (Frank Millman) Date: Wed, 17 Sep 2014 17:52:40 +0200 Subject: [OT] Question about Git branches References: Message-ID: "Sergey Organov" wrote in message news:lvbtd2$fsg$1 at speranza.aioe.org... > "Frank Millman" writes: >> Hi all >> [snip lots of really valuable information] > Thanks a stack, Sergey, that is a really useful explanation. For the record, this is where my initial confusion came from. The following quote comes from the book Pro Git, by Scott Chacon. It is typical of the advice found in other tutorials and notes I have read. """ Let's go through a simple example of branching and merging with a workflow that you might use in the real world. You'll follow these steps: 1. Do work on a web site. 2. Create a branch for a new story you're working on. 3. Do some work in that branch. At this stage, you'll receive a call that another issue is critical and you need a hotfix. You'll do the following: 1. Revert back to your production branch. 2. Create a branch to add the hotfix. 3. After it's tested, merge the hotfix branch, and push to production. 4. Switch back to your original story and continue working. """ Nowhere does it state that you must commit or stash your current changes before switching branches. Maybe it is implied by 'revert', but as a newbie I had missed that. With your help and input from others, I have a much better understanding now. Frank From Seymore4Head at Hotmail.invalid Wed Sep 17 11:55:06 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Wed, 17 Sep 2014 11:55:06 -0400 Subject: the python shell window is already executing a command References: <4jrh1adtbsvnr9o20r9k3hfe4nkrkps2dk@4ax.com> Message-ID: On Wed, 17 Sep 2014 04:02:16 -0400, Terry Reedy wrote: >On 9/16/2014 10:17 PM, Seymore4Head wrote: >> I have googled for a solution to this problem. None I have tried >> worked. >> >> I have a very short program that runs for a count of 20 and ends. >> What I do is click on the IDLE window and without making any changes I >> just hit f5 to rerun the program. > >Do you mean click on the Idle editor window? > >> Sometimes I get the error "the python shell window is already >> executing a command" and sometimes not. >> >> I am using XP and Python 3.4.1. >> >> Is there a way to rerun a program without getting this error? > >Normally, hitting f5 kills the previous process if it is still running >and starts the one in the editor. Please post a minimal program that >exhibits the problem. It happens in almost every program I have written. I just tried this one again. I could run the program by pushing f5. The first couple of times it would run again by switching back to IDLE and pressing f5, but after the second or third time, it gives an error that the python shell window is already executing a command. If I make a change to the program, like adding or deleting a 0 from "rounds" the program will run without generating an error, but if I try to re run the program without changing anything, I get the error almost every time. Here is one. import random count =0 rounds=1000 heads=0 tails=0 ht=[0,1] while count References: Message-ID: On Thu, Sep 18, 2014 at 1:52 AM, Frank Millman wrote: > Nowhere does it state that you must commit or stash your current changes > before switching branches. Maybe it is implied by 'revert', but as a newbie > I had missed that. No, it's more implied in "Do some work". Basically, what you should be doing, as much as possible, is making changes and immediately committing them. This applies to all forms of source control; once you're done sorting everything out, you can then squash the entire topic branch into a single commit that you put onto the main branch, or you can keep the full history (I prefer to do the latter). All magic comes at a price [1], and the price of the time travel that git lets you do is the discipline of making frequent commits while you work. As I see it, that's pretty cheap for the power you get :) [1] You're welcome to hear that in the voice of Rumpelstiltskin if you wish ChrisA From ian.g.kelly at gmail.com Wed Sep 17 12:12:18 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 17 Sep 2014 10:12:18 -0600 Subject: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` In-Reply-To: References: <06397cb3-8baf-4af1-8152-ff7c3f6ceb62@googlegroups.com> <151e45ce-444d-441c-b59b-67e2aee3882b@googlegroups.com> Message-ID: On Wed, Sep 17, 2014 at 9:40 AM, Chris Angelico wrote: > On Thu, Sep 18, 2014 at 1:34 AM, Ian Kelly wrote: >> On Wed, Sep 17, 2014 at 9:29 AM, Chris Angelico wrote: >>> On Thu, Sep 18, 2014 at 1:16 AM, cool-RR wrote: >>>> I didn't ask for the modulo, I agree it should remain NaN. I'm talking about the floor division. >>>> >>> >>> Invariant: div*y + mod == x. >>> >>> If mod is NaN, there is no possible value for div that will make the >>> invariant true, ergo it too has to be NaN. >> >> That still doesn't make the invariant true. By this argument div could >> be 42, and the invariant would hold equally well (i.e. not at all). > > Nothing can possibly make it true, so there are only two > possibilities: return NaN, or raise an exception. I could see raising an exception, since the docs state "the result is (q, a % b), where q is usually math.floor(a / b) but may be 1 less than that" and it's already been established that math.floor(float('inf')) raises an exception (although interesting note: in Python 2 the docs claimed the same thing, but math.floor(float('inf')) returned float('inf') and divmod already returned float('nan'); so I don't think that the behavior of math.floor is really the origin of this). But the point I'm trying to make is that returning NaN here is every bit as arbitrary as returning None or False, because there *is* a value that makes actual mathematical sense to return, even if it fails to maintain the invariant on account of the modulus addition (which should just be omitted in this case). Here's another edge case that fails the invariant. Why should divmod return inf here but not in the first case? >>> divmod(1e300, 1e-300) (inf, 4.891554850853602e-301) >>> _[0] * 1e-300 + _[1] inf From andiroots at gmail.com Wed Sep 17 12:27:55 2014 From: andiroots at gmail.com (Andi Vaganerd) Date: Wed, 17 Sep 2014 09:27:55 -0700 (PDT) Subject: xlrd Can't find workbook in OLE2 compound document Message-ID: Hello, I'm trying to open an excel file (.xlsx) using python module xlrd. And I'm getting this error over here: "Can't find workbook in OLE2 compound document" Is there anybody here already got this problem? How do you resolve it? I've a very simple python program to open that, but it just doesn't open, here is my very simple code: ============================================ import xlrd def import_workbook_protected( path ): wb = xlrd.open_workbook( path ) if __name__ == "__main__": path = "workbook_for_test.xlsx" import_workbook_protected( path ) ============================================ The only thing differente from others excel files, is that this workbook is protected, not with password, but I can't write on it, just open and read (on my computer, not on python) Thanks! From ian.g.kelly at gmail.com Wed Sep 17 12:30:23 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 17 Sep 2014 10:30:23 -0600 Subject: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` In-Reply-To: References: <06397cb3-8baf-4af1-8152-ff7c3f6ceb62@googlegroups.com> <151e45ce-444d-441c-b59b-67e2aee3882b@googlegroups.com> Message-ID: On Wed, Sep 17, 2014 at 9:40 AM, Chris Angelico wrote: > On Thu, Sep 18, 2014 at 1:34 AM, Ian Kelly wrote: >> On Wed, Sep 17, 2014 at 9:29 AM, Chris Angelico wrote: >>> On Thu, Sep 18, 2014 at 1:16 AM, cool-RR wrote: >>>> I didn't ask for the modulo, I agree it should remain NaN. I'm talking about the floor division. >>>> >>> >>> Invariant: div*y + mod == x. >>> >>> If mod is NaN, there is no possible value for div that will make the >>> invariant true, ergo it too has to be NaN. >> >> That still doesn't make the invariant true. By this argument div could >> be 42, and the invariant would hold equally well (i.e. not at all). > > Nothing can possibly make it true, so there are only two > possibilities: return NaN, or raise an exception. Actually, I think we're focusing on the wrong element of the tuple. The fact is that there are values that can make the invariant true. For example, divmod(inf, 1) could return (inf, 0). inf * 1 + 0 = inf. (inf, 1), or (inf, ) would work equally well. The *only* reason the invariant can't be maintained is because we're committed to returning nan for the second element for some reason. From ram.rachum at gmail.com Wed Sep 17 12:33:33 2014 From: ram.rachum at gmail.com (cool-RR) Date: Wed, 17 Sep 2014 09:33:33 -0700 (PDT) Subject: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` In-Reply-To: References: <06397cb3-8baf-4af1-8152-ff7c3f6ceb62@googlegroups.com> <151e45ce-444d-441c-b59b-67e2aee3882b@googlegroups.com> Message-ID: On Wednesday, September 17, 2014 6:30:04 PM UTC+3, Chris Angelico wrote: > On Thu, Sep 18, 2014 at 1:16 AM, cool-RR wrote: > > I didn't ask for the modulo, I agree it should remain NaN. I'm talking about the floor division. > > Invariant: div*y + mod == x. > If mod is NaN, there is no possible value for div that will make the > invariant true, ergo it too has to be NaN. > ChrisA Chris, why is this invariant `div*y + mod == x` so important? Maybe it's more important to return a mathematically reasonable result for the the floor-division result than to maintain this invariant? Thanks, Ram. From rosuav at gmail.com Wed Sep 17 12:37:50 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 18 Sep 2014 02:37:50 +1000 Subject: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` In-Reply-To: References: <06397cb3-8baf-4af1-8152-ff7c3f6ceb62@googlegroups.com> <151e45ce-444d-441c-b59b-67e2aee3882b@googlegroups.com> Message-ID: On Thu, Sep 18, 2014 at 2:33 AM, cool-RR wrote: > On Wednesday, September 17, 2014 6:30:04 PM UTC+3, Chris Angelico wrote: >> On Thu, Sep 18, 2014 at 1:16 AM, cool-RR wrote: >> > I didn't ask for the modulo, I agree it should remain NaN. I'm talking about the floor division. >> >> Invariant: div*y + mod == x. >> If mod is NaN, there is no possible value for div that will make the >> invariant true, ergo it too has to be NaN. >> ChrisA > > Chris, why is this invariant `div*y + mod == x` so important? Maybe it's more important to return a mathematically reasonable result for the the floor-division result than to maintain this invariant? It's important because it's documented :) You can expect whatever you like, but if something's a documented invariant, that's more important than your expectations. Now, why was divmod documented as returning values adhering to that invariant? You'd have to ask the developers, I've no idea. ChrisA From ian.g.kelly at gmail.com Wed Sep 17 14:03:27 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 17 Sep 2014 12:03:27 -0600 Subject: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` In-Reply-To: References: <06397cb3-8baf-4af1-8152-ff7c3f6ceb62@googlegroups.com> Message-ID: On Wed, Sep 17, 2014 at 9:10 AM, Chris Angelico wrote: > And while it's > conceivable to define that infinity divided by anything is infinity, > and infinity modulo anything is zero, that raises serious issues of > primality and such; I'm not sure that that would really help anything. I missed that this point was already discussed. Can you elaborate on the "serious issues of primality and such"? Since infinity is not a natural number, its primality is undefined, so I don't see the issue here. From nad at acm.org Wed Sep 17 14:08:46 2014 From: nad at acm.org (Ned Deily) Date: Wed, 17 Sep 2014 11:08:46 -0700 Subject: Python docs not accessible from IDLE References: Message-ID: In article , Wolfgang Maier wrote: > On 09/17/2014 01:15 PM, Peter Otten wrote: > > Wolfgang Maier wrote: > >> On 09/17/2014 11:45 AM, Peter Otten wrote: > >>> Wolfgang Maier wrote: > >>> > >>>> since a few days, when I select Help -> Python Docs from the IDLE menu, > >>>> the link to the documentation that it tries to open in my browser isn't > >>>> working anymore. > >>>> The URL IDLE uses (copied from the browser address bar) is : > >>>> docs.python.org/3.4 > >>>> and you have to add a terminal slash for it to work. > >>>> Now I don't know why it stopped working > >>>> (browser update, change on the python docs server, others? > >>>> I'm running idle-python3.4 on Ubuntu 14.04 and Firefox 32.0), > >>>> but a possible fix may be to simply make IDLE add the slash. [...] > So it somehow seems to have picked up a port number during redirection, > no idea why. > > > 2) curl shows that the first redirect (from http://docs.python.org/3.4) > gives HTTP/1.1 301 Moved Permanently as the first response from the > server, but the second redirect (from https://docs.python.org/3.4) gives: > > HTTP/1.1 200 Connection established > > HTTP/1.1 301 Moved Permanently > > which looks a bit weird (but as I said no other browser I've tested > seems to have a problem with that). > > So it looks like this is not really a Python issue though I'd still like > to find out how to solve it. There have been a number of changes in recent months to the PSF web infrastructure, all with the aim to provide more reliable, faster, and secure services. These have included moving servers to new hosts, adding a commercial content delivery network to the frond-end of high traffic sites, and default use of encrypted connections (https). As such, there are a number of moving parts and possible loose ends. If you are still having issues, chances are you aren't the only one. If so, please contact the PSF infrastructure team via email or IRC: https://wiki.python.org/moin/PSFInfrastructure -- Ned Deily, nad at acm.org From breamoreboy at yahoo.co.uk Wed Sep 17 16:38:20 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 17 Sep 2014 21:38:20 +0100 Subject: Problems in python pandas In-Reply-To: References: Message-ID: On 16/09/2014 19:08, prashant.mudgal at accenture.com wrote: > Hi All, > > I am having some problem in python. > I'm sorry that I can't help you directly but as you haven't had any answers this http://pandas.pydata.org/community.html states "Have a question about pandas? Your first stop should be Stack Overflow. Search for an existing answer to your question, or post a new one (and make sure you include the ?pandas? tag). You can also chat with other users on the #pydata channel on irc.freenode.net." -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rosuav at gmail.com Wed Sep 17 17:37:55 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 18 Sep 2014 07:37:55 +1000 Subject: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` In-Reply-To: References: <06397cb3-8baf-4af1-8152-ff7c3f6ceb62@googlegroups.com> Message-ID: On Thu, Sep 18, 2014 at 4:03 AM, Ian Kelly wrote: > On Wed, Sep 17, 2014 at 9:10 AM, Chris Angelico wrote: >> And while it's >> conceivable to define that infinity divided by anything is infinity, >> and infinity modulo anything is zero, that raises serious issues of >> primality and such; I'm not sure that that would really help anything. > > I missed that this point was already discussed. Can you elaborate on > the "serious issues of primality and such"? Since infinity is not a > natural number, its primality is undefined, so I don't see the issue > here. It's not something I've personally worked with, so I'm trying to dredge stuff up from my brain, but I think there's something along the lines of "stuff shouldn't be a multiple of everything" and the Prime Number Theorem. But that may just be a case where float != real. ChrisA From cubicool at gmail.com Wed Sep 17 18:45:04 2014 From: cubicool at gmail.com (Jeremy Moles) Date: Wed, 17 Sep 2014 15:45:04 -0700 (PDT) Subject: Properly Using 3.4.1 & Valgrind Message-ID: <4a65eb8d-4fba-400a-81bc-ee029c2a8f66@googlegroups.com> Hey guys. I'm using the Python 3.4.1 release tarball, and am trying to configure it for usage with valgrind. I have followed all of the common, well-documented steps online such as uncommenting Py_USING_MEMORY_DEBUGGER, compiling with --with-pydebug, --with-valgrind, and --without-pymalloc. I've tried uncommenting everything in the provided suppression file, as well. However, no matter what I do with my configuration/build, I cannot get Python to stop reporting thousands of lines of leaks. In fact, every call to Py_MALLOC results in valgrind believing a leak has occurred, so you can imagine there would be a legion of errors just firing up the interpreter. What is the modern, accepted way of using Python3 with valgrind, and what should my expectations be? I really like relying on Valgrind as an additional source of informative debugging information (though not exclusively), and any help resolving this would be appreciated. At a minimum, I'd expect simply opening/closing the interpreter to generate no leak warnings. I'm perfectly fine making suppression files for small issues here or there (especially in libraries/modules), but I find it hard to believe a project as well-maintained as Python has this many "valid" leaks. I'm pretty sure the problem is me. :) Thanks! From tjreedy at udel.edu Wed Sep 17 18:56:47 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 17 Sep 2014 18:56:47 -0400 Subject: the python shell window is already executing a command In-Reply-To: References: <4jrh1adtbsvnr9o20r9k3hfe4nkrkps2dk@4ax.com> Message-ID: On 9/17/2014 11:55 AM, Seymore4Head wrote: > On Wed, 17 Sep 2014 04:02:16 -0400, Terry Reedy > wrote: >> On 9/16/2014 10:17 PM, Seymore4Head wrote: >>> What I do is click on the IDLE window and without making any changes I >>> just hit f5 to rerun the program. >>> Sometimes I get the error "the python shell window is already >>> executing a command" and sometimes not. You left out an important part of the error message ""please wait until it is finished." >>> I am using XP and Python 3.4.1. I am using 3.4.1 on Win 7. >>> Is there a way to rerun a program without getting this error? Follow the instruction you were given, but omitted, or see below. >> Normally, hitting f5 kills the previous process if it is still running >> and starts the one in the editor. Please post a minimal program that >> exhibits the problem. > > It happens in almost every program I have written. I just tried this > one again. I could run the program by pushing f5. The first couple > of times it would run again by switching back to IDLE and pressing f5, > but after the second or third time, it gives an error that the python > shell window is already executing a command. > > If I make a change to the program, like adding or deleting a 0 from > "rounds" the program will run without generating an error, but if I > try to re run the program without changing anything, I get the error > almost every time. > > > Here is one. > > import random > count =0 > rounds=1000 > heads=0 > tails=0 > ht=[0,1] > while count coin=random.choice(ht) > if coin == 0: > heads=heads+1 > elif coin == 1: > tails=tails+1 > count = count + 1 > print (heads,tails) > print ('Heads {:.2%} Tails "{:.2%} "'.format(heads/rounds, > tails/rounds)) I am unable to reproduce the problem. When I run this program from an Idle editor, it finished before I can click on the Editor window and hit F5 again. The same remains true with 1 or 2 zeros added. With 1000000 rounds, I get the expected behavior, which is no ouput from the cancelled process and a clean restart. A little digging with Idle's grep (Find in Files) shows that the message is produced by this code in idlelib/PyShell.py, about 825. def display_executing_dialog(self): tkMessageBox.showerror( "Already executing", "The Python Shell window is already executing a command; " "please wait until it is finished.", master=self.tkconsole.text) This function is only called here (about line 735) def runcommand(self, code): "Run the code without invoking the debugger" # The code better not raise an exception! if self.tkconsole.executing: self.display_executing_dialog() How is this run? Run-Module F5 invokes ScriptBinding.run_module_event(116) and thence _run_module_event (129). This methods includes this. if PyShell.use_subprocess: interp.restart_subprocess(with_cwd=False) restart_subprocess includes these lines (starting at 470): # Kill subprocess, spawn a new one, accept connection. self.rpcclt.close() self.terminate_subprocess() console = self.tkconsole ... console.executing = False # == self.tkconsole ... self.transfer_path(with_cwd=with_cwd) transfer_path calls runcommand but only after tkconsole.executing has been set to False. But this only happens if PyShell.use_subprocess is True, which it normally is, but not if one starts Idle with the -n option. After conditionally calling interp.restart_subprocess, _run_module_event directly calls interp.runcommand, which can fail when running with -n. Are you? This is the only way I know to get the error message. Is so, the second way to not get the error message is to not use -n and run normally. -- Terry Jan Reedy From tjreedy at udel.edu Wed Sep 17 19:23:51 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 17 Sep 2014 19:23:51 -0400 Subject: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` In-Reply-To: References: <06397cb3-8baf-4af1-8152-ff7c3f6ceb62@googlegroups.com> Message-ID: On 9/17/2014 10:55 AM, cool-RR wrote: > Terry, that doesn't really answer the question "why", it just pushes > it back to the documentation. Is there a real answer why? Why return > NaN when Inf would make mathematical sense? IEEE float('inf') and float('nan') are engineering, not math constructs. I showed that the result is consistent with the math definition. Another result (including raising) might be also. Many choices concerting inf and nan are arbitrary and any 'why' can be debated. -- Terry Jan Reedy From tjreedy at udel.edu Wed Sep 17 19:32:43 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 17 Sep 2014 19:32:43 -0400 Subject: Python docs not accessible from IDLE In-Reply-To: References: Message-ID: On 9/17/2014 2:08 PM, Ned Deily wrote: > In article , > Wolfgang Maier wrote: >> On 09/17/2014 01:15 PM, Peter Otten wrote: >>> Wolfgang Maier wrote: >> 2) curl shows that the first redirect (from http://docs.python.org/3.4) >> gives HTTP/1.1 301 Moved Permanently as the first response from the >> server, but the second redirect (from https://docs.python.org/3.4) gives: >> >> HTTP/1.1 200 Connection established >> >> HTTP/1.1 301 Moved Permanently >> >> which looks a bit weird (but as I said no other browser I've tested >> seems to have a problem with that). >> >> So it looks like this is not really a Python issue though I'd still like >> to find out how to solve it. > > There have been a number of changes in recent months to the PSF web > infrastructure, all with the aim to provide more reliable, faster, and > secure services. These have included moving servers to new hosts, > adding a commercial content delivery network to the frond-end of high > traffic sites, and default use of encrypted connections (https). As > such, there are a number of moving parts and possible loose ends. If > you are still having issues, chances are you aren't the only one. If > so, please contact the PSF infrastructure team via email or IRC: > > https://wiki.python.org/moin/PSFInfrastructure Ned, is there any reason to not add the trailing '/' to the url for 3.4.2? I verified that it is being added by python.org when connecting from win7 with FF. How about adding the 's' for 'https'? -- Terry Jan Reedy From jumppanen.jussi at gmail.com Wed Sep 17 20:29:53 2014 From: jumppanen.jussi at gmail.com (jumppanen.jussi at gmail.com) Date: Wed, 17 Sep 2014 17:29:53 -0700 (PDT) Subject: [ANN] Jedi Python Autocomplete in Zeus IDE In-Reply-To: <5419a994$0$29976$c3e8da3$5496439d@news.astraweb.com> References: <0f54bd4e-d7c1-4981-a3ea-db9ea35be74d@googlegroups.com> <5419736c$0$29998$c3e8da3$5496439d@news.astraweb.com> <97219f74-6b3c-4216-8147-f6561f0e7c8f@googlegroups.com> <5419a994$0$29976$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thursday, September 18, 2014 1:32:53 AM UTC+10, Steven D'Aprano wrote: I have created some confusion since the code on the forum site is not exactly the same as the code that I used in the post from above. Sorry about that :( > Here is the specific image: > > http://www.zeusedit.com/images/jedi_autocomplete.png > > That behaviour makes more sense than the behaviour shown in the > screen shot. Perhaps the image needs to be updated. This is what that image represents. Using the correct code from the forum link in my test.py file, the screen shot above represents the scenario where you have this code: def overdrawn(self): return self.| and the Jedi Macro is run from the navigator panel (on the left). I have doctored the original image above to better show the actual location of the cursor. With that list showing if I now continue to type *bala* then what I will see is this: http://www.zeusedit.com/images/jedi_autocomplete1.png This is how the autocomplete is *meant* to work, but if you are not seeing that behaviour then you have probably found a bug :( Cheers Jussi From nad at acm.org Wed Sep 17 20:46:38 2014 From: nad at acm.org (Ned Deily) Date: Wed, 17 Sep 2014 17:46:38 -0700 Subject: Python docs not accessible from IDLE References: Message-ID: In article , Terry Reedy wrote: > Ned, is there any reason to not add the trailing '/' to the url for > 3.4.2? I verified that it is being added by python.org when connecting > from win7 with FF. How about adding the 's' for 'https'? There is no reason not to add both at this point, although the old url *should* continue to work. Using those changes avoids a couple of redirects. -- Ned Deily, nad at acm.org From thomas at orozco.fr Wed Sep 17 20:55:21 2014 From: thomas at orozco.fr (Thomas Orozco) Date: Wed, 17 Sep 2014 17:55:21 -0700 Subject: [ANN] Jedi Python Autocomplete in Zeus IDE In-Reply-To: <5419a994$0$29976$c3e8da3$5496439d@news.astraweb.com> References: <0f54bd4e-d7c1-4981-a3ea-db9ea35be74d@googlegroups.com> <5419736c$0$29998$c3e8da3$5496439d@news.astraweb.com> <97219f74-6b3c-4216-8147-f6561f0e7c8f@googlegroups.com> <5419a994$0$29976$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Sep 17, 2014 at 8:32 AM, Steven D'Aprano wrote: > > jumppanen.jussi at gmail.com wrote: > > > On Wednesday, September 17, 2014 9:42:16 PM UTC+10, Steven D'Aprano wrote: > [...] > >> According to the screen shot there, if you have typed > >> > >> self.balan > >> > >> the autocomplete will offer the list: > >> > >> balance > >> close > > > > I'm not seeing that behaviour :? > > Look at the screen shot on the page you linked to: > > http://www.zeusedit.com/zforum/viewtopic.php?t=7200 > > Here is the specific image: > > http://www.zeusedit.com/images/jedi_autocomplete.png The cursor is actually on the line above (where the current content is *self.* ? not *self.balan*). In other words, the cursor is currently in the "overdrawn" method, not the "close" method. From jumppanen.jussi at gmail.com Wed Sep 17 21:12:21 2014 From: jumppanen.jussi at gmail.com (jumppanen.jussi at gmail.com) Date: Wed, 17 Sep 2014 18:12:21 -0700 (PDT) Subject: [ANN] Jedi Python Autocomplete in Zeus IDE In-Reply-To: References: <0f54bd4e-d7c1-4981-a3ea-db9ea35be74d@googlegroups.com> <5419736c$0$29998$c3e8da3$5496439d@news.astraweb.com> <97219f74-6b3c-4216-8147-f6561f0e7c8f@googlegroups.com> <5419a994$0$29976$c3e8da3$5496439d@news.astraweb.com> Message-ID: <573b25bb-86ff-4935-9b06-2a9879513fe6@googlegroups.com> On Thursday, September 18, 2014 10:55:57 AM UTC+10, Thomas Orozco wrote: > In other words, the cursor is currently in the "overdrawn" method, not > the "close" method. That is correct. To better reflect this I've added the actual cursor location to the image: http://www.zeusedit.com/images/jedi_autocomplete.png To see that change might need a reloaded in the browser. Cheers Jussi From Seymore4Head at Hotmail.invalid Wed Sep 17 21:34:14 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Wed, 17 Sep 2014 21:34:14 -0400 Subject: the python shell window is already executing a command References: <4jrh1adtbsvnr9o20r9k3hfe4nkrkps2dk@4ax.com> Message-ID: <5gdk1appae03ngjlot2hg574udmnc0iqg9@4ax.com> On Wed, 17 Sep 2014 18:56:47 -0400, Terry Reedy wrote: >On 9/17/2014 11:55 AM, Seymore4Head wrote: >> On Wed, 17 Sep 2014 04:02:16 -0400, Terry Reedy >> wrote: >>> On 9/16/2014 10:17 PM, Seymore4Head wrote: >>>> What I do is click on the IDLE window and without making any changes I >>>> just hit f5 to rerun the program. >>>> Sometimes I get the error "the python shell window is already >>>> executing a command" and sometimes not. > >You left out an important part of the error message ""please wait until >it is finished." > >>>> I am using XP and Python 3.4.1. > >I am using 3.4.1 on Win 7. > >>>> Is there a way to rerun a program without getting this error? > >Follow the instruction you were given, but omitted, or see below. > >>> Normally, hitting f5 kills the previous process if it is still running >>> and starts the one in the editor. Please post a minimal program that >>> exhibits the problem. >> >> It happens in almost every program I have written. I just tried this >> one again. I could run the program by pushing f5. The first couple >> of times it would run again by switching back to IDLE and pressing f5, >> but after the second or third time, it gives an error that the python >> shell window is already executing a command. >> >> If I make a change to the program, like adding or deleting a 0 from >> "rounds" the program will run without generating an error, but if I >> try to re run the program without changing anything, I get the error >> almost every time. >> >> >> Here is one. >> >> import random >> count =0 >> rounds=1000 >> heads=0 >> tails=0 >> ht=[0,1] >> while count> coin=random.choice(ht) >> if coin == 0: >> heads=heads+1 >> elif coin == 1: >> tails=tails+1 >> count = count + 1 >> print (heads,tails) >> print ('Heads {:.2%} Tails "{:.2%} "'.format(heads/rounds, >> tails/rounds)) > >I am unable to reproduce the problem. When I run this program from an >Idle editor, it finished before I can click on the Editor window and hit >F5 again. The same remains true with 1 or 2 zeros added. With 1000000 >rounds, I get the expected behavior, which is no ouput from the >cancelled process and a clean restart. > >A little digging with Idle's grep (Find in Files) shows that the message >is produced by this code in idlelib/PyShell.py, about 825. > > def display_executing_dialog(self): > tkMessageBox.showerror( > "Already executing", > "The Python Shell window is already executing a command; " > "please wait until it is finished.", > master=self.tkconsole.text) > >This function is only called here (about line 735) > def runcommand(self, code): > "Run the code without invoking the debugger" > # The code better not raise an exception! > if self.tkconsole.executing: > self.display_executing_dialog() > > >How is this run? Run-Module F5 invokes >ScriptBinding.run_module_event(116) and thence _run_module_event (129). >This methods includes this. > if PyShell.use_subprocess: > interp.restart_subprocess(with_cwd=False) > >restart_subprocess includes these lines (starting at 470): > # Kill subprocess, spawn a new one, accept connection. > self.rpcclt.close() > self.terminate_subprocess() > console = self.tkconsole > ... > console.executing = False # == self.tkconsole > ... > self.transfer_path(with_cwd=with_cwd) > >transfer_path calls runcommand but only after tkconsole.executing has >been set to False. But this only happens if PyShell.use_subprocess is >True, which it normally is, but not if one starts Idle with the -n option. > >After conditionally calling interp.restart_subprocess, _run_module_event >directly calls interp.runcommand, which can fail when running with -n. >Are you? This is the only way I know to get the error message. Is so, >the second way to not get the error message is to not use -n and run >normally. Sorry. I don't speak python yet. Quite a few of the above terms are new to me. It may be that was trying to run the program again before the current one was finished. In the past I was getting the error when I was (almost) sure the program had finished. I will be more careful in the future, but I will also keep an eye out for the problem to repeat. I just tried to run the above program again and gave it more time to finish and I did not get the error, so it could well be I was jumping the gun. Thanks From steve+comp.lang.python at pearwood.info Wed Sep 17 22:50:53 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 18 Sep 2014 12:50:53 +1000 Subject: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` References: <06397cb3-8baf-4af1-8152-ff7c3f6ceb62@googlegroups.com> <151e45ce-444d-441c-b59b-67e2aee3882b@googlegroups.com> Message-ID: <541a488e$0$29987$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > On Thu, Sep 18, 2014 at 1:34 AM, Ian Kelly wrote: >> On Wed, Sep 17, 2014 at 9:29 AM, Chris Angelico wrote: >>> Invariant: div*y + mod == x. >>> >>> If mod is NaN, there is no possible value for div that will make the >>> invariant true, ergo it too has to be NaN. >> >> That still doesn't make the invariant true. By this argument div could >> be 42, and the invariant would hold equally well (i.e. not at all). > > Nothing can possibly make it true, so there are only two > possibilities: return NaN, or raise an exception. If nothing can make it true, then it is not an invariant, and your argument is no longer valid. -- Steven From steve+comp.lang.python at pearwood.info Wed Sep 17 23:11:53 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 18 Sep 2014 13:11:53 +1000 Subject: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` References: <06397cb3-8baf-4af1-8152-ff7c3f6ceb62@googlegroups.com> <151e45ce-444d-441c-b59b-67e2aee3882b@googlegroups.com> Message-ID: <541a4d7a$0$29980$c3e8da3$5496439d@news.astraweb.com> cool-RR wrote: > Chris, why is this invariant `div*y + mod == x` so important? Maybe it's > more important to return a mathematically reasonable result for the the > floor-division result than to maintain this invariant? You keep talking about floor(inf) == inf being "mathematically reasonable", but I'm not convinced that it is. Can you justify why you think it is mathematically reasonable? Remember that IEEE-754 inf represents two different concepts: (1) A large but finite number which has overflowed. (2) Actual mathematical infinity ?. Even in the case of actual mathematical infinity[1], the result of floor(?) isn't clear to me. Floor is supposed to return an integer, how do you know that ? is integer valued? You can do ? % 1 to see what the fractional part is, but that gives NaN, so justify your belief that ? is integer-valued. [1] But *which* mathematical infinity? One of the cardinal infinities, the alephs, or one of the ordinal infinities, the omegas and the epsilons? (There are an infinite number of *all three*.) Is c just another name for aleph-1, or is distinct from all the alephs? Even professional mathematicians tread warily when doing arithmetic on infinities. -- Steven From steve+comp.lang.python at pearwood.info Wed Sep 17 23:29:52 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 18 Sep 2014 13:29:52 +1000 Subject: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` References: <06397cb3-8baf-4af1-8152-ff7c3f6ceb62@googlegroups.com> Message-ID: <541a51b1$0$29991$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > On Thu, Sep 18, 2014 at 4:03 AM, Ian Kelly wrote: >> On Wed, Sep 17, 2014 at 9:10 AM, Chris Angelico wrote: >>> And while it's >>> conceivable to define that infinity divided by anything is infinity, >>> and infinity modulo anything is zero, that raises serious issues of >>> primality and such; I'm not sure that that would really help anything. >> >> I missed that this point was already discussed. Can you elaborate on >> the "serious issues of primality and such"? Since infinity is not a >> natural number, its primality is undefined, so I don't see the issue >> here. > > It's not something I've personally worked with, so I'm trying to > dredge stuff up from my brain, but I think there's something along the > lines of "stuff shouldn't be a multiple of everything" and the Prime > Number Theorem. But that may just be a case where float != real. I don't think that the Prime Number Theorem has anything to say about transfinite numbers (infinities). It says that for sufficiently large values of n, the number of primes below n asymptotically approaches the the integral of 1/ln(x) between 2 and n: ?(n) ~ Li(n) (Note that in this case, ? is not pi = 3.1414... but is the "prime counting function", thus proving that no matter how famous or well-known a particular mathematical symbol is, somebody will insist on using it for something else.) http://mathworld.wolfram.com/PrimeNumberTheorem.html Perhaps you are thinking of the Fundamental Theorem of Arithmetic, which states that every positive integer except 1 can be uniquely factorized into a product of one or more primes? http://mathworld.wolfram.com/FundamentalTheoremofArithmetic.html But that doesn't apply to infinity, which isn't an integer. -- Steven From rosuav at gmail.com Wed Sep 17 23:47:12 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 18 Sep 2014 13:47:12 +1000 Subject: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` In-Reply-To: <541a51b1$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <06397cb3-8baf-4af1-8152-ff7c3f6ceb62@googlegroups.com> <541a51b1$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Sep 18, 2014 at 1:29 PM, Steven D'Aprano wrote: > Perhaps you are thinking of the Fundamental Theorem of Arithmetic, which > states that every positive integer except 1 can be uniquely factorized into > a product of one or more primes? > > http://mathworld.wolfram.com/FundamentalTheoremofArithmetic.html > > But that doesn't apply to infinity, which isn't an integer. May have been that, or maybe was something different altogether. I was trying to relocate the info I'd been reading (ages ago), but without success. To be honest, I was hoping someone else would do the "Of course, I know what you mean" part for me :) But it's ended up more like the Goon Show: "How do you intend tipping Mount Everest on its side?" "Well, isn't it obvious?" with no result forthcoming. Sorry for the noise! Infinities are plenty weird, just this one specific weirdness wasn't right. ChrisA From tjreedy at udel.edu Wed Sep 17 23:50:56 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 17 Sep 2014 23:50:56 -0400 Subject: the python shell window is already executing a command In-Reply-To: <5gdk1appae03ngjlot2hg574udmnc0iqg9@4ax.com> References: <4jrh1adtbsvnr9o20r9k3hfe4nkrkps2dk@4ax.com> <5gdk1appae03ngjlot2hg574udmnc0iqg9@4ax.com> Message-ID: On 9/17/2014 9:34 PM, Seymore4Head wrote: > On Wed, 17 Sep 2014 18:56:47 -0400, Terry Reedy >> A little digging with Idle's grep (Find in Files) shows that the message >> is produced by this code in idlelib/PyShell.py, about 825. >> >> def display_executing_dialog(self): >> tkMessageBox.showerror( >> "Already executing", >> "The Python Shell window is already executing a command; " >> "please wait until it is finished.", >> master=self.tkconsole.text) >> >> This function is only called here (about line 735) >> def runcommand(self, code): >> "Run the code without invoking the debugger" >> # The code better not raise an exception! >> if self.tkconsole.executing: >> self.display_executing_dialog() >> >> >> How is this run? Run-Module F5 invokes >> ScriptBinding.run_module_event(116) and thence _run_module_event (129). >> This methods includes this. >> if PyShell.use_subprocess: >> interp.restart_subprocess(with_cwd=False) >> >> restart_subprocess includes these lines (starting at 470): >> # Kill subprocess, spawn a new one, accept connection. >> self.rpcclt.close() >> self.terminate_subprocess() >> console = self.tkconsole >> ... >> console.executing = False # == self.tkconsole >> ... >> self.transfer_path(with_cwd=with_cwd) >> >> transfer_path calls runcommand but only after tkconsole.executing has >> been set to False. But this only happens if PyShell.use_subprocess is >> True, which it normally is, but not if one starts Idle with the -n option. >> >> After conditionally calling interp.restart_subprocess, _run_module_event >> directly calls interp.runcommand, which can fail when running with -n. >> Are you? This is the only way I know to get the error message. Is so, >> the second way to not get the error message is to not use -n and run >> normally. > > Sorry. I don't speak python yet. Quite a few of the above terms are > new to me. > > It may be that was trying to run the program again before the current > one was finished. In the past I was getting the error when I was > (almost) sure the program had finished. I will be more careful in the > future, but I will also keep an eye out for the problem to repeat. > I just tried to run the above program again and gave it more time to > finish and I did not get the error, so it could well be I was jumping > the gun. My question was "How do you start Idle?" (I can make a difference.) -- Terry Jan Reedy From cubicool at gmail.com Thu Sep 18 01:08:32 2014 From: cubicool at gmail.com (Jeremy Moles) Date: Wed, 17 Sep 2014 22:08:32 -0700 (PDT) Subject: Properly Using 3.4.1 & Valgrind In-Reply-To: <4a65eb8d-4fba-400a-81bc-ee029c2a8f66@googlegroups.com> References: <4a65eb8d-4fba-400a-81bc-ee029c2a8f66@googlegroups.com> Message-ID: On Wednesday, September 17, 2014 6:46:21 PM UTC-4, Jeremy Moles wrote: > Hey guys. I'm using the Python 3.4.1 release tarball, and am trying to configure it for usage with valgrind. I have followed all of the common, well-documented steps online such as uncommenting Py_USING_MEMORY_DEBUGGER, compiling with --with-pydebug, --with-valgrind, and --without-pymalloc. I've tried uncommenting everything in the provided suppression file, as well. > > > > However, no matter what I do with my configuration/build, I cannot get Python to stop reporting thousands of lines of leaks. In fact, every call to Py_MALLOC results in valgrind believing a leak has occurred, so you can imagine there would be a legion of errors just firing up the interpreter. > > > > What is the modern, accepted way of using Python3 with valgrind, and what should my expectations be? I really like relying on Valgrind as an additional source of informative debugging information (though not exclusively), and any help resolving this would be appreciated. > > > > At a minimum, I'd expect simply opening/closing the interpreter to generate no leak warnings. I'm perfectly fine making suppression files for small issues here or there (especially in libraries/modules), but I find it hard to believe a project as well-maintained as Python has this many "valid" leaks. I'm pretty sure the problem is me. :) > > > > Thanks! I would also like to add that I've tried building the newest valgrind from today's SVN, and have also had a hand at manually forcing normal malloc usage in Python. Neither of those changed anything, so I've reverted back to standard 3.4.1 for now. From dieter at handshake.de Thu Sep 18 01:53:38 2014 From: dieter at handshake.de (dieter) Date: Thu, 18 Sep 2014 07:53:38 +0200 Subject: xlrd Can't find workbook in OLE2 compound document References: Message-ID: <87a95xo4nx.fsf@handshake.de> Andi Vaganerd writes: > I'm trying to open an excel file (.xlsx) using python module xlrd. > And I'm getting this error over here: > > "Can't find workbook in OLE2 compound document" I interprete this message as follows: the excel content in your file is wrapped in an atypical way (an OLE2 compound document) and "xlrd" does not fully support this way. Looking at the "xlrd" source code (searching for "OLE2") may give you more hints. > ... > The only thing differente from others excel files, is that this workbook is protected, not with password, but I can't write on it, just open and read (on my computer, not on python) Likely, this kind of protection causes excel to choose a special wrapping, not fully supported by "xlrd". From wxjmfauth at gmail.com Thu Sep 18 02:22:28 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 17 Sep 2014 23:22:28 -0700 (PDT) Subject: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` In-Reply-To: <06397cb3-8baf-4af1-8152-ff7c3f6ceb62@googlegroups.com> References: <06397cb3-8baf-4af1-8152-ff7c3f6ceb62@googlegroups.com> Message-ID: Le mardi 16 septembre 2014 23:40:44 UTC+2, cool-RR a ?crit?: > While debugging my code I found that the bug was because I assumed that something like `divmod(float('inf'), 1)` would be equal to `(float('inf'), float('nan'))`, while Python returns `(float('nan'), float('nan'))`. Why does Python make the division result be NaN in this case? `float('inf') / 1` is still `float('inf')`. > On one side, it is very nice, Python offers this "non finite arithmetic" (just to give a name). But on the other side it is also a plague: one never knows how to handle calculations properly. In an application which pretends to be solid, it's necessary to duplicate the checkings in a unnecessary way. In short, a lack of consistency. >>> 1e300*1e300 inf >>> exp(1e300) Traceback (most recent call last): File "", line 1, in OverflowError: math range error >>> jmf From marko at pacujo.net Thu Sep 18 02:45:06 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 18 Sep 2014 09:45:06 +0300 Subject: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` References: <06397cb3-8baf-4af1-8152-ff7c3f6ceb62@googlegroups.com> Message-ID: <87sijp5swd.fsf@elektro.pacujo.net> wxjmfauth at gmail.com: > In short, a lack of consistency. > >>>> 1e300*1e300 > inf >>>> exp(1e300) > Traceback (most recent call last): > File "", line 1, in > OverflowError: math range error Good point! Maybe IEEE had some specific numeric algorithms in mind when it introduced inf and nan. However, I have a feeling an exception would be a sounder response whenever the arithmetics leaves the solid ground. Marko From ian.g.kelly at gmail.com Thu Sep 18 02:51:23 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 18 Sep 2014 00:51:23 -0600 Subject: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` In-Reply-To: References: <06397cb3-8baf-4af1-8152-ff7c3f6ceb62@googlegroups.com> Message-ID: On Wed, Sep 17, 2014 at 3:37 PM, Chris Angelico wrote: > It's not something I've personally worked with, so I'm trying to > dredge stuff up from my brain, but I think there's something along the > lines of "stuff shouldn't be a multiple of everything" and the Prime > Number Theorem. But that may just be a case where float != real. Certainly no finite number can be a multiple of everything. Are you perchance thinking of the proof of Euclid's theorem? From wxjmfauth at gmail.com Thu Sep 18 03:13:56 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Thu, 18 Sep 2014 00:13:56 -0700 (PDT) Subject: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` In-Reply-To: <87sijp5swd.fsf@elektro.pacujo.net> References: <06397cb3-8baf-4af1-8152-ff7c3f6ceb62@googlegroups.com> <87sijp5swd.fsf@elektro.pacujo.net> Message-ID: <3c75b14e-0d87-47dc-b626-e9d5fffc9cbc@googlegroups.com> Le jeudi 18 septembre 2014 08:45:21 UTC+2, Marko Rauhamaa a ?crit?: > wxjmfauth at gmail.com: > > > > > In short, a lack of consistency. > > > > > >>>> 1e300*1e300 > > > inf > > >>>> exp(1e300) > > > Traceback (most recent call last): > > > File "", line 1, in > > > OverflowError: math range error > > > > Good point! > > > > Maybe IEEE had some specific numeric algorithms in mind when it > > introduced inf and nan. However, I have a feeling an exception would be > > a sounder response whenever the arithmetics leaves the solid ground. > > Nothing to do with IEEE. It's a pure Python question. If Python is using its own algorithmics for some "type of numbers" and at the same time it uses (or it has to use) a C library with a different algorithmics, conflicts are expected. In my previous example, both solutions are valid. The both solutions at the same time -> problem. jmf From norman.ives at gmail.com Thu Sep 18 03:22:14 2014 From: norman.ives at gmail.com (norman.ives at gmail.com) Date: Thu, 18 Sep 2014 00:22:14 -0700 (PDT) Subject: Controlling ALLUSERS property in non-interactive MSI installer (Python 3.4.1) Message-ID: <32279730-e179-4ed2-b5d0-05be6e613d4d@googlegroups.com> Hey list I need to install a private copy of Python on Windows 7 and 8, for use only by one specific tool. The install should happen as part of the installation of the tool. I can control TARGETDIR and extensions (via ADDLOCAL) but I'm failing to install "just for this user". I've been trying variations on msiexec /i python-3.4.1.msi /qb! ALLUSERS=0 WHICHUSERS=JUSTME I found the WHICHUSERS property by inspecting the install log (/l*v). This is not working - I still end up with an install using ALLUSERS=1, according to the log. Can anyone comment on this issue? Typical users will not have admin rights, so I assume in that case ALLUSERS will default to 0, but I have not yet tested. Thanks for your attention! From ram.rachum at gmail.com Thu Sep 18 04:43:10 2014 From: ram.rachum at gmail.com (cool-RR) Date: Thu, 18 Sep 2014 01:43:10 -0700 (PDT) Subject: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` In-Reply-To: <541a4d7a$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <06397cb3-8baf-4af1-8152-ff7c3f6ceb62@googlegroups.com> <151e45ce-444d-441c-b59b-67e2aee3882b@googlegroups.com> <541a4d7a$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <550a6dfe-d4d3-4e2b-b9bd-31a1d26e6ca3@googlegroups.com> On Thursday, September 18, 2014 6:12:08 AM UTC+3, Steven D'Aprano wrote: > cool-RR wrote: > > Chris, why is this invariant `div*y + mod == x` so important? Maybe it's > > more important to return a mathematically reasonable result for the the > > floor-division result than to maintain this invariant? > > You keep talking about floor(inf) == inf being "mathematically reasonable", > but I'm not convinced that it is. Can you justify why you think it is > mathematically reasonable? http://i.imgur.com/9SoBbXG.png > [1] But *which* mathematical infinity? One of the cardinal infinities, the > alephs, or one of the ordinal infinities, the omegas and the epsilons? The alephs are about sizes of sets, they have nothing to do with limits. When talking about limits, which is what this is about, there is no need for any variety of infinities. Thanks, Ram. From ap501228 at gmail.com Thu Sep 18 04:57:17 2014 From: ap501228 at gmail.com (ap501228 at gmail.com) Date: Thu, 18 Sep 2014 01:57:17 -0700 (PDT) Subject: Hierarchical consolidation in Python Message-ID: <4ecde3a0-3891-450b-aba3-39c91add58e2@googlegroups.com> I am looking for some tips as to how Python could be used to solve a simple business problem involving consolidation of financial data across a company with a number of business units rolling up to a department and departments rolling up to the whole organization. Company = Department(1)+Department(2)+...Department (N) Department(1)= Unit(1,1)+Unit(1,2)+...+Unit(1,K) ... Department(N)= Unit(N,1)+Unit(N,2)+..+Unit(N,K) Suppose,for each unit, Unit(i,j) we have a time series of 3 variables: Income(i,j) , Expenses(i,j) and Surplus(i,j) = Income(i,j)- Expenses(i,j) Required to find: (1)Income, Expenses and Surplus consolidated for all units within a Department; and (2)Income, Expenses and Surplus consolidated for all departments within the company. I would welcome any help in expressing this problem directly in Python. Also, are there any Python modules or packages that enable problems of this type to be solved. Thanks in advance for any help. From rosuav at gmail.com Thu Sep 18 05:09:35 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 18 Sep 2014 19:09:35 +1000 Subject: Hierarchical consolidation in Python In-Reply-To: <4ecde3a0-3891-450b-aba3-39c91add58e2@googlegroups.com> References: <4ecde3a0-3891-450b-aba3-39c91add58e2@googlegroups.com> Message-ID: On Thu, Sep 18, 2014 at 6:57 PM, wrote: > Required to find: > > (1)Income, Expenses and Surplus consolidated for all units within a Department; and > (2)Income, Expenses and Surplus consolidated for all departments within the company. > > I would welcome any help in expressing this problem directly in Python. Also, are there any Python modules or packages that enable problems of this type to be solved. Thanks in advance for any help. This actually sounds more like a data-driven problem than a code-driven one. If you store everything in a database table, with one row for each business unit, and their departments, income, and expenses, you could the do queries like this: SELECT sum(income), sum(expenses), sum(income-expenses) as surplus FROM units GROUP BY department and that'd give you the per-department stats. Drop the GROUP BY to get stats for the whole company. If the job's simple enough, or if you already have the data in some other format, you could do the same thing in Python code. It's basically the same thing again - accumulate data by department, or across the whole company. ChrisA From steve+comp.lang.python at pearwood.info Thu Sep 18 05:25:57 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 18 Sep 2014 19:25:57 +1000 Subject: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` References: <06397cb3-8baf-4af1-8152-ff7c3f6ceb62@googlegroups.com> <87sijp5swd.fsf@elektro.pacujo.net> Message-ID: <541aa526$0$29993$c3e8da3$5496439d@news.astraweb.com> Marko Rauhamaa wrote: > Maybe IEEE had some specific numeric algorithms in mind when it > introduced inf and nan. However, I have a feeling an exception would be > a sounder response whenever the arithmetics leaves the solid ground. I'm afraid that you're missing the essential point of INF and quiet NANs, namely that they *don't* cause an exception. That is their point. Back in the Dark Ages of numeric computing, prior to IEEE-754, all was chaos. Numeric computing was a *mess*. To give an example of how bad it was, there were well-known computers where: x != 0 would pass, but then: 1.0/x would fail with a Division By Zero error (which could mean a segfault). Another machine could have 1.0*x overflow; a whole class of IBM machines had 1.0*x lop off one bit of precision each time you called it, so that multiplying by one would gradually and irreversibly change the number. Chip designers had a cavalier attitude towards the accuracy of floating point arithmetic, preferring to optimise for speed even when the result was wrong. Writing correct, platform-independent floating point code was next to impossible. When IEEE-754 was designed, the target was low-level languages similar to C, Pascal, Algol, Lisp, etc. There were no exceptions in the Python sense, but many platforms provided signals, where certain operations could signal an exceptional case and cause an interrupt. IEEE-754 standardised those hardware-based signals and required any compliant system to provide them. But it also provided a mechanism for *not* interrupting a long running calculation just because an exception occurred. Remember that not all exceptions are necessarily fatal. You can choose whether exceptions in a calculation will cause a signal, or quietly continue. It even defines two different kinds of NANs, signalling and quiet NANs: signalling NANs are supposed to signal, always, and quiet NANs are supposed to either silently propagate or signal, whichever you choose. Instead of peppering your code with dozens, even hundreds of Look Before You Leap checks for error conditions, or installing a single signal handler which will catch exceptions from anywhere in your application, you have the choice of also allowing calculations to continue to the end even if they reach an exceptional case. You can then inspect the result and decide what to do: report an error, re-do the calculation with different values, skip that iteration, whatever is appropriate. The standard even gives NANs a payload, so that they can carry diagnostic information. For instance, NAN[1] might mean 0/0, while NAN[2] might mean INF-INF. The Standard Apple Numerics Environment (SANE) in the 1980s and 90s supported that, and it worked really well. Alas, I don't know any other language or library that even offers a way to inspect the NAN payload, let alone promises to set it consistently. In any case, other error handling strategies continue to work, or at least they are supposed to work. A good way to understand how the IEEE-754 standard is supposed to work is to read and use the decimal.py module. (Strictly speaking, decimal doesn't implement IEEE-754, but another, similar, standard.) Python's binary floats, which are a thin wrapper around the platform C libraries, is sad and impoverished compared to what IEEE-754 offers. -- Steven From breamoreboy at yahoo.co.uk Thu Sep 18 06:30:51 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 18 Sep 2014 11:30:51 +0100 Subject: Hierarchical consolidation in Python In-Reply-To: <4ecde3a0-3891-450b-aba3-39c91add58e2@googlegroups.com> References: <4ecde3a0-3891-450b-aba3-39c91add58e2@googlegroups.com> Message-ID: On 18/09/2014 09:57, ap501228 at gmail.com wrote: > I am looking for some tips as to how Python could be used to solve a simple business problem involving consolidation of financial data across a company with a number of business units rolling up to a department and departments rolling up to the whole organization. > > Company = Department(1)+Department(2)+...Department (N) > Department(1)= Unit(1,1)+Unit(1,2)+...+Unit(1,K) > ... > Department(N)= Unit(N,1)+Unit(N,2)+..+Unit(N,K) > > Suppose,for each unit, Unit(i,j) we have a time series of 3 variables: > > Income(i,j) , Expenses(i,j) and Surplus(i,j) = Income(i,j)- Expenses(i,j) > > Required to find: > > (1)Income, Expenses and Surplus consolidated for all units within a Department; and > (2)Income, Expenses and Surplus consolidated for all departments within the company. > > I would welcome any help in expressing this problem directly in Python. Also, are there any Python modules or packages that enable problems of this type to be solved. Thanks in advance for any help. > Maybe complete overkill here but this animal http://pandas.pydata.org/ is worth looking at. I'll quote "pandas is an open source, BSD-licensed library providing high-performance, easy-to-use data structures and data analysis tools for the Python programming language.". -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From ram.rachum at gmail.com Thu Sep 18 07:55:37 2014 From: ram.rachum at gmail.com (cool-RR) Date: Thu, 18 Sep 2014 04:55:37 -0700 (PDT) Subject: Is there a canonical way to check whether an iterable is ordered? Message-ID: My function gets an iterable of an unknown type. I want to check whether it's ordered. I could check whether it's a `set` or `frozenset`, which would cover many cases, but I wonder if I can do better. Is there a nicer way to check whether an iterable is ordered or not? Thanks, Ram. From rosuav at gmail.com Thu Sep 18 08:10:42 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 18 Sep 2014 22:10:42 +1000 Subject: Is there a canonical way to check whether an iterable is ordered? In-Reply-To: References: Message-ID: On Thu, Sep 18, 2014 at 9:55 PM, cool-RR wrote: > My function gets an iterable of an unknown type. I want to check whether it's ordered. I could check whether it's a `set` or `frozenset`, which would cover many cases, but I wonder if I can do better. Is there a nicer way to check whether an iterable is ordered or not? > An iterable is always ordered. You call next() and you get the next value. Are you asking if there's a way to find out if the order matters? Not easily. What's your use-case? Why do you need to know? Also, you're still using Google Groups, which means your formatting is b0rked. Please can you use something better, or else look into fixing this. ChrisA From wxjmfauth at gmail.com Thu Sep 18 08:57:17 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Thu, 18 Sep 2014 05:57:17 -0700 (PDT) Subject: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` In-Reply-To: <541aa526$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <06397cb3-8baf-4af1-8152-ff7c3f6ceb62@googlegroups.com> <87sijp5swd.fsf@elektro.pacujo.net> <541aa526$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: Le jeudi 18 septembre 2014 11:26:14 UTC+2, Steven D'Aprano a ?crit?: > Marko Rauhamaa wrote: > > > > > Maybe IEEE had some specific numeric algorithms in mind when it > > > introduced inf and nan. However, I have a feeling an exception would be > > > a sounder response whenever the arithmetics leaves the solid ground. > > > > I'm afraid that you're missing the essential point of INF and quiet NANs, > > namely that they *don't* cause an exception. That is their point. > > > > Back in the Dark Ages of numeric computing, prior to IEEE-754, all was > > chaos. Numeric computing was a *mess*. To give an example of how bad it > > was, there were well-known computers where: > > > > x != 0 > > > > would pass, but then: > > > > 1.0/x > > > > would fail with a Division By Zero error (which could mean a segfault). > > Another machine could have 1.0*x overflow; a whole class of IBM machines > > had 1.0*x lop off one bit of precision each time you called it, so that > > multiplying by one would gradually and irreversibly change the number. Chip > > designers had a cavalier attitude towards the accuracy of floating point > > arithmetic, preferring to optimise for speed even when the result was > > wrong. Writing correct, platform-independent floating point code was next > > to impossible. > > > > When IEEE-754 was designed, the target was low-level languages similar to C, > > Pascal, Algol, Lisp, etc. There were no exceptions in the Python sense, but > > many platforms provided signals, where certain operations could signal an > > exceptional case and cause an interrupt. IEEE-754 standardised those > > hardware-based signals and required any compliant system to provide them. > > > > But it also provided a mechanism for *not* interrupting a long running > > calculation just because an exception occurred. Remember that not all > > exceptions are necessarily fatal. You can choose whether exceptions in a > > calculation will cause a signal, or quietly continue. It even defines two > > different kinds of NANs, signalling and quiet NANs: signalling NANs are > > supposed to signal, always, and quiet NANs are supposed to either silently > > propagate or signal, whichever you choose. > > > > Instead of peppering your code with dozens, even hundreds of Look Before You > > Leap checks for error conditions, or installing a single signal handler > > which will catch exceptions from anywhere in your application, you have the > > choice of also allowing calculations to continue to the end even if they > > reach an exceptional case. You can then inspect the result and decide what > > to do: report an error, re-do the calculation with different values, skip > > that iteration, whatever is appropriate. > > > > The standard even gives NANs a payload, so that they can carry diagnostic > > information. For instance, NAN[1] might mean 0/0, while NAN[2] might mean > > INF-INF. The Standard Apple Numerics Environment (SANE) in the 1980s and > > 90s supported that, and it worked really well. Alas, I don't know any other > > language or library that even offers a way to inspect the NAN payload, let > > alone promises to set it consistently. > > > > In any case, other error handling strategies continue to work, or at least > > they are supposed to work. > > > > A good way to understand how the IEEE-754 standard is supposed to work is to > > read and use the decimal.py module. (Strictly speaking, decimal doesn't > > implement IEEE-754, but another, similar, standard.) Python's binary > > floats, which are a thin wrapper around the platform C libraries, is sad > > and impoverished compared to what IEEE-754 offers. > > > > >>> def docalc1(i): ... if i == 0: ... t = 1 / 0 ... else: ... return float('inf') ... >>> try: ... r = docalc1(1) ... if math.isinf(r): ... print('do something because inf') ... except ZeroDivisionError: ... print('do something else because error is raised') ... do something because inf >>> try: ... r = docalc1(0) ... if math.isinf(r): ... print('do something because inf') ... except ZeroDivisionError: ... print('do something else because error is raised') ... do something else because error is raised Annoying. One does not know the result *before* executing any calculations. jmf From roy at panix.com Thu Sep 18 08:58:47 2014 From: roy at panix.com (Roy Smith) Date: Thu, 18 Sep 2014 08:58:47 -0400 Subject: Is there a canonical way to check whether an iterable is ordered? References: Message-ID: In article , Chris Angelico wrote: > On Thu, Sep 18, 2014 at 9:55 PM, cool-RR wrote: > > My function gets an iterable of an unknown type. I want to check whether > > it's ordered. I could check whether it's a `set` or `frozenset`, which > > would cover many cases, but I wonder if I can do better. Is there a nicer > > way to check whether an iterable is ordered or not? > > > > An iterable is always ordered. You call next() and you get the next > value. I suspect what he meant was "How can I tell if I'm iterating over an ordered collection?", i.e. iterating over a list vs. iterating over a set. Is there anything which requires an iterator to be deterministic? For example, let's say I have an iterable, i, and I do: list1 = [item for item in i] list2 = [item for item in i] am I guaranteed that list1 == list2? It will be for all the collections I can think of in the standard library, but if I wrote my own class with an __iter__() which yielded the items in a non-deterministic order, would I be violating something other than the principle of least astonishment? From juan0christian at gmail.com Thu Sep 18 09:30:46 2014 From: juan0christian at gmail.com (Juan Christian) Date: Thu, 18 Sep 2014 10:30:46 -0300 Subject: Best approach to get data from web page continuously Message-ID: I'll write a python (Python 3.4.1) script to fetch for new data (topics) from this page (http://steamcommunity.com/app/440/tradingforum) continuously. All the topics follow this structure: It will work like that: I'll get the last topics, do some background checking regarding user level, inventory value, account age, and other things, if the user pass in the checking, I'll print some info and links in the terminal. The only thing I need to know to start is: What's the better way the get this data? Beautiful Soup 4 + requests? urllib? Others? Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu Sep 18 09:33:25 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 18 Sep 2014 23:33:25 +1000 Subject: Is there a canonical way to check whether an iterable is ordered? In-Reply-To: References: Message-ID: On Thu, Sep 18, 2014 at 10:58 PM, Roy Smith wrote: > I suspect what he meant was "How can I tell if I'm iterating over an > ordered collection?", i.e. iterating over a list vs. iterating over a > set. Right, which is what I meant by asking if the order mattered. When you iterate over a set, you'll get some kind of order (because iterables have to have an order), but it won't mean anything. > Is there anything which requires an iterator to be deterministic? For > example, let's say I have an iterable, i, and I do: > > list1 = [item for item in i] > list2 = [item for item in i] > > am I guaranteed that list1 == list2? It will be for all the collections > I can think of in the standard library, but if I wrote my own class with > an __iter__() which yielded the items in a non-deterministic order, > would I be violating something other than the principle of least > astonishment? It's not guaranteed. If you do exactly that, with no operations in between, then yes, all the stdlib collections will (AFAIK) give you matching lists, but that's definitely not required by iterator protocol. The one thing you can rely on (and therefore must comply with, when you design an iterable) is that iteration will hit every element exactly once. Implementing that on most collections means returning the values in some internal representational order, something that's consistent across the lifetime of the iterator; having that not be consistent across multiple iterators would be the exception, not the rule. There would be a few special cases where you specifically *want to* have the lists differ, though. Imagine DNS records: perhaps you have four A records for some name, and you want to distribute load between them [1]. You could have your name server do something like this: class _cl_iter: def __init__(self, lst, start): self._data = lst self._start = self._next = start def __iter__(self): return self def __next__(self): if self._next is None: raise StopIteration val = self._data[self._next] self._next = (self._next + 1) % len(self._data) if self._next == self._start: self._next = None return val class CircularList: def __init__(self, it): self._data = list(it) self._next = -1 def __iter__(self): self._next = (self._next + 1) % len(self._data) return _cl_iter(self._data, self._next) Every time you iterate over a given CircularList, you'll get the same results, but starting at a different point: >>> lst = CircularList(("192.0.2.1","192.0.2.2","192.0.2.3","192.0.2.4")) >>> list(lst) ['192.0.2.1', '192.0.2.2', '192.0.2.3', '192.0.2.4'] >>> list(lst) ['192.0.2.2', '192.0.2.3', '192.0.2.4', '192.0.2.1'] >>> list(lst) ['192.0.2.3', '192.0.2.4', '192.0.2.1', '192.0.2.2'] >>> list(lst) ['192.0.2.4', '192.0.2.1', '192.0.2.2', '192.0.2.3'] So if you have a whole bunch of these for your different A records, and you return them in iteration order to each client, you'll end up with different clients getting them in a different order, with minimal extra storage space. (This is Py3 code; to make it Py2 compatible, probably all you need to do is subclass object and rename __next__ to next.) But this is a pretty unusual case. I would expect that most objects will either iterate consistently until mutated, or return only what wasn't previously consumed (like an iterator, which is itself iterable). ChrisA [1] This isn't true load-balancing, of course, but it's a simple way to distribute requests a bit. It's better than nothing. From tjreedy at udel.edu Thu Sep 18 09:46:29 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 18 Sep 2014 09:46:29 -0400 Subject: Is there a canonical way to check whether an iterable is ordered? In-Reply-To: References: Message-ID: On 9/18/2014 8:58 AM, Roy Smith wrote: > I suspect what he meant was "How can I tell if I'm iterating over an > ordered collection?", i.e. iterating over a list vs. iterating over a > set. One can check whether the iterable is a tuple, list, range, or tuple or list iterator (the latter not being re-iterable). >>> type(iter([])) >>> type(iter(())) > Is there anything which requires an iterator to be deterministic? No. An iterator can yields random number, input from a non-deterministic source -- human or mechanical, or items from a collection in shuffled order. Generator that do such can easily be turned into the __iter__ method of a class. > For example, let's say I have an iterable, i, and I do: > > list1 = [item for item in i] > list2 = [item for item in i] If i is an iterator or other non-reiterable, list2 will be empty. If i is an instance of a class with a non-deterministic __iter__ method, list2 will not necessarily be either empty or a copy of list1. > am I guaranteed that list1 == list2? Clearly not. > It will be for all the collections I can think of in the standard library, but if I wrote my own class with > an __iter__() which yielded the items in a non-deterministic order, > would I be violating something other than the principle of least > astonishment? There should not be any astonishment. 'Iterable' is a much broader category than 'deterministically re-iterable iterable'. -- Terry Jan Reedy From invalid at invalid.invalid Thu Sep 18 10:33:11 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 18 Sep 2014 14:33:11 +0000 (UTC) Subject: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` References: <06397cb3-8baf-4af1-8152-ff7c3f6ceb62@googlegroups.com> <87sijp5swd.fsf@elektro.pacujo.net> <541aa526$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2014-09-18, Steven D'Aprano wrote: > Marko Rauhamaa wrote: > >> Maybe IEEE had some specific numeric algorithms in mind when it >> introduced inf and nan. However, I have a feeling an exception would be >> a sounder response whenever the arithmetics leaves the solid ground. > > I'm afraid that you're missing the essential point of INF and quiet NANs, > namely that they *don't* cause an exception. That is their point. And it is a very important point. I spent a number of years working with floating point in process control where the non-signalling (propogating) behavior of IEEE inf and NaNs was exactly the right thing. You've got a set of inputs, and a set of outputs each of which depend on some (but not usually all of the inputs). When one of the inputs goes invalid (NaN) or wonky (creating an infinity), it's vitally important that the computations _all_ got carried out and _all_ of the outputs got calculated and updated. Not updating an output was simply not an option. Some outputs end up as NaNs or infinities and some are valid, but _all_ of them get set to the proper value for the given set of inputs. Using exceptions would have required a whole "shadow" set of calculations and logic to try to figure out which outputs were still valid and could be calculated, and which ones were not valid. It would have at least tripled the amount of code required -- and it probably wouldn't have worked right. -- Grant Edwards grant.b.edwards Yow! My mind is a potato at field ... gmail.com From joel.goldstick at gmail.com Thu Sep 18 11:11:01 2014 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Thu, 18 Sep 2014 11:11:01 -0400 Subject: Controlling ALLUSERS property in non-interactive MSI installer (Python 3.4.1) In-Reply-To: <32279730-e179-4ed2-b5d0-05be6e613d4d@googlegroups.com> References: <32279730-e179-4ed2-b5d0-05be6e613d4d@googlegroups.com> Message-ID: On Thu, Sep 18, 2014 at 3:22 AM, wrote: > Hey list > > I need to install a private copy of Python on Windows 7 and 8, for use only by one specific tool. The install should happen as part of the installation of the tool. > > I can control TARGETDIR and extensions (via ADDLOCAL) but I'm failing to install "just for this user". > > I've been trying variations on > > msiexec /i python-3.4.1.msi /qb! ALLUSERS=0 WHICHUSERS=JUSTME > > I found the WHICHUSERS property by inspecting the install log (/l*v). > > This is not working - I still end up with an install using ALLUSERS=1, according to the log. > > Can anyone comment on this issue? Typical users will not have admin rights, so I assume in that case ALLUSERS will default to 0, but I have not yet tested. > > Thanks for your attention! > -- > https://mail.python.org/mailman/listinfo/python-list You may want to check out this: http://virtualenvwrapper.readthedocs.org/en/latest/install.html VirtualEnv creates a python environment that is separate from that on the system, and is accessible by a user -- Joel Goldstick http://joelgoldstick.com From Seymore4Head at Hotmail.invalid Thu Sep 18 11:24:56 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Thu, 18 Sep 2014 11:24:56 -0400 Subject: the python shell window is already executing a command References: <4jrh1adtbsvnr9o20r9k3hfe4nkrkps2dk@4ax.com> <5gdk1appae03ngjlot2hg574udmnc0iqg9@4ax.com> Message-ID: <22ul1a9bfsehco2kk5jb0uif8mpm33ue37@4ax.com> On Wed, 17 Sep 2014 23:50:56 -0400, Terry Reedy wrote: >On 9/17/2014 9:34 PM, Seymore4Head wrote: >> On Wed, 17 Sep 2014 18:56:47 -0400, Terry Reedy > >>> A little digging with Idle's grep (Find in Files) shows that the message >>> is produced by this code in idlelib/PyShell.py, about 825. >>> >>> def display_executing_dialog(self): >>> tkMessageBox.showerror( >>> "Already executing", >>> "The Python Shell window is already executing a command; " >>> "please wait until it is finished.", >>> master=self.tkconsole.text) >>> >>> This function is only called here (about line 735) >>> def runcommand(self, code): >>> "Run the code without invoking the debugger" >>> # The code better not raise an exception! >>> if self.tkconsole.executing: >>> self.display_executing_dialog() >>> >>> >>> How is this run? Run-Module F5 invokes >>> ScriptBinding.run_module_event(116) and thence _run_module_event (129). >>> This methods includes this. >>> if PyShell.use_subprocess: >>> interp.restart_subprocess(with_cwd=False) >>> >>> restart_subprocess includes these lines (starting at 470): >>> # Kill subprocess, spawn a new one, accept connection. >>> self.rpcclt.close() >>> self.terminate_subprocess() >>> console = self.tkconsole >>> ... >>> console.executing = False # == self.tkconsole >>> ... >>> self.transfer_path(with_cwd=with_cwd) >>> >>> transfer_path calls runcommand but only after tkconsole.executing has >>> been set to False. But this only happens if PyShell.use_subprocess is >>> True, which it normally is, but not if one starts Idle with the -n option. >>> >>> After conditionally calling interp.restart_subprocess, _run_module_event >>> directly calls interp.runcommand, which can fail when running with -n. >>> Are you? This is the only way I know to get the error message. Is so, >>> the second way to not get the error message is to not use -n and run >>> normally. >> >> Sorry. I don't speak python yet. Quite a few of the above terms are >> new to me. >> >> It may be that was trying to run the program again before the current >> one was finished. In the past I was getting the error when I was >> (almost) sure the program had finished. I will be more careful in the >> future, but I will also keep an eye out for the problem to repeat. >> I just tried to run the above program again and gave it more time to >> finish and I did not get the error, so it could well be I was jumping >> the gun. > >My question was "How do you start Idle?" >(I can make a difference.) The way I start IDLE is to go to my programs folder and right click on file.py in the directory and select "edit with IDLE". From joel.goldstick at gmail.com Thu Sep 18 11:49:18 2014 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Thu, 18 Sep 2014 11:49:18 -0400 Subject: Best approach to get data from web page continuously In-Reply-To: References: Message-ID: On Thu, Sep 18, 2014 at 9:30 AM, Juan Christian wrote: > I'll write a python (Python 3.4.1) script to fetch for new data (topics) > from this page (http://steamcommunity.com/app/440/tradingforum) > continuously. > > All the topics follow this structure: href="http://steamcommunity.com/app/440/tradingforum/TOPIC_ID/"> > > It will work like that: I'll get the last topics, do some background > checking regarding user level, inventory value, account age, and other > things, if the user pass in the checking, I'll print some info and links in > the terminal. The only thing I need to know to start is: What's the better > way the get this data? Beautiful Soup 4 + requests? urllib? Others? Requests is a lot simpler than urllib. I've used BS4. There is something called scrapy that is similar I think > > Thanks. > > -- > https://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com From chris.barker at noaa.gov Thu Sep 18 12:19:37 2014 From: chris.barker at noaa.gov (chris.barker at noaa.gov) Date: Thu, 18 Sep 2014 09:19:37 -0700 (PDT) Subject: Best practice for opening files for newbies? Message-ID: <0081d786-d218-495a-b79f-8882e786d7d0@googlegroups.com> Folks, I'm in the position of teaching Python to beginners (beginners to Python, anyway). I'm teaching Python2 -- because that is still what most of the code "in the wild" is in. I do think I"ll transition to Python 3 fairly soon, as it's not too hard for folks to back-port their knowledge, but for now, it's Py2 -- and I'm hoping not to have that debate on this thread. But I do want to keep the 2->3 transition in mind, so where it's not too hard, want to teach approaches that will transition well to py3. So: there are way too many ways to open a simple file to read or write a bit of text (or binary): open() file() io.open() codecs.open() others??? I'm thinking that way to go now with modern Py2 is: from io import open then use open() ..... IIUC, this will give the user an open() that behaves the same way as py3's open() (identical?). The only issue (so far) I've run into is this: In [51]: f = io.open("test_file.txt", 'w') In [52]: f.write("some string") --------------------------------------------------------------------------- TypeError Traceback (most recent call last) in () ----> 1 f.write("some string") TypeError: must be unicode, not str I'm OK with that -- I think it's better for folks learning py2 now to get used to Unicode up front anyway. But any other issues? Is this a good way to go? By the way: I note that the default encoding for io.open on my system (OS-X) is utf-8, despite: In [54]: sys.getdefaultencoding() Out[54]: 'ascii' How is that determined? -CHB From larry.martell at gmail.com Thu Sep 18 12:27:53 2014 From: larry.martell at gmail.com (Larry Martell) Date: Thu, 18 Sep 2014 10:27:53 -0600 Subject: hashlib suddenly broken Message-ID: I am on a mac running 10.8.5, python 2.7 Suddenly, many of my scripts started failing with: ValueError: unsupported hash type sha1 Googling this showed that it's an issue with hashlib with a common cause being a file called hashlib.py that gets in the way of the interpreter finding the standard hashlib module, but that doesn't seem to be the case: >>> import hashlib ERROR:root:code for hash sha1 was not found. Traceback (most recent call last): File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 139, in globals()[__func_name] = __get_hash(__func_name) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 103, in __get_openssl_constructor return __get_builtin_constructor(name) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 91, in __get_builtin_constructor raise ValueError('unsupported hash type %s' % name) ValueError: unsupported hash type sha1 And that file has not changed any time recently: $ ls -l /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py -rw-r--r-- 1 root wheel 5013 Apr 12 2013 /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py This just started happening yesterday, and I cannot think of anything that I've done that could cause this. From rosuav at gmail.com Thu Sep 18 12:37:42 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 19 Sep 2014 02:37:42 +1000 Subject: Best practice for opening files for newbies? In-Reply-To: <0081d786-d218-495a-b79f-8882e786d7d0@googlegroups.com> References: <0081d786-d218-495a-b79f-8882e786d7d0@googlegroups.com> Message-ID: On Fri, Sep 19, 2014 at 2:19 AM, wrote: > So: there are way too many ways to open a simple file to read or write a bit of text (or binary): > > open() Personally, I'd just use this, all the way through - and not importing from io, either. But others may disagree. Be clear about what's text and what's bytes, everywhere. When you do make the jump to Py3, you'll have to worry about text files vs binary files, and if you need to support Windows as well as Unix, you need to get that right anyway, so just make sure you get the two straight. Going Py3 will actually make your job quite a bit easier, there; but even if you don't, save yourself a lot of trouble later on by keeping the difference very clear. And you can save yourself some more conversion trouble by tossing this at the top of every .py file you write: from __future__ import print_function, division, unicode_literals But mainly, just go with the simple open() call and do the job the easiest way you can. And go Py3 as soon as you can, because ... > because that is still what most of the code "in the wild" is in. ... this statement isn't really an obvious truth any more (it's hard to say what "most" code is), and it's definitely not going to remain so for the long-term future. For people learning Python today, unless they plan on having a really short career in programming, more of their time will be after 2020 than before it, and Python 3 is the way to go. Plus, it's just way WAY easier to get Unicode right in Py3 than in Py2. Save yourself the hassle! ChrisA From chris.barker at noaa.gov Thu Sep 18 12:35:48 2014 From: chris.barker at noaa.gov (chris.barker at noaa.gov) Date: Thu, 18 Sep 2014 09:35:48 -0700 (PDT) Subject: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` In-Reply-To: References: <06397cb3-8baf-4af1-8152-ff7c3f6ceb62@googlegroups.com> Message-ID: <1f3b8ce6-614a-4b99-9660-a6ef35eda75f@googlegroups.com> On Wednesday, September 17, 2014 11:22:42 PM UTC-7, wxjm... at gmail.com wrote: > >>> 1e300*1e300 > > inf > > >>> exp(1e300) > > Traceback (most recent call last): > > File "", line 1, in > > OverflowError: math range error FWIW, numpy is a bit more consistent: In [89]: numpy.exp(1e300) Out[89]: inf This is more critical in numpy, because that result may have been one of a big huge array of values -- you really don't want the entire array operation to raise and Exception because of one odd value. It's be nice if Python's math module did more than simply wrap the default i implementation of the underlying C lib -- it's gotten better over the years (Inf and NaN used to be really hard to get), but still not quite what it could be. -Chris From gordon at panix.com Thu Sep 18 12:47:59 2014 From: gordon at panix.com (John Gordon) Date: Thu, 18 Sep 2014 16:47:59 +0000 (UTC) Subject: hashlib suddenly broken References: Message-ID: In Larry Martell writes: > Googling this showed that it's an issue with hashlib with a common > cause being a file called hashlib.py that gets in the way of the > interpreter finding the standard hashlib module, but that doesn't seem > to be the case: Perhaps hashlib imports some other module which has a local module of the same name? SHA1 has been deprecated for some time. Maybe a recent OS update finally got rid of it altogether? -- 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 python.list at tim.thechases.com Thu Sep 18 10:32:15 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 18 Sep 2014 09:32:15 -0500 Subject: Is there a canonical way to check whether an iterable is ordered? In-Reply-To: References: Message-ID: <20140918093215.3f807f78@bigbox.christie.dr> On 2014-09-18 08:58, Roy Smith wrote: > I suspect what he meant was "How can I tell if I'm iterating over > an ordered collection?", i.e. iterating over a list vs. iterating > over a set. > > list1 = [item for item in i] > list2 = [item for item in i] > > am I guaranteed that list1 == list2? It will be for all the > collections I can think of in the standard library, For stdlib *collections*, yes, but if you're just talking generic iterators, then it can become exhausted in the first: with open('example.txt') as f: list1 = [item for item in f] list2 = [item for item in f] assert list1 == list2, "Not equal" The OP would have to track the meta-information regarding whether the iterable was sorted. At least for dicts, order is guaranteed by the specs as long as the container isn't modified between iterations[1], but I don't see any similar claim for sets. You can always test the thing: def foo(iterable): if isinstance(iterable, (set, frozenset)): iterable = sorted(iterable) for thing in iterable: do_stuff(thing) but nothing prevents that from being called with an unsorted list. That said, sorting in the stdlib is pretty speedy on pre-sorted lists, so I'd just start by sorting whatever it is that you have, unless you're positive it's already sorted. -tkc [1] https://docs.python.org/2/library/stdtypes.html#dict.items From ian.g.kelly at gmail.com Thu Sep 18 13:05:00 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 18 Sep 2014 11:05:00 -0600 Subject: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` In-Reply-To: <1f3b8ce6-614a-4b99-9660-a6ef35eda75f@googlegroups.com> References: <06397cb3-8baf-4af1-8152-ff7c3f6ceb62@googlegroups.com> <1f3b8ce6-614a-4b99-9660-a6ef35eda75f@googlegroups.com> Message-ID: On Thu, Sep 18, 2014 at 10:35 AM, wrote: > It's be nice if Python's math module did more than simply wrap the default i implementation of the underlying C lib -- it's gotten better over the years (Inf and NaN used to be really hard to get), but still not quite what it could be. I think there's not a whole lot that can be done due to backward compatibility issues. Python 3 did make some progress (e.g. math.floor now returns an int instead of a float). From steve+comp.lang.python at pearwood.info Thu Sep 18 13:07:35 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 19 Sep 2014 03:07:35 +1000 Subject: hashlib suddenly broken References: Message-ID: <541b1158$0$29967$c3e8da3$5496439d@news.astraweb.com> Larry Martell wrote: > I am on a mac running 10.8.5, python 2.7 > > Suddenly, many of my scripts started failing with: > > ValueError: unsupported hash type sha1 [...] > This just started happening yesterday, and I cannot think of anything > that I've done that could cause this. Ah, the ol' "I didn't change anything, I swear!" excuse *wink* But seriously... did you perhaps upgrade Python prior to yesterday? Or possibly an automatic update ran? Check the creation/last modified dates on: /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py but I expect that's probably not where the problem lies. My *wild guess* is that your system updated SSL, and removed some underlying SHA-1 library needed by hashlib. SHA-1 is pretty old, and there is now a known attack on it, so some over-zealous security update may have removed it. If that's the case, it really is over-zealous, for although SHA-1 is deprecated, the threat is still some years away. Microsoft, Google and Mozilla have all announced that they will continue accepting it until 2017. I can't imagine why Apple would removed it so soon. -- Steven From rosuav at gmail.com Thu Sep 18 13:18:02 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 19 Sep 2014 03:18:02 +1000 Subject: hashlib suddenly broken In-Reply-To: <541b1158$0$29967$c3e8da3$5496439d@news.astraweb.com> References: <541b1158$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Sep 19, 2014 at 3:07 AM, Steven D'Aprano wrote: > but I expect that's probably not where the problem lies. My *wild guess* is > that your system updated SSL, and removed some underlying SHA-1 library > needed by hashlib. SHA-1 is pretty old, and there is now a known attack on > it, so some over-zealous security update may have removed it. Or, more likely, the actual code for sha1 is imported from somewhere else, and *that* module is what's been shadowed. What happens if you change directory to something with absolutely no .py files in it, then start interactive Python and try importing hashlib? Maybe you have an openssl.py or something. ChrisA From extasia at extasia.org Thu Sep 18 14:11:11 2014 From: extasia at extasia.org (David Alban) Date: Thu, 18 Sep 2014 11:11:11 -0700 Subject: program to generate data helpful in finding duplicate large files Message-ID: greetings, i'm a long time perl programmer who is learning python. i'd be interested in any comments you might have on my code below. feel free to respond privately if you prefer. i'd like to know if i'm on the right track. the program works, and does what i want it to do. is there a different way a seasoned python programmer would have done things? i would like to learn the culture as well as the language. am i missing anything? i know i'm not doing error checking below. i suppose comments would help, too. i wanted a program to scan a tree and for each regular file, print a line of text to stdout with information about the file. this will be data for another program i want to write which finds sets of duplicate files larger than a parameter size. that is, using output from this program, the sets of files i want to find are on the same filesystem on the same host (obviously, but i include hostname in the data to be sure), and must have the same md5 sum, but different inode numbers. the output of the code below is easier for a human to read when paged through 'less', which on my mac renders the ascii nuls as "^@" in reverse video. thanks, david *usage: dupscan [-h] [--start-directory START_DIRECTORY]* *scan files in a tree and print a line of information about each regular file* *optional arguments:* * -h, --help show this help message and exit* * --start-directory START_DIRECTORY, -d START_DIRECTORY* * specifies the root of the filesystem tree to be* * processed* *#!/usr/bin/python* *import argparse* *import hashlib* *import os* *import re* *import socket* *import sys* *from stat import ** *ascii_nul = chr(0)* * # from: http://stackoverflow.com/questions/1131220/get-md5-hash-of-big-files-in-python * * # except that i use hexdigest() rather than digest()* *def md5_for_file(f, block_size=2**20):* * md5 = hashlib.md5()* * while True:* * data = f.read(block_size)* * if not data:* * break* * md5.update(data)* * return md5.hexdigest()* *thishost = socket.gethostname()* *parser = argparse.ArgumentParser(description='scan files in a tree and print a line of information about each regular file')* *parser.add_argument('--start-directory', '-d', default='.', help='specifies the root of the filesystem tree to be processed')* *args = parser.parse_args()* *start_directory = re.sub( '/+$', '', args.start_directory )* *for directory_path, directory_names, file_names in os.walk( start_directory ):* * for file_name in file_names:* * file_path = "%s/%s" % ( directory_path, file_name )* * lstat_info = os.lstat( file_path )* * mode = lstat_info.st_mode* * if not S_ISREG( mode ) or S_ISLNK( mode ):* * continue* * f = open( file_path, 'r' )* * md5sum = md5_for_file( f )* * dev = lstat_info.st_dev* * ino = lstat_info.st_ino* * nlink = lstat_info.st_nlink* * size = lstat_info.st_size* * sep = ascii_nul* * print "%s%c%s%c%d%c%d%c%d%c%d%c%s" % ( thishost, sep, md5sum, sep, dev, sep, ino, sep, nlink, sep, size, sep, file_path )* *exit( 0 )* -- Our decisions are the most important things in our lives. *** Live in a world of your own, but always welcome visitors. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ckaynor at zindagigames.com Thu Sep 18 14:45:41 2014 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Thu, 18 Sep 2014 11:45:41 -0700 Subject: program to generate data helpful in finding duplicate large files In-Reply-To: References: Message-ID: On Thu, Sep 18, 2014 at 11:11 AM, David Alban wrote: > *#!/usr/bin/python* > > *import argparse* > *import hashlib* > *import os* > *import re* > *import socket* > *import sys* > > *from stat import ** > Generally, from import * imports are discouraged as they tend to populate your namespace and have issues with accidentally overriding imported functions/variables. Generally, its more Pythonic to use the other imports (or import as) and reference with the namespace, as you are doing everywhere else. The main case where from import * is recommended is API imports (for example, importing the API of one module into another, such as for inter-platform, inter-version, or accelerator support). > > *ascii_nul = chr(0)* > > * # from: > http://stackoverflow.com/questions/1131220/get-md5-hash-of-big-files-in-python > * > * # except that i use hexdigest() rather than digest()* > *def md5_for_file(f, block_size=2**20):* > * md5 = hashlib.md5()* > * while True:* > * data = f.read(block_size)* > * if not data:* > * break* > * md5.update(data)* > * return md5.hexdigest()* > > *thishost = socket.gethostname()* > > *parser = argparse.ArgumentParser(description='scan files in a tree and > print a line of information about each regular file')* > *parser.add_argument('--start-directory', '-d', default='.', > help='specifies the root of the filesystem tree to be processed')* > *args = parser.parse_args()* > > *start_directory = re.sub( '/+$', '', args.start_directory )* > I'm not sure this is actually needed. Its also not platform-independent as some platforms (eg, Windows) primary uses "\" instead. > > *for directory_path, directory_names, file_names in os.walk( > start_directory ):* > * for file_name in file_names:* > * file_path = "%s/%s" % ( directory_path, file_name )* > os.path.join would be more cross-platform than the string formatting. Basically, this line would become file_path = os.path.join(directory_path, file_name) os.path.join will also ensure that, regardless of the inputs, the paths will only be joined by a single slash. > * lstat_info = os.lstat( file_path )* > > * mode = lstat_info.st_mode* > > * if not S_ISREG( mode ) or S_ISLNK( mode ):* > * continue* > > * f = open( file_path, 'r' )* > * md5sum = md5_for_file( f )* > The Pythonic thing to do here would be to use a "with" statement to ensure the file is closed in a timely manner. This requires Python 2.6 or newer (2.5 works as well with a future directive). This would require the above two lines to become: with open( file_path, 'r' ) as f: md5sum = md5_for_file( f ) I do note that you never explicitly close the files (which is done via the with statement in my example). While generally fine as CPython will close them automatically when no longer referenced, its not a good practice to get into. Other versions of Python may have delays before the file is closed, which could then result in errors if processing a huge number of files. The with statement will ensure the file is closed immediately after the md5 computation finishes, even if there is an error computing the md5. Note that in any case, the OS should automatically close the file when the process exits, but this is likely even worse than relying on Python to close them for you. Additionally, you may want to specify binary mode by using open(file_path, 'rb') to ensure platform-independence ('r' uses Universal newlines, which means on Windows, Python will convert "\r\n" to "\n" while reading the file). Additionally, some platforms will treat binary files differently. You may also want to put some additional error handling in here. For example, the file could be deleted between the "walk" call and the "open" call, the file may not be readable (locked by other processes, incorrect permissions, etc). Without knowing your use case, you may need to deal with those cases, or maybe having the script fail out with an error message is good enough. > * dev = lstat_info.st_dev* > * ino = lstat_info.st_ino* > * nlink = lstat_info.st_nlink* > * size = lstat_info.st_size* > > * sep = ascii_nul* > > * print "%s%c%s%c%d%c%d%c%d%c%d%c%s" % ( thishost, sep, md5sum, sep, > dev, sep, ino, sep, nlink, sep, size, sep, file_path )* > You could use sep.join(thishost, md5sum, dev, nio, nlink, size, file_path) rather than a string format here, presuming all the input values are strings (you can call the str function on the values to convert them, which will do the same as the "%s" formatter). I don't know how much control you have over the output format (you said you intend to pipe this output into other code), but if you can change it, I would suggest either using a pure binary format, using a more human-readable separator than chr(0), or at least providing an argument to the script to set the separator (I believe Linux has a -0 argument for many of its scripts). Also, it seems odd that you include socket.gethostname() in the output, as that will always be the system you are running the code on, and not the system you are retrieving data for (os.walk will work on network paths, including UNC paths). *exit( 0 )* > The only other thing I see is that I would probably break the code into a few additional functions, and put the argument parsing and initial call into a "if name == '__main__':" block. This would allow your code to be imported in the future and called by other Python scripts as a module, as well as allowing it to be executed as a script from the command line. This will not matter if you only ever intend to use this script as a command-line call, but could be useful if you want to reuse the code later in a larger project. To do this, however, you would need to make the function yield/return the results, rather than directly print. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu Sep 18 14:48:51 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 19 Sep 2014 04:48:51 +1000 Subject: program to generate data helpful in finding duplicate large files In-Reply-To: References: Message-ID: On Fri, Sep 19, 2014 at 4:11 AM, David Alban wrote: > i'm a long time perl programmer who is learning python. i'd be interested > in any comments you might have on my code below. feel free to respond > privately if you prefer. i'd like to know if i'm on the right track. Sure! Happy to help out. But first, a comment about your English, as shown above: It's conventional to capitalize in certain places, and it does make your prose more readable. Just as PEP 8 does for Python code, tidy spelling and linguistic conventions make it easier for other "English programmers" (wordsmiths?) to follow what you're doing. I've trimmed out any parts of your code that I don't have comments on. > ascii_nul = chr(0) You use this in exactly one place, to initialize sep. I'd either set sep up here, or use ascii_nul down below (probably the former). But if you're going to have a named constant, the Python convention is to upper-case it: ASCII_NUL = chr(0). > def md5_for_file(f, block_size=2**20): > md5 = hashlib.md5() > while True: > data = f.read(block_size) > if not data: > break > md5.update(data) > return md5.hexdigest() This is used by opening a file and then passing the open file to this function. Recommendation: Pass a file name, and have this function open and close the file itself. Then it'll also be a candidate for the obvious tidyup of using the file as a context manager - the 'with' statement guarantees that the file will be promptly closed. > thishost = socket.gethostname() (Be aware that this won't always give you a useful value. You may want to provide a default.) > start_directory = re.sub( '/+$', '', args.start_directory ) Hello, Perl programmer :) When there's text to manipulate, you first reach for a regular expression. What's this looking to do, exactly? Trim off any trailing slashes? Python has a clearer way to write that: start_directory = args.start_directory.rstrip("/") Lots of text manipulation in Python is done with methods on the string itself. Have an explore - there's all sorts of powerful stuff there. > for directory_path, directory_names, file_names in os.walk( start_directory > ): Personally, I believe in Huffman coding my names. For locals that exist for the sole purpose of loop iteration (particularly the third one, which you use in one place), I'd use shorter names: for path, dirs, files in os.walk(start_directory): for fn in files: > lstat_info = os.lstat( file_path ) > dev = lstat_info.st_dev > ino = lstat_info.st_ino > nlink = lstat_info.st_nlink > size = lstat_info.st_size > > sep = ascii_nul > > print "%s%c%s%c%d%c%d%c%d%c%d%c%s" % ( thishost, sep, md5sum, sep, dev, > sep, ino, sep, nlink, sep, size, sep, file_path ) Python 3 turns print into a function, which is able to do this rather more cleanly. You can call on the new behaviour in a Python 2 program by putting this immediately under your shebang: from __future__ import print_function And then you can write the print call like this: print(thishost, md5sum, dev, ino, nlink, size, file_path, sep=chr(0)) Or, eliminating all the assignment to locals: st = os.lstat( file_path ) print(thishost, md5sum, st.st_dev, st.st_ino, st.st_nlink, st.st_size, file_path, sep=chr(0)) That's shorter than your original line, *and* it doesn't have all the assignments :) > exit( 0 ) Unnecessary - if you omit this, you'll exit 0 implicitly at the end of the script. Standard rule of programming: There's always another way to do it. Standard rule of asking for advice: There's always someone who will advocate another way of doing it. It's up to you to decide which advice is worth following, which is worth taking note of but not actually following, and which is to be thrown out as rubbish :) All the best! ChrisA From rosuav at gmail.com Thu Sep 18 14:50:54 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 19 Sep 2014 04:50:54 +1000 Subject: program to generate data helpful in finding duplicate large files In-Reply-To: References: Message-ID: On Fri, Sep 19, 2014 at 4:45 AM, Chris Kaynor wrote: >> from stat import * > > > Generally, from import * imports are discouraged as they tend to populate > your namespace and have issues with accidentally overriding imported > functions/variables. Generally, its more Pythonic to use the other imports > (or import as) and reference with the namespace, as you are doing everywhere > else. The main case where from import * is recommended is API imports (for > example, importing the API of one module into another, such as for > inter-platform, inter-version, or accelerator support). > I was going to say the same thing, except that this module specifically is documented as recommending that. I still don't like "import *", but either this is a special case, or the docs need to be changed. ChrisA From chris.barker at noaa.gov Thu Sep 18 14:54:25 2014 From: chris.barker at noaa.gov (chris.barker at noaa.gov) Date: Thu, 18 Sep 2014 11:54:25 -0700 (PDT) Subject: Best practice for opening files for newbies? In-Reply-To: References: <0081d786-d218-495a-b79f-8882e786d7d0@googlegroups.com> Message-ID: <6ff0bf76-73a9-44d1-9619-8226c52c8fb9@googlegroups.com> On Thursday, September 18, 2014 9:38:00 AM UTC-7, Chris Angelico wrote: > On Fri, Sep 19, 2014 at 2:19 AM, wrote: > > So: there are way too many ways to open a simple file to read or write a bit of text (or binary): > > open() > > Personally, I'd just use this, all the way through - and not importing > > from io, either. But others may disagree. well the trick there is that it's a serious trick to work with non-ascii compatible text files if you do that... > Be clear about what's text and what's bytes, everywhere. When you do > make the jump to Py3, you'll have to worry about text files vs binary > files, and if you need to support Windows as well as Unix, you need to > get that right anyway, so just make sure you get the two straight. yup -- I've always emphasized that point, but from a py2 perspective (and with the built in open() file object, what is a utf-8 encoded file? text or bytes? It's bytes -- and you need to do the decoding yourself. Why make people do that? In the past, I started with open(), ignored unicode for a while then when I introduced unicode, I pointed them to codecs.open() (I hadn't discovered io.open yet ). Maybe I should stick with this approach, but it feels like a bad idea. > Save yourself a lot of trouble later on by keeping > the difference very clear. exactly -- but it's equally clear, and easier and more robust to have two types of files: binary and text, where text requires a known encoding. Rather than three types: binary, ascii text and encoded text, which is really binary, which you can then decode to make text.... Think of somethign as simple and common as loping through the lines in a file! > And you can save yourself some more > conversion trouble by tossing this at the top of every .py file you > > write: > > from __future__ import print_function, division, unicode_literals yup -- I've been thinking of recommending that to my students as well -- particularly unicode_literal > But mainly, just go with the simple open() call and do the job the > easiest way you can. And go Py3 as soon as you can, because ... A discussion for another thread.... Thanks, -Chris From tjreedy at udel.edu Thu Sep 18 15:05:53 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 18 Sep 2014 15:05:53 -0400 Subject: the python shell window is already executing a command In-Reply-To: <22ul1a9bfsehco2kk5jb0uif8mpm33ue37@4ax.com> References: <4jrh1adtbsvnr9o20r9k3hfe4nkrkps2dk@4ax.com> <5gdk1appae03ngjlot2hg574udmnc0iqg9@4ax.com> <22ul1a9bfsehco2kk5jb0uif8mpm33ue37@4ax.com> Message-ID: On 9/18/2014 11:24 AM, Seymore4Head wrote: > On Wed, 17 Sep 2014 23:50:56 -0400, Terry Reedy > wrote: >> My question was "How do you start Idle?" >> (I can make a difference.) > > The way I start IDLE is to go to my programs folder and right click on > file.py in the directory and select "edit with IDLE". A couple more questions; after you run the file once, is there a warning above the first >>> prompt? If, after the program stop and you see a second >>> prompt and run >>> import sys; len(sys.modules), 'array' in sys.modules what is the result? If you run the program multiple times and get the error message, please cut and paste the whole message and the lines above, up to 10 or 15. -- Terry Jan Reedy From larry.martell at gmail.com Thu Sep 18 15:18:36 2014 From: larry.martell at gmail.com (Larry Martell) Date: Thu, 18 Sep 2014 13:18:36 -0600 Subject: hashlib suddenly broken In-Reply-To: References: Message-ID: On Thu, Sep 18, 2014 at 10:47 AM, John Gordon wrote: > In Larry Martell writes: > >> Googling this showed that it's an issue with hashlib with a common >> cause being a file called hashlib.py that gets in the way of the >> interpreter finding the standard hashlib module, but that doesn't seem >> to be the case: > > Perhaps hashlib imports some other module which has a local module of the > same name? It's failing on the 'import _sha' in hashlib.py: 66 def __get_builtin_constructor(name): 67 try: 68 if name in ('SHA1', 'sha1'): 69 -> import _sha 70 return _sha.new (Pdb) s ImportError: 'No module named _sha' > > SHA1 has been deprecated for some time. Maybe a recent OS update finally > got rid of it altogether? I did not do an OS, or any other upgrade or install. From larry.martell at gmail.com Thu Sep 18 15:22:04 2014 From: larry.martell at gmail.com (Larry Martell) Date: Thu, 18 Sep 2014 13:22:04 -0600 Subject: hashlib suddenly broken In-Reply-To: <541b1158$0$29967$c3e8da3$5496439d@news.astraweb.com> References: <541b1158$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Sep 18, 2014 at 11:07 AM, Steven D'Aprano wrote: > Larry Martell wrote: > >> I am on a mac running 10.8.5, python 2.7 >> >> Suddenly, many of my scripts started failing with: >> >> ValueError: unsupported hash type sha1 > [...] >> This just started happening yesterday, and I cannot think of anything >> that I've done that could cause this. > > Ah, the ol' "I didn't change anything, I swear!" excuse *wink* > > But seriously... did you perhaps upgrade Python prior to yesterday? Or > possibly an automatic update ran? No, I did not upgrade or install anything. > Check the creation/last modified dates on: > > /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py That was in my original post: $ ls -l /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py -rw-r--r-- 1 root wheel 5013 Apr 12 2013 /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py > but I expect that's probably not where the problem lies. My *wild guess* is > that your system updated SSL, and removed some underlying SHA-1 library > needed by hashlib. SHA-1 is pretty old, and there is now a known attack on > it, so some over-zealous security update may have removed it. > > If that's the case, it really is over-zealous, for although SHA-1 is > deprecated, the threat is still some years away. Microsoft, Google and > Mozilla have all announced that they will continue accepting it until 2017. > I can't imagine why Apple would removed it so soon. So you know how I could check and see if I have SHA-1 and when my SSL was updated? From larry.martell at gmail.com Thu Sep 18 15:23:24 2014 From: larry.martell at gmail.com (Larry Martell) Date: Thu, 18 Sep 2014 13:23:24 -0600 Subject: hashlib suddenly broken In-Reply-To: References: <541b1158$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Sep 18, 2014 at 11:18 AM, Chris Angelico wrote: > On Fri, Sep 19, 2014 at 3:07 AM, Steven D'Aprano > wrote: >> but I expect that's probably not where the problem lies. My *wild guess* is >> that your system updated SSL, and removed some underlying SHA-1 library >> needed by hashlib. SHA-1 is pretty old, and there is now a known attack on >> it, so some over-zealous security update may have removed it. > > Or, more likely, the actual code for sha1 is imported from somewhere > else, and *that* module is what's been shadowed. What happens if you > change directory to something with absolutely no .py files in it, then > start interactive Python and try importing hashlib? Maybe you have an > openssl.py or something. I still get the same error. From larry.martell at gmail.com Thu Sep 18 15:46:07 2014 From: larry.martell at gmail.com (Larry Martell) Date: Thu, 18 Sep 2014 13:46:07 -0600 Subject: hashlib suddenly broken In-Reply-To: References: <541b1158$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Sep 18, 2014 at 1:22 PM, Larry Martell wrote: > On Thu, Sep 18, 2014 at 11:07 AM, Steven D'Aprano > wrote: >> Larry Martell wrote: >> >>> I am on a mac running 10.8.5, python 2.7 >>> >>> Suddenly, many of my scripts started failing with: >>> >>> ValueError: unsupported hash type sha1 >> [...] >>> This just started happening yesterday, and I cannot think of anything >>> that I've done that could cause this. >> >> Ah, the ol' "I didn't change anything, I swear!" excuse *wink* >> >> But seriously... did you perhaps upgrade Python prior to yesterday? Or >> possibly an automatic update ran? > > No, I did not upgrade or install anything. > >> Check the creation/last modified dates on: >> >> /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py > > That was in my original post: > > $ ls -l /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py > -rw-r--r-- 1 root wheel 5013 Apr 12 2013 > /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py > > >> but I expect that's probably not where the problem lies. My *wild guess* is >> that your system updated SSL, and removed some underlying SHA-1 library >> needed by hashlib. SHA-1 is pretty old, and there is now a known attack on >> it, so some over-zealous security update may have removed it. >> >> If that's the case, it really is over-zealous, for although SHA-1 is >> deprecated, the threat is still some years away. Microsoft, Google and >> Mozilla have all announced that they will continue accepting it until 2017. >> I can't imagine why Apple would removed it so soon. > > > So you know how I could check and see if I have SHA-1 and when my SSL > was updated? Nothing appears to have been recently changed: $ ls -la /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/OpenSSL total 224 drwxr-xr-x 12 root wheel 408 Jun 20 2012 . drwxr-xr-x 41 root wheel 1394 Apr 13 2013 .. -rwxr-xr-x 1 root wheel 124736 Apr 12 2013 SSL.so -rw-r--r-- 1 root wheel 965 Apr 12 2013 __init__.py -rw-r--r-- 1 root wheel 991 Apr 12 2013 __init__.pyc -rwxr-xr-x 1 root wheel 168544 Apr 12 2013 crypto.so -rwxr-xr-x 1 root wheel 40864 Apr 12 2013 rand.so drwxr-xr-x 12 root wheel 408 Jun 20 2012 test -rw-r--r-- 1 root wheel 1010 Apr 12 2013 tsafe.py -rw-r--r-- 1 root wheel 1775 Apr 12 2013 tsafe.pyc -rw-r--r-- 1 root wheel 176 Apr 12 2013 version.py -rw-r--r-- 1 root wheel 293 Apr 12 2013 version.pyc From Seymore4Head at Hotmail.invalid Thu Sep 18 15:58:11 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Thu, 18 Sep 2014 15:58:11 -0400 Subject: the python shell window is already executing a command References: <4jrh1adtbsvnr9o20r9k3hfe4nkrkps2dk@4ax.com> <5gdk1appae03ngjlot2hg574udmnc0iqg9@4ax.com> <22ul1a9bfsehco2kk5jb0uif8mpm33ue37@4ax.com> Message-ID: On Thu, 18 Sep 2014 15:05:53 -0400, Terry Reedy wrote: >On 9/18/2014 11:24 AM, Seymore4Head wrote: >> On Wed, 17 Sep 2014 23:50:56 -0400, Terry Reedy >> wrote: > >>> My question was "How do you start Idle?" >>> (I can make a difference.) >> >> The way I start IDLE is to go to my programs folder and right click on >> file.py in the directory and select "edit with IDLE". > >A couple more questions; after you run the file once, is there a warning >above the first >>> prompt? If, after the program stop and you see a >second >>> prompt and run > >>> import sys; len(sys.modules), 'array' in sys.modules >what is the result? > >If you run the program multiple times and get the error message, please >cut and paste the whole message and the lines above, up to 10 or 15. I think it might be that I was trying to re run the program too soon. I haven't messed with any programming too much, but I did re run the program I posted and gave it more time to finish. That seems to have been the problem. If I run into the problem again after making sure the program has finished, I will update. Thanks From __peter__ at web.de Thu Sep 18 16:23:18 2014 From: __peter__ at web.de (Peter Otten) Date: Thu, 18 Sep 2014 22:23:18 +0200 Subject: program to generate data helpful in finding duplicate large files References: Message-ID: David Alban wrote: > * sep = ascii_nul* > > * print "%s%c%s%c%d%c%d%c%d%c%d%c%s" % ( thishost, sep, md5sum, sep, > dev, sep, ino, sep, nlink, sep, size, sep, file_path )* file_path may contain newlines, therefore you should probably use "\0" to separate the records. The other fields may not contain whitespace, so it's safe to use " " as the field separator. When you deserialize the record you can prevent the file_path from being broken by providing maxsplit to the str.split() method: for record in infile.read().split("\0"): print(record.split(" ", 6)) Splitting into records without reading the whole data into memory left as an exercise ;) From gordon at panix.com Thu Sep 18 16:21:14 2014 From: gordon at panix.com (John Gordon) Date: Thu, 18 Sep 2014 20:21:14 +0000 (UTC) Subject: hashlib suddenly broken References: Message-ID: In Larry Martell writes: > It's failing on the 'import _sha' in hashlib.py: > 66 def __get_builtin_constructor(name): > 67 try: > 68 if name in ('SHA1', 'sha1'): > 69 -> import _sha > 70 return _sha.new > (Pdb) s > ImportError: 'No module named _sha' This appears to differ from the error you originally reported: > File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", > line 91, in __get_builtin_constructor > raise ValueError('unsupported hash type %s' % name) > ValueError: unsupported hash type sha1 Could there be two different versions of hashlib.py on your system? -- 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 nad at acm.org Thu Sep 18 16:44:59 2014 From: nad at acm.org (Ned Deily) Date: Thu, 18 Sep 2014 13:44:59 -0700 Subject: hashlib suddenly broken References: <541b1158$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Larry Martell wrote: > On Thu, Sep 18, 2014 at 1:22 PM, Larry Martell > wrote: > > On Thu, Sep 18, 2014 at 11:07 AM, Steven D'Aprano > > wrote: > >> Larry Martell wrote: > >>> I am on a mac running 10.8.5, python 2.7 > >>> Suddenly, many of my scripts started failing with: > >>> > >>> ValueError: unsupported hash type sha1 > >> [...] > >>> This just started happening yesterday, and I cannot think of anything > >>> that I've done that could cause this. [...] > > So you know how I could check and see if I have SHA-1 and when my SSL > > was updated? IIRC, the _sha1 extension module is only built for Python 2.7 if the necessary OpenSSL libraries (libssl and libcrypto) are not available when Python is built. They are available on OS X so, normally, you won't see an _sha1.so with Pythons there. hashlib.py first tries to import _hashlib.so and check that if it was built with the corresponding OpenSSL API and then calls it. On OS X many Python builds, including the Apple system Pythons and the python.org Pythons, are dynamically linked to the system OpenSSL libs in /usr/lib. From your original post, I'm assuming you are using the Apple-supplied system Python 2.7 on OS X 10.8.5. If so, you should see something like this: $ sw_vers ProductName: Mac OS X ProductVersion: 10.8.5 BuildVersion: 12F45 $ /usr/bin/python2.7 Python 2.7.2 (default, Oct 11 2012, 20:14:37) [GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import _hashlib >>> dir(_hashlib) ['__doc__', '__file__', '__name__', '__package__', 'new', 'openssl_md5', 'openssl_sha1', 'openssl_sha224', 'openssl_sha256', 'openssl_sha384', 'openssl_sha512'] >>> _hashlib.__file__ '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/l ib-dynload/_hashlib.so' >>> ^D $ otool -L '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/l ib-dynload/_hashlib.so' /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/li b-dynload/_hashlib.so: /usr/lib/libssl.0.9.8.dylib (compatibility version 0.9.8, current version 47.0.0) /usr/lib/libcrypto.0.9.8.dylib (compatibility version 0.9.8, current version 47.0.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0) $ ls -l /usr/lib/libssl.0.9.8.dylib -rwxr-xr-x 1 root wheel 620848 Sep 18 13:13 /usr/lib/libssl.0.9.8.dylib $ ls -l /usr/lib/libcrypto.0.9.8.dylib -rwxr-xr-x 1 root wheel 2712368 Sep 18 13:13 /usr/lib/libcrypto.0.9.8.dylib Note that this was taken *after* installing the latest 10.8.5 Security Update for 10.8 (Security Update 2014-004, http://support.apple.com/kb/ht6443) which was just released today; that includes an updated OpenSSL. But, I tried this today just before installing the update and it worked the same way, with older modification dates. The python.org Python 2.7.x should look very similar but with /Library/Frameworks paths instead of /System/Library/Frameworks. Other Pythons (e.g. MacPorts or Homebrew) may be using their own copies of OpenSSL libraries. -- Ned Deily, nad at acm.org From christian at python.org Thu Sep 18 16:49:35 2014 From: christian at python.org (Christian Heimes) Date: Thu, 18 Sep 2014 22:49:35 +0200 Subject: hashlib suddenly broken In-Reply-To: References: <541b1158$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: <541B455F.3040401@python.org> On 18.09.2014 21:23, Larry Martell wrote: > On Thu, Sep 18, 2014 at 11:18 AM, Chris Angelico wrote: >> On Fri, Sep 19, 2014 at 3:07 AM, Steven D'Aprano >> wrote: >>> but I expect that's probably not where the problem lies. My *wild guess* is >>> that your system updated SSL, and removed some underlying SHA-1 library >>> needed by hashlib. SHA-1 is pretty old, and there is now a known attack on >>> it, so some over-zealous security update may have removed it. >> >> Or, more likely, the actual code for sha1 is imported from somewhere >> else, and *that* module is what's been shadowed. What happens if you >> change directory to something with absolutely no .py files in it, then >> start interactive Python and try importing hashlib? Maybe you have an >> openssl.py or something. > > I still get the same error. The Python's implementation of SHA-1 either comes from _hashlib (which wraps OpenSSL) or from _sha (which uses code from LibTomCrypt and doesn't require external dependencies. Python 2.7 doesn't have a _sha module if OpenSSL is available at compile time. Please try to import _hashlib and see what happens. On Linux: >>> import _hashlib >>> _hashlib.__file__ '/usr/lib/python2.7/lib-dynload/_hashlib.x86_64-linux-gnu.so' >>> _hashlib.openssl_sha1() >>> _hashlib.openssl_sha1().hexdigest() 'da39a3ee5e6b4b0d3255bfef95601890afd80709' From larry.martell at gmail.com Thu Sep 18 17:30:22 2014 From: larry.martell at gmail.com (Larry Martell) Date: Thu, 18 Sep 2014 15:30:22 -0600 Subject: hashlib suddenly broken In-Reply-To: References: Message-ID: On Thu, Sep 18, 2014 at 2:21 PM, John Gordon wrote: > In Larry Martell writes: > >> It's failing on the 'import _sha' in hashlib.py: > >> 66 def __get_builtin_constructor(name): >> 67 try: >> 68 if name in ('SHA1', 'sha1'): >> 69 -> import _sha >> 70 return _sha.new > >> (Pdb) s >> ImportError: 'No module named _sha' > > This appears to differ from the error you originally reported: > >> File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", >> line 91, in __get_builtin_constructor >> raise ValueError('unsupported hash type %s' % name) >> ValueError: unsupported hash type sha1 It's the lower level error that triggers the initial error I reported. The ImportError is caught and the ValueError is reported. > Could there be two different versions of hashlib.py on your system? No, I checked and there is only the ones for the various python versions. And none that were recently installed or modified. And you can see the full path reported by python is the expected one. From larry.martell at gmail.com Thu Sep 18 17:38:10 2014 From: larry.martell at gmail.com (Larry Martell) Date: Thu, 18 Sep 2014 15:38:10 -0600 Subject: hashlib suddenly broken In-Reply-To: References: <541b1158$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Sep 18, 2014 at 2:44 PM, Ned Deily wrote: > In article > , > Larry Martell wrote: >> On Thu, Sep 18, 2014 at 1:22 PM, Larry Martell >> wrote: >> > On Thu, Sep 18, 2014 at 11:07 AM, Steven D'Aprano >> > wrote: >> >> Larry Martell wrote: >> >>> I am on a mac running 10.8.5, python 2.7 >> >>> Suddenly, many of my scripts started failing with: >> >>> >> >>> ValueError: unsupported hash type sha1 >> >> [...] >> >>> This just started happening yesterday, and I cannot think of anything >> >>> that I've done that could cause this. > [...] >> > So you know how I could check and see if I have SHA-1 and when my SSL >> > was updated? > > IIRC, the _sha1 extension module is only built for Python 2.7 if the > necessary OpenSSL libraries (libssl and libcrypto) are not available > when Python is built. They are available on OS X so, normally, you > won't see an _sha1.so with Pythons there. hashlib.py first tries to > import _hashlib.so and check that if it was built with the corresponding > OpenSSL API and then calls it. On OS X many Python builds, including > the Apple system Pythons and the python.org Pythons, are dynamically > linked to the system OpenSSL libs in /usr/lib. From your original post, > I'm assuming you are using the Apple-supplied system Python 2.7 on OS X > 10.8.5. Yes, I am using the Apple-supplied system Python 2.7 on OS X 10.8.5. > If so, you should see something like this: > > $ sw_vers > ProductName: Mac OS X > ProductVersion: 10.8.5 > BuildVersion: 12F45 > $ /usr/bin/python2.7 > Python 2.7.2 (default, Oct 11 2012, 20:14:37) > [GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on > darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> import _hashlib >>>> dir(_hashlib) > ['__doc__', '__file__', '__name__', '__package__', 'new', 'openssl_md5', > 'openssl_sha1', 'openssl_sha224', 'openssl_sha256', 'openssl_sha384', > 'openssl_sha512'] >>>> _hashlib.__file__ > '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/l > ib-dynload/_hashlib.so' >>>> ^D > $ otool -L > '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/l > ib-dynload/_hashlib.so' > /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/li > b-dynload/_hashlib.so: > /usr/lib/libssl.0.9.8.dylib (compatibility version 0.9.8, current > version 47.0.0) > /usr/lib/libcrypto.0.9.8.dylib (compatibility version 0.9.8, current > version 47.0.0) > /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current > version 169.3.0) > $ ls -l /usr/lib/libssl.0.9.8.dylib > -rwxr-xr-x 1 root wheel 620848 Sep 18 13:13 > /usr/lib/libssl.0.9.8.dylib > $ ls -l /usr/lib/libcrypto.0.9.8.dylib > -rwxr-xr-x 1 root wheel 2712368 Sep 18 13:13 > /usr/lib/libcrypto.0.9.8.dylib I get identical output, with the exception of the mod dates on those 2 files: $ ls -l /usr/lib/libssl.0.9.8.dylib -rwxr-xr-x 1 root wheel 620768 Sep 19 2013 /usr/lib/libssl.0.9.8.dylib $ ls -l /usr/lib/libcrypto.0.9.8.dylib -rwxr-xr-x 1 root wheel 2724720 Sep 19 2013 /usr/lib/libcrypto.0.9.8.dylib > Note that this was taken *after* installing the latest 10.8.5 Security > Update for 10.8 (Security Update 2014-004, > http://support.apple.com/kb/ht6443) which was just released today; that > includes an updated OpenSSL. Do you think I should install this update? Perhaps that would restore whatever is missing. > But, I tried this today just before > installing the update and it worked the same way, with older > modification dates. The python.org Python 2.7.x should look very > similar but with /Library/Frameworks paths instead of > /System/Library/Frameworks. Other Pythons (e.g. MacPorts or Homebrew) > may be using their own copies of OpenSSL libraries. From larry.martell at gmail.com Thu Sep 18 17:39:54 2014 From: larry.martell at gmail.com (Larry Martell) Date: Thu, 18 Sep 2014 15:39:54 -0600 Subject: hashlib suddenly broken In-Reply-To: <541B455F.3040401@python.org> References: <541b1158$0$29967$c3e8da3$5496439d@news.astraweb.com> <541B455F.3040401@python.org> Message-ID: On Thu, Sep 18, 2014 at 2:49 PM, Christian Heimes wrote: > On 18.09.2014 21:23, Larry Martell wrote: >> On Thu, Sep 18, 2014 at 11:18 AM, Chris Angelico wrote: >>> On Fri, Sep 19, 2014 at 3:07 AM, Steven D'Aprano >>> wrote: >>>> but I expect that's probably not where the problem lies. My *wild guess* is >>>> that your system updated SSL, and removed some underlying SHA-1 library >>>> needed by hashlib. SHA-1 is pretty old, and there is now a known attack on >>>> it, so some over-zealous security update may have removed it. >>> >>> Or, more likely, the actual code for sha1 is imported from somewhere >>> else, and *that* module is what's been shadowed. What happens if you >>> change directory to something with absolutely no .py files in it, then >>> start interactive Python and try importing hashlib? Maybe you have an >>> openssl.py or something. >> >> I still get the same error. > > The Python's implementation of SHA-1 either comes from _hashlib (which > wraps OpenSSL) or from _sha (which uses code from LibTomCrypt and > doesn't require external dependencies. Python 2.7 doesn't have a _sha > module if OpenSSL is available at compile time. > > Please try to import _hashlib and see what happens. On Linux: > >>>> import _hashlib >>>> _hashlib.__file__ > '/usr/lib/python2.7/lib-dynload/_hashlib.x86_64-linux-gnu.so' >>>> _hashlib.openssl_sha1() > >>>> _hashlib.openssl_sha1().hexdigest() > 'da39a3ee5e6b4b0d3255bfef95601890afd80709' $ python Python 2.7.2 (default, Oct 11 2012, 20:14:37) [GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import _hashlib >>> _hashlib.__file__ '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_hashlib.so' >>> _hashlib.openssl_sha1() Traceback (most recent call last): File "", line 1, in ValueError: unsupported hash type >>> _hashlib.openssl_sha1().hexdigest() Traceback (most recent call last): File "", line 1, in ValueError: unsupported hash type From christian at python.org Thu Sep 18 18:17:08 2014 From: christian at python.org (Christian Heimes) Date: Fri, 19 Sep 2014 00:17:08 +0200 Subject: hashlib suddenly broken In-Reply-To: References: <541b1158$0$29967$c3e8da3$5496439d@news.astraweb.com> <541B455F.3040401@python.org> Message-ID: <541B59E4.9060508@python.org> On 18.09.2014 23:39, Larry Martell wrote: > $ python > Python 2.7.2 (default, Oct 11 2012, 20:14:37) > [GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> import _hashlib >>>> _hashlib.__file__ > '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_hashlib.so' >>>> _hashlib.openssl_sha1() > Traceback (most recent call last): > File "", line 1, in > ValueError: unsupported hash type >>>> _hashlib.openssl_sha1().hexdigest() > Traceback (most recent call last): > File "", line 1, in > ValueError: unsupported hash type > For unknown reasions your OpenSSL version doesn't support SHA-1. Please try these two commands on the command line to check version and digest support of your OpenSSL: $ echo -n '' | openssl dgst -sha1 -hex (stdin)= da39a3ee5e6b4b0d3255bfef95601890afd80709 $ openssl version OpenSSL 1.0.1f 6 Jan 2014 Please also check which OpenSSL libcrypto is used by the _hashlib.so shared library. On OSX otool -L should give a similar output as ldd on Linux: $ otool -L /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_hashlib.so Christian From nad at acm.org Thu Sep 18 18:19:43 2014 From: nad at acm.org (Ned Deily) Date: Thu, 18 Sep 2014 15:19:43 -0700 Subject: hashlib suddenly broken References: <541b1158$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Larry Martell wrote: > Do you think I should install this update? Perhaps that would restore > whatever is missing. Yes. You should install the update in any case and it's unlikely to make the hashlib situation worse :=) -- Ned Deily, nad at acm.org From greg.ewing at canterbury.ac.nz Thu Sep 18 19:08:56 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 19 Sep 2014 11:08:56 +1200 Subject: program to generate data helpful in finding duplicate large files In-Reply-To: References: Message-ID: Chris Angelico wrote: > On Fri, Sep 19, 2014 at 4:45 AM, Chris Kaynor wrote: > >>>from stat import * > > I was going to say the same thing, except that this module > specifically is documented as recommending that. I still don't like > "import *", but either this is a special case, or the docs need to be > changed. I think it's something of a special case. The main issue with import * is that it makes it hard for someone reading the code to tell where names are coming from. However, all the names in the stat module are prefixed with S_ or ST_ and are well-known stat-related names from the unix C library, so there is less room for confusion in this case. -- Greg From roy at panix.com Thu Sep 18 19:52:28 2014 From: roy at panix.com (Roy Smith) Date: Thu, 18 Sep 2014 19:52:28 -0400 Subject: Is there a canonical way to check whether an iterable is ordered? References: Message-ID: In article , Chris Angelico wrote: > The one thing you can rely on (and therefore must comply with, when > you design an iterable) is that iteration will hit every element > exactly once. Does it actually say that somewhere? For example: for i in bag.pick_randomly_with_replacement(n=5): print i shouldn't do that. From rosuav at gmail.com Thu Sep 18 22:45:11 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 19 Sep 2014 12:45:11 +1000 Subject: Is there a canonical way to check whether an iterable is ordered? In-Reply-To: References: Message-ID: On Fri, Sep 19, 2014 at 9:52 AM, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> The one thing you can rely on (and therefore must comply with, when >> you design an iterable) is that iteration will hit every element >> exactly once. > > Does it actually say that somewhere? For example: > > for i in bag.pick_randomly_with_replacement(n=5): > print i > > shouldn't do that. When you pick randomly from a population, you create a new population, which may have duplicates compared to the original. (For efficiency's sake it probably won't all actually exist immediately, but conceptually it does exist.) That's what you're iterating over - not the bag itself. ChrisA From rosuav at gmail.com Thu Sep 18 22:51:47 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 19 Sep 2014 12:51:47 +1000 Subject: the python shell window is already executing a command In-Reply-To: References: <4jrh1adtbsvnr9o20r9k3hfe4nkrkps2dk@4ax.com> <5gdk1appae03ngjlot2hg574udmnc0iqg9@4ax.com> <22ul1a9bfsehco2kk5jb0uif8mpm33ue37@4ax.com> Message-ID: On Fri, Sep 19, 2014 at 5:05 AM, Terry Reedy wrote: > A couple more questions; after you run the file once, is there a warning > above the first >>> prompt? If, after the program stop and you see a second >>>> prompt and run >>>> import sys; len(sys.modules), 'array' in sys.modules > what is the result? What's significant about the array module here? I'm a little puzzled. ChrisA From steve+comp.lang.python at pearwood.info Fri Sep 19 01:00:10 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 19 Sep 2014 15:00:10 +1000 Subject: hashlib suddenly broken References: <541b1158$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: <541bb85b$0$6599$c3e8da3$5496439d@news.astraweb.com> Ned Deily wrote: > In article > , > Larry Martell wrote: >> Do you think I should install this update? Perhaps that would restore >> whatever is missing. > > Yes. You should install the update in any case and it's unlikely to make > the hashlib situation worse :=) However, it is likely to make it impossible to diagnose the problem and stop it from happening again. It's not normal behaviour to have functionality just disappear overnight like this. If Larry is telling the truth that there were no updates running, *how did the sha-1 library disappear*? Larry, I recommend that you try Christian's suggestions before upgrading: $ echo -n '' | openssl dgst -sha1 -hex (stdin)= da39a3ee5e6b4b0d3255bfef95601890afd80709 $ openssl version OpenSSL 1.0.1f 6 Jan 2014 -- Steven From steve+comp.lang.python at pearwood.info Fri Sep 19 01:04:51 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 19 Sep 2014 15:04:51 +1000 Subject: Is there a canonical way to check whether an iterable is ordered? References: Message-ID: <541bb974$0$6599$c3e8da3$5496439d@news.astraweb.com> cool-RR wrote: > My function gets an iterable of an unknown type. I want to check whether > it's ordered. I could check whether it's a `set` or `frozenset`, which > would cover many cases, but I wonder if I can do better. Is there a nicer > way to check whether an iterable is ordered or not? See the collections.abc module: https://docs.python.org/3/library/collections.abc.html I think what you want is: import collections.abc isinstance(it, collections.abc.Sequence) Prior to 3.3, you would use: # Untested. import collections isinstance(it, collections.Sequence) -- Steven From steve+comp.lang.python at pearwood.info Fri Sep 19 01:15:16 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 19 Sep 2014 15:15:16 +1000 Subject: Is there a canonical way to check whether an iterable is ordered? References: Message-ID: <541bbbe6$0$29982$c3e8da3$5496439d@news.astraweb.com> Roy Smith wrote: > Is there anything which requires an iterator to be deterministic? Absolutely not. py> def spam(): ... while True: ... n = random.randint(0, 10) ... s = ' '.join(['spam']*n) ... if not s: ... return ... yield s + '!' ... py> for s in spam(): ... print(s) ... spam spam spam spam spam spam! spam spam! spam spam spam spam spam spam spam spam spam! spam spam spam spam spam spam spam! py> > For > example, let's say I have an iterable, i, and I do: > > list1 = [item for item in i] > list2 = [item for item in i] Don't do that. Just write: list1 = list(i) list2 = list(i) > am I guaranteed that list1 == list2? No. However, as far as I am aware, there are no built-ins that will fail that test, yet. Although the iteration order of dicts and sets is arbitrary, I think that (at least to date) it will be the same order every time you iterate over the dict or set within a single run of the Python interpreter. (Provided the dict or set hasn't changed.) That's not a language guarantee though. It's an implementation detail. In principle, it could be different each time: s = set("abcd") list(s) => returns ['d', 'a', 'b', 'c'] list(s) => returns ['c', 'a', 'd', 'b'] > It will be for all the collections > I can think of in the standard library, but if I wrote my own class with > an __iter__() which yielded the items in a non-deterministic order, > would I be violating something other than the principle of least > astonishment? Nope. -- Steven From rosuav at gmail.com Fri Sep 19 01:40:06 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 19 Sep 2014 15:40:06 +1000 Subject: Is there a canonical way to check whether an iterable is ordered? In-Reply-To: <541bbbe6$0$29982$c3e8da3$5496439d@news.astraweb.com> References: <541bbbe6$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Sep 19, 2014 at 3:15 PM, Steven D'Aprano wrote: > However, as far as I am aware, there are no built-ins that will fail that > test, yet. Although the iteration order of dicts and sets is arbitrary, I > think that (at least to date) it will be the same order every time you > iterate over the dict or set within a single run of the Python interpreter. > (Provided the dict or set hasn't changed.) > > That's not a language guarantee though. It's an implementation detail. In > principle, it could be different each time: > > s = set("abcd") > list(s) > => returns ['d', 'a', 'b', 'c'] > list(s) > => returns ['c', 'a', 'd', 'b'] Possibly for the set, but the dict is guaranteed some measure of stability: https://docs.python.org/3.4/library/stdtypes.html#dict-views """If keys, values and items views are iterated over with no intervening modifications to the dictionary, the order of items will directly correspond.""" Also, a little above: """ iter(d) Return an iterator over the keys of the dictionary. This is a shortcut for iter(d.keys()). """ So if iterating over d.keys() and then d.values() with no mutations is guaranteed to give the same order, then so is iterating over d.keys(), then d.keys(), then d.values(), and since there's no magic in iterating over d.values(), it logically follows that iterating over d.keys() twice will give the same order. But yes, it's conceivable that the set might change iteration order arbitrarily. I don't know of any good reason for it to, but it certainly isn't forbidden. ChrisA From steve+comp.lang.python at pearwood.info Fri Sep 19 01:45:51 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 19 Sep 2014 15:45:51 +1000 Subject: program to generate data helpful in finding duplicate large files References: Message-ID: <541bc310$0$29975$c3e8da3$5496439d@news.astraweb.com> David Alban wrote: > *#!/usr/bin/python* > > *import argparse* > *import hashlib* > *import os* > *import re* > *import socket* > *import sys* Um, how did you end up with leading and trailing asterisks? That's going to stop your code from running. > *from stat import ** "import *" is slightly discouraged. It's not that it's bad, per se, it's mostly designed for use at the interactive interpreter, and it can lead to a few annoyances if you don't know what you are doing. So be careful of using it when you don't need to. [...] > *start_directory = re.sub( '/+$', '', args.start_directory )* I don't think you need to do that, and you certainly don't need to pull out the nuclear-powered bulldozer of regular expressions just to crack the peanut of stripping trailing slashes from a string. start_directory = args.start_directory.rstrip("/") ought to do the job. [...] > * f = open( file_path, 'r' )* > * md5sum = md5_for_file( f )* You never close the file, which means Python will close it for you, when it is good and ready. In the case of some Python implementations, that might not be until the interpreter shuts down, which could mean that you run out of file handles! Better is to explicitly close the file: f = open(file_path, 'r') md5sum = md5_for_file(f) f.close() or if you are using a recent version of Python and don't need to support Python 2.4 or older: with open(file_path, 'r') as f: md5sum = md5_for_file(f) (The "with" block automatically closes the file when you exit the indented block.) > * sep = ascii_nul* Seems a strange choice of a delimiter. > * print "%s%c%s%c%d%c%d%c%d%c%d%c%s" % ( thishost, sep, md5sum, sep, > dev, sep, ino, sep, nlink, sep, size, sep, file_path )* Arggh, my brain! *wink* Try this instead: s = '\0'.join([thishost, md5sum, dev, ino, nlink, size, file_path]) print s > *exit( 0 )* No need to explicitly call sys.exit (just exit won't work) at the end of your code. If you exit by falling off the end of your program, Python uses a exit code of zero. Normally, you should only call sys.exit to: - exit with a non-zero code; - to exit early. -- Steven From rosuav at gmail.com Fri Sep 19 02:45:22 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 19 Sep 2014 16:45:22 +1000 Subject: program to generate data helpful in finding duplicate large files In-Reply-To: <541bc310$0$29975$c3e8da3$5496439d@news.astraweb.com> References: <541bc310$0$29975$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Sep 19, 2014 at 3:45 PM, Steven D'Aprano wrote: > David Alban wrote: >> *import sys* > > Um, how did you end up with leading and trailing asterisks? That's going to > stop your code from running. They're not part of the code, they're part of the mangling of the formatting. So this isn't a code issue, it's a mailing list / newsgroup one. David, if you set your mail/news client to send plain text only (not rich text or HTML or formatted or anything like that), you'll avoid these problems. >> * sep = ascii_nul* > > Seems a strange choice of a delimiter. But one that he explained in his body :) >> * print "%s%c%s%c%d%c%d%c%d%c%d%c%s" % ( thishost, sep, md5sum, sep, >> dev, sep, ino, sep, nlink, sep, size, sep, file_path )* > > Arggh, my brain! *wink* > > Try this instead: > > s = '\0'.join([thishost, md5sum, dev, ino, nlink, size, file_path]) > print s That won't work on its own; several of the values are integers. So either they need to be str()'d or something in the output system needs to know to convert them to strings. I'm inclined to the latter option, which simply means importing print_function from __future__ and setting sep=chr(0). >> *exit( 0 )* > > No need to explicitly call sys.exit (just exit won't work) at the end of > your code. Hmm, you sure exit won't work? I normally use sys.exit to set return values (though as you say, it's unnecessary at the end of the program), but I tested it (Python 2.7.3 on Debian) and it does seem to be functional. Do you know what provides it? ChrisA From wxjmfauth at gmail.com Fri Sep 19 02:48:04 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Thu, 18 Sep 2014 23:48:04 -0700 (PDT) Subject: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` In-Reply-To: <1f3b8ce6-614a-4b99-9660-a6ef35eda75f@googlegroups.com> References: <06397cb3-8baf-4af1-8152-ff7c3f6ceb62@googlegroups.com> <1f3b8ce6-614a-4b99-9660-a6ef35eda75f@googlegroups.com> Message-ID: <91f47abd-6c64-459b-b87f-ef3ec5cc3980@googlegroups.com> Le jeudi 18 septembre 2014 18:36:03 UTC+2, chris.... at noaa.gov a ?crit?: > On Wednesday, September 17, 2014 11:22:42 PM UTC-7, wxjm... at gmail.com wrote: > > > >>> 1e300*1e300 > > > > > > inf > > > > > > >>> exp(1e300) > > > > > > Traceback (most recent call last): > > > > > > File "", line 1, in > > > > > > OverflowError: math range error > > > > FWIW, numpy is a bit more consistent: > > > > In [89]: numpy.exp(1e300) > > Out[89]: inf > > > > This is more critical in numpy, because that result may have been one of a big huge array of values -- you really don't want the entire array operation to raise and Exception because of one odd value. > > > > It's be nice if Python's math module did more than simply wrap the default i implementation of the underlying C lib -- it's gotten better over the years (Inf and NaN used to be really hard to get), but still not quite what it could be. > Silly argument. One single "inf" may be enough to not pursuit any further calculations. So the only way is to always test if one get "valid" values (values which have a "sense")- Example: 2-dimensional Fourier transormation. If the transformation of the first raw (columns) return one single such value, it's not worth to continue to calculate in "vacuum". As I already said, this "not finite arithmetic" may look very appealing, in many cases, it is an annoying double sword. Note: I wrote "Numerical Recipes" in Python. This kind of problem is particulary accute in "linear algebra". jmf PS math.isinf() --> has_array_inf() ?! From elearn2014 at gmail.com Fri Sep 19 04:05:03 2014 From: elearn2014 at gmail.com (luofeiyu) Date: Fri, 19 Sep 2014 16:05:03 +0800 Subject: sqlite3.OperationalError: near ".": syntax error Message-ID: <541BE3AF.3060505@gmail.com> C:\Users\pengsir>sqlite3 F:\\workspace\\china\\data\\china.sqlite SQLite version 3.8.5 2014-06-04 14:06:34 Enter ".help" for usage hints. sqlite> .tables balance cash fi_di ipo profile quote capital dividend fund majority profit sqlite> import slqite3 con = sqlite3.connect('F:\\workspace\\china\\data\\china.sqlite') cur = con.cursor() cur.execute('.tables') Traceback (most recent call last): File "", line 1, in sqlite3.OperationalError: near ".": syntax error why can't get the right tables in " cur.execute('.tables')" ? From elearn2014 at gmail.com Fri Sep 19 04:09:28 2014 From: elearn2014 at gmail.com (luofeiyu) Date: Fri, 19 Sep 2014 16:09:28 +0800 Subject: sqlite3.OperationalError: near ".": syntax error Message-ID: <541BE4B8.9010301@gmail.com> C:\Users\pengsir>d:\\sqlite3 F:\\workspace\\china\\data\\china.sqlite SQLite version 3.8.5 2014-06-04 14:06:34 Enter ".help" for usage hints. sqlite> .tables balance cash fi_di ipo profile quote capital dividend fund majority profit sqlite> import slqite3 con = sqlite3.connect('F:\\workspace\\china\\data\\china.sqlite') cur = con.cursor() cur.execute('.tables') Traceback (most recent call last): File "", line 1, in sqlite3.OperationalError: near ".": syntax error why " cur.execute('.tables') " can't get output? From lele at metapensiero.it Fri Sep 19 04:47:41 2014 From: lele at metapensiero.it (Lele Gaifax) Date: Fri, 19 Sep 2014 10:47:41 +0200 Subject: sqlite3.OperationalError: near ".": syntax error References: <541BE4B8.9010301@gmail.com> Message-ID: <877g102dzm.fsf@nautilus.nautilus> luofeiyu writes: > why " cur.execute('.tables') " can't get output? Most probably because that is not an SQL statement, but a command implemented by the SQLite command line client. To get the list of tables, the following may work for you: >>> import sqlite3 >>> con = sqlite3.connect('development.db') >>> cur = con.cursor() >>> res = cur.execute("select * from sqlite_master where type='table'") >>> print(list(res)) [('table', 'clubs', 'clubs', 2, 'CREATE TABLE clubs....)] See http://www.sqlite.org/faq.html#q7 for details. hth, ciao, lele. -- nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia. lele at metapensiero.it | -- Fortunato Depero, 1929. From __peter__ at web.de Fri Sep 19 04:52:34 2014 From: __peter__ at web.de (Peter Otten) Date: Fri, 19 Sep 2014 10:52:34 +0200 Subject: sqlite3.OperationalError: near ".": syntax error References: <541BE4B8.9010301@gmail.com> Message-ID: luofeiyu wrote: > C:\Users\pengsir>d:\\sqlite3 F:\\workspace\\china\\data\\china.sqlite > SQLite version 3.8.5 2014-06-04 14:06:34 > Enter ".help" for usage hints. > sqlite> .tables > balance cash fi_di ipo profile quote > capital dividend fund majority profit > sqlite> > > import slqite3 > con = sqlite3.connect('F:\\workspace\\china\\data\\china.sqlite') > cur = con.cursor() > cur.execute('.tables') > > > Traceback (most recent call last): > File "", line 1, in > sqlite3.OperationalError: near ".": syntax error > > > why " cur.execute('.tables') " can't get output? .tables is a feature of the sqlite console, not part of sqlite's sql. Use cur.execute("select name from sqlite_master where type = 'table';") to emulate the command in python. From steve+comp.lang.python at pearwood.info Fri Sep 19 06:59:08 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 19 Sep 2014 20:59:08 +1000 Subject: Is there a canonical way to check whether an iterable is ordered? References: <541bbbe6$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: <541c0c7d$0$29992$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > On Fri, Sep 19, 2014 at 3:15 PM, Steven D'Aprano > wrote: >> However, as far as I am aware, there are no built-ins that will fail that >> test, yet. Although the iteration order of dicts and sets is arbitrary, I >> think that (at least to date) it will be the same order every time you >> iterate over the dict or set within a single run of the Python >> interpreter. (Provided the dict or set hasn't changed.) >> >> That's not a language guarantee though. It's an implementation detail. In >> principle, it could be different each time: >> >> s = set("abcd") >> list(s) >> => returns ['d', 'a', 'b', 'c'] >> list(s) >> => returns ['c', 'a', 'd', 'b'] > > Possibly for the set, but the dict is guaranteed some measure of > stability: > > https://docs.python.org/3.4/library/stdtypes.html#dict-views > """If keys, values and items views are iterated over with no > intervening modifications to the dictionary, the order of items will > directly correspond.""" Yes, but that doesn't mean that if you iterate over them twice, they will necessarily be the same each time. The promise is that: keys = list(mydict) values = list(mydict.values()) assert keys == [item[0] for item in mydict.items()] assert values == [item[1] for item in mydict.items()] But *not* this: keys1 = list(mydict) keys2 = list(mydict) assert keys1 == keys2 It's hard to think of an implementation which would support the first but not the second, but if you did, Python would allow it :-) [...] > So if iterating over d.keys() and then d.values() with no mutations is > guaranteed to give the same order, then so is iterating over d.keys(), > then d.keys(), then d.values(), Not so! So long as the iteration of values() matched the *second* iteration of keys(), it would be allowed. There's nothing which says that the first iteration of keys() has to match the second. Here's a proof of concept of what would be allowed: import random class MyDict: def __init__(self, items): self._items = list(dict(items).items()) self._flags = [False, False, False] def keys(self): k = [item[0] for item in self._items] self._check(0) return k def values(self): k = [item[1] for item in self._items] self._check(1) return k def items(self): k = self._items[:] self._check(2) return k def _check(self, i): self._flags[i] = True if self._flags == [True, True, True]: random.shuffle(self._items) self._flags = [False, False, False] -- Steven From steve+comp.lang.python at pearwood.info Fri Sep 19 07:04:39 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 19 Sep 2014 21:04:39 +1000 Subject: program to generate data helpful in finding duplicate large files References: <541bc310$0$29975$c3e8da3$5496439d@news.astraweb.com> Message-ID: <541c0dc9$0$29992$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > On Fri, Sep 19, 2014 at 3:45 PM, Steven D'Aprano > wrote: >> s = '\0'.join([thishost, md5sum, dev, ino, nlink, size, file_path]) >> print s > > That won't work on its own; several of the values are integers. Ah, so they are! > So > either they need to be str()'d or something in the output system needs > to know to convert them to strings. I'm inclined to the latter option, > which simply means importing print_function from __future__ and > setting sep=chr(0). > >>> *exit( 0 )* >> >> No need to explicitly call sys.exit (just exit won't work) at the end of >> your code. > > Hmm, you sure exit won't work? In the interactive interpreter, exit is bound to a special helper object: py> exit Use exit() or Ctrl-D (i.e. EOF) to exit Otherwise, you'll get NameError. > I normally use sys.exit Like I said, sys.exit is fine :-) Of course you can "from sys import exit", or "exit = sys.exit", but the OP's code didn't include either of those. -- Steven From rosuav at gmail.com Fri Sep 19 07:19:53 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 19 Sep 2014 21:19:53 +1000 Subject: Is there a canonical way to check whether an iterable is ordered? In-Reply-To: <541c0c7d$0$29992$c3e8da3$5496439d@news.astraweb.com> References: <541bbbe6$0$29982$c3e8da3$5496439d@news.astraweb.com> <541c0c7d$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Sep 19, 2014 at 8:59 PM, Steven D'Aprano wrote: >> https://docs.python.org/3.4/library/stdtypes.html#dict-views >> """If keys, values and items views are iterated over with no >> intervening modifications to the dictionary, the order of items will >> directly correspond.""" >> So if iterating over d.keys() and then d.values() with no mutations is >> guaranteed to give the same order, then so is iterating over d.keys(), >> then d.keys(), then d.values(), > > Not so! So long as the iteration of values() matched the *second* iteration > of keys(), it would be allowed. There's nothing which says that the first > iteration of keys() has to match the second. I disagree. Between the first iteration of keys() and the iteration of values(), there were no modifications to the dictionary - another iteration over keys() isn't a modification - ergo the guarantee ought to hold. If you replace that inner iteration with the opening of a file, or the division of a float by a Decimal, or the definition of a new class, I'm sure everyone would agree that the guarantee still holds, because they don't change the dict; so why should iterating over keys() be any different? ChrisA From rosuav at gmail.com Fri Sep 19 07:25:04 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 19 Sep 2014 21:25:04 +1000 Subject: Is there a canonical way to check whether an iterable is ordered? In-Reply-To: <541c0c7d$0$29992$c3e8da3$5496439d@news.astraweb.com> References: <541bbbe6$0$29982$c3e8da3$5496439d@news.astraweb.com> <541c0c7d$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Sep 19, 2014 at 8:59 PM, Steven D'Aprano wrote: > Here's a proof of concept of what would be allowed: > > import random > class MyDict: > def __init__(self, items): > self._items = list(dict(items).items()) > self._flags = [False, False, False] > def keys(self): > k = [item[0] for item in self._items] > self._check(0) > return k > def values(self): > k = [item[1] for item in self._items] > self._check(1) > return k > def items(self): > k = self._items[:] > self._check(2) > return k > def _check(self, i): > self._flags[i] = True > if self._flags == [True, True, True]: > random.shuffle(self._items) > self._flags = [False, False, False] Also, this can't possibly offer the same guarantee. Watch: d = MyDict(some_lot_of_items) d.values(); d.items() # mutate the dict in whatever way you like pairs = zip(d.keys(), d.values()) This might well create mismatched pairs, because after generating the keys() return value, the list gets shuffled, prior to generating values() in the same expression. This would not be allowed. ChrisA From rosuav at gmail.com Fri Sep 19 07:36:37 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 19 Sep 2014 21:36:37 +1000 Subject: program to generate data helpful in finding duplicate large files In-Reply-To: <541c0dc9$0$29992$c3e8da3$5496439d@news.astraweb.com> References: <541bc310$0$29975$c3e8da3$5496439d@news.astraweb.com> <541c0dc9$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Sep 19, 2014 at 9:04 PM, Steven D'Aprano wrote: >> Hmm, you sure exit won't work? > > In the interactive interpreter, exit is bound to a special helper object: > > py> exit > Use exit() or Ctrl-D (i.e. EOF) to exit > > Otherwise, you'll get NameError. It's not the interactive interpreter alone. I tried it in a script before posting. Python 2.7.3 on Linux, 2.6.8 on Linux, 3.5.0ish Linux, 2.7.8 Windows, 2.6.5 Windows, 3.3.0 Windows, and 3.4.0 Windows, all work perfectly, with (AFAIK) default settings. The only one that I tried that doesn't is: C:\>type canIexit.py import sys print(sys.version) print(exit) print(type(exit)) exit(1) C:\>python canIexit.py 2.4.5 (#1, Jul 22 2011, 02:01:04) [GCC 4.1.1] Use Ctrl-Z plus Return to exit. Traceback (most recent call last): File "canIexit.py", line 5, in ? exit(1) TypeError: 'str' object is not callable I've no idea how far back to go before it comes up with a NameError. However, this is provided (as is made clear by the type lines) by site.py, and so can be disabled. But with default settings, it is possible to use exit(1) to set your return value. ChrisA From steve+comp.lang.python at pearwood.info Fri Sep 19 07:46:01 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 19 Sep 2014 21:46:01 +1000 Subject: Is there a canonical way to check whether an iterable is ordered? References: <541bbbe6$0$29982$c3e8da3$5496439d@news.astraweb.com> <541c0c7d$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: <541c177a$0$29969$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > On Fri, Sep 19, 2014 at 8:59 PM, Steven D'Aprano > wrote: >> Here's a proof of concept of what would be allowed: [...] > Also, this can't possibly offer the same guarantee. Watch: > > d = MyDict(some_lot_of_items) > d.values(); d.items() > # mutate the dict in whatever way you like > pairs = zip(d.keys(), d.values()) > > This might well create mismatched pairs, because after generating the > keys() return value, the list gets shuffled, prior to generating > values() in the same expression. This would not be allowed. That would be a bug, and an easy one to fix. Every mutation of the dict would have to reset the internal flags back to the starting state. -- Steven From rosuav at gmail.com Fri Sep 19 07:56:05 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 19 Sep 2014 21:56:05 +1000 Subject: Is there a canonical way to check whether an iterable is ordered? In-Reply-To: <541c177a$0$29969$c3e8da3$5496439d@news.astraweb.com> References: <541bbbe6$0$29982$c3e8da3$5496439d@news.astraweb.com> <541c0c7d$0$29992$c3e8da3$5496439d@news.astraweb.com> <541c177a$0$29969$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Sep 19, 2014 at 9:46 PM, Steven D'Aprano wrote: > Chris Angelico wrote: > >> On Fri, Sep 19, 2014 at 8:59 PM, Steven D'Aprano >> wrote: >>> Here's a proof of concept of what would be allowed: > [...] >> Also, this can't possibly offer the same guarantee. Watch: >> >> d = MyDict(some_lot_of_items) >> d.values(); d.items() >> # mutate the dict in whatever way you like >> pairs = zip(d.keys(), d.values()) >> >> This might well create mismatched pairs, because after generating the >> keys() return value, the list gets shuffled, prior to generating >> values() in the same expression. This would not be allowed. > > That would be a bug, and an easy one to fix. Every mutation of the dict > would have to reset the internal flags back to the starting state. What if there's no mutation, then? Just calling values() and items() means that the zip of keys and values will make mismatches. ChrisA From steve+comp.lang.python at pearwood.info Fri Sep 19 07:58:50 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 19 Sep 2014 21:58:50 +1000 Subject: Is there a canonical way to check whether an iterable is ordered? References: <541bbbe6$0$29982$c3e8da3$5496439d@news.astraweb.com> <541c0c7d$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: <541c1a7b$0$29976$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > On Fri, Sep 19, 2014 at 8:59 PM, Steven D'Aprano > wrote: >>> https://docs.python.org/3.4/library/stdtypes.html#dict-views >>> """If keys, values and items views are iterated over with no >>> intervening modifications to the dictionary, the order of items will >>> directly correspond.""" >>> So if iterating over d.keys() and then d.values() with no mutations is >>> guaranteed to give the same order, then so is iterating over d.keys(), >>> then d.keys(), then d.values(), >> >> Not so! So long as the iteration of values() matched the *second* >> iteration of keys(), it would be allowed. There's nothing which says that >> the first iteration of keys() has to match the second. > > I disagree. Between the first iteration of keys() and the iteration of > values(), there were no modifications to the dictionary - another > iteration over keys() isn't a modification - ergo the guarantee ought > to hold. All it says is that keys/values/items will correspond, not keys/keys, etc. Hmmm. On second thought, there is a problem with this: a = list(mydict) c = list(mydict.items()) # now the internal order is shuffled b = list(mydict.values()) assert list(zip(a, b)) == c and the assertion fails. So I guess that rules out dict internal order changing during a single run of the interpreter, unless the dict is modified. Anyway, that's just dicts. Custom iterables can change any time they like. -- Steven From rosuav at gmail.com Fri Sep 19 08:06:47 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 19 Sep 2014 22:06:47 +1000 Subject: Is there a canonical way to check whether an iterable is ordered? In-Reply-To: <541c1a7b$0$29976$c3e8da3$5496439d@news.astraweb.com> References: <541bbbe6$0$29982$c3e8da3$5496439d@news.astraweb.com> <541c0c7d$0$29992$c3e8da3$5496439d@news.astraweb.com> <541c1a7b$0$29976$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Sep 19, 2014 at 9:58 PM, Steven D'Aprano wrote: > All it says is that keys/values/items will correspond, not keys/keys, etc. > > Hmmm. On second thought, there is a problem with this: > > a = list(mydict) > c = list(mydict.items()) # now the internal order is shuffled > b = list(mydict.values()) > assert list(zip(a, b)) == c > > and the assertion fails. > > So I guess that rules out dict internal order changing during a single run > of the interpreter, unless the dict is modified. Precisely. If you iterate keys, keys, values with no mutations in between, the first keys has to correspond to values, and the second keys has to correspond to values, ergo they must correspond to each other. > Anyway, that's just dicts. Custom iterables can change any time they like. Oh, sure. That's a very specific promise of the dict, nothing else. The set might well randomize, if it wished. But we still come back to there being no reason for it to change. ChrisA From alister.nospam.ware at ntlworld.com Fri Sep 19 08:26:19 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Fri, 19 Sep 2014 12:26:19 GMT Subject: Is there a canonical way to check whether an iterable is ordered? References: <541bbbe6$0$29982$c3e8da3$5496439d@news.astraweb.com> <541c0c7d$0$29992$c3e8da3$5496439d@news.astraweb.com> <541c177a$0$29969$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, 19 Sep 2014 21:56:05 +1000, Chris Angelico wrote: > On Fri, Sep 19, 2014 at 9:46 PM, Steven D'Aprano > wrote: >> Chris Angelico wrote: >> >>> On Fri, Sep 19, 2014 at 8:59 PM, Steven D'Aprano >>> wrote: >>>> Here's a proof of concept of what would be allowed: >> [...] >>> Also, this can't possibly offer the same guarantee. Watch: >>> >>> d = MyDict(some_lot_of_items) >>> d.values(); d.items() >>> # mutate the dict in whatever way you like pairs = zip(d.keys(), >>> d.values()) >>> >>> This might well create mismatched pairs, because after generating the >>> keys() return value, the list gets shuffled, prior to generating >>> values() in the same expression. This would not be allowed. >> >> That would be a bug, and an easy one to fix. Every mutation of the dict >> would have to reset the internal flags back to the starting state. > > What if there's no mutation, then? Just calling values() and items() > means that the zip of keys and values will make mismatches. > > ChrisA As far as I understand it the order of keys in a dict is not guaranteed iterating over the same dict twice (without changes) does not have to return the keys in the same order. In my installation of python the order does remain constant unless the dict is modified but I am reasonably sure this is just due to implementation detail & should not be relied upon. As simple amateur I may be mistaken. -- "Tell the truth and run." -- Yugoslav proverb From rosuav at gmail.com Fri Sep 19 08:36:59 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 19 Sep 2014 22:36:59 +1000 Subject: Is there a canonical way to check whether an iterable is ordered? In-Reply-To: References: <541bbbe6$0$29982$c3e8da3$5496439d@news.astraweb.com> <541c0c7d$0$29992$c3e8da3$5496439d@news.astraweb.com> <541c177a$0$29969$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Sep 19, 2014 at 10:26 PM, alister wrote: > As far as I understand it the order of keys in a dict is not guaranteed > iterating over the same dict twice (without changes) does not have to > return the keys in the same order. The exact guarantee is that you can iterate over keys() followed by values() and they will correspond. This implies (in the strict logical sense of the word "implies", as well as the common sense of the same word) that iterating multiple times over keys() will correspond, which is the point I drew above. ChrisA From extasia at extasia.org Fri Sep 19 09:32:02 2014 From: extasia at extasia.org (David Alban) Date: Fri, 19 Sep 2014 06:32:02 -0700 Subject: Fwd: program to generate data helpful in finding duplicate large files Message-ID: here is my reworked code in a plain text email. ---------- Forwarded message ---------- From: Date: Thu, Sep 18, 2014 at 3:58 PM Subject: Re: program to generate data helpful in finding duplicate large files To: python-list at python.org thanks for the responses. i'm having quite a good time learning python. On Thu, Sep 18, 2014 at 11:45 AM, Chris Kaynor wrote: > > Additionally, you may want to specify binary mode by using open(file_path, 'rb') to ensure platform-independence ('r' uses Universal newlines, which means on Windows, Python will convert "\r\n" to "\n" while reading the file). Additionally, some platforms will treat binary files differently. would it be good to use 'rb' all the time? On Thu, Sep 18, 2014 at 11:48 AM, Chris Angelico wrote: > > On Fri, Sep 19, 2014 at 4:11 AM, David Alban wrote: > > exit( 0 ) > > Unnecessary - if you omit this, you'll exit 0 implicitly at the end of > the script. aha. i've been doing this for years even with perl, and apparently it's not necessary in perl either. i was influenced by shell. this shell code: if [[ -n $report_mode ]] ; then do_report fi exit 0 is an example of why you want the last normally executed shell statement to be "exit 0". if you omit the exit statement it in this example, and $report_mode is not set, your shell program will give a non-zero return code and appear to have terminated with an error. in shell the last expression evaluated determines the return code to the os. ok, i don't need to do this in python. On Thu, Sep 18, 2014 at 1:23 PM, Peter Otten <__peter__ at web.de> wrote: > > file_path may contain newlines, therefore you should probably use "\0" to > separate the records. i chose to stick with ascii nul as the default field separator, but i added a --field-separator option in case someone wants human readable output. style question: if there is only one, possibly short statement in a block, do folks usually move it up to the line starting the block? if not S_ISREG( mode ) or S_ISLNK( mode ): return vs. if not S_ISREG( mode ) or S_ISLNK( mode ): return or even: with open( file_path, 'rb' ) as f: md5sum = md5_for_file( file_path ) fyi, here are my changes: usage: dupscan [-h] [--start-directory START_DIRECTORY] [--field-separator FIELD_SEPARATOR] scan files in a tree and print a line of information about each regular file optional arguments: -h, --help show this help message and exit --start-directory START_DIRECTORY, -d START_DIRECTORY Specify the root of the filesystem tree to be processed. The default is '.' --field-separator FIELD_SEPARATOR, -s FIELD_SEPARATOR Specify the string to use as a field separator in output. The default is the ascii nul character. #!/usr/bin/python import argparse import hashlib import os from platform import node from stat import S_ISREG, S_ISLNK ASCII_NUL = chr(0) # from: http://stackoverflow.com/questions/1131220/get-md5-hash-of-big-files-in-python # except that i use hexdigest() rather than digest() def md5_for_file( path, block_size=2**20 ): md5 = hashlib.md5() with open( path, 'rb' ) as f: while True: data = f.read(block_size) if not data: break md5.update(data) return md5.hexdigest() def file_info( directory, basename, field_separator=ASCII_NUL ): file_path = os.path.join( directory, basename ) st = os.lstat( file_path ) mode = st.st_mode if not S_ISREG( mode ) or S_ISLNK( mode ): return with open( file_path, 'rb' ) as f: md5sum = md5_for_file( file_path ) return field_separator.join( [ thishost, md5sum, str( st.st_dev ), str( st.st_ino ), str( st.st_nlink ), str( st.st_size ), file_path ] ) if __name__ == "__main__": parser = argparse.ArgumentParser(description='scan files in a tree and print a line of information about each regular file') parser.add_argument('--start-directory', '-d', default='.', help='''Specify the root of the filesystem tree to be processed. The default is '.' ''') parser.add_argument('--field-separator', '-s', default=ASCII_NUL, help='Specify the string to use as a field separator in output. The default is the ascii nul character.') args = parser.parse_args() start_directory = args.start_directory.rstrip('/') field_separator = args.field_separator thishost = node() if thishost == '': thishost='[UNKNOWN]' for directory_path, directory_names, file_names in os.walk( start_directory ): for file_name in file_names: print file_info( directory_path, file_name, field_separator ) -- Our decisions are the most important things in our lives. *** Live in a world of your own, but always welcome visitors. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Fri Sep 19 09:59:34 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 19 Sep 2014 23:59:34 +1000 Subject: program to generate data helpful in finding duplicate large files In-Reply-To: References: Message-ID: On Fri, Sep 19, 2014 at 11:32 PM, David Alban wrote: > thanks for the responses. i'm having quite a good time learning python. Awesome! But while you're at it, you may want to consider learning English on the side; capitalization does make your prose more readable. Also, it makes you look careless - you appear not to care about your English, so it's logical to expect that you may not care about your Python either. That may be completely false, but it's still the impression you're creating. > On Thu, Sep 18, 2014 at 11:45 AM, Chris Kaynor > wrote: >> >> Additionally, you may want to specify binary mode by using open(file_path, >> 'rb') to ensure platform-independence ('r' uses Universal newlines, which >> means on Windows, Python will convert "\r\n" to "\n" while reading the >> file). Additionally, some platforms will treat binary files differently. > > would it be good to use 'rb' all the time? Only if you're reading binary files. In the program you're doing here, yes; you want binary mode. > if you omit the exit statement it in this example, and > $report_mode is not set, your shell program will give a non-zero return code > and appear to have terminated with an error. in shell the last expression > evaluated determines the return code to the os. IMO that's a terrible misfeature. If you actually want the return value to be propagated, you should have to say so - something like: #!/bin/sh run_program exit $? Fortunately, Python isn't like that. > style question: if there is only one, possibly short statement in a block, > do folks usually move it up to the line starting the block? > > if not S_ISREG( mode ) or S_ISLNK( mode ): > return > > vs. > > if not S_ISREG( mode ) or S_ISLNK( mode ): return > > or even: > > with open( file_path, 'rb' ) as f: md5sum = md5_for_file( file_path ) Only if it's really short AND it makes very good sense that way. Some people would say "never". In the first case, I might do it, but not the second. (Though that's not necessary at all, there; md5_for_file opens and closes the file, so you don't need to open it redundantly before calling.) ChrisA From larry.martell at gmail.com Fri Sep 19 11:09:56 2014 From: larry.martell at gmail.com (Larry Martell) Date: Fri, 19 Sep 2014 09:09:56 -0600 Subject: hashlib suddenly broken In-Reply-To: <541bb85b$0$6599$c3e8da3$5496439d@news.astraweb.com> References: <541b1158$0$29967$c3e8da3$5496439d@news.astraweb.com> <541bb85b$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Sep 18, 2014 at 11:00 PM, Steven D'Aprano wrote: > Ned Deily wrote: > >> In article >> , >> Larry Martell wrote: >>> Do you think I should install this update? Perhaps that would restore >>> whatever is missing. >> >> Yes. You should install the update in any case and it's unlikely to make >> the hashlib situation worse :=) > > However, it is likely to make it impossible to diagnose the problem and stop > it from happening again. > > It's not normal behaviour to have functionality just disappear overnight > like this. If Larry is telling the truth that there were no updates > running, *how did the sha-1 library disappear*? > > Larry, I recommend that you try Christian's suggestions before upgrading: > > $ echo -n '' | openssl dgst -sha1 -hex > (stdin)= da39a3ee5e6b4b0d3255bfef95601890afd80709 > > $ openssl version > OpenSSL 1.0.1f 6 Jan 2014 I download the update and rebooted to install it, and my machine would not reboot. It was just spinning and spinning. I powered it down and rebooted it and it said "There are updates to install. Do you want install them or just reboot without installing them?" I chose the latter. It rebooted and now hashlib is working again. That made me think the updates were in fact installed, but when I run the software update utility it says the updates have not been installed. It's all very weird. But it's working again. Thanks everyone for the help!! From steve+comp.lang.python at pearwood.info Fri Sep 19 12:22:43 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 20 Sep 2014 02:22:43 +1000 Subject: program to generate data helpful in finding duplicate large files References: Message-ID: <541c5855$0$30003$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > On Fri, Sep 19, 2014 at 11:32 PM, David Alban wrote: >> thanks for the responses. i'm having quite a good time learning python. > > Awesome! But while you're at it, you may want to consider learning > English on the side; capitalization does make your prose more > readable. Also, it makes you look careless - you appear not to care > about your English, so it's logical to expect that you may not care > about your Python either. That may be completely false, but it's still > the impression you're creating. Speaking of learning English... http://bash.org/?949621 I used to work with programmers whose spelling is awful. I know for a fact that at least some of them had Vim's on-the-fly spell checking turned on: http://www.linux.com/learn/tutorials/357267:using-spell-checking-in-vim nevertheless their commit messages and documentation was full of things like "make teh function reqire a posative index". (No wonder we ended up stuck with 'referer'.) I heard one of them mention that even though he sees the words are misspelled, he deliberately doesn't bother fixing them because its not important. I guess he just liked the look of his text having highlighted words scattered throughout the editor. Some other things programmers have taught me are unimportant: - accurate, up-to-date documentation; - error checking; - correctness; - code that meets functional requirements; - telling the project manager that you're going to miss a hard deadline; - turning up to work the day after deploying a new system, so you will be on hand if something goes wrong. But I'm not bitter. And apropos of nothing: http://bash.org/?835030 -- Steven From rosuav at gmail.com Fri Sep 19 13:07:51 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 20 Sep 2014 03:07:51 +1000 Subject: program to generate data helpful in finding duplicate large files In-Reply-To: <541c5855$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <541c5855$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Sep 20, 2014 at 2:22 AM, Steven D'Aprano wrote: > I heard one of them mention that even though he sees the words are > misspelled, he deliberately doesn't bother fixing them because its not > important. I guess he just liked the look of his text having highlighted > words scattered throughout the editor. > > Some other things programmers have taught me are unimportant: > > - accurate, up-to-date documentation; > - error checking; > - correctness; > - code that meets functional requirements; > - telling the project manager that you're going to miss a hard deadline; > - turning up to work the day after deploying a new system, so you will > be on hand if something goes wrong. We all have our different perspectives on what's important. I see code and coding as more important than sleep, so I've been known keep coding long past everyone else is in bed. (Though extreme states of sleep deprivation do tend to result in code that needs to be corrected later, so there are limits.) Maybe your bovine orkers just have different priorities. Like KLOC production, or their TPS reports. Also: Agree with your bash.org links. ChrisA From ian.g.kelly at gmail.com Fri Sep 19 13:20:14 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 19 Sep 2014 11:20:14 -0600 Subject: program to generate data helpful in finding duplicate large files In-Reply-To: References: <541bc310$0$29975$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Sep 19, 2014 at 12:45 AM, Chris Angelico wrote: > On Fri, Sep 19, 2014 at 3:45 PM, Steven D'Aprano >> s = '\0'.join([thishost, md5sum, dev, ino, nlink, size, file_path]) >> print s > > That won't work on its own; several of the values are integers. So > either they need to be str()'d or something in the output system needs > to know to convert them to strings. I'm inclined to the latter option, > which simply means importing print_function from __future__ and > setting sep=chr(0). Personally, I lean toward converting them with map in this case: s = '\0'.join(map(str, [thishost, md5sum, dev, ino, nlink, size, file_path])) From rosuav at gmail.com Fri Sep 19 13:36:33 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 20 Sep 2014 03:36:33 +1000 Subject: program to generate data helpful in finding duplicate large files In-Reply-To: References: <541bc310$0$29975$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Sep 20, 2014 at 3:20 AM, Ian Kelly wrote: > On Fri, Sep 19, 2014 at 12:45 AM, Chris Angelico wrote: >> On Fri, Sep 19, 2014 at 3:45 PM, Steven D'Aprano >>> s = '\0'.join([thishost, md5sum, dev, ino, nlink, size, file_path]) >>> print s >> >> That won't work on its own; several of the values are integers. So >> either they need to be str()'d or something in the output system needs >> to know to convert them to strings. I'm inclined to the latter option, >> which simply means importing print_function from __future__ and >> setting sep=chr(0). > > Personally, I lean toward converting them with map in this case: > > s = '\0'.join(map(str, [thishost, md5sum, dev, ino, nlink, size, > file_path])) There are many ways to do it. I'm not seeing this as particularly less ugly than the original formatting code, tbh, but it does work. ChrisA From alfredopiacentini at aol.fr Fri Sep 19 13:45:13 2014 From: alfredopiacentini at aol.fr (Alfredo Piacentini Ex Syz Geneve) Date: Fri, 19 Sep 2014 10:45:13 -0700 (PDT) Subject: AVVOCATO PEDOFILOMOSESSUALE ED ASSASSINO DANIELE MINOTTI (FACEBOOK). OLTRE CHE NAZI, MEGALAVA EURO MAFIOSI, E, COME DETTO, MANDANTE DI OMICIDI O "SUICIDATE"! STALKER DI EROE CIVILE MICHELE NISTA SU ORDINE DI TIRANNO FASCIOCAMORRISTA SILVIO In-Reply-To: References: Message-ID: <17a04e75-4037-4b22-892d-66d2e0b76425@googlegroups.com> OCHO AD AVVOCATO PEDOFILOMOSESSUALE ED ASSASSINO: DANIELE MINOTTI (FACEBOOK)! OLTRE CHE MEGALAVA EURO MAFIOSI E BERLUSCONAZIFASCISTA"! STALKER DI GENIO, RE MIDA, EROE CIVILE MICHELE NISTA SU ORDINE DI TIRANNO PEDOFILO TANTO QUANTO: SILVIO BERLUSCONI! 1 OCHO AD AVVOCATO "BERLUSCONIANISSIMAMENTE", MEGA RICICLA CASH MAFIOSO, NAZIFASCISTA, ASSASSINO E PEDOFILOMOSESSUALE: DANIELE MINOTTI ( PURE SU FACEBOOK) DI RAPALLO E GENOVA! TUTTI SANNO DI SUE "FESTE" SATANISTISSIME "ATTE A SODOMIZZARE ZINGARELLI DI 6-8 ANNI (A SANREMO, CON DON RICCARDO SEPPIA E COL TANTE VOLTE CONDANNATO A GALERA, PAOLO BARRAI DEL CRIMINALISSIMO BLOG MERCATO "MERDATO" LIBERO.. MA NON SOLO... E FRA POCO.. TUTTI I NOMI E COGNOMI)!!! OCCHIO, PLS, ALL'AVVOCATO PIU' INFIMAMENTE NAZISTA, MEGA LAVA CASH MAFIOSO, MANDANTE DI OMICIDI E "SUICIDATE", E COME SE NON BASTASSE, ACCLARATO PEDOFILOMOSESSUALE, CHE ESISTA ( IL VOMITO VA' SULLA PARTE "PEDOFILO", PIU' CHE OMOSESSUALE, ANCHE SE IL MEGA SODMIZZATORE DI BAMBINI, DANIELE MINOTTI, LO E' ENTRAMBE LE COSE; OLTRE AD ESSERE UN VERMINOSO CODARDO: METTEVA DELLE SUE FOTO CON FACCE DA ASSOLUTO PERICOLOSISSIMO MANICACO SESSUALE, SU TUTTA INTERNET... ED OVVIAMENTE, ORA, DOPO CHE LE ABBIAM FATTE NOTARE SU MIGLIAIA DI SITI, DA TOPO DI FOGNA, DETTE FOTO LE HA FATTE SUBITO IMBOSCARE)! COME SE NON BASTASSE, PURE FREQUENTISSIMO MANDANTE DI "SUICIDATE" ED OMICIDI: DANIELE MINOTTI DI GENOVA E RAPALLO. Criminalissimo Studio Legale pro Mafia, Camorra, Ndrangheta e Neonazisti assassini, di noto pedofilomosessuale Daniele Minotti :: Genova - Rapallo Via della Libert?, 4/10 - 16035 - Rapallo (GE) (Tribunale di Chiavari) Via XX Settembre, 3/13 - 16121 - Genova RICICLANTE DA ANNI CASH KILLER DEGLI EMANUELLO DI COSA NOSTRA, BASATI A GENOVA. http://www.ilsecoloxix.it/p/genova/2011/05/19/AOJ0cAV-rischio_gronda_arresti.shtml O DEI FEROCI SICARI DELLA NDRANGHETA: I RAMPINO. SEMPRE BASATI A GENOVA. http://www.ilsecoloxix.it/p/genova/2013/06/05/APjJUSgF-ndrangheta_terra_liguria.shtml BASTARDO VERO, PEDERASTA PERVERTITO DANIELE MINOTTI DI GENOVA E RAPALLO: TUTTI SANNO DELLE ORGE PEDOFILE CHE FACEVA CON DON RICCARDO SEPPIA A SANREMO. FRA SIMBOLI DEMONIACI E TERRIFICANTI SODOMIZZAZIONI DI BAMBINI DI 6-8 ANNI ( E AHIME.. FATEMI SDRAMMATIZZARE, PLS... ANCHE 6-8 ANI). BAMBINI ZINGARELLI! D'ALTRONDE, TOPI DI FOGNA CODARDI E SPIETATI COME IL CRIMINALISSIMO AVVOCATO DANIELE MINOTTI DI GENOVA CHE ALTRO AVREBBERO POTUTO RACCATTARE? IL TUTTO FRA CHILI DI COCAINA, MEGA CASH MAFIOSO, E SCIOCCANTISSIMAMENTE, DOZZINE DI TESSERE FASCIOCAMORRISTE DI FORZA ITALIA, FRATELLI D'ITALIA, CASA POUND, FIAMMA TRICOLORE E LEGA NORD. IL DAVVERO "AVVOCATO DEL DIAVOLO", IL BASTARDO MASSONE NAZISTA, IL VERME MASSO-NAZISTA ( MERDA ASSASSINA P2ISTICA PER INTENDERCI), MEGA LAVA CASH MAFIOSO, MANDANTE DI "SUICIDATE" ED OMICIDI A RAFFICA, SEMPRE INC.LANTE BAMBINI O POCO PIU' CHE BAMBINI, DANIELE MINOTTI DI GENOVA E RAPALLO, D'ALTRONDE, I PEDOFILOMOSESSUALI O PEDOFILI IN GENERE LI AMA, SE NE SENTE STRA PARTE, LI DIFENDE. NON CI CREDETE??? VOLETE FARE GLI STRUZZI, CHE PER FRATELLANZA MASSO-N-AZIFASCISTA, PREFERISCONO METTERE LA TESTA DOVE GIRANO I VERMI, SOTTO TERRA??? GIVE A LOOK RIGHT NOW, THEN, PLS:http://www.ansa.it/liguria/notizie/2014/06/20/adescava-minori-sul-web-condannato_36c57304-90aa-4c7f-8463-c7d610ed10dd.html http://iltirreno.gelocal.it/massa/cronaca/2013/04/19/news/casolare-a-luci-rosse-il-pm-7-anni-e-mezzo-all-ex-dipendente-nca-1.6917147 2 E SE GOOGLATE " DANIELE MINOTTI PEDOPORNOGRAFIA" VEDRETE CHE IN TUTTI I SUOI ARTICOLI, SOTTILISSIMAMENTE ( E MANCO TANTO, SOTTILISSIMAMENTE) DIFENDE I PEDOFILI, MINIMIZZA O ELUDE LE LORO ABERRANTI, SPEZZA VITE, COLPE! LI SUPPORTA: OVVIO, E' UN VERME SODOMIZZA BAMBINI LUI IN PRIMO! DA RINCHIUDERE IN GALERA O MANICOMIO CRIMINALE SUBITO: AVRA' GIA' UCCISO E FATTO SCOMPARIRE QUALCHE BIMBO CHE HA INCULATO! O PRESTO LO FARA'! QUI SALVIAMO VITE DI PICCOLISSIME CREATURE CON QUESTI SCRITTI!!! SALVIAMO IL MONDO!!! MA TORNIAMO ORA A STO, PURE TERRORISTA NERO ( ED IN NERO), COME CITATO, FREQUENTE MANDANTE DI OMICIDI, "SUICIDATE" O TERRIFICANTI ISTIGAZIONI AL SUICIDIO: DANIELE MINOTTI DI RAPALLO E GENOVA. DA TANTISSIMI ANNI, VIA VARI CODARDI NICKS, MINACCIANTE MORTE E FACENTE KILLING STALKING A GENIO, SORT OF RE MIDA ED EROE CIVILE MICHELE NISTA, SU CERTISSIMO ORDINE DI AL CAPONE MISTO AD ADOLF HITLER: SILVIO BERLUSCONI ( VIA SUOI CA-N-AZISTI GIULIANO FERRARA, MAURIZIO BELPIETRO, DANIELA GARNERO "SANTANCHE'" E/O ALTRI TOPASTRI DI FOGNA CON SVASTICA AL BRACCIO, DEL CASO). IN QUANTO IL SEMPRE VINCENTISSIMO MICHELE NISTA DIEDE AL CANCRO DEL MONDO INTERO, SILVIO BERLUSCONI, GIUSTAMENTE, DEL DITTATORE, DURANTE UNA TELEFONATA I DUE EBBERO MOLTI ANNI FA. A SEGUITO DI QUESTO, IL COLLETTO LERCISSIMAMENTE INTRISO DI MAFIA, CAMORRA, NDRANGHETA, NAZIFASCISMO, PEDOFILIA, SUOI ORDINI DI OMICIDI E STRAGI, SILVIO BERLUSCONI, FECE DI TUTTO PER DISTRUGGERE LA POSIZIONE DI MICHELE NISTA DI QUASI NUMERO UNO DELLA BORSA DI MILANO, NEGLI ANNI 90. COI METODI PIU' CRIMINALI E VIGLIACCHI POSSIBILE! NON RIUSCENDOLO A DISTRUGGERE PROFESSIONALMENTE ( ESSENDO MICHELE NISTA IN FIUTO BORSISTICO, POLITICO ED INVESTIGATIVO, MOLTO PROBABILMENTE, IL NUMERO UNO DI TUTTO IL PIANETA TERRA), CI RIUSCI' "SOLO" AMMAZZANDOGLI IL PADRE ( CON BASTARDISSIMAMENTE ASSASSINO "METODO FERRULLI") E CERCANDO POI DI UCCIDERE MICHELE, "SOLO" ALTRE 4 VOLTE ( FACENDOGLI SPARIRE I FRENI ANDANDO IN AUTOSTRADA AD OLTRE 120 KM ALL'ORA, PER " SOLO" 3 VOLTE, STESSO MODO CON CUI SILVIO BERLUSCONI FECE AMMAZZARE I GENITORI DI CLEMENTINA FORLEO https://it.answers.yahoo.com/question/index?qid=20100118105650AAhOMTQ RIPETENDO LO STESSO, POI, CON CLEMENTINA FORLEO STESSA http://www.leiweb.it/celebrity/personaggi-news/10_a_clementina-forleo-strani-incidenti.shtml http://straker-61.blogspot.be/2009/12/il-giudice-forleo-coinvolto-in-un.html E IN UN QUARTO CASO, ATTRAVERSO UN AGGUATO FISICO, PREPARATO IN OGNI DETTAGLIO, DA POI FAR PASSARE PER MALORE, COME ACCADUTO COL GRANDE PAPA' DI MICHELE: NOTO " ASSASSINO BERLUSCONIANISSIMO "METODO FERRULLI" http://ricerca.repubblica.it/repubblica/archivio/repubblica/2014/07/06/da-aldrovandi-a-ferrulli-la-stessa-follia-degli-agenti16.html)! VIA VARIE OVRA E GESTAPO PUBBLICHE E PRIVATE DEL, NON SI DICE MAI ABBASTANZA, MEGA MANDANTE DI OMICIDI E STRAGI, BASTARDISSIMO, SPIETATO ASSASSINO SILVIO BERLUSCONI ( NON PER NIENTE LO STESSO VOLEVA " DISARTICOLARE CON TRAUMA", OSSIA U-C-C-I-D-E-N-D-O E FACENDO SEMBRARE IL TUTTO, FINTISSIMI INCIDENTI, INFARTI O SUICIDI, CHI NON SOTTO LE SUE SUOLE ALTE COME QUELLE DEI PAGLIACCI SU TRAMPOLI, A CUI ASSOMIGLIA IN TUTTO http://www.grnet.it/news/95-news/852-segreto-di-stato-sulle-schedature-illegali-berlusconi-salva-pollari-a-pompa.html ... MA TORNEREMO SU QUESTO CON MILIONI DI BLOGS, DOVESSIMO MORIRE DI INFARTO SU UNA TASTIERA, OGGI STESSO). PASSIAMO DI NUOVO, ORA, PLEASE, A UNO DEI SICARI KILLER DI SILVIO BERLUSCONI: L'AVVOCATO OMICIDA E PEDOFILOMOSESSUALE DANIELE MINOTTI (OLTRE CHE NAZI E MEGALAVA EURO MAFIOSI)! 3 INCITA I VERMI DI ESTREMISSIMA DESTRA COME LUI, DI TUTTO IL MONDO, I KAMERADEN KILLER DEI TEA PARTIES, AD UCCIDERE, PRIMA CIVILMENTE E PROFESSIONALMENTE, POI, SE NON "ABBASTANZA INTIMIDITI', DEL TUTTO, CHIUNQUE CRITICHI "TROPPO" I SUO LIDER MAXIMI (LIDER MAXIMI IN TUTTO, SPECIE IN PEDOFILIA, FASCIOCAMORRA ED ORDINI DI OMICIDI E STRAGI): SILVIO BERLUSCONI E LICIO GELLI (CITATI NAZIMAFIOSI DEI TEA PARTIES DI CUI E' STRA PARTE, L'INCULA BAMBINI DANIELE MINOTTI DI GENOVA E RAPALLO, INSIEME AD ALTRO VERME CRIMINALISSIMO: GIACOMO ZUCCO, OVVIAMENTE, PURE LUI, MEGA LAVA SOLDI DI COSA NOSTRA, CAMORRA E NDRANGHETA, SPECIE VIA BITCOINS, ED ESSENDO "BERLUSCONES CLASSIC E NON SPECIAL", PURE LUI NOTO PEDOFILOMOSESSUALE)! CON IL QUALE CONDIVIDE PURE, UNA, DA VOMITARE ANCHE LA BILE, TESSERA DEI PEDERASTA CHE "SON ORGOGLIOSI DI FAR SESSO CON BAMBINI", QUELLA DELL'ORGOGLIO PEDOFILO, OSSIA QUELLA DEI "North American Man-Boy Amore Association" http://www.today.it/rassegna/giornata-orgoglio-pedofilo.html STO PUTRIDISSIMO TOPO DI FOGNA DI DANIELE MINOTTI DEL FORO DI CHIAVARI ( ALTRA SDRAMMATIZZAZIONE, PLS: CHIAVARI, SI, E' DI CERTO LA COSA PIU' BELLA AL MONDO, MA ANCHE LA PIU' BRUTTA, QUANDO LO SI FA DEPRAVATISSIMAMENTE CON I BAMBINI, COME FA SEMPRE STO ESCREMENTOSO PEDERASTA DI DANIELE MINOTTI DI RAPALLO E GENOVA) E' OVVIAMENTE PURE UN BASTARDO RAZZISTA. AUSPICA LA MORTE SOCIALE, " MA ANCHE NON SOLO.. ANCHE TOTALISSIMA" ... DI CHIUNQUE NATO SOTTO LA VERMINOSAMENTE PIDUISTICA AREZZO (DA DOVE VENGONO, NON PER NIENTE, PURE LA BAGASCIONA PREFERITA DA LICIO GELLI, MARIA ELENA BOSCHI.. E SUO PADRE, PORCO SCHIFOSO BANCHIERE DI COSA NOSTRA, CAMORRA E NDRANGHETA, PIER LUIGI BOSCHI DI BANCA ETRURIA... CHE CON LE LORO "RIFORME IMPOSTE DA HITLERIANISSIMA WILLA WANDA", PORTERANNO IL PAESE A NUOVE SVASTICHE, A NUOVI REGIMI ASSASSINISSIMAMENTE DI ESTREMA DESTRA, UNITI AD OVVIA BANCAROTTA E GUERRA CIVILE). COLLABORA, NON PER NIENTE, CON IL VERME ASSASSINO DANIELE MINOTTI DI RAPALLO E GENOVA, IL NOTO AVANZO DI GALERA, CAPO DEL KU KLUK KLAN, ANZI, KAPO' DEL " KU KLUK KLAN PADANO", OVVIAMENTE, ACCLARATO PEDOFILOMOSESSUALE TANTO QUANTO: PAOLO BARRAI. DELL' IMMENSAMENTE CRIMINALE BLOG MERCATO LIBERO = MERDATO LIBERO ( CON CUI, NON PER NIENTE, NON FA ALTRO CHE RICICLARE, VIA MERDOSAMENTE CRIMINALI BITCOINS, SOLDI DI COSA NOSTRA, CAMORRA, NDRANGHETA, COME FRUTTO DI LADRATE E MEGA CORRUZIONE DI LL, LEGA LADRONA, ED EX PDL, POPOLO DI LADRONI, INSIEME AL PRIMA MENZIONATO NOTO SUPER RICICLA SOLDI MAFIOSI: GIACOMO ZUCCO DEI TEA PARTIES... IL TUTTO VIA NAZIMAFIOSA PANAMA O BITCOINS STESSI http://www.ticinonews.ch/ticino/159874/lugano-panama-tre-processi-per-riciclaggio http://www.corriere.it/esteri/14_gennaio_13/panama-polizia-scopre-7-milioni-dollari-doppiofondo-otto-valigie-b0196cb8-7c5a-11e3-bc95-3898e25f75f1.shtml http://www.liberainformazione.org/2013/04/16/panama-segreto-bancario-e-narcotraffico/ http://www.repubblica.it/economia/finanza/2014/01/28/news/bitcoin_arresti_traffico_droga-77128457/ http://www.repubblica.it/economia/2014/07/09/news/bitcoin_terrorismo_riciclaggio-91119086/ ECCO UN POST CHE DIMOSTRA LA LERCISSIMA ARROGANZA NAZINDRANGHETISTA, NAZIMAFIOSA, NAZICAMORRISTA DEI MEGA LAVA CASH ASSASSINO, NONCH? ACCLARATI SCHIFOSI PEDOFILI DI FORZA ITALIA: PAOLO BARRAI, GIACOMO ZUCCO E DANIELE MINOTTI! MA CHE MOSTRA ANCHE QUANTO SIA IDIOTA, CANE IN BORSA, BRUCIA RISPARMI A RAFFICA, L'AVANZO DI GALERA PAOLO BARRAI, CHE PREVEDEVA QUI, IL BIT COIN A ANDANTE DA 700 A 70.000, MENTRE VALE 500 CIRCA! OLE'! http://ilpunto-borsainvestimenti.blogspot.be/2014/03/bitcoin-con-giacomo-zucco-stiamo-ridendo.html). TRATTASI DI VERI E PROPRI AL CAPONE MISTI AD ADOLF HITLER DELLA POLITICA (NERA E SPECIALMENTE "IN NERO")! E FINANZA! 4 CHE IMBOSCANO MEGA VALIGIE PIENE DI CONTANTE KILLER ( http://ilpunto-borsainvestimenti.blogspot.be/2014/08/il-contante-come-strumento-di-marketing.html), PRESSO CRIMINALISSIMA FINTER BANK LUGANO DI COLLETTI MALAVITOSI TANTO QUANTO: FILIPPO CRIPPA E GIOVANNI DAI CAS! A VOI IL "BANCHIERE TOPO DI FOGNA" FILIPPO M CRIPPA DI FZB FINTER ZURICH BANK LUGANO http://www.linkedin.com/pub/filippo-m-crippa/a/a09/826 A VOI IL BANCHIERE AMATISSIMO DA TUTTI I SICARI MAFIOSI DI QUESTO PIANETA: GIOVANNI DEI CAS DI FZB FINTER ZURICH BANK LUGANOhttp://www.linkedin.com/pub/giovanni-dei-cas/2/262/654 MA QUESTI MEGA RICICLAGGI DI CASH SUPER ASSASSINO, AVVENGONO ANCHE PRESSO SCHIFOSISSIMAMENTE CRIMINALE FINECO DI ALTRO BANCHIERE, NOTORIAMENTE AMATISSIMO DA COSA NOSTRA, CAMORRA E NDRANGHETA: ALESSANDRO FOTI DI FINECO BANK, BEN APPUNTO https://www.unicreditgroup.eu/it/governance/management/alessandro-foti.html COMPLICI DI STO TOPO DI FOGNA ASSASSINO E PEDOFILOMOSESSUALE, AVVOCATO DANIELE MINOTTI DI RAPALLO E GENOVA, SONO TANTISSIMI. TUTTI OVVIAMENTE DEI GIRI MAFIOSI E FASCISTI DI SILVIO BERLUSCONI! COLLABORA CON LUI UN EX "BAMBINI DI SATANA", MEGA RICICLA SOLDI ASSASSINI PRESSO BANCA CARIM RIMINI: GABRIELE SILVAGNI. COME ANCHE UN EX "BESTIE DI SATANA", FACCENDIERE MALAVITOSO: MATTEO PARDU DI LA SPEZIA http://www.linkedin.com/pub/matteo-pardu/20/588/906 OLTRE CHE UNA VERME CHE MEGA TRUFFA VIA WEB E FA SEMPRE PERDERE TUTTI I RISPARMI DI OGNI BOCCALONE DA LUI ACCALAPPIATO, BASTARDISSIMO CRIMINALE FEDERICO IZZI DI ROMA. NOTO COME ZIO ROMOLO! VICINO AD ENRICO NICOLETTI, NOTO MALAVITOSO BANCHIERE DELLA BANCA DELLA MAGLIANA http://www.agoravox.it/Arrestato-Enrico-Nicoletti-il.html E AI CRUDELISSIMI ASSASSINI "CASALESI", VIA, NOTORIAMENTE, MEGA OMICIDA FAMIGLIA CAMORRISTA DEI BARDELLINO http://www.ilfattoquotidiano.it/2011/12/10/affari-politici-camorra-formia-avamposto-laziale-casalesi/176674/ PRESSO FORMIA E LATINA ( NON PER NIENTE, DI LATINA, SONO ANCHE I CRIMINALI SCARSI, "SCARSI" IN UMANITA' IN PRIMIS: I SCARSI SONO UNA FAMIGLIA DI DELINQUENTI MOSTRUOSI, SOCI DI QUESTO AL CAPONE DELLA FINANZA, BRUCIA RISPARMI A TONNELLATE, AVANZO DI GALERA FEDERICO IZZI "ZIO ROMOLO"... E PARLO DEL NOTO PEDOFILO, STRAPPA E VENDI ORGANI DI BAMBINI, GINECOLOGO ASSASSINO ALESSANDRO SCARSI, GIA' VARIE VOLTE FINITO IN GALERA http://archiviostorico.corriere.it/2003/febbraio/15/Ginecologo_sfruttatore_co_10_0302151733.shtml E SUO FIGLIO, MEGA RICICLA SOLDI DI CAMORRA, NDRANGHETA E MAFIA: ANDREA SCARSI DI BANCA IFIGEST http://it.linkedin.com/pub/andrea-scarsi/9/4a/67a). VI SONO COME COMPLICI ANCHE DUE LERCIE BALDRACCHE NAZIFASCISTE: ELISA COGNO E PIERA CLERICO DI FRUIMEX ALBA. TRATTASI DI BATTONE PIENE DI SIFILIDE (LA PRIMA FIGLIA DELLA SECONDA) CHE FACEVANO CENTINAIA DI ORGE AD (H)AR(D)CORE (INSIEME.. BAGASCIONE MADRE E FIGLIA... CHE SCHIFO... PUAH) E RICICLANO "BERLUSCONIANISSIMAMENTE" MONTAGNE DI CASH ASSASSINO, VIA LORO SUPER MALAVITOSA FRUIMEX DI ALBA http://it.linkedin.com/pub/elisa-alba-elisa-fruimex/1b/25b/212 COME SCHIFOSO COMPLICE E' ANCHE UN TERRORISTA DI ESTREMISSIMA DESTRA, UNA MERDACCIA DI SERVIZI SEGRETI DEVIATISSIMI, ANCHE LUI, NOTO PEDOFILO ASSASSINO: MAURIZIO BARBERO DI ALBA, PURE, E DI TECHNOSKY MONTESETTEPANI http://it.linkedin.com/pub/maurizio-barbero/8/197/a52 PER NON DIRE POI DEL VERME MEGA RICICLATORE DI SOLDI MAFIOSI GIANPIERO SAMORI', SUPER ATTIVO DA DECENNI A FAR CRIMINI ECONOMICI A PALLONE A CURACAO, PER FRANCESCO CORALLO E SILVIO BERLUSCONI: ALIAS COSA NOSTRA, CAMORRA E NDRANGHETA COME AL SOLITO! http://www.corriere.it/politica/12_novembre_19/affari-samori-tra-san-marino-curacao-gerevini_b46c36fc-3213-11e2-942f-a1cc3910a89d.shtml http://ronaldwederfoort.blogspot.fr/2014/01/curacao-italian-sicilian-mafia.html A FRA NON MOLTO PER OCEANI DI ALTRI DETTAGLI. 5 PS1 STO AVANZO DI GALERA, AVVOCATO NAZINDRANGHETISTA DANIELE MINOTTI DEL TRIBUNALE DI CHIAVARI, FACEVA ANCHE DA COLLANTE FRA IL SUO CAMERATA PAESANO, LADRO, MEGA CORROTTO, E SPIETAMENTE MANDANTE DI OMICIDI, CLAUDIO SCAJOLA, E LA NDRANGHETA. http://www.repubblica.it/politica/2014/05/10/news/il_patto_scajola-matacena_cos_la_ndrangheta_fece_crescere_forza_italia-85725761/ ERA L'ORGANIZZATORE, LA BASTARDISSIMA MENTE DI QUESTO CODARDO, OMICIDA, MA-F-ASCISTA ATTACCO NEI CONFRONTI DI POVERI SENZA TETTO A GENOVA https://www.youtube.com/watch?v=aZIwPGqUfvE ERA "AMICO INTIMO" DEL KILLER DI SILVIO FANELLA, OVVIAMENTE, "NAZIGENOVESE" COME LUI: GIOVANNI BATTISTA CENITI! CON CUI NON PER NIENTE CONDIVIDEVA TRAME MEGA KILLER, ANCHE INTERNAZIONALI, PRESSO PARECCHIE CASA POUND, SPECIE DI ZONA VERBANIA: http://www.ilfattoquotidiano.it/2014/07/17/omicidio-fanella-la-rete-nera-di-ceniti-dal-trentino-al-kosovo/1060862/ http://roma.repubblica.it/cronaca/2014/07/04/news/mokbel_fanella_e_ceniti_ecco_il_giro_d_affari_dell_estrema_destra-90638562/ MEGLIO MORTI CHE ARRESI! CHE SIA 25 APRILE 1945 BIS! I NUOVI PARTIGIANI ( E NON CERTO, NAZIMAFIOSI KILLER "PAR-TEA"GIANI)! DA BRUXELLES, LONDON, RIO DE JANEIRO, MANAGUA (OVE TIFIAMO PER UN NUOVO VINCENTISSIMO CANALE OCEANO-PACIFICO "DI CENTRO-SINISTRA" PER SURCLUSSARE QUELLO MA-F-ASCISTA DI PANAMA DEI BASTARDI CRIMINALISSIMI VALTER LAVITOLA, RICARDO MARTINELLI, PAOLO BARRAI, SILVIO BERLUSCONI E NOTO AMBASCIATORE DI "COSA NOSTRA, CAMORRA E NDRANGHETA" GIANCARLO MARIA CURCIO http://www.globalist.it/Detail_News_Display?ID=2828), SAN JOSE DI COSTARICA, HABANA VIEJA, CARACAS ( OVE STIAMO PREPARANDO UN FORTISSIMO RECUPERO ECONOMICO E SOCIALE), ACCRA, JOHANNESBURG, PECHINO, TORONTO, NEW YORK ( QUELLA DEL GRANDISSIMO DEMOCRAT, PROSSIMAMENTE, US PRESIDENT: BILL DE BLASIO)! PS2 E CHE SIA CHIARO, IO NON SON PER NULLA GENIO, RE MIDA ED EROE CIVILE MICHELE NISTA. NON LO SONO, ANCHE SE LO VORREI DI CERTO ESSERE, VISTO IL SUO ECCEZIONALE GENIO E FIUTO. DA ASSOLUTI NUMERI UNO AL MONDO. E CHE VEDREI BENISSIMO SULLA SEGGIOLA DI STO CESSO NAZISTA E NDRANGHETISTA DI MATTEO RENZI, CORROTTISSIMO DA SILVIO BERLUSCONI, PER FARE LEGGI, E PRENDERE DECISIONI, PRO, QUEST'ULTIMA "FASCIOCAMORRISTAM ED PEDOFILAM PERSONAM". DA POSIZIONE DI FINTISSIMO CENTRO SINISTRA, CHE E' ORMAI, IN REALTA', ESTREMISSIMA DESTRA. CERCANDO COSI' DI FREGARE TUTTI ( DA APPOSTAZIONE INASPETTATA)! SGOZZANDO A MORTE, DEMOCRAZIA, GIUSTIZIA, E LIBERTA'. NON SONO GENIO, RE MIDA ED EROE CIVILE MICHELE NISTA, CHE, MAI DIMENTICHIAMOCI, PERO', OVUNQUE IN VITA SUA ABBIA MESSO LE MANI, HA SEMPRE, SEMPRE E STRA SEMPRE, RESO LE PIETRE, ORO. COME QUANDO CIRCA VENTENNE, PREVEDETTE E CON TRE MESI DI ANTICIPO IL MEGA CROLLO DEL DOW JONES DELL'OTTOBRE 1987. AVVENUTO POI PUNTUALISSIMAMENTE, FRA LO SHOCK DI TUTTI, IN BORSA, A MILANO, CHE LO INIZIARONO A CHIAMARE "IL PROFETA" ( ED INTANTO SI STRAPPAVANO DALLE MANI, MICHELE STESSO, DA UN POSTO DI LAVORO ALL'ALTRO, IN QUANTO RENDEVA SEMPRE, DESKS CHE FACEVANO ZERO PROFITTI, MILIARDARIE, PUR SE IN LIRE, UN ANNO DOPO.. DA QUI IL PASSAGGIO DEL SUO NICK, COL TEMPO, DA "PROFETA" A "RE MIDA".. E SENZA MAI CHE GIOCASSE SPORCO, SENZA MAI CHE CORROMPESSE O ELUDESSE UNA LIRA, CHE UNA, DI TASSE). A SEGUIRE, MICHELE PREVEDETTE ALLA PERFEZIONE IL MEGA RIALZO DEL DOW JONES DELL'ERA BILL CLINTON, IL CROLLO DEL NASDAQ CON L'ARRIVO ABUSIVISSIMO, FIGLIO DI MEGA FRODI ELETTORALI, DI "ADOLF HITLER - GEORGE [WC] BUSH". E SPECIALMENTE, QUI, ANTICIPANDO IL TUTTO VIA INTERNET, DAVANTI AGLI OCCHI DEL MONDO INTERO, MICHELE URLO' NEL SETTEMBRE 2007 CHE IL DOW JONES SAREBBE CROLLATO DA 13400 A 6900 ENTRO UN SOLO ANNO! TUTTI A DARGLI DEL MATTO, MA IL DOW JONES UN ANNO DOPO VALEVA ESATTAMENTE 6900! LI TUTTI A DARGLI DEL GENIO! 6 COME PREVEDETTE ALLA PERFEZIONE IL PIU' CHE RADDOPPIO DEL DOW JONES NELL'ERA DELL'AMMIRABILE OBAMA BARACK ( RIALZO DA LUI PREVISTO, SEMPRE DAVANTI AGLI OCCHI DEL MONDO INTERO, DI NUOVO, VIA INTERNET, BEN SEI MESI PRIMA DI QUANDO INIZIO' A VERIFICARSI: DA LUI ANTICIPATO NEL OTTOBRE 2008, VERIFICATOSI NEL MARZO 2009, ESATTAMENTE, NEL PERIODO DA LUI PREVISTO SEI MESI PRIMA). E DA APRILE 2014, RIPETO, DA APRILE 2014, MICHELE HA DETTO A TUTTI "NOI", CHE IL DOW JONES SAREBBE SALITO ANCORA, MA PER POI MINICROLLARE NELLA PARTE FINALE DEL LUGLIO 2014: ACCADUTO AL MILLESIMO. E "NOI" SAPPIAMO GIA' ANCHE DOVE SARA' IL DOW JONES ALLE PROSSIME ELEZIONI USA DEL 2016. E SIAMO CERTI CHE SARA' ESATTISSIMAMENTE LI, OVE CE LO HA DETTO LUI: GENIO, RE MIDA ED EROE CIVILE MICHELE NISTA. CON LUI SI VINCE SEMPRE E STRA SEMPRE, ALTRO CHE POR-C-ORROTTO BERLUSCONICCHIO SGOZZA DEMOCRAZIA, GIUSTIZIA E LIBERTA', PROVETTO DITTATORE PAZZO: MATTEO RENZI. IL VERME RI-SDOGANATORE DEL BASTARDAMENTE ASSASSINO, BERLUSCONISMO, OSSIA MAFIA, CAMORRA, NDRANGHETA, FASCISMO E PEDOFILIA, A PALAZZO CHIGI! PUAH!!! Op maandag 18 augustus 2014 15:37:14 UTC+2 schreef Antony Whitehouse London: > AVVOCATO PEDOFILOMOSESSUALE ED ASSASSINO DANIELE MINOTTI (FACEBOOK). OLTRE CHE NAZI, MEGALAVA EURO MAFIOSI, E, COME DETTO, MANDANTE DI OMICIDI O "SUICIDATE"! STALKER DI EROE CIVILE MICHELE NISTA SU ORDINE DI TIRANNO FASCIOCAMORRISTA SILVIO BERLUSCONI!! > > > > 1 > > OCHO AD AVVOCATO "BERLUSCONIANISSIMAMENTE", MEGA RICICLA CASH MAFIOSO, NAZIFASCISTA, ASSASSINO E PEDOFILOMOSESSUALE: DANIELE MINOTTI ( PURE SU FACEBOOK) DI RAPALLO E GENOVA! TUTTI SANNO DI SUE "FESTE" SATANISTISSIME "ATTE A SODOMIZZARE" ZINGARELLI DI 6-8 ANNI (A SANREMO, CON DON RICCARDO SEPPIA E COL TANTE VOLTE CONDANNATO A GALERA, PAOLO BARRAI DEL CRIMINALISSIMO BLOG MERCATO "MERDATO" LIBERO.. MA NON SOLO... E FRA POCO.. TUTTI I NOMI E COGNOMI)!!! > > > > OCCHIO, PLS, ALL'AVVOCATO PIU' INFIMAMENTE NAZISTA, MEGA LAVA CASH MAFIOSO, MANDANTE DI OMICIDI E "SUICIDATE", E COME SE NON BASTASSE, ACCLARATO PEDOFILMOSESSUALE, CHE ESISTA ( IL VOMITO VA' SULLA PARTE "PEDOFILO", PIU' CHE OMOSESSUALE, ANCHE SE IL MEGA SODMIZZATORE DI BAMBINI, DANIELE MINOTTI, LO E' ENTRAMBE LE COSE; OLTRE AD ESSERE UN VERMINOSO CODARDO: METTEVA DELLE SUE FOTO CON FACCE DA ASSOLUTO PERICOLOSISSIMO MANICACO SESSUALE, SU TUTTA INTERNET... ED OVVIAMENTE, ORA, DOPO CHE LE ABBIAM FATTE NOTARE SU MIGLIAIA DI SITI, DA TOPO DI FOGNA, DETTE FOTO LE HA FATTE SUBITO IMBOSCARE)! COME SE NON BASTASSE, PURE FREQUENTISSIMO MANDANTE DI "SUICIDATE" ED OMICIDI: DANIELE MINOTTI DI GENOVA E RAPALLO. > > > > Criminalissimo Studio Legale pro Mafia, Camorra, Ndrangheta e Neonazisti assassini, di noto pedofilomosessuale Daniele Minotti :: Genova - Rapallo > > Via della Libert?, 4/10 - 16035 - Rapallo (GE) (Tribunale di Chiavari) > > > > Tel. e fax +39 0185 57 880 > > > > Via XX Settembre, 3/13 - 16121 - Genova > > > > Fax +39 010 91 63 11 54 > > > > Fax to email +39 010 91 63 11 54 > > > > Cell. +39 335 5949904 - Skype daniele_minotti > > > > RICICLANTE DA ANNI CASH KILLER DEGLI EMANUELLO DI COSA NOSTRA, BASATI A GENOVA. http://www.ilsecoloxix.it/p/genova/2011/05/19/AOJ0cAV-rischio_gronda_arresti.shtml > > > > O DEI FEROCI SICARI DELLA NDRANGHETA: I RAMPINO. SEMPRE BASATI A GENOVA. http://www.ilsecoloxix.it/p/genova/2013/06/05/APjJUSgF-ndrangheta_terra_liguria.shtml > > > > BASTARDO VERO, PEDERASTA PERVERTITISSIMO DANIELE MINOTTI DI GENOVA E RAPALLO: TUTTI SANNO DELLE ORGE PEDOFILE CHE FACEVA CON DON RICCARDO SEPPIA A SANREMO. FRA SIMBOLI DEMONIACI E TERRIFICANTI SODOMIZZAZIONI DI BAMBINI DI 6-8 ANNI ( E AHIME.. FATEMI SDRAMMATIZZARE, PLS... ANCHE 6-8 ANI). BAMBINI ZINGARELLI! D'ALTRONDE, TOPI DI FOGNA CODARDI E SPIETATI COME IL CRIMINALISSIMO AVVOCATO DANIELE MINOTTI DI GENOVA CHE ALTRO AVREBBERO POTUTO RACCATTARE? IL TUTTO FRA CHILI DI COCAINA, MEGA CASH MAFIOSO, E SCIOCCANTISSIMAMENTE, DOZZINE DI TESSERE FASCIOCAMORRISTE DI FORZA ITALIA, FRATELLI D'ITALIA, CASA POUND, FIAMMA TRICOLORE E LEGA NORD. IL DAVVERO "AVVOCATO DEL DIAVOLO", IL BASTARDO MASSONE NAZISTA, IL VERME MASSO-NAZISTA ( MERDA ASSASSINA P2ISTICA PER INTENDERCI), MEGA LAVA CASH MAFIOSO, MANDANTE DI "SUICIDATE" ED OMICIDI A RAFFICA, SEMPRE SODOMIZZANTE POCO PIU' CHE BAMBINI, DANIELE MINOTTI DI GENOVA E RAPALLO, D'ALTRONDE, I PEDOFILOMOSESSUALI O PEDOFILI IN GENERE LI AMA, SE NE SENTE STRA PARTE, LI DIFENDE. NON CI CREDETE??? VOLETE FARE GLI STRUZZI, CHE PER FRATELLANZA MASSO-N-AZIFASCISTA, PREFERISCONO METTERE LA TESTA DOVE GIRANO I VERMI, SOTTO TERRA??? GIVE A LOOK RIGHT NOW, THEN, PLS: http://www.ansa.it/liguria/notizie/2014/06/20/adescava-minori-sul-web-condannato_36c57304-90aa-4c7f-8463-c7d610ed10dd.html > > http://iltirreno.gelocal.it/massa/cronaca/2013/04/19/news/casolare-a-luci-rosse-il-pm-7-anni-e-mezzo-all-ex-dipendente-nca-1.6917147 > > E SE GOOGLATE " DANIELE MINOTTI PEDOPORNOGRAFIA" VEDRETE CHE IN TUTTI I SUOI ARTICOLI, SOTTILISSIMAMENTE ( E MANCO TANTO, SOTTILISSIMAMENTE) DIFENDE I PEDOFILI, LI SUPPORTA: OVVIO, E' UN VERME SODOMIZZA BAMBINI LUI IN PRIMO! DA RINCHIUDERE IN GALERA O MANICOMIO SUBITO: AVRA' GIA' UCCISO E FATTO SCOMPARIRE QUALCHE BIMBO CHE HA INCULATO! O PRESTO LO FARA'! QUI SALVIAMO VITE DI PICCOLISSIME CREATURE CON QUESTI SCRITTI!!! SALVIAMO IL MONDO!!! > > > > 2 > > MA TORNIAMO ORA A STO, PURE TERRORISTA NERO ( ED IN NERO), COME CITATO, FREQUENTE MANDANTE DI OMICIDI, "SUICIDATE" O TERRIFICANTI ISTIGAZIONI AL SUICIDIO: DANIELE MINOTTI DI RAPALLO E GENOVA. INCITA I VERMI DI ESTREMISSIMA DESTRA COME LUI, DI TUTTO IL MONDO, I KAMERADEN KILLER DEI TEA PARTIES, AD AMMAZZARE, NELLA MERDA BASTARDAMENTE DITTATORIALE DI "RENZUSCONIA" ( O OVUNQUE SIANO NEL GLOBO), CHIUNQUE CRITICHI "TROPPO" I SUO LIDER MAXIMI, E LIDER MAXIMI IN TUTTO, SPECIE IN PEDOFILIA, FASCIOCAMORRA ED ORDINI DI UCCISIONI E STRAGI: SILVIO BERLUSCONI E LICIO GELLI (CITATI NAZIMAFIOSI DEI TEA PARTIES DI CUI E' STRA PARTE, INSIEME AD ALTRO VERME BERLUSCONAZISTA E CRIMINALISSIMO: GIACOMO ZUCCO, OVVIAMENTE, PURE LUI, MEGA LAVA SOLDI DI COSA NOSTRA, CAMORRA E NDRANGHETA, SPECIE VIA BITCOINS, E PURE LUI NOTO PEDOFILOMOSESSUALE TANTO QUANTO)! CON IL QUALE CONDIVIDE PURE, UNA, DA VOMITARE ANCHE LA BILE, TESSERA DEI PEDERASTA CHE "SON ORGOGLIOSI DI FAR SESSO CON BAMBINI", QUELLA DELL'ORGOGLIO PEDOFILO, OSSIA QUELLA DEI > > "North American Man-Boy Amore Association" > > http://www.today.it/rassegna/giornata-orgoglio-pedofilo.html > > STO PUTRIDISSIMO TOPO DI FOGNA DI DANIELE MINOTTI DEL FORO DI CHIAVARI ( ALTRA SDRAMMATIZZAZIONE, PLS.. CHIAVARI SI.. E' DI CERTO LA COSA PIU' BELLA AL MONDO, MA ANCHE LA PIU' BRUTTA, QUANDO LO SI FA DEPRAVATISSIMAMENTE CON I BAMBINI, COME FA SEMPRE STO ESCREMENTOSO PEDOFILOMOSESSUALE DI DANIELE MINOTTI DI RAPALLO E GENOVA) E' OVVIAMENTE PURE UN BASTARDO RAZZISTA. AUSPICA LA MORTE SOCIALE, " MA ANCHE NON SOLO.. ANCHE TOTALISSIMA" , DI CHIUNQUE NATO SOTTO LA VERMINOSAMENTE PIDUISTICA AREZZO (DA DOVE VENGONO, NON PER NIENTE, PURE LA PUTTANONA PREFERITA DA LICIO GELLI, MARIA ELENA BOSCHI, E IL BANCHIERE FRA I PI? USATI DAI KILLER DELLE MAFIE DI MEZZO GLOBO, PIER LUIGI BOSCHI DI BANCA ETRURIA, CHE CON LE LORO "RIFORME IMPOSTE DA HITLERIANISSIMA WILLA WANDA", PORTERANNO IL PAESE A NUOVE SVASTICHE, A NUOVI REGIMI ASSASSINISSIMAMENTE DI ESTREMA DESTRA, ANTICIPATI DA OVVIA BANCAROTTA E GUERRA CIVILE). COLLABORA, NON PER NIENTE, CON IL, COME LUI, AVANZO DI GALERA, CAPO DEL KU KLUK KLAN, ANZI, KAPO' DEL " KU KLUK KLAN PADANO", OVVIAMENTE, ACCLARATO PEDOFILOMOSESSUALE TANTO QUANTO: PAOLO BARRAI DELL' IMMENSAMENTE MALAVITOSO BLOG MERCATO LIBERO = MERDATO LIBERO ( CON CUI, NON PER NIENTE, NON FA ALTRO CHE RICICLARE, VIA MERDOSAMENTE CRIMINALI BITCOINS, SOLDI DI COSA NOSTRA, CAMORRA, NDRANGHETA, COME FRUTTO DI LADRATE E MEGA CORRUZIONE DI LL, LEGA LADRONA, ED EX PDL, POPOLO DI LADRONI, INSIEME AL PRIMA MENZIONATO NOTO SUPER RICICLA SOLDI DI MAFIOSISSIMI, GIACOMO ZUCCO DEI TEA PARTIES... IL TUTTO VIA NAZIMAFIOSA PANAMA O BITCOINS! > > http://www.repubblica.it/economia/finanza/2014/01/28/news/bitcoin_arresti_traffico_droga-77128457/ http://www.repubblica.it/economia/2014/07/09/news/bitcoin_terrorismo_riciclaggio-91119086/ > > ECCO UN POST CHE DIMOSTRA LA LERCISSIMA ARROGANZA NAZINDRANGHETISTA, NAZIMAFIOSA, NAZICAMORRISTA DEI MEGA LAVA CASH ASSASSINO, NONCH? ACCLARATI PEDOFILI BERLUSCONIANI: PAOLO BARRAI, GIACOMO ZUCCO E DANIELE MINOTTI! MA CHE MOSTRA ANCHE QUANTO SIA IDIOTA, CANE IN BORSA, BRUCIA RISPARMI A RAFFICA, L'AVANZO DI GALERA PAOLO BARRAI, CHE PREVEDEVA IL BIT COIN A ANDANTE DA 700 A 70.000, MENTRE VALE ( IN QUANTO "NOI", DA GRANDI "NUOVI PARTIGIANI" LO ABBIAMO SPACCATO IN GIU FINO A) 500 CIRCA! OLE'! http://ilpunto-borsainvestimenti.blogspot.be/2014/03/bitcoin-con-giacomo-zucco-stiamo-ridendo.html). TRATTASI DI VERI E PROPRI AL CAPONE MISTI AD ADOLF HITLER DELLA POLITICA (NERA E SPECIALMENTE "IN NERO")! E FINANZA! CHE IMBOSCANO MEGA VALIGIE PIENE DI CONTANTE KILLER ( http://ilpunto-borsainvestimenti.blogspot.be/2014/08/il-contante-come-strumento-di-marketing.html), PRESSO CRIMINALISSIMA FINTER BANK LUGANO DI COLLETTI MALAVITOSI TANTO QUANTO: FILIPPO CRIPPA E GIOVANNI DAI CAS! > > > > 3 > > A VOI IL "BANCHIERE TOPO DI FOGNA" FILIPPO M CRIPPA DI FZB FINTER ZURICH BANK LUGANO > > http://www.linkedin.com/pub/filippo-m-crippa/a/a09/826 A VOI IL BANCHIERE AMATISSIMO DA TUTTI I SICARI MAFIOSI DI QUESTO PIANETA: GIOVANNI DEI CAS DI FZB FINTER ZURICH BANK LUGANO http://www.linkedin.com/pub/giovanni-dei-cas/2/262/654 MA QUESTI MEGA RICICLAGGI DI CASH SUPER ASSASSINO, AVVENGONO ANCHE PRESSO SCHIFOSISSIMAMENTE CRIMINALE FINECO DI ALTRO BANCHIERE, NOTORIAMENTE AMATISSIMO DA COSA NOSTRA, NDRANGHETA E CAMORRA: ALESSANDRO FOTI DI FINECO BANK, BEN APPUNTO. > > https://www.unicreditgroup.eu/it/governance/management/alessandro-foti.html COME SE NON BASTASSE, IL PEDOFILOMOSESSUALE, NAZINDRANGHETISTA, ASSASSINO AVVOCATO DANIELE MINOTTI ? UN TUTT' UNO CON UN NOTO TERRORISTA DI ESTREMISSIMA DESTRA, MEGA OMICIDA, ED "OVVIAMENTE" PURE LUI NOTO PEDOFILO: ANGELO PEGLI. RIFUGIATOSI IN ECUADOR, A GUAYAQUIL, PER NON PASSARE ANNI IN GALERA A MARASSI. OVVIAMENTE, VIA REGIA DI SOLITO MEGA FIGLIO DI TROIA, BASTARDO "NERO" ( E QUASI SEMPRE "IN NERO"), AVVOCATO BASTARDISSIMAMENTE CRIMINALE: DANIELE MINOTTI DI GENOVA E RAPALLO. CHE COLLABORA ANCHE CON UN ALTRO NOTO DEPRAVATO SESSUALE E MEGA LAVA SOLDI MAFIOSI: GABRIELE SILVAGNI DI BANCA CARIM RIMINI. ED UN FACCENDIERE ESTREMISSIMAMENTE DELINQUENTE: MATTEO PARDU DI LA SPEZIA http://www.linkedin.com/pub/matteo-pardu/20/588/906 OLTRE CHE CON UNA BESTIA CHE MEGA TRUFFA VIA WEB E FA SEMPRE PERDERE TUTTI I RISPARMI DI TUTTI, BASTARDO CRIMINALISSIMO FEDERICO IZZI DI ROMA. NOTO COME ZIO ROMOLO! VICINISSIMO AD ENRICO NICOLETTI, NOTO BANCHIERE DELLA BANCA DELLA MAGLIANA http://www.agoravox.it/Arrestato-Enrico-Nicoletti-il.html E AI CRUDELISSIMI ASSASSINI "CASALESI", VIA, NOTORIAMENTE, MEGA OMICIDA FAMIGLIA CAMORRISTA DEI BARDELLINO http://www.ilfattoquotidiano.it/2011/12/10/affari-politici-camorra-formia-avamposto-laziale-casalesi/176674/ PRESSO FORMIA E LATINA ( NON PER NIENTE, DI LATINA, SONO ANCHE I CRIMINALISSIMI SCARSI, "SCARSI" IN UMANITA', SPECIALMENTE... NAZISTI.. A CAPO, ANZI, A KAPO' DI QUESTO SITO http://www.unionesatanistiitaliani.it/ I SCARSI SONO UNA FAMIGLIA DI CRIMINALI MOSTRUOSI, SOCI DI QUESTO AL CAPONE DELLA FINANZA, BRUCIA RISPARMI A TONNELLATE, VERME SUPER CRIMINALE FEDERICO IZZI "ZIO ROMOLO"... E PARLO DEL NOTO PEDOFILO, STRAPPA E VENDI ORGANI DI BAMBINI, GINECOLOGO ASSASSINO ALESSANDRO SCARSI, GIA' VARIE VOLTE FINITO IN GALERA http://archiviostorico.corriere.it/2003/febbraio/15/Ginecologo_sfruttatore_co_10_0302151733.shtml E DI SUO FIGLIO, MEGA RICICLA SOLDI DI MAFIA, CAMORRA E NDRANGHETA, VERME CRIMINALE TANTO QUANTO ANDREA SCARSI DI BANCA IFIGEST http://it.linkedin.com/pub/andrea-scarsi/9/4a/67a). A FRA NON MOLTO PER OCEANI DI ALTRI DETTAGLI. > > PS > > STO AVANZO DI GALERA, AVVOCATO NAZIMAFIOSO DANIELE MINOTTI DEL TRIBUNALE DI CHIAVARI, FACEVA ANCHE DA COLLANTE FRA IL SUO CAMERATA PAESANO, LADRO, MEGA CORROTTO, E SPIETAMENTE KILLER, CLAUDIO SCAJOLA E LA NDRANGHETA. http://www.repubblica.it/politica/2014/05/10/news/il_patto_scajola-matacena_cos_la_ndrangheta_fece_crescere_forza_italia-85725761/ > > ERA L'ORGANIZZATORE, LA BASTARDISSIMA MENTE DI QUESTO CODARDO, OMICIDA, MA-F-ASCISTA ATTACCO NEI CONFRONTI DI POVERI SENZA TETTO A GENOVA > > https://www.youtube.com/watch?v=aZIwPGqUfvE > > ERA "AMICO INTIMO" DEL KILLER DI ESTREMISSIMA DESTRA, OVVIAMENTE, "NAZIGENOVESE" COME LUI: GIOVANNI BATTISTA CENITI! CON CUI NON PER NIENTE CONDIVIDEVA TRAME MEGA KILLER, ANCHE INTERNAZIONALI, PRESSO TANTE CASA POUND: > > http://www.ilfattoquotidiano.it/2014/07/17/omicidio-fanella-la-rete-nera-di-ceniti-dal-trentino-al-kosovo/1060862/ http://roma.repubblica.it/cronaca/2014/07/04/news/mokbel_fanella_e_ceniti_ecco_il_giro_d_affari_dell_estrema_destra-90638562/ > > https://www.youtube.com/watch?v=QmxJVLqyQNI > > NEI PROSSIMI MESI TONNELLATE DI ALTRI FONDAMENTALI DETTAGLI! > > > > 4 > > MEGLIO MORTI CHE ARRESI! > > CHE SIA 25 APRILE 1945 BIS! > > I NUOVI PARTIGIANI ( E NON CERTO, NAZIMAFIOSI ASSASSINI "PAR-TEA"GIANI)! > > DA BRUXELLES, LONDON, RIO DE JANEIRO, HABANA VIEJA, MANAGUA, SAN JOSE DI COSTARICA, CARACAS ( OVE STIAMO PREPARANDO UN FORTISSIMO RECUPERO ECONOMICO E SOCIALE), ACCRA, JOHANNESBURG, PECHINO, TOKYO, TORONTO, NEW YORK ( QUELLA DEL GRANDISSIMO DEMOCRAT, PROSSIMAMENTE, US PRESIDENT: BILL DE BLASIO)! E CHE SIA CHIARO, IO NON SON PER NULLA GENIO, RE MIDA ED EROE CIVILE MICHELE NISTA. NON LO SONO, ANCHE SE LO VEDREI BENISSIMO SULLA SEGGIOLA DI STO CESSO NAZISTA E MAFIOSO DI MATTEO RENZI, CORROTTISSIMO DA SILVIO BERLUSCONI, PER FARE LEGGI, E PRENDERE DECISIONI, PRO, QUEST'ULTIMA "FASCIOCAMORRISTAM ED PEDOFILAM PERSONAM". DA POSIZIONE DI FINTISSIMO CENTRO SINISTRA, CHE E' ORMAI IN REALTA', ESTREMISSIMA DESTRA. CERCANDO COSI' DI FREGARE TUTTI! SGOZZANDO A MORTE, DEMOCRAZIA, GIUSTIZIA, E LIBERTA'. NON SONO GENIO, RE MIDA ED EROE CIVILE MICHELE NISTA, CHE, MAI DIMENTICHIAMOCI, OVUNQUE IN VITA SUA ABBIA MESSO LE MANI, HA SEMPRE, SEMPRE E STRA SEMPRE RESO LE PIETRE, ORO. COME QUANDO CIRCA VENTENNE, PREVEDETTE E CON TRE MESI DI ANTICIPO IL MEGA CROLLO DEL DOW JONES DELL'OTTOBRE 1987. AVVENUTO FRA LO SHOCK DI TUTTI, IN BORSA, A MILANO, CHE LO INIZIARONO A CHIAMARE " IL PROFETA" ( ED INTANTO SI STRAPPAVANO DALLE MANI, MICHELE,. DA UN POSTO DI LAVORO ALL'ALTRO, IN QUANTO RENDEVA SEMPRE, DESKS CHE FACEVANO ZERO PROFITTI, MILIARDARIE, PUR SE IN LIRE, SUBITO DOPO.. DA QUI IL PASSAGGIO DEL SUO NICK, COLE TEMPO, DA "PROFETA" A " RE MIDA".. E SENZA MAI CHE GIOCASSE SPORCO, SENZA MAI CHE CORROMPESSE O ELUDESSE UNA LIRA, CHE UNA, DI TASSE). A SEGUIRE, MICHELE PREVEDETTE ALLA PERFEZIONE IL MEGA RIALZO DELL'ERA CLINTON, IL CROLLO DEL NASDAQ CON L'ARRIVO ABUSIVISSIMO, FIGLIO DI MEGA FRODI ELETTORALI, DI " ADOLF HITLER - GEORGE [WC] BUSH ". E SPECIALMENTE, QUI, ANTICIPANDO IL TUTTO VIA INTERNET, DAVANTI AGLI OCCHI DEL MONDO INTERO, MICHELE URLO' NEL SETTEMBRE 2007 CHE IL DOW JONES SAREBBE CROLLATO DA 13400 A 6900 ENTRO UN SOLO ANNO! TUTTI A DARGLI DEL MATTO, MA IL DOW JONES UN ANNO DOPO VALEVA ESATTAMENTE 6900. LI TUTTI A DARGLI DEL GENIO! COME PREVEDETTE ALLA PERFEZIONE IL PIU' CHE RADDOPPIO DEL DOW JONES NELL'ERA DELL'AMMIRABILE OBAMA BARACK ( RIALZO DA LUI PREVISTO SEMPRE DAVANTI AGLI OCCHI DEL MONDO INTERO, DI NUOVO, VIA INTERNET, BEN SEI MESI PRIMA DI QUANDO INIZIO' A VERIFICARSI: NEL 3.2009). E DA APRILE 2014, RIPETO, DA APRILE 2014, MICHELE HA DETTO A TUTTI "NOI", CHE IL DOW JONES SAREBBE SALITO ANCORA, MA PER POI SEMICROLLARE NELLA PARTE FINALE DEL LUGLIO 2014: ACCADUTO AL MILLESIMO. E "NOI" SAPPIAMO GIA' ANCHE DOVE SARA' IL DOW JONES ALLE PROSSIME ELEZIONI USA DEL 2016. E SIAMO CERTI CHE SARA' ESATTISSIMAMENTE LI, OVE CE LO HA DETTO LUI: GENIO, RE MIDA ED EROE CIVILE MICHELE NISTA. CON LUI SI VINCE SEMPRE E STRA SEMPRE, ALTRO CHE POR-C-ORROTTO BERLUSCONICCHIO SGOZZA DEMOCRAZIA, GIUSTIZIA E LIBERTA', PROVETTO DITTATORE PAZZO: MATTEO RENZI ( CHE MICHELE CI DICE FINIRA' PEGGIO DI B-O-TTINO CRAXI, E QUINDI CI CREDIAMO, OLTRE CHE LO STRA AUSPICHIAMO... BASTA CHE ACCADA PRESTO, PRIMA CHE IMPONGA ALTRE RIFORME CON LA SVASTICA AL BRACCIO, CHE MANCO HITLER AVREBBE OSATO ANCHE SOLO PENSARE, NON FARE). IL VERME RI SDOGANATORE DI ASSASSINISSIME MAFIA, CAMORRA, NDRANGHETA, FASCISMO E PEDOFILIA, A PALAZZO CHIGI. PUAH. From tjreedy at udel.edu Fri Sep 19 15:43:37 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 19 Sep 2014 15:43:37 -0400 Subject: the python shell window is already executing a command In-Reply-To: References: <4jrh1adtbsvnr9o20r9k3hfe4nkrkps2dk@4ax.com> <5gdk1appae03ngjlot2hg574udmnc0iqg9@4ax.com> <22ul1a9bfsehco2kk5jb0uif8mpm33ue37@4ax.com> Message-ID: On 9/18/2014 10:51 PM, Chris Angelico wrote: > On Fri, Sep 19, 2014 at 5:05 AM, Terry Reedy wrote: >> A couple more questions; after you run the file once, is there a warning >> above the first >>> prompt? If, after the program stop and you see a second >>>>> prompt and run >>>>> import sys; len(sys.modules), 'array' in sys.modules >> what is the result? > > What's significant about the array module here? I'm a little puzzled. 'array' is alphabetically the first module imported in the default two-process mode but not in the one-process mode selected by a command line '-n'. To the best of my understanding, the message reported, which I found in the code, should only appear in one-process mode. Seymour reported that he started Idle by right-clicking on the file and selecting 'Edit with Idle'. Asking the above question is easier then trying to get him to directly determine what command line is associated with 'Edit with Idle' on his particular machine. -- Terry Jan Reedy From rosuav at gmail.com Fri Sep 19 15:47:40 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 20 Sep 2014 05:47:40 +1000 Subject: the python shell window is already executing a command In-Reply-To: References: <4jrh1adtbsvnr9o20r9k3hfe4nkrkps2dk@4ax.com> <5gdk1appae03ngjlot2hg574udmnc0iqg9@4ax.com> <22ul1a9bfsehco2kk5jb0uif8mpm33ue37@4ax.com> Message-ID: On Sat, Sep 20, 2014 at 5:43 AM, Terry Reedy wrote: > On 9/18/2014 10:51 PM, Chris Angelico wrote: >> >> On Fri, Sep 19, 2014 at 5:05 AM, Terry Reedy wrote: >>> >>> A couple more questions; after you run the file once, is there a warning >>> above the first >>> prompt? If, after the program stop and you see a >>> second >>>>>> >>>>>> prompt and run >>>>>> import sys; len(sys.modules), 'array' in sys.modules >>> >>> what is the result? >> >> >> What's significant about the array module here? I'm a little puzzled. > > > 'array' is alphabetically the first module imported in the default > two-process mode but not in the one-process mode selected by a command line > '-n'. To the best of my understanding, the message reported, which I found > in the code, should only appear in one-process mode. > > Seymour reported that he started Idle by right-clicking on the file and > selecting 'Edit with Idle'. Asking the above question is easier then trying > to get him to directly determine what command line is associated with 'Edit > with Idle' on his particular machine. Ah! Nice one. :) Get the info you want with a very simple copy/paste line of code. Cryptic, but effective. ChrisA From alextrapp at googlemail.com Fri Sep 19 17:11:24 2014 From: alextrapp at googlemail.com (alextrapp at googlemail.com) Date: Fri, 19 Sep 2014 14:11:24 -0700 (PDT) Subject: Google Appengine Proxy Post method error Message-ID: So I got the Labnol Google Appengine proxy but it can't handle the Post method aka error 405. I need help adding this method to the script: mirror.py = http://pastebin.com/2zRsdi3U transform_content.py = http://pastebin.com/Fw7FCncA main.html = http://pastebin.com/HTBH3y5T All other files are just small files for appengine that don't carry sufficient code for this. Hope you guys can help. Thanks in advance :) From tjreedy at udel.edu Fri Sep 19 18:02:58 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 19 Sep 2014 18:02:58 -0400 Subject: Is there a canonical way to check whether an iterable is ordered? In-Reply-To: References: Message-ID: On 9/18/2014 10:45 PM, Chris Angelico wrote: > On Fri, Sep 19, 2014 at 9:52 AM, Roy Smith wrote: >> In article , >> Chris Angelico wrote: >> >>> The one thing you can rely on (and therefore must comply with, when >>> you design an iterable) is that iteration will hit every element in what, a collection that exists separately from the iteration? or a collection generated by the iteration? This is actually two statements in one -- what the user can rely on, which I claim is very little (see below) -- and what the designer must 'comply with', which is correspondingly very little (again see below) except as the designer claims otherwise in specific documentation. >>> exactly once. There are only two things to rely on without further, special case, information. iter(iterable) = iterator (if not, 'iterable' is not an iterable) next(iterator) = object or raises StopIteration (with raising not guaranteed) The conceptual flaw in the statement above, as I think originally intended, is the notion that 'every element [of a collection]' exists, or is defined before the iteration. Iterators can be creative, in the sense of generating collections as they go, in a manner not determined by the past. It is also possible that the next item depends on what the iterator user has done with previous items. Such feedback loops are common for programs that interact with users. If the statement above is interpreted retrospectively, as "iteration hits every item of the sequence it generates", then it is trivially true and is equivalent to "iteration yields every element that it yields, in the order that it yields them". To paraphase the OP's question, given completion of yielded1 = [item for item in iterable] yielded2 = [item for item in yielded1] then yielded2 == yielded1 *is* guarenteed. But this is all that is guaranteed. Itertools.tee operates similarly to the above code except that processing of the duplicate streams can be interleaved. There is an internal queue of items yielded on one branch not the other. For best operation, accesses should be interleaved, with the maximum lag bounded. Itertools.tee guarantees that the two branches yield the same items in the same order. >> Does it actually say that somewhere? For example: >> >> for i in bag.pick_randomly_with_replacement(n=5): >> print i >> >> shouldn't do that. > > When you pick randomly from a population, you create a new population, > which may have duplicates compared to the original. (For efficiency's > sake it probably won't all actually exist immediately, but > conceptually it does exist.) When the next item depends on feedback from the user, that conceptual trick does not work as well. > That's what you're iterating over - not the bag itself. If one iterates over anything other that a sequence, in forward order, then one is, in effect, iterating over a new sequence generated from the 'base' collection. In particular, set and dict iteration iterates over an arbitrary serialization of the set or dict. In the example above, the underlying collection (or specification thereof) and size of selection can be hidden away in a class instance so that the code may just look like 'for i in my_iterable:", just as for iterating over a set. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Fri Sep 19 19:33:15 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 20 Sep 2014 09:33:15 +1000 Subject: program to generate data helpful in finding duplicate large files References: <541bc310$0$29975$c3e8da3$5496439d@news.astraweb.com> <541c0dc9$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: <541cbd3c$0$29988$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > On Fri, Sep 19, 2014 at 9:04 PM, Steven D'Aprano > wrote: >>> Hmm, you sure exit won't work? >> >> In the interactive interpreter, exit is bound to a special helper object: >> >> py> exit >> Use exit() or Ctrl-D (i.e. EOF) to exit >> >> Otherwise, you'll get NameError. > > It's not the interactive interpreter alone. I tried it in a script > before posting. Well I'll be mogadored. Serves me right for not testing before posting. [...] > I've no idea how far back to go before it comes up with a NameError. > However, this is provided (as is made clear by the type lines) by > site.py, and so can be disabled. But with default settings, it is > possible to use exit(1) to set your return value. It's a bad idea to rely on features added to site.py, since they aren't necessarily going to be available at all sites or in all implementations: steve at orac:/home/steve$ ipy IronPython 2.6 Beta 2 DEBUG (2.6.0.20) on .NET 2.0.50727.1433 Type "help", "copyright", "credits" or "license" for more information. >>> exit(2) steve at orac:/home/steve$ Bugger me, I'm going home! -- Steven From ycui at outlook.com Fri Sep 19 19:36:27 2014 From: ycui at outlook.com (Frank Cui) Date: Fri, 19 Sep 2014 21:36:27 -0200 Subject: Python assignment auto-grading Message-ID: Hi Folks, I'm seeking some suggestions and recommendations for python assignments auto grading. Hopefully this tool will have all or some of the following attributes : 1) Easy to set up and maintain (i.e. minimal workload in terms of sysadmin and webdev, is there a recommended cloud service ? )2) The main workload from the instructor side would only be writing the test cases and mark distributions on the assignments3) Convenient process for student enrolment and assignment publishing. I have already read this post on stackexchange http://programmers.stackexchange.com/questions/181068/how-to-create-an-auto-grader-in-and-for-python, and hope to know if there is a ready or semi-ready to use open-source projects and products for this purpose which are lightweight and easy to use. ThanksFrank -------------- next part -------------- An HTML attachment was scrubbed... URL: From cs at zip.com.au Fri Sep 19 20:27:45 2014 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 20 Sep 2014 10:27:45 +1000 Subject: program to generate data helpful in finding duplicate large files In-Reply-To: References: Message-ID: <20140920002745.GA43639@cskk.homeip.net> On 19Sep2014 23:59, Chris Angelico wrote: >On Fri, Sep 19, 2014 at 11:32 PM, David Alban wrote: >> if you omit the exit statement it in this example, and >> $report_mode is not set, your shell program will give a non-zero return code >> and appear to have terminated with an error. in shell the last expression >> evaluated determines the return code to the os. > >IMO that's a terrible misfeature. If you actually want the return >value to be propagated, you should have to say so - something like: > >#!/bin/sh >run_program >exit $? > >Fortunately, Python isn't like that. IMO, it is good that the shell is like that. It isn't Python. A great many small shell scripts are one liner wrappers, and this serves them well. A great many more are a lot of prep work followed by a major (and final) command. These are also served well. There is the hazard where someone careless goes: ... main script ... echo "script failed!" >&2 and accidentally exits with 0 (success). For further fun, I run my shell scripts with the -e and -u options turned on. And of course for complicated stuff I usually maintain a $xit variable, setting it to 1 when something goes blam, and finishing such scripts with: exit $xit But for wrappers, the shell default exit design is handy. Cheers, Cameron Simpson From the back of the research lab, the sound of a large metallic pile of loose objects collapsing, accompanied by a loud "Aaaaiiieeyyrrgghhh!!" from George. A few seconds of silence, then: "I'll have to call you back." From cs at zip.com.au Fri Sep 19 20:30:33 2014 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 20 Sep 2014 10:30:33 +1000 Subject: program to generate data helpful in finding duplicate large files In-Reply-To: <541c5855$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <541c5855$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20140920003033.GA55961@cskk.homeip.net> On 20Sep2014 02:22, Steven D'Aprano wrote: >[...] I used to work with programmers whose spelling is awful. [...] >nevertheless their commit messages and documentation was full of things >like "make teh function reqire a posative index". [...] >I heard one of them mention that even though he sees the words are >misspelled, he deliberately doesn't bother fixing them because its not >important. I guess he just liked the look of his text having highlighted >words scattered throughout the editor. I guess he just liked the idea of having terrible search results:-( Cheers, Cameron Simpson There is one evil which...should never be passed over in silence but be continually publicly attacked, and that is corruption of the language... - W.H. Auden From tjreedy at udel.edu Fri Sep 19 23:28:23 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 19 Sep 2014 23:28:23 -0400 Subject: Python docs not accessible from IDLE In-Reply-To: References: Message-ID: On 9/17/2014 8:46 PM, Ned Deily wrote: > In article , Terry Reedy > wrote: >> Ned, is there any reason to not add the trailing '/' to the url for >> 3.4.2? I verified that it is being added by python.org when connecting >> from win7 with FF. How about adding the 's' for 'https'? > > There is no reason not to add both at this point, although the old url > *should* continue to work. Using those changes avoids a couple of > redirects. Done. -- Terry Jan Reedy From rosuav at gmail.com Sat Sep 20 00:47:48 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 20 Sep 2014 14:47:48 +1000 Subject: program to generate data helpful in finding duplicate large files In-Reply-To: <541cbd3c$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <541bc310$0$29975$c3e8da3$5496439d@news.astraweb.com> <541c0dc9$0$29992$c3e8da3$5496439d@news.astraweb.com> <541cbd3c$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Sep 20, 2014 at 9:33 AM, Steven D'Aprano wrote: > It's a bad idea to rely on features added to site.py, since they aren't > necessarily going to be available at all sites or in all implementations: > > steve at orac:/home/steve$ ipy > IronPython 2.6 Beta 2 DEBUG (2.6.0.20) on .NET 2.0.50727.1433 > Type "help", "copyright", "credits" or "license" for more information. >>>> exit(2) > steve at orac:/home/steve$ > > Bugger me, I'm going home! This is the real reason for not relying on site.py: rosuav at sikorsky:~$ python -S Python 2.7.3 (default, Mar 13 2014, 11:03:55) [GCC 4.7.2] on linux2 >>> exit Traceback (most recent call last): File "", line 1, in NameError: name 'exit' is not defined ChrisA From rosuav at gmail.com Sat Sep 20 00:53:39 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 20 Sep 2014 14:53:39 +1000 Subject: program to generate data helpful in finding duplicate large files In-Reply-To: <20140920002745.GA43639@cskk.homeip.net> References: <20140920002745.GA43639@cskk.homeip.net> Message-ID: On Sat, Sep 20, 2014 at 10:27 AM, Cameron Simpson wrote: > IMO, it is good that the shell is like that. It isn't Python. > > A great many small shell scripts are one liner wrappers, and this serves > them well. A great many more are a lot of prep work followed by a major (and > final) command. These are also served well. > > There is the hazard where someone careless goes: > > ... main script ... > echo "script failed!" >&2 > > and accidentally exits with 0 (success). > > For further fun, I run my shell scripts with the -e and -u options turned > on. > > And of course for complicated stuff I usually maintain a $xit variable, > setting it to 1 when something goes blam, and finishing such scripts with: > > exit $xit > > But for wrappers, the shell default exit design is handy. What you're saying here is that there are times when it's convenient, and other times when it's inconvenient. And sure! That's definitely true. What I contest, though, is that having it this way is the better design. Even if the bulk of shell scripts are wrappers for single commands and want to exit with their return values (which I suspect is not the case), I believe the better design would be to have them put a simple tag onto it like "|| exit $?". Of course, there's no changing it now. ChrisA From rosuav at gmail.com Sat Sep 20 01:01:27 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 20 Sep 2014 15:01:27 +1000 Subject: Is there a canonical way to check whether an iterable is ordered? In-Reply-To: References: Message-ID: On Sat, Sep 20, 2014 at 8:02 AM, Terry Reedy wrote: >> That's what you're iterating over - not the bag itself. > > If one iterates over anything other that a sequence, in forward order, then > one is, in effect, iterating over a new sequence generated from the 'base' > collection. In particular, set and dict iteration iterates over an > arbitrary serialization of the set or dict. Yeah, that's basically what I was trying to say. Didn't realize how empty the statement was till you dug deeper into it, heh. Yes, an iterator yields the items it yields, in the order it yields them... *twiddles thumbs* ChrisA From ben+python at benfinney.id.au Sat Sep 20 02:29:50 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 20 Sep 2014 16:29:50 +1000 Subject: program to generate data helpful in finding duplicate large files References: <541c5855$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <85ha02vm75.fsf@benfinney.id.au> Steven D'Aprano writes: > I heard one [programmer] mention that even though he sees the words > are misspelled, he deliberately doesn't bother fixing them because its > not important. I guess he just liked the look of his text having > highlighted words scattered throughout the editor. If it's who I'm thinking of (or, heck, any one of a hundred similar cow-orkers), the text editor would not show English spelling errors since they're not interested in the English text in their program code :-) -- \ ?Spam will be a thing of the past in two years' time.? ?Bill | `\ Gates, 2004-01-24 | _o__) | Ben Finney From gandalf at shopzeus.com Sat Sep 20 06:00:05 2014 From: gandalf at shopzeus.com (=?ISO-8859-2?Q?Nagy_L=E1szl=F3_Zsolt?=) Date: Sat, 20 Sep 2014 12:00:05 +0200 Subject: pad binary string with a given byte value (python 3) Message-ID: <541D5025.4070604@shopzeus.com> >>> BS = 16 >>> pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS) >>> pad('L') 'L\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f' >>> pad(b'L') Traceback (most recent call last): File "", line 1, in File "", line 1, in TypeError: can't concat bytes to str How do I write this function so it can pad byte strings? chr(charcode) creates a normal string, not a binary string. I can figure out way for example this: >>> b'T'+bytearray([32]) but it just don't seem right to create a list, then convert it to a byte array and then convert it to a binary string. What am I missing? -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. From __peter__ at web.de Sat Sep 20 08:05:43 2014 From: __peter__ at web.de (Peter Otten) Date: Sat, 20 Sep 2014 14:05:43 +0200 Subject: pad binary string with a given byte value (python 3) References: <541D5025.4070604@shopzeus.com> Message-ID: Nagy L?szl? Zsolt wrote: > >>> BS = 16 > >>> pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS) > >>> pad('L') > 'L\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f' > >>> pad(b'L') > Traceback (most recent call last): > File "", line 1, in > File "", line 1, in > TypeError: can't concat bytes to str > > How do I write this function so it can pad byte strings? chr(charcode) > creates a normal string, not a binary string. > > I can figure out way for example this: > > >>> b'T'+bytearray([32]) > > but it just don't seem right to create a list, then convert it to a byte > array and then convert it to a binary string. What am I missing? bytes/str.ljust() >>> def pad(b, n=16, c=b"\x0f"): ... length = (len(b)+n-1)//n*n ... return b.ljust(length, c) ... >>> pad(b"abc", 5) b'abc\x0f\x0f' >>> pad(b"abcde", 5) b'abcde' >>> pad(b"abcdef", 5) b'abcdef\x0f\x0f\x0f\x0f' >>> pad("abcde", 5, "*") 'abcde' >>> pad("abcdef", 5, "*") 'abcdef****' From steve+comp.lang.python at pearwood.info Sat Sep 20 08:12:39 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 20 Sep 2014 22:12:39 +1000 Subject: pad binary string with a given byte value (python 3) References: Message-ID: <541d6f39$0$29977$c3e8da3$5496439d@news.astraweb.com> Nagy L?szl? Zsolt wrote: > >>> BS = 16 > >>> pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS) > >>> pad('L') > 'L\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f' > >>> pad(b'L') > Traceback (most recent call last): > File "", line 1, in > File "", line 1, in > TypeError: can't concat bytes to str > > How do I write this function so it can pad byte strings? chr(charcode) > creates a normal string, not a binary string. > > I can figure out way for example this: > > >>> b'T'+bytearray([32]) > > but it just don't seem right to create a list, then convert it to a byte > array and then convert it to a binary string. What am I missing? You don't need to write your own function, just use the relevant string and bytes methods. Use the ljust and rjust (left and right justify) methods: To add padding on the left, justify on the right, and vise versa: py> "Hello".ljust(20, "\x0f") 'Hello\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f' py> "Hello".rjust(20, "\x0f") '\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0fHello' (The default fill character is space.) The same works for bytes, except you have to make sure your fill char is also a byte: py> b"Hello".rjust(20, b"\x0f") b'\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0fHello' py> b"Hello".ljust(20, b"\x0f") b'Hello\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f' -- Steven From gandalf at shopzeus.com Sat Sep 20 08:21:50 2014 From: gandalf at shopzeus.com (=?UTF-8?B?TmFneSBMw6FzemzDsyBac29sdA==?=) Date: Sat, 20 Sep 2014 14:21:50 +0200 Subject: pad binary string with a given byte value (python 3) In-Reply-To: References: <541D5025.4070604@shopzeus.com> Message-ID: <541D715E.9000102@shopzeus.com> > bytes/str.ljust() > >>>> def pad(b, n=16, c=b"\x0f"): > ... length = (len(b)+n-1)//n*n > ... return b.ljust(length, c) Thanks! -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. From __peter__ at web.de Sat Sep 20 08:27:16 2014 From: __peter__ at web.de (Peter Otten) Date: Sat, 20 Sep 2014 14:27:16 +0200 Subject: pad binary string with a given byte value (python 3) References: <541D5025.4070604@shopzeus.com> Message-ID: Nagy L?szl? Zsolt wrote: > I can figure out way for example this: > > >>> b'T'+bytearray([32]) > > but it just don't seem right to create a list, then convert it to a byte > array and then convert it to a binary string. What am I missing? By the way, you can repeat bytes (and strings) by multiplying: >>> b"\x01"*3 b'\x01\x01\x01' >>> b"ab"*3 b'ababab' From gandalf at shopzeus.com Sat Sep 20 08:31:17 2014 From: gandalf at shopzeus.com (=?ISO-8859-1?Q?Nagy_L=E1szl=F3_Zsolt?=) Date: Sat, 20 Sep 2014 14:31:17 +0200 Subject: pad binary string with a given byte value (python 3) In-Reply-To: <541D715E.9000102@shopzeus.com> References: <541D5025.4070604@shopzeus.com> <541D715E.9000102@shopzeus.com> Message-ID: <541D7395.6030709@shopzeus.com> >> bytes/str.ljust() >> >>>>> def pad(b, n=16, c=b"\x0f"): >> ... length = (len(b)+n-1)//n*n >> ... return b.ljust(length, c) > Thanks! One more question. How do I create a single char binary string from a number? E.g. >>> bytes([65]) b'A' It seems to be wrong again. The bytes constructor requires a sequence, and I don't like creating a list or a tuple just to convert it into a binary string. -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. From __peter__ at web.de Sat Sep 20 08:37:22 2014 From: __peter__ at web.de (Peter Otten) Date: Sat, 20 Sep 2014 14:37:22 +0200 Subject: pad binary string with a given byte value (python 3) References: <541D5025.4070604@shopzeus.com> <541D715E.9000102@shopzeus.com> <541D7395.6030709@shopzeus.com> Message-ID: Nagy L?szl? Zsolt wrote: > >>> bytes/str.ljust() >>> >>>>>> def pad(b, n=16, c=b"\x0f"): >>> ... length = (len(b)+n-1)//n*n >>> ... return b.ljust(length, c) >> Thanks! > One more question. How do I create a single char binary string from a > number? E.g. > > >>> bytes([65]) > b'A' > > It seems to be wrong again. The bytes constructor requires a sequence, > and I don't like creating a list or a tuple just to convert it into a > binary string. Unfortunately I'm not aware of a function similar to chr() that creates bytes. From nicholascannon1 at gmail.com Sat Sep 20 09:16:40 2014 From: nicholascannon1 at gmail.com (Nicholas Cannon) Date: Sat, 20 Sep 2014 06:16:40 -0700 (PDT) Subject: Love to get some feedback on my first python app!!! Message-ID: <42e68de9-7528-46fc-8c74-c0baa1d6199e@googlegroups.com> I have created my first python program and I have learnt a lot about python from this group and wanted some feedback. I am still improving it and trying to tackle some performance and GUI stuff so keep that in mind. I don't think it is the best program but is a good product of 3 months of python. link: https://github.com/nicodasiko/Article-Grab From juan0christian at gmail.com Sat Sep 20 09:44:45 2014 From: juan0christian at gmail.com (Juan Christian) Date: Sat, 20 Sep 2014 10:44:45 -0300 Subject: Class Inheritance from different module Message-ID: I have the following structure: Third-party API installed via pip: steamapi / app.py consts.py core.py users.py [...] My script: test.py In the API, the module users.py has a class 'SteamUser' and I want to mimic it's usage on my code, like this: import steamapi [...] class User(Inheritance from API): def __init__(self, ID): steamapi.core.APIConnection(api_key = KEY) super( " Inheritance SteamUser" (ID)) # creates the user using the API [...] So that in my code when I need to create a new user, I just call 'usr = User("XXXXXXX")' instead of calling 'usr = steamapi.user.SteamUser(76561197996416028)', is that possible? And of course, I want to have access to all the class methods like 'name', 'country_code', 'time_created', 'avatar', 'friends' and so on. And finally, is that a good approach, pythonic? If not, what would be a good way? -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Sat Sep 20 10:31:16 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 21 Sep 2014 00:31:16 +1000 Subject: Class Inheritance from different module References: Message-ID: <541d8fb5$0$29971$c3e8da3$5496439d@news.astraweb.com> Juan Christian wrote: [...] > In the API, the module users.py has a class 'SteamUser' and I want to > mimic it's usage on my code, like this: > > import steamapi > > [...] > > class User(Inheritance from API): What do you mean, "Inheritance from API"? You can't inherit from an API, only from classes. > def __init__(self, ID): > steamapi.core.APIConnection(api_key = KEY) > super( " Inheritance SteamUser" (ID)) # creates the user using the API > > [...] > > So that in my code when I need to create a new user, I just call 'usr = > User("XXXXXXX")' instead of calling 'usr = > steamapi.user.SteamUser(76561197996416028)', is that possible? I would do something like this: # untested def make_user(ID): steamapi.core.APIConnection(api_key = KEY) return steamapi.user.SteamUser(76561197996416028) usr = make_user("XXXXXXXXX") No need for inheritance. make_user returns an actual SteamUser instance, not some subclass. -- Steven From rosuav at gmail.com Sat Sep 20 10:58:44 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 21 Sep 2014 00:58:44 +1000 Subject: Love to get some feedback on my first python app!!! In-Reply-To: <42e68de9-7528-46fc-8c74-c0baa1d6199e@googlegroups.com> References: <42e68de9-7528-46fc-8c74-c0baa1d6199e@googlegroups.com> Message-ID: On Sat, Sep 20, 2014 at 11:16 PM, Nicholas Cannon wrote: > I have created my first python program and I have learnt a lot about python from this group and wanted some feedback. I am still improving it and trying to tackle some performance and GUI stuff so keep that in mind. I don't think it is the best program but is a good product of 3 months of python. > > link: https://github.com/nicodasiko/Article-Grab Sure! But first, a couple of points that aren't specifically Python... Firstly, you're using Google Groups. Until someone gets inside Google and fixes up the code, it will make a mess of every post made through it. Please use something better... either subscribe to the mailing list and do everything through email, or access the newsgroup comp.lang.python via a better client, or something of the sort. Secondly, a note about verb tenses in English. You have this commit message on the (as of 20140921) latest commit: """Fixed some bugs and did some GUI changes""" And these comments in the code: #search API rawData = urllib.urlopen('http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q='+encodedQuery).read() #loads data from API into json jsonData = json.loads(rawData) #extracts the results from API searchResults = jsonData['responseData']['results'] The more normal way to write these would be in present tense, in a more imperative style: "Fix some bugs", "Load data", "Extract results". (Although these comments are actually quite redundant - all they do is tell you what the single next line of code does.) You may also notice that the camelCase variable names you're using are in stark contrast to the rest of the language. It's normal to use lower_case_with_underscores instead. Now, let's have a look at the code itself. query = queryVar.get() ... and further down ... global queryVar queryVar = StringVar() You don't need to say "global" at top level. Everything at top-level is global. However, I generally like to, as much as possible, define things higher in the file than their usages - so that as you read the file, the first reference to anything is the one that tells you what it is. That may not be practical here, but it's something to keep in mind. (This is why import statements generally go at the top of the file, for instance.) The language doesn't require it, but it does make the code easier for a human to read. links = [] for result in searchResults: #loops through the searchResults data to find the title and URL of the pages #and then add the links to the links list title = result['title'] link = result['url'] links.append(link) print links You're not doing anything with the title, so what you have here is a loop that builds up a list from empty, by repeated appends. That's a perfect job for a list comprehension: links = [result['url'] for result in searchResults] I'm not sure why you print the links to stdout there - is that some left-over debugging code? Although, the only thing you do with the list of URLs is to iterate over it, once. You could simply merge the two loops into one: for result in searchResults: url = result['url'] pageData = urllib.urlopen(url).read() ... etc ... Your text insertion is a little inconsistent: you put the URL and title at the cursor position, then the body at the end. Is that intentional? If so, that deserves a comment - which would be much more useful than the comments that say what we can read in the code already. textDisplay.insert(INSERT, 'This spider searches for information on your query and will display it here!') You haven't written a spider here :) You're just calling on Google's spider and showing some information. Similarly, the verb "CRAWL" on your button isn't really accurate - and isn't particularly helpful to the user either. I'd just word it in terms of how the user will value it, and say "Search" on the button. Keep it simple. queryWidgit = Entry(frame, textvariable=queryVar, fg='Blue', bd=5, width=50) It's normally "Widget", not "Widgit". Not significant, but you seem to have consistently used two i's, including in your comments. Well, you asked for feedback. That's normally going to consist of people pointing out where they think you did badly. But ultimately, this is all relatively minor, so if the program works, consider yourself to have broadly succeeded. ChrisA From breamoreboy at yahoo.co.uk Sat Sep 20 11:30:58 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 20 Sep 2014 16:30:58 +0100 Subject: Love to get some feedback on my first python app!!! In-Reply-To: References: <42e68de9-7528-46fc-8c74-c0baa1d6199e@googlegroups.com> Message-ID: On 20/09/2014 15:58, Chris Angelico wrote: > On Sat, Sep 20, 2014 at 11:16 PM, Nicholas Cannon > wrote: > > You may > also notice that the camelCase variable names you're using are in > stark contrast to the rest of the language. It's normal to use > lower_case_with_underscores instead. That may be the PEP 8 guideline but I don't regard it as normal, I find camelCase far easier to read. -- 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 Sat Sep 20 11:48:57 2014 From: __peter__ at web.de (Peter Otten) Date: Sat, 20 Sep 2014 17:48:57 +0200 Subject: Class Inheritance from different module References: Message-ID: Juan Christian wrote: > I have the following structure: > > Third-party API installed via pip: > steamapi / > app.py > consts.py > core.py > users.py > [...] > > My script: > test.py > > > In the API, the module users.py has a class 'SteamUser' and I want to > mimic it's usage on my code, like this: > > import steamapi > > [...] > > class User(Inheritance from API): > def __init__(self, ID): > steamapi.core.APIConnection(api_key = KEY) > super( " Inheritance SteamUser" (ID)) # creates the user using the API > > [...] > > So that in my code when I need to create a new user, I just call 'usr = > User("XXXXXXX")' instead of calling 'usr = > steamapi.user.SteamUser(76561197996416028)', is that possible? Yes, it doesn't matter in what module a baseclass is defined. Just go ahead and import it: # untested import steamapi.user class User(steamapi.user.User): def __init__(self, userid=None, userurl=None): super().__init__(userid, userurl) # code specific to you subclass > And of > course, I want to have access to all the class methods like 'name', > 'country_code', 'time_created', 'avatar', 'friends' and so on. That's the very idea of subclassing. > And finally, is that a good approach, pythonic? It depends ;) If you are planning only small adjustments it might be an option to write a few helper functions together with the original steamapi.user.User class and be done. > If not, what would be a good way? Generally speaking the Python community often favours duck-typing or composition over inheritance. I'm not prepared to go into a lengthy discussion over this -- if you are interested you have to try a search engine or rely on the usual suspects ;) From kabugimatu at gmail.com Sat Sep 20 12:37:15 2014 From: kabugimatu at gmail.com (kabugimatu at gmail.com) Date: Sat, 20 Sep 2014 09:37:15 -0700 (PDT) Subject: Pybuez Client sending messages to j2me Server In-Reply-To: <5858a389-7b9f-4f29-848a-1ef80861c8ad@m24g2000vbp.googlegroups.com> References: <5858a389-7b9f-4f29-848a-1ef80861c8ad@m24g2000vbp.googlegroups.com> Message-ID: On Wednesday, May 6, 2009 11:38:16 AM UTC+3, CkurtM wrote: > I have a problem with recieving requests on j2me based bluetooth > server using RFCOMM. I can send messages from the j2me client to > python server, but cant receive from the python bluetooth client to > j2me server, it only connects but doesnt receive??.I can send copy of > code on request. > I'm using pybluez on python 2.6 > and standard javax.bluetooth for the mobile interface. Any help wud be > welcome. > Thanks in advance. Hi CkurtM, Can you please post your J2ME Client Code that connects to Python Server ? I actually From nicholascannon1 at gmail.com Sat Sep 20 21:33:31 2014 From: nicholascannon1 at gmail.com (Nicholas Cannon) Date: Sat, 20 Sep 2014 18:33:31 -0700 (PDT) Subject: Love to get some feedback on my first python app!!! In-Reply-To: <42e68de9-7528-46fc-8c74-c0baa1d6199e@googlegroups.com> References: <42e68de9-7528-46fc-8c74-c0baa1d6199e@googlegroups.com> Message-ID: On Saturday, September 20, 2014 9:17:27 PM UTC+8, Nicholas Cannon wrote: > I have created my first python program and I have learnt a lot about python from this group and wanted some feedback. I am still improving it and trying to tackle some performance and GUI stuff so keep that in mind. I don't think it is the best program but is a good product of 3 months of python. > > > > link: https://github.com/nicodasiko/Article-Grab Yeah this is exactly what I was looking for I know the comments are horrible and I had no idea about the camelCase stuff. Should I use ''' Use this commenting on my functions or not. I think they are called docStrings or something ''' I have a free day today and I am going to fix up some GUI stuff and try and slim down the processing and amount of variables because it doesnt really run as fast. Thanks for the help Chris Angelico! From rosuav at gmail.com Sat Sep 20 21:48:18 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 21 Sep 2014 11:48:18 +1000 Subject: Love to get some feedback on my first python app!!! In-Reply-To: References: <42e68de9-7528-46fc-8c74-c0baa1d6199e@googlegroups.com> Message-ID: On Sun, Sep 21, 2014 at 11:33 AM, Nicholas Cannon wrote: > Yeah this is exactly what I was looking for I know the comments are horrible and I had no idea about the camelCase stuff. Should I use > ''' > Use this commenting on my functions or not. I think they are called docStrings or something > ''' Yes, they're called docstrings (without the capital S - again, Python doesn't tend to work that way). You can find info and advice all over the web about how to write good, useful docstrings. ChrisA From hanziyuan08 at gmail.com Sat Sep 20 23:39:24 2014 From: hanziyuan08 at gmail.com (8pa2y han) Date: Sat, 20 Sep 2014 20:39:24 -0700 (PDT) Subject: one problem in cx_Freeze4.3.3 for Python3.4 Message-ID: <2b99e7ed-6972-46d0-948c-41a79a9cf145@googlegroups.com> #torrent.py --------------------- import re import urllib.request import urllib.parse urltemp = 'https://btdigg.org/search?info_hash=&q=' urlinput = urllib.parse.quote(input('Please input keywords:')) url = urltemp + urlinput print('--------------------Searching--------------------'+'\n'+url) content = urllib.parse.unquote(urllib.request.urlopen(url).read().decode('utf-8')) recon = re.findall(r'href="(magnet:.+?)"',content) print('--------------------Order address--------------------'+'\n'+str(recon)) a=[] for temp in recon: b = re.sub(';','&',temp) a.append(b) print('--------------------Right address--------------------'+'\n'+str(a)) print('--------------------Address has been updated--------------------') file = open('torrent.txt','w') for temp2 in a: file.write(temp2+'\n') file.close() -------------------------------------- I use cx_Freeze to project it into '.exe',but when I turn on 'torrent.exe' it tips that: AttributeError: 'module object has no attribute '_fix_up_module' -------------------------------------- cx_Freeze log: --------------- creating directory dist copying D:\Program Files\Python\lib\site-packages\cx_freeze-4.3.3-py3.4-win32.egg\cx_Freeze\bases\Console.exe -> dist\torrent.exe copying C:\Windows\SYSTEM32\python34.dll -> dist\python34.dll writing zip file dist\torrent.exe Name File ---- ---- m __main__ torrent.py m _bisect m _bootlocale m _bz2 D:\Program Files\Python\DLLs\_bz2.pyd m _codecs m _codecs_cn m _codecs_hk m _codecs_iso2022 m _codecs_jp m _codecs_kr m _codecs_tw m _collections m _collections_abc m _datetime m _dummy_thread m _functools m _hashlib D:\Program Files\Python\DLLs\_hashlib.pyd m _heapq m _imp m _io m _locale m _lzma D:\Program Files\Python\DLLs\_lzma.pyd m _md5 m _multibytecodec m _operator m _osx_support D:\Program Files\Python\lib\_osx_support.py m _random m _sha1 m _sha256 m _sha512 m _socket D:\Program Files\Python\DLLs\_socket.pyd m _sre m _ssl D:\Program Files\Python\DLLs\_ssl.pyd m _stat m _string m _strptime m _struct m _thread m _threading_local m _warnings m _weakref m _weakrefset m abc m argparse m array m atexit m base64 m binascii m bisect D:\Program Files\Python\lib\bisect.py m builtins m bz2 m calendar m codecs P collections m collections.abc m contextlib m copy m copyreg m cx_Freeze__init__ D:\Program Files\Python\lib\site-packages\cx_freeze-4.3.3-py3.4-win32.egg\cx_Freeze\initscripts\Console.py m datetime P distutils D:\Program Files\Python\lib\distutils\__init__.py m distutils.debug D:\Program Files\Python\lib\distutils\debug.py m distutils.errors D:\Program Files\Python\lib\distutils\errors.py m distutils.log D:\Program Files\Python\lib\distutils\log.py m distutils.spawn D:\Program Files\Python\lib\distutils\spawn.py m distutils.sysconfig D:\Program Files\Python\lib\distutils\sysconfig.py m distutils.text_file D:\Program Files\Python\lib\distutils\text_file.py m dummy_threading P email D:\Program Files\Python\lib\email\__init__.py m email._encoded_words D:\Program Files\Python\lib\email\_encoded_words.py m email._header_value_parser D:\Program Files\Python\lib\email\_header_value_parser.py m email._parseaddr D:\Program Files\Python\lib\email\_parseaddr.py m email._policybase D:\Program Files\Python\lib\email\_policybase.py m email.base64mime D:\Program Files\Python\lib\email\base64mime.py m email.charset D:\Program Files\Python\lib\email\charset.py m email.contentmanager D:\Program Files\Python\lib\email\contentmanager.py m email.encoders D:\Program Files\Python\lib\email\encoders.py m email.errors D:\Program Files\Python\lib\email\errors.py m email.feedparser D:\Program Files\Python\lib\email\feedparser.py m email.generator D:\Program Files\Python\lib\email\generator.py m email.header D:\Program Files\Python\lib\email\header.py m email.headerregistry D:\Program Files\Python\lib\email\headerregistry.py m email.iterators D:\Program Files\Python\lib\email\iterators.py m email.message D:\Program Files\Python\lib\email\message.py m email.parser D:\Program Files\Python\lib\email\parser.py m email.policy D:\Program Files\Python\lib\email\policy.py m email.quoprimime D:\Program Files\Python\lib\email\quoprimime.py m email.utils D:\Program Files\Python\lib\email\utils.py P encodings m encodings.aliases m encodings.ascii m encodings.base64_codec m encodings.big5 m encodings.big5hkscs m encodings.bz2_codec m encodings.charmap m encodings.cp037 m encodings.cp1006 m encodings.cp1026 m encodings.cp1125 m encodings.cp1140 m encodings.cp1250 m encodings.cp1251 m encodings.cp1252 m encodings.cp1253 m encodings.cp1254 m encodings.cp1255 m encodings.cp1256 m encodings.cp1257 m encodings.cp1258 m encodings.cp273 m encodings.cp424 m encodings.cp437 m encodings.cp500 m encodings.cp65001 m encodings.cp720 m encodings.cp737 m encodings.cp775 m encodings.cp850 m encodings.cp852 m encodings.cp855 m encodings.cp856 m encodings.cp857 m encodings.cp858 m encodings.cp860 m encodings.cp861 m encodings.cp862 m encodings.cp863 m encodings.cp864 m encodings.cp865 m encodings.cp866 m encodings.cp869 m encodings.cp874 m encodings.cp875 m encodings.cp932 m encodings.cp949 m encodings.cp950 m encodings.euc_jis_2004 m encodings.euc_jisx0213 m encodings.euc_jp m encodings.euc_kr m encodings.gb18030 m encodings.gb2312 m encodings.gbk m encodings.hex_codec m encodings.hp_roman8 m encodings.hz m encodings.idna m encodings.iso2022_jp m encodings.iso2022_jp_1 m encodings.iso2022_jp_2 m encodings.iso2022_jp_2004 m encodings.iso2022_jp_3 m encodings.iso2022_jp_ext m encodings.iso2022_kr m encodings.iso8859_1 m encodings.iso8859_10 m encodings.iso8859_11 m encodings.iso8859_13 m encodings.iso8859_14 m encodings.iso8859_15 m encodings.iso8859_16 m encodings.iso8859_2 m encodings.iso8859_3 m encodings.iso8859_4 m encodings.iso8859_5 m encodings.iso8859_6 m encodings.iso8859_7 m encodings.iso8859_8 m encodings.iso8859_9 m encodings.johab m encodings.koi8_r m encodings.koi8_u m encodings.latin_1 m encodings.mac_arabic m encodings.mac_centeuro m encodings.mac_croatian m encodings.mac_cyrillic m encodings.mac_farsi m encodings.mac_greek m encodings.mac_iceland m encodings.mac_latin2 m encodings.mac_roman m encodings.mac_romanian m encodings.mac_turkish m encodings.mbcs m encodings.palmos m encodings.ptcp154 m encodings.punycode m encodings.quopri_codec m encodings.raw_unicode_escape m encodings.rot_13 m encodings.shift_jis m encodings.shift_jis_2004 m encodings.shift_jisx0213 m encodings.tis_620 m encodings.undefined m encodings.unicode_escape m encodings.unicode_internal m encodings.utf_16 m encodings.utf_16_be m encodings.utf_16_le m encodings.utf_32 m encodings.utf_32_be m encodings.utf_32_le m encodings.utf_7 m encodings.utf_8 m encodings.utf_8_sig m encodings.uu_codec m encodings.zlib_codec m enum D:\Program Files\Python\lib\enum.py m errno m fnmatch D:\Program Files\Python\lib\fnmatch.py m ftplib D:\Program Files\Python\lib\ftplib.py m functools m gc m genericpath m getopt D:\Program Files\Python\lib\getopt.py m getpass D:\Program Files\Python\lib\getpass.py m gettext m gzip D:\Program Files\Python\lib\gzip.py m hashlib D:\Program Files\Python\lib\hashlib.py m heapq P http D:\Program Files\Python\lib\http\__init__.py m http.client D:\Program Files\Python\lib\http\client.py m http.cookiejar D:\Program Files\Python\lib\http\cookiejar.py P importlib D:\Program Files\Python\lib\importlib\__init__.py P importlib D:\Program Files\Python\lib\importlib\__init__.py m importlib._bootstrap m importlib._bootstrap D:\Program Files\Python\lib\importlib\_bootstrap.py m importlib.machinery D:\Program Files\Python\lib\importlib\machinery.py m importlib.util D:\Program Files\Python\lib\importlib\util.py m io m itertools m keyword m linecache m locale P logging D:\Program Files\Python\lib\logging\__init__.py m lzma D:\Program Files\Python\lib\lzma.py m math m mimetypes D:\Program Files\Python\lib\mimetypes.py m msvcrt m nt m ntpath m nturl2path D:\Program Files\Python\lib\nturl2path.py m operator m optparse m os m posixpath m py_compile D:\Program Files\Python\lib\py_compile.py m quopri m random D:\Program Files\Python\lib\random.py m re m reprlib m shutil D:\Program Files\Python\lib\shutil.py m socket D:\Program Files\Python\lib\socket.py m sre_compile m sre_constants m sre_parse m ssl D:\Program Files\Python\lib\ssl.py m stat m string m stringprep m struct m sys m tarfile D:\Program Files\Python\lib\tarfile.py m tempfile D:\Program Files\Python\lib\tempfile.py m textwrap m threading m time m token m tokenize m traceback m types m unicodedata D:\Program Files\Python\DLLs\unicodedata.pyd P urllib D:\Program Files\Python\lib\urllib\__init__.py m urllib.error D:\Program Files\Python\lib\urllib\error.py m urllib.parse D:\Program Files\Python\lib\urllib\parse.py m urllib.request D:\Program Files\Python\lib\urllib\request.py m urllib.response D:\Program Files\Python\lib\urllib\response.py m uu D:\Program Files\Python\lib\uu.py m warnings m weakref m winreg m zipfile D:\Program Files\Python\lib\zipfile.py m zipimport m zlib Missing modules: ? _dummy_threading imported from dummy_threading ? _scproxy imported from urllib.request ? ce imported from os ? doctest imported from heapq ? grp imported from shutil, tarfile ? org.python.core imported from copy ? os.path imported from os, py_compile, shutil ? posix imported from os ? pwd imported from getpass, posixpath, shutil, tarfile ? subprocess imported from os ? termios imported from getpass This is not necessarily a problem - the modules may not be needed on this platform. copying D:\Program Files\Python\DLLs\_bz2.pyd -> dist\_bz2.pyd copying D:\Program Files\Python\DLLs\_hashlib.pyd -> dist\_hashlib.pyd copying D:\Program Files\Python\DLLs\_lzma.pyd -> dist\_lzma.pyd copying D:\Program Files\Python\DLLs\_socket.pyd -> dist\_socket.pyd copying D:\Program Files\Python\DLLs\_ssl.pyd -> dist\_ssl.pyd copying D:\Program Files\Python\DLLs\unicodedata.pyd -> dist\unicodedata.pyd --------------------------------------- From nicholascannon1 at gmail.com Sat Sep 20 23:44:13 2014 From: nicholascannon1 at gmail.com (Nicholas Cannon) Date: Sat, 20 Sep 2014 20:44:13 -0700 (PDT) Subject: Love to get some feedback on my first python app!!! In-Reply-To: <42e68de9-7528-46fc-8c74-c0baa1d6199e@googlegroups.com> References: <42e68de9-7528-46fc-8c74-c0baa1d6199e@googlegroups.com> Message-ID: I have just committed a new main.py file on github. I added alot more comments and slimmed down the getinfo() function. From nicholascannon1 at gmail.com Sun Sep 21 04:53:46 2014 From: nicholascannon1 at gmail.com (Nicholas Cannon) Date: Sun, 21 Sep 2014 01:53:46 -0700 (PDT) Subject: Love to get some feedback on my first python app!!! In-Reply-To: <42e68de9-7528-46fc-8c74-c0baa1d6199e@googlegroups.com> References: <42e68de9-7528-46fc-8c74-c0baa1d6199e@googlegroups.com> Message-ID: On Saturday, September 20, 2014 9:17:27 PM UTC+8, Nicholas Cannon wrote: > I have created my first python program and I have learnt a lot about python from this group and wanted some feedback. I am still improving it and trying to tackle some performance and GUI stuff so keep that in mind. I don't think it is the best program but is a good product of 3 months of python. > > > > link: https://github.com/nicodasiko/Article-Grab I just updated the whole app to include a scroll bar, loading bar and I used multi threading to update the scroll bar whilst scraping the data from the web. I need to work on performance though but I have defiantly improved it now! From geniusrko at gmail.com Sun Sep 21 09:10:16 2014 From: geniusrko at gmail.com (aws Al-Aisafa) Date: Sun, 21 Sep 2014 06:10:16 -0700 (PDT) Subject: pgs4a fails to build Message-ID: <9e5e6761-dcbf-47a7-b630-70e5c0018890@googlegroups.com> Hi everyone. So I have this problem with building with pgs4a. when I try to build I always end with this error: /home/aws/Desktop/pgs4a-0.9.6/android-sdk/tools/ant/build.xml:483: SDK does not have any Build Tools installed. could you please help me? Thank you in advance. From breamoreboy at yahoo.co.uk Sun Sep 21 09:28:01 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 21 Sep 2014 14:28:01 +0100 Subject: Error from hg.python.org Message-ID: I've noticed this a few times recently using the Sync command from TortoiseHg on Windows 8.1. % hg pull --verbose --update --config ui.merge=internal:merge http://hg.python.org/cpython HTTP Error: 500 (Internal Server Error) [command returned code 255 Sun Sep 21 14:22:52 2014] Is this related to an upgrade that has been done in the last few weeks or is that a complete red herring? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From Nikolaus at rath.org Sun Sep 21 11:48:15 2014 From: Nikolaus at rath.org (Nikolaus Rath) Date: Sun, 21 Sep 2014 08:48:15 -0700 Subject: ssl.SSLError: [SSL: BAD_WRITE_RETRY] bad write retry (_ssl.c:1636) Message-ID: <87r3z5m0u8.fsf@vostro.rath.org> Hello, Can someone explain help me understand what this exception means? [...] File "/usr/local/lib/python3.4/dist-packages/dugong-3.2-py3.4.egg/dugong/__init__.py", line 584, in _co_send len_ = self._sock.send(buf) File "/usr/lib/python3.4/ssl.py", line 679, in send v = self._sslobj.write(data) ssl.SSLError: [SSL: BAD_WRITE_RETRY] bad write retry (_ssl.c:1636) Presumably this is generated by OpenSSL, but how do I figure out what it means? The best I found in the OpenSSL documentation is https://www.openssl.org/docs/crypto/err.html, and Google only found brought me to https://stackoverflow.com/questions/2997218. Best, -Nikolaus -- GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F ?Time flies like an arrow, fruit flies like a Banana.? From tjreedy at udel.edu Sun Sep 21 13:02:43 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 21 Sep 2014 13:02:43 -0400 Subject: Error from hg.python.org In-Reply-To: References: Message-ID: On 9/21/2014 9:28 AM, Mark Lawrence wrote: > I've noticed this a few times recently using the Sync command from > TortoiseHg on Windows 8.1. > > % hg pull --verbose --update --config ui.merge=internal:merge > http://hg.python.org/cpython > HTTP Error: 500 (Internal Server Error) > [command returned code 255 Sun Sep 21 14:22:52 2014] > > Is this related to an upgrade that has been done in the last few weeks > or is that a complete red herring? You might ask on the core-mentorship list. -- Terry Jan Reedy From geniusrko at gmail.com Sun Sep 21 22:00:24 2014 From: geniusrko at gmail.com (aws Al-Aisafa) Date: Sun, 21 Sep 2014 19:00:24 -0700 (PDT) Subject: pgs4a fails to build In-Reply-To: References: <9e5e6761-dcbf-47a7-b630-70e5c0018890@googlegroups.com> Message-ID: <3660b250-aa8a-42d2-9ac5-b4c660f9e0d8@googlegroups.com> Yes I've followed and installed everything From vek.m1234 at gmail.com Sun Sep 21 22:31:28 2014 From: vek.m1234 at gmail.com (vek.m1234 at gmail.com) Date: Sun, 21 Sep 2014 19:31:28 -0700 (PDT) Subject: SOAPpy: Expected to find node type 'Element' with name 'CountriesFetchingRequest'; Found node type 'Element' with name 'FetchCountries' Message-ID: <257bc927-4ada-4020-8b9c-7781d0802bbc@googlegroups.com> I'm messing with SOAP, trying to write a small library to handle stuff I buy from Aramex (shipper). I'm learning XML/SOAP and I'm familiar with RPC from C (Stevens) but no other relevant experience. If this is incredibly dumb just ignore it since I'll probably figure it out eventually. I'm trying to get a list of countries by calling the CoutriesFetchingRequest method - this is documented here: http://www.aramex.com/developers/aramex-apis/47442/Location-Services-API http://www.aramex.com/content/uploads/109/232/46790/aramex-location-api-manual.pdf It takes as its arguments a 'ClientInfo' data-structure and 'Code' which is a string. There is also a 'FetchCountries' method with an 'input' and 'output' something. However python was more clear, print server.show_methods(): Method Name: FetchCountries In #0: parameters ((u'http://ws.aramex.net/ShippingAPI/v1/', u'CountriesFetchingRequest')) The trouble is I don't understand how to call 'CoutriesFetchingRequest' or pass it to FetchCountries. Could someone clarify? The WSDL for Aramex has this: http://www.aramex.com/content/uploads/109/232/46790/location-api-wsdl.zip My python code: #!/usr/bin/python import xml, fpconst, logging from SOAPpy import WSDL from suds.client import Client logging.basicConfig(level=logging.INFO) logging.getLogger('suds.client').setLevel(logging.DEBUG) foo = { 'AccountCountryCode' : 'JO', 'AccountEntity' : 'AMM', 'AccountNumber' : '20016', 'AccountPin' : '331421', 'UserName' : 'testingxxx at aramex.com', 'Password' : 'R123456789$r', 'Version' : 'v1.0', 'Source' : '', 'Transaction' : { 'Reference1' : '001', 'Reference2' : '002', 'Reference3' : '003', 'Reference4' : '004', 'Reference5' : '005' } } wsdl_file = '/home/veek/location-api-wsdl/Location-API-WSDL.wsdl' server = WSDL.Proxy(wsdl_file) print server.methods.keys() print dir(server) print server.show_methods() callInfo = server.methods['FetchCountries'] print type(callInfo) print dir(callInfo) for arg in callInfo.inparams: print arg.name.ljust(15), arg.type server.namespace = 'http://ws.aramex.net/ShippingAPI/v1/' x = server.FetchCountries.CountriesFetchingRequest(foo) The output i get is: [u'FetchCountries', u'FetchCountry', u'ValidateAddress', u'FetchCities', u'FetchOffices'] ['__doc__', '__getattr__', '__init__', '__module__', '__str__', 'methods', 'show_methods', 'soapproxy', 'wsdl'] Method Name: FetchCountries In #0: parameters ((u'http://ws.aramex.net/ShippingAPI/v1/', u'CountriesFetchingRequest')) Out #0: parameters ((u'http://ws.aramex.net/ShippingAPI/v1/', u'CountriesFetchingResponse')) None ['__doc__', '__init__', '__module__', 'addInHeaderInfo', 'addInParameter', 'addOutHeaderInfo', 'addOutParameter', 'documentation', 'encodingStyle', 'getInHeaders', 'getInParameters', 'getOutHeaders', 'getOutParameters', 'getReturnParameter', 'inheaders', 'inparams', 'location', 'methodName', 'namespace', 'outheaders', 'outparams', 'retval', 'setReturnParameter', 'soapAction', 'style', 'transport', 'use'] parameters (u'http://ws.aramex.net/ShippingAPI/v1/', u'CountriesFetchingRequest') SOAPpy.Types.faultType: From bizcor at gmail.com Thu Sep 18 18:58:13 2014 From: bizcor at gmail.com (bizcor at gmail.com) Date: Thu, 18 Sep 2014 15:58:13 -0700 Subject: program to generate data helpful in finding duplicate large files In-Reply-To: References: Message-ID: thanks for the responses. i'm having quite a good time learning python. On Thu, Sep 18, 2014 at 11:45 AM, Chris Kaynor wrote: > > Additionally, you may want to specify binary mode by using open(file_path, > 'rb') to ensure platform-independence ('r' uses Universal newlines, which > means on Windows, Python will convert "\r\n" to "\n" while reading the > file). Additionally, some platforms will treat binary files differently. > would it be good to use 'rb' all the time? On Thu, Sep 18, 2014 at 11:48 AM, Chris Angelico wrote: > On Fri, Sep 19, 2014 at 4:11 AM, David Alban wrote: > > exit( 0 ) > > Unnecessary - if you omit this, you'll exit 0 implicitly at the end of > the script. > aha. i've been doing this for years even with perl, and apparently it's not necessary in perl either. i was influenced by shell. this shell code: * if [[ -n $report_mode ]] ; then* * do_report* * fi* * exit 0* is an example of why you want the last normally executed shell statement to be "exit 0". if you omit the exit statement it in this example, and $report_mode is not set, your shell program will give a non-zero return code and appear to have terminated with an error. in shell the last expression evaluated determines the return code to the os. ok, i don't need to do this in python. On Thu, Sep 18, 2014 at 1:23 PM, Peter Otten <__peter__ at web.de> wrote: > > file_path may contain newlines, therefore you should probably use "\0" to > separate the records. i chose to stick with ascii nul as the default field separator, but i added a --field-separator option in case someone wants human readable output. style question: if there is only one, possibly short statement in a block, do folks usually move it up to the line starting the block? *if not S_ISREG( mode ) or S_ISLNK( mode ):* * return* vs. *if not S_ISREG( mode ) or S_ISLNK( mode ): return* or even: *with open( file_path, 'rb' ) as f: md5sum = md5_for_file( file_path )* fyi, here are my changes: *usage: dupscan [-h] [--start-directory START_DIRECTORY]* * [--field-separator FIELD_SEPARATOR]* *scan files in a tree and print a line of information about each regular file* *optional arguments:* * -h, --help show this help message and exit* * --start-directory START_DIRECTORY, -d START_DIRECTORY* * Specify the root of the filesystem tree to be* * processed. The default is '.'* * --field-separator FIELD_SEPARATOR, -s FIELD_SEPARATOR* * Specify the string to use as a field separator in* * output. The default is the ascii nul character.* *#!/usr/bin/python* *import argparse* *import hashlib* *import os* *from platform import node* *from stat import S_ISREG, S_ISLNK* *ASCII_NUL = chr(0)* * # from: http://stackoverflow.com/questions/1131220/get-md5-hash-of-big-files-in-python * * # except that i use hexdigest() rather than digest()* *def md5_for_file( path, block_size=2**20 ):* * md5 = hashlib.md5()* * with open( path, 'rb' ) as f:* * while True:* * data = f.read(block_size)* * if not data:* * break* * md5.update(data)* * return md5.hexdigest()* *def file_info( directory, basename, field_separator=ASCII_NUL ):* * file_path = os.path.join( directory, basename )* * st = os.lstat( file_path )* * mode = st.st_mode* * if not S_ISREG( mode ) or S_ISLNK( mode ): * * return* * with open( file_path, 'rb' ) as f:* * md5sum = md5_for_file( file_path )* * return field_separator.join( [ thishost, md5sum, str( st.st_dev ), str( st.st_ino ), str( st.st_nlink ), str( st.st_size ), file_path ] )* *if __name__ == "__main__":* * parser = argparse.ArgumentParser(description='scan files in a tree and print a line of information about each regular file')* * parser.add_argument('--start-directory', '-d', default='.', help='''Specify the root of the filesystem tree to be processed. The default is '.' ''')* * parser.add_argument('--field-separator', '-s', default=ASCII_NUL, help='Specify the string to use as a field separator in output. The default is the ascii nul character.')* * args = parser.parse_args()* * start_directory = args.start_directory.rstrip('/')* * field_separator = args.field_separator* * thishost = node()* * if thishost == '':* * thishost='[UNKNOWN]'* * for directory_path, directory_names, file_names in os.walk( start_directory ):* * for file_name in file_names:* * print file_info( directory_path, file_name, field_separator )* -- Live in a world of your own, but always welcome visitors. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dieter at handshake.de Mon Sep 22 02:46:32 2014 From: dieter at handshake.de (dieter) Date: Mon, 22 Sep 2014 08:46:32 +0200 Subject: ssl.SSLError: [SSL: BAD_WRITE_RETRY] bad write retry (_ssl.c:1636) References: <87r3z5m0u8.fsf@vostro.rath.org> Message-ID: <8761ggtanr.fsf@handshake.de> Nikolaus Rath writes: > Can someone explain help me understand what this exception means? > > [...] > File "/usr/local/lib/python3.4/dist-packages/dugong-3.2-py3.4.egg/dugong/__init__.py", line 584, in _co_send > len_ = self._sock.send(buf) > File "/usr/lib/python3.4/ssl.py", line 679, in send > v = self._sslobj.write(data) > ssl.SSLError: [SSL: BAD_WRITE_RETRY] bad write retry (_ssl.c:1636) > > Presumably this is generated by OpenSSL, but how do I figure out what it > means? The best I found in the OpenSSL documentation is > https://www.openssl.org/docs/crypto/err.html, and Google only found > brought me to https://stackoverflow.com/questions/2997218. I would first look at the source: "_ssl.c" (source of the Python module interfacing with OpenSSL) near line 1636. Likely, this only reports a problem reported by "OpenSSL". Next step would then be to look at the "OpenSSL" documentation or source to find out what the error reported by "OpenSSL" means. From dieter at handshake.de Mon Sep 22 02:53:51 2014 From: dieter at handshake.de (dieter) Date: Mon, 22 Sep 2014 08:53:51 +0200 Subject: SOAPpy: Expected to find node type 'Element' with name 'CountriesFetchingRequest'; Found node type 'Element' with name 'FetchCountries' References: <257bc927-4ada-4020-8b9c-7781d0802bbc@googlegroups.com> Message-ID: <871tr4tabk.fsf@handshake.de> vek.m1234 at gmail.com writes: > I'm messing with SOAP, trying to write a small library to handle stuff I buy from Aramex (shipper). I'm learning XML/SOAP and I'm familiar with RPC from C (Stevens) but no other relevant experience. If this is incredibly dumb just ignore it since I'll probably figure it out eventually. > ... > The trouble is I don't understand how to call 'CoutriesFetchingRequest' or pass it to FetchCountries. Could someone clarify? I have no experience with "SOAPpy", but with "suds" (another Python SAOP client). A "suds" client exposes two attributes "factory" and "service". You use the "factory" to create Python objects for types defined by the WSDL; you then set their attributes with standard Python means (maybe involving other "factory" calls). Finally you call the methods via the "service" attribute passing arguments of the appropiate type in the normal Python way. I suppose, it is similar with "SOAPpy". Looking at its documentation and/or its examples may provide you with the necessary details. Otherwise, you could also use "suds". From ngangsia at gmail.com Mon Sep 22 04:09:41 2014 From: ngangsia at gmail.com (ngangsia akumbo) Date: Mon, 22 Sep 2014 01:09:41 -0700 (PDT) Subject: Python advice Message-ID: <9b76b07d-db88-4e08-9abe-10df1ac9953e@googlegroups.com> I have learned python for some time now. I am developing apps using django. I need some advice. I want to be able to write big programs using python. I have not been able to do that as of now. I need a way forward on what more free ebooks i can get mt hands on so i can accomplish my goals. I need some advice. should i go on to learn other languages like java or c++ cos i want to be able to using all these knowledge for games, desktop, mobile and web. i start learning java and i seem it is more real life. it looks real that python. any advice From ngangsia at gmail.com Mon Sep 22 04:14:40 2014 From: ngangsia at gmail.com (ngangsia akumbo) Date: Mon, 22 Sep 2014 01:14:40 -0700 (PDT) Subject: Python advice In-Reply-To: <9b76b07d-db88-4e08-9abe-10df1ac9953e@googlegroups.com> References: <9b76b07d-db88-4e08-9abe-10df1ac9953e@googlegroups.com> Message-ID: <420ceb53-761f-41fe-bc92-5d0cbea6fb6a@googlegroups.com> PRESENTLY I AM READING A BOOK MASTERING PYTHON ALGORITHMS. IT MAKES MUCH SENSE From vek.m1234 at gmail.com Mon Sep 22 05:00:58 2014 From: vek.m1234 at gmail.com (vek.m1234 at gmail.com) Date: Mon, 22 Sep 2014 02:00:58 -0700 (PDT) Subject: Love to get some feedback on my first python app!!! In-Reply-To: References: <42e68de9-7528-46fc-8c74-c0baa1d6199e@googlegroups.com> Message-ID: <9bed8e07-9e22-4131-92e8-f950cb5c0d18@googlegroups.com> One thing I noticed with that code was the size of your function, and excessive comments. It reminds me of my bubble_sort.c program in school/college - everything plonked into 'main'. Try writing it like this: 1. #!/usr/bin/python or #!/usr/bin/env python The leading #! is read by the kernel when it has to start the interpreter (exec), so don't stick your comment in there. 2. Try to align the imports so they look pretty 3. Don't use whacking big functions and then stick endless explanatory comments Use the function name as a comment instead - divide your program up into little tasks. Try to make the stuff generic - def url_extract(content, pattern): def extract_url def extract_title def tk_init Use #------------------------------------------------------------------- to demarcate sections, very common functions go into a utility-library, not so common functions at the section at start of the file, and so on.. 4. Don't skimp on the sys.exit() or def debug (which should be in your utilities lib) 5. Don't do :x = foo('.................................') instead: var_name = '..........................' # make it global x = foo(var_name) 6. To build a string do: param1 = xyz1 + xyz2 x = foo(param1) From vek.m1234 at gmail.com Mon Sep 22 05:10:10 2014 From: vek.m1234 at gmail.com (vek.m1234 at gmail.com) Date: Mon, 22 Sep 2014 02:10:10 -0700 (PDT) Subject: Python advice In-Reply-To: <420ceb53-761f-41fe-bc92-5d0cbea6fb6a@googlegroups.com> References: <9b76b07d-db88-4e08-9abe-10df1ac9953e@googlegroups.com> <420ceb53-761f-41fe-bc92-5d0cbea6fb6a@googlegroups.com> Message-ID: <065fb41c-8398-461d-b71f-103824160c7d@googlegroups.com> 1. Python Essential Reference, Python Standard Library by Example/Dive into Python 2. C (K.N.King), C++(Eckel), Python, Make, GCC, Lex/Yacc/Bison, Some HTML/CSS/XML/Javascript/XLTS+Python 3. I don't like Java much - never tried it. From rosuav at gmail.com Mon Sep 22 05:23:15 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 22 Sep 2014 19:23:15 +1000 Subject: Love to get some feedback on my first python app!!! In-Reply-To: <9bed8e07-9e22-4131-92e8-f950cb5c0d18@googlegroups.com> References: <42e68de9-7528-46fc-8c74-c0baa1d6199e@googlegroups.com> <9bed8e07-9e22-4131-92e8-f950cb5c0d18@googlegroups.com> Message-ID: On Mon, Sep 22, 2014 at 7:00 PM, wrote: > One thing I noticed with that code was the size of your function, and excessive comments. It reminds me of my bubble_sort.c program in school/college - everything plonked into 'main'. > > Try writing it like this: I'd like to see justifications for some of the advice you're giving here. Quite a bit of it I disagree with :) > 1. #!/usr/bin/python or #!/usr/bin/env python > > The leading #! is read by the kernel when it has to start the interpreter (exec), so don't stick your comment in there. Very much optional. Even on Unix systems, it's not necessary unless you want it to be executable. > 2. Try to align the imports so they look pretty You mean adding extra spaces? Not advised. Or something else? Definitely needs more explanation (maybe an example) and justification (why do it?). > 3. Don't use whacking big functions and then stick endless explanatory comments > Use the function name as a comment instead - divide your program up into little tasks. Try to make the stuff generic - def url_extract(content, pattern): > > def extract_url > > def extract_title > > def tk_init > > Use > #------------------------------------------------------------------- > to demarcate sections, very common functions go into a utility-library, > not so common functions at the section at start of the file, and so on.. If functions are defined and then called from exactly one place, there's no need to put them anywhere else. Just inline them. It's not as if the indentation is getting out of hand here - getinfo() tops out at just three tabs in, which is nothing. I've gone to seven a number of times, and there's one particular piece of code I have that goes as far as nine - though that's not something I'd recommend! Different people will put the limit at different points, but three is never going to be excessive. (Cue someone pointing out to me a situation in which three really is excessive, but sure, that'll be a fun spin-off thread.) > 4. Don't skimp on the sys.exit() or def debug (which should be in your utilities lib) More explanation needed, please. What are you trying to do here? What would be different? > 5. Don't do :x = foo('.................................') > instead: > var_name = '..........................' # make it global > x = foo(var_name) Uhhh, why??!? > 6. To build a string do: > > param1 = xyz1 + xyz2 > x = foo(param1) Ditto. Why?!? ChrisA From breamoreboy at yahoo.co.uk Mon Sep 22 05:55:39 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 22 Sep 2014 10:55:39 +0100 Subject: pgs4a fails to build In-Reply-To: <3660b250-aa8a-42d2-9ac5-b4c660f9e0d8@googlegroups.com> References: <9e5e6761-dcbf-47a7-b630-70e5c0018890@googlegroups.com> <3660b250-aa8a-42d2-9ac5-b4c660f9e0d8@googlegroups.com> Message-ID: On 22/09/2014 03:00, aws Al-Aisafa wrote: > Yes I've followed and installed everything > Please provide some context when you reply and to whom you are replying, thank you. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From narayannaik.05 at gmail.com Mon Sep 22 05:59:58 2014 From: narayannaik.05 at gmail.com (narayan naik) Date: Mon, 22 Sep 2014 15:29:58 +0530 Subject: face detection Message-ID: good evening sir, I am doing my M.Tech project on face detection,I am confused with the face detection algorithm,can you please tell me the simple and best algorithm. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Mon Sep 22 07:37:41 2014 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 22 Sep 2014 13:37:41 +0200 (CEST) Subject: Class Inheritance from different module In-Reply-To: Message-ID: <1708546287.7032216.1411385861221.JavaMail.root@sequans.com> > class User(Inheritance from API): > def __init__(self, ID): > steamapi.core.APIConnection(api_key = KEY) > super( " Inheritance SteamUser" (ID)) # creates the user using the > API > > > [...] > > > So that in my code when I need to create a new user, I just call 'usr > = User("XXXXXXX")' instead of calling 'usr = > steamapi.user.SteamUser(76561197996416028)', is that possible? [snip -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From nicholascannon1 at gmail.com Mon Sep 22 07:43:51 2014 From: nicholascannon1 at gmail.com (Nicholas Cannon) Date: Mon, 22 Sep 2014 04:43:51 -0700 (PDT) Subject: How to not enable a user to close the root tkinter window Message-ID: <6dffdfb3-82b3-4746-8f39-d6bfa727f439@googlegroups.com> I have a project I am working on(https://github.com/nicodasiko/Article-Grab) which grabs info from the internet then displays it on the screen. It is a multithreaded program so as the function that retrieves the data from the internet there is also another function running in parallel which updates a ttk loading bar. Pretty simple multi threaded stuff. But I found out that the user can close the window whilst the threads are running which generates an error and is not healthy. Is there a way I can make the root tkinter window not close whilst the threads are running. I did this with the search bar and search button. Or can I safely stop the running threads and make them drop everything error free? Any help will be apreciated! From vek.m1234 at gmail.com Mon Sep 22 07:47:44 2014 From: vek.m1234 at gmail.com (vek.m1234 at gmail.com) Date: Mon, 22 Sep 2014 04:47:44 -0700 (PDT) Subject: Love to get some feedback on my first python app!!! In-Reply-To: References: <42e68de9-7528-46fc-8c74-c0baa1d6199e@googlegroups.com> <9bed8e07-9e22-4131-92e8-f950cb5c0d18@googlegroups.com> Message-ID: 1. It's feedback not a mathematical proof. 2. I hope the OP tries what I suggested - it's all entirely optional. @OP I have no idea what that program does because it's well commented. You aren't using variable and function names to good effect and are resorting to excessive comments. Additionally, I think you are mangling your display text but I'm not sure. textDisplay.insert should be a function that you pass args to. def spit_msg(text): textDisplay.insert(text) spit_msg("go away doo doo bird") Any time you see repeated text in your program, wrap it in a single func and simplify. try: def create_root_window(): rather than letting all your funny parts dangle around naked. From rosuav at gmail.com Mon Sep 22 07:56:37 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 22 Sep 2014 21:56:37 +1000 Subject: How to not enable a user to close the root tkinter window In-Reply-To: <6dffdfb3-82b3-4746-8f39-d6bfa727f439@googlegroups.com> References: <6dffdfb3-82b3-4746-8f39-d6bfa727f439@googlegroups.com> Message-ID: On Mon, Sep 22, 2014 at 9:43 PM, Nicholas Cannon wrote: > Or can I safely stop the running threads and make them drop everything error free? This would be what I'd recommend. If someone wants to close your program, s/he should be allowed to - imagine if internet traffic is costly [1] and the query was done accidentally. So what you need is to have the shutdown divided into three steps: 1) Close the window, or at least show visually that it's shutting down. 2) Send a signal to the worker threads 3) When the worker threads all shut down, terminate the program. You can handle step 3 simply by ensuring that the threads aren't marked as daemons. Python won't shut down until they're all gone. Step 1 is, I suspect, already happening. So all you need to do is message the worker thread - and that can be done simply by setting a global variable or something. However, I'm not seeing any use of threads in your code. What thread is being cut off? What's the error you're seeing? ChrisA [1] "costly" might not mean money, although it can. But imagine you're on a slow connection and you can't afford to have other programs lagging out something that's important. From vek.m1234 at gmail.com Mon Sep 22 08:00:53 2014 From: vek.m1234 at gmail.com (vek.m1234 at gmail.com) Date: Mon, 22 Sep 2014 05:00:53 -0700 (PDT) Subject: Love to get some feedback on my first python app!!! In-Reply-To: <42e68de9-7528-46fc-8c74-c0baa1d6199e@googlegroups.com> References: <42e68de9-7528-46fc-8c74-c0baa1d6199e@googlegroups.com> Message-ID: <4e75613a-706a-4441-b94a-49dbedf3df28@googlegroups.com> https://github.com/Veek/Python/blob/master/IRC/Hexchat/fake_ctcp.py that's not too bad as far as readability is concerned and it's bereft of all comments {:p From rosuav at gmail.com Mon Sep 22 08:09:04 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 22 Sep 2014 22:09:04 +1000 Subject: Love to get some feedback on my first python app!!! In-Reply-To: References: <42e68de9-7528-46fc-8c74-c0baa1d6199e@googlegroups.com> <9bed8e07-9e22-4131-92e8-f950cb5c0d18@googlegroups.com> Message-ID: On Mon, Sep 22, 2014 at 9:47 PM, wrote: > 1. It's feedback not a mathematical proof. > 2. I hope the OP tries what I suggested - it's all entirely optional. Doesn't change the fact that you need to justify your recommendations, at least when they're not obvious. You're suggesting a number of things which are definitely not the same as I'd recommend, and I can't evaluate them because you haven't explained *why* you give that advice. > @OP > I have no idea what that program does because it's well commented. You aren't using variable and function names to good effect and are resorting to excessive comments. Comments are not bad. His variable names aren't nearly as bad as you imply. I can read the code *just fine*. Either you're exaggerating, or you're trolling, or you're extremely dim. I'm not sure which. > Additionally, I think you are mangling your display text but I'm not sure. > textDisplay.insert should be a function that you pass args to. > > def spit_msg(text): > textDisplay.insert(text) > > spit_msg("go away doo doo bird") > > Any time you see repeated text in your program, wrap it in a single func and simplify. Not every one-liner needs to be a function. Not all repeated text needs to be wrapped up. You can always add another level of indirection, and it's frequently not necessary. > try: > def create_root_window(): > rather than letting all your funny parts dangle around naked. This seems incomplete. What's this try block for? What's the function for? Will it be called from more than one place? If not, why wrap it up? Again, you need to explain *why* something needs to be changed. Telling someone "do this, this, this, and this" is almost completely useless, because it doesn't teach any better programming practices - in fact, it may teach a black-box programming style that's good only for novices (like saying "always put 'from __future__ import print_function' at the top of your Python files", which might be a perfectly good thing to do, but at some point you need to explain why). Also, you're posting on a mailing list and newsgroup. Please include context in your posts so we know what you're talking about. ChrisA From jeanmichel at sequans.com Mon Sep 22 08:09:33 2014 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 22 Sep 2014 14:09:33 +0200 (CEST) Subject: Class Inheritance from different module In-Reply-To: <1708546287.7032216.1411385861221.JavaMail.root@sequans.com> Message-ID: <1324132767.7034754.1411387773293.JavaMail.root@sequans.com> ----- Original Message ----- > From: "Jean-Michel Pichavant" > To: "Juan Christian" > Cc: "Python" > Sent: Monday, 22 September, 2014 1:37:41 PM > Subject: Re: Class Inheritance from different module > > > > class User(Inheritance from API): > > def __init__(self, ID): > > steamapi.core.APIConnection(api_key = KEY) > > super( " Inheritance SteamUser" (ID)) # creates the user using the > > API > > > > > > [...] > > > > > > So that in my code when I need to create a new user, I just call > > 'usr > > = User("XXXXXXX")' instead of calling 'usr = > > steamapi.user.SteamUser(76561197996416028)', is that possible? > [snip Sorry, sent the message by mistake. Anyway if you just want a nice way to create an instance, you may simply write import steamapi.user.SteamUser as User usr = User('whatever') However you don't create an APIConnection when creating a user, it does not make much sense, you only need one API connection per session and it will be shared by all the User objects. # Note ApiConnection is a singleton, and you only need to execute this once, in you app/script initialization for instance. api = APIConnection(api_key='dlkfnsdlfn') # query the database user1 = User('user1') user2 = User('user2') Cheers, JM NB: I assumed you were using https://github.com/smiley/steamapi NB2 : because APIConnection is a singleton, your original code probably works just fine, I'm just not a big fan of breaking to python module design -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From rosuav at gmail.com Mon Sep 22 08:23:00 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 22 Sep 2014 22:23:00 +1000 Subject: Love to get some feedback on my first python app!!! In-Reply-To: <4e75613a-706a-4441-b94a-49dbedf3df28@googlegroups.com> References: <42e68de9-7528-46fc-8c74-c0baa1d6199e@googlegroups.com> <4e75613a-706a-4441-b94a-49dbedf3df28@googlegroups.com> Message-ID: On Mon, Sep 22, 2014 at 10:00 PM, wrote: > https://github.com/Veek/Python/blob/master/IRC/Hexchat/fake_ctcp.py > that's not too bad as far as readability is concerned and it's bereft of all comments {:p Sure, I can work out what it's doing without comments. Doesn't mean comments are bad, though. Also, without comments, I have no idea *why* it's doing what it does. For instance, this: > def debug(msg): > hexchat.prnt('{}'.format(msg)) Why not just do this: debug = hexchat.prnt Or, better still, just use hexchat.prnt() everywhere, instead of having a local name? (You happily use hexchat.* in other places.) Is it meant to be monkey-patched externally? Is it meant to be a one-place edit? What's the purpose of this one-line function? > date = str(date_s) + ' ' + str(hour) + ':' + str(min) + ':' + str(sec) You use .format() in places where it's completely unnecessary, but eschew it when it would make your code more readable. date = "%s %s:%s:%s" % (date_s, hour, min, sec) date = "{} {}:{}:{}".format(date_s, hour, min, sec) So, comments would definitely help. In some cases, would help a lot. ChrisA From larry.martell at gmail.com Mon Sep 22 09:02:43 2014 From: larry.martell at gmail.com (Larry Martell) Date: Mon, 22 Sep 2014 09:02:43 -0400 Subject: Love to get some feedback on my first python app!!! In-Reply-To: References: <42e68de9-7528-46fc-8c74-c0baa1d6199e@googlegroups.com> <4e75613a-706a-4441-b94a-49dbedf3df28@googlegroups.com> Message-ID: On Mon, Sep 22, 2014 at 8:23 AM, Chris Angelico wrote: > So, comments would definitely help. In some cases, would help a lot. This is me: http://xkcd.com/1421/ From nicholascannon1 at gmail.com Mon Sep 22 09:17:10 2014 From: nicholascannon1 at gmail.com (Nicholas Cannon) Date: Mon, 22 Sep 2014 06:17:10 -0700 (PDT) Subject: Love to get some feedback on my first python app!!! In-Reply-To: <42e68de9-7528-46fc-8c74-c0baa1d6199e@googlegroups.com> References: <42e68de9-7528-46fc-8c74-c0baa1d6199e@googlegroups.com> Message-ID: Ok I'm confused. Do I need to do better comments? I know the text is not that great but that is my next obstacle I am going to tackle. I mostly need to know where I am going wrong such as what is expectable readable code and what is not and how to fix this. This is good feedback thanks to all of you guys. All I want to do is learn and become better and neater! From nicholascannon1 at gmail.com Mon Sep 22 09:19:10 2014 From: nicholascannon1 at gmail.com (Nicholas Cannon) Date: Mon, 22 Sep 2014 06:19:10 -0700 (PDT) Subject: Love to get some feedback on my first python app!!! In-Reply-To: <42e68de9-7528-46fc-8c74-c0baa1d6199e@googlegroups.com> References: <42e68de9-7528-46fc-8c74-c0baa1d6199e@googlegroups.com> Message-ID: Also I have just been coding for about and hour and a half and added a lot more code to it but it is not fully finished yet so it is not on github yet. From rosuav at gmail.com Mon Sep 22 09:21:10 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 22 Sep 2014 23:21:10 +1000 Subject: Love to get some feedback on my first python app!!! In-Reply-To: References: <42e68de9-7528-46fc-8c74-c0baa1d6199e@googlegroups.com> <4e75613a-706a-4441-b94a-49dbedf3df28@googlegroups.com> Message-ID: On Mon, Sep 22, 2014 at 11:02 PM, Larry Martell wrote: > On Mon, Sep 22, 2014 at 8:23 AM, Chris Angelico wrote: >> So, comments would definitely help. In some cases, would help a lot. > > This is me: > > http://xkcd.com/1421/ Also me. I have apologized to my future selves on a number of occasions. And of course, very VERY frequently, I have answered my future selves' questions. That, I think, is the primary purpose of code comments. It's a kind of limited-range time travel: I can travel back in time, ask myself a question, and get an answer. ChrisA From rosuav at gmail.com Mon Sep 22 09:28:48 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 22 Sep 2014 23:28:48 +1000 Subject: Love to get some feedback on my first python app!!! In-Reply-To: References: <42e68de9-7528-46fc-8c74-c0baa1d6199e@googlegroups.com> Message-ID: On Mon, Sep 22, 2014 at 11:17 PM, Nicholas Cannon wrote: > Ok I'm confused. Do I need to do better comments? I know the text is not that great but that is my next obstacle I am going to tackle. I mostly need to know where I am going wrong such as what is expectable readable code and what is not and how to fix this. This is good feedback thanks to all of you guys. All I want to do is learn and become better and neater! > Your comments aren't terrible. Just imagine yourself reading this code six months from now, having not touched it in between, and imagine all the questions you'd ask yourself. Then answer them. Conversely, if something would be patently obvious to your future self, don't bother commenting it. Have a read of some of the tips here. You may find them helpful. http://www.catb.org/esr/faqs/hacker-howto.html ChrisA From vek.m1234 at gmail.com Mon Sep 22 09:35:51 2014 From: vek.m1234 at gmail.com (vek.m1234 at gmail.com) Date: Mon, 22 Sep 2014 06:35:51 -0700 (PDT) Subject: Love to get some feedback on my first python app!!! In-Reply-To: References: <42e68de9-7528-46fc-8c74-c0baa1d6199e@googlegroups.com> <9bed8e07-9e22-4131-92e8-f950cb5c0d18@googlegroups.com> Message-ID: @Chris, Hi, I don't like your style of posting - please kill file me. @Everybody else - I don't like Chris and his style of posting (overuse of the 'troll' word and perceived aggression). I shall be ignoring him for a year (barring an emergency). Good communication demands that I announce this. Please don't misconstrue this as rudeness on my part. If you feel that he is asking something of pertinence, feel free to include it in your posts for a reply. From illusiontechniques at gmail.com Mon Sep 22 09:48:43 2014 From: illusiontechniques at gmail.com (C Smith) Date: Mon, 22 Sep 2014 06:48:43 -0700 Subject: Love to get some feedback on my first python app!!! In-Reply-To: References: <42e68de9-7528-46fc-8c74-c0baa1d6199e@googlegroups.com> <9bed8e07-9e22-4131-92e8-f950cb5c0d18@googlegroups.com> Message-ID: I wouldn't take it personally, just defend your position. I think that is what he is looking for. We are all adults here (maybe?). You guys should be able to work it out. A tangential skill to programming is being able to give and take criticism well, even if you think it crosses the line. On Mon, Sep 22, 2014 at 6:35 AM, wrote: > @Chris, Hi, I don't like your style of posting - please kill file me. > > @Everybody else - I don't like Chris and his style of posting (overuse of the 'troll' word and perceived aggression). I shall be ignoring him for a year (barring an emergency). Good communication demands that I announce this. Please don't misconstrue this as rudeness on my part. If you feel that he is asking something of pertinence, feel free to include it in your posts for a reply. > -- > https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Mon Sep 22 09:57:33 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 22 Sep 2014 23:57:33 +1000 Subject: Love to get some feedback on my first python app!!! In-Reply-To: References: <42e68de9-7528-46fc-8c74-c0baa1d6199e@googlegroups.com> <9bed8e07-9e22-4131-92e8-f950cb5c0d18@googlegroups.com> Message-ID: On Mon, Sep 22, 2014 at 11:48 PM, C Smith wrote: > I wouldn't take it personally, just defend your position. I think that > is what he is looking for. We are all adults here (maybe?). You guys > should be able to work it out. A tangential skill to programming is > being able to give and take criticism well, even if you think it > crosses the line. Precisely. Asking for justification isn't meant to imply that there is none. But it's like back in my high school maths lessons: if you don't show your working, there's no way to discuss the details, and if the conclusion is wrong (or in this case, is disagreed with), you can't do anything with it. With the intermediate steps given, we can discuss, explain, and maybe find that we mostly agree. ChrisA From larry at hastings.org Mon Sep 22 10:15:51 2014 From: larry at hastings.org (Larry Hastings) Date: Mon, 22 Sep 2014 15:15:51 +0100 Subject: [RELEASE] Python 3.4.2rc1 is now available Message-ID: <54202F17.3010008@hastings.org> On behalf of the Python development community and the Python 3.4 release team, I'm chuffed to announce the availability of Python 3.4.2rc1. Python 3.4.2 has many bugfixes and other small improvements over 3.4.1. One new feature for Mac OS X users: the OS X installers are now distributed as signed installer package files compatible with the OS X Gatekeeper security feature. You can download it here: https://www.python.org/download/releases/3.4.2 Be seeing you, //arry/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Mon Sep 22 10:32:27 2014 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 22 Sep 2014 16:32:27 +0200 (CEST) Subject: Love to get some feedback on my first python app!!! In-Reply-To: Message-ID: <1875566412.7055487.1411396347279.JavaMail.root@sequans.com> ----- Original Message ----- > From: "Chris Angelico" > Cc: python-list at python.org > Sent: Saturday, 20 September, 2014 4:58:44 PM > Subject: Re: Love to get some feedback on my first python app!!! [snip] > > #search API > rawData = > urllib.urlopen('http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q='+encodedQuery).read() > #loads data from API into json > jsonData = json.loads(rawData) > #extracts the results from API > searchResults = jsonData['responseData']['results'] > > The more normal way to write these would be in present tense, in a > more imperative style: "Fix some bugs", "Load data", "Extract > results". (Although these comments are actually quite redundant - all > they do is tell you what the single next line of code does.) I used to belong to the cult "don't repeat yourself" in the comments, being angry against people who thought I couldn't understand by myself the simplest line of code. But I changed my mind. I've read some code comments over the years and best ones (imo) where those which where actually repeating themselves. Golden rules of comments: # state what you plan to do doIt() For instance: cells = ['a', 'b' 'c'] # print the first cell print cell[1] A bug that is easily spotted thanks to the comment. It's all about implementation versus intentions. Also note that comment should be written for the future self, and most importantly, for the current others. JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From joel.goldstick at gmail.com Mon Sep 22 10:45:32 2014 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Mon, 22 Sep 2014 10:45:32 -0400 Subject: Love to get some feedback on my first python app!!! In-Reply-To: <1875566412.7055487.1411396347279.JavaMail.root@sequans.com> References: <1875566412.7055487.1411396347279.JavaMail.root@sequans.com> Message-ID: On Mon, Sep 22, 2014 at 10:32 AM, Jean-Michel Pichavant wrote: > ----- Original Message ----- >> From: "Chris Angelico" >> Cc: python-list at python.org >> Sent: Saturday, 20 September, 2014 4:58:44 PM >> Subject: Re: Love to get some feedback on my first python app!!! > [snip] >> >> #search API >> rawData = >> urllib.urlopen('http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q='+encodedQuery).read() >> #loads data from API into json >> jsonData = json.loads(rawData) >> #extracts the results from API >> searchResults = jsonData['responseData']['results'] >> >> The more normal way to write these would be in present tense, in a >> more imperative style: "Fix some bugs", "Load data", "Extract >> results". (Although these comments are actually quite redundant - all >> they do is tell you what the single next line of code does.) > > I used to belong to the cult "don't repeat yourself" in the comments, being angry against people who thought I couldn't understand by myself the simplest line of code. > > But I changed my mind. I've read some code comments over the years and best ones (imo) where those which where actually repeating themselves. > Golden rules of comments: > > # state what you plan to do > doIt() > > For instance: > > cells = ['a', 'b' 'c'] > # print the first cell > print cell[1] > > A bug that is easily spotted thanks to the comment. It's all about implementation versus intentions. Also note that comment should be written for the future self, and most importantly, for the current others. > > JM > Docstrings -- look them up. Then you can run pydocs (and help!) on your code and see excellent documentation I would break up the big function into a few smaller ones that are easier to describe. Unless there is something very weird in the code, I don't think #inline comments saying the obvious are useful, but a summary at the top of the module, function, class, etc. is important -- Joel Goldstick http://joelgoldstick.com From rosuav at gmail.com Mon Sep 22 10:50:15 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 23 Sep 2014 00:50:15 +1000 Subject: Love to get some feedback on my first python app!!! In-Reply-To: <1875566412.7055487.1411396347279.JavaMail.root@sequans.com> References: <1875566412.7055487.1411396347279.JavaMail.root@sequans.com> Message-ID: On Tue, Sep 23, 2014 at 12:32 AM, Jean-Michel Pichavant wrote: > For instance: > > cells = ['a', 'b' 'c'] > # print the first cell > print cell[1] > > A bug that is easily spotted thanks to the comment. It's all about implementation versus intentions. Also note that comment should be written for the future self, and most importantly, for the current others. I do see your point, but there's a serious problem here of code edits. It's really easy to zip through and find all occurrences of some name and change them - and miss the one in the comment. In this particular case, I'm not actually sure where the bug is: is it in the first line (should be "cell = ...") or the third ("print cells[1]")? Either way, the comment doesn't make it any clearer, because the plural rule in English doesn't always match naming of variables. Also, it's common in English to count from 1, but in code to count from 0; so there's another bug (and this might be the one you thought easily spotted) - it should either be "cell[0]" in the third line, or "print the 1th cell" in the second. (Plus, there's a comma omitted. That list has two elements, but I think it's meant to have three. However, I'm guessing that's a transcription error, or a construction-in-email error, and nothing to do with what you're saying.) Now, compare this similar code: cells = ['Chris Angelico', 'rosuav at gmail.com', 142857] # print the email address print(cells[2]) This says *why* it's doing what it does - what the meaning of the index is. And it, too, has a clearly visible bug, because when it prints out an integer, the comment makes it obvious that it's done the wrong thing. This is, IMO, much more useful. If the code gets edited (maybe the name used to be in two fields for First Name and Last Name, and then someone realized how bad an idea that is - but forgot to update the index), the original intention is visible; if it just says "print out cell #2", it's not so helpful. So basically, don't *purely* repeat yourself, but give some info that's a level behind the code. ChrisA From victor.stinner at gmail.com Mon Sep 22 10:58:50 2014 From: victor.stinner at gmail.com (Victor Stinner) Date: Mon, 22 Sep 2014 16:58:50 +0200 Subject: [python-committers] [RELEASE] Python 3.4.2rc1 is now available In-Reply-To: <54202F17.3010008@hastings.org> References: <54202F17.3010008@hastings.org> Message-ID: Someone broke test_pydoc. Example: http://buildbot.python.org/all/builders/AMD64%20FreeBSD%2010.0%203.4/builds/481/steps/test/logs/stdio Victor 2014-09-22 16:15 GMT+02:00 Larry Hastings : > > > On behalf of the Python development community and the Python 3.4 release > team, I'm chuffed to announce the availability of Python 3.4.2rc1. Python > 3.4.2 has many bugfixes and other small improvements over 3.4.1. One new > feature for Mac OS X users: the OS X installers are now distributed as > signed installer package files compatible with the OS X Gatekeeper security > feature. > > You can download it here: > > https://www.python.org/download/releases/3.4.2 > > > Be seeing you, > > > /arry > > _______________________________________________ > python-committers mailing list > python-committers at python.org > https://mail.python.org/mailman/listinfo/python-committers > From vek.m1234 at gmail.com Mon Sep 22 11:12:12 2014 From: vek.m1234 at gmail.com (vek.m1234 at gmail.com) Date: Mon, 22 Sep 2014 08:12:12 -0700 (PDT) Subject: Love to get some feedback on my first python app!!! In-Reply-To: References: <42e68de9-7528-46fc-8c74-c0baa1d6199e@googlegroups.com> <9bed8e07-9e22-4131-92e8-f950cb5c0d18@googlegroups.com> Message-ID: @CSmith Hi, I'm sorry, I wish I could acquiesce but I think it's better for me to stay clear. There's criticism, and there's name calling ('dim' 'troll'). Reiterating what I said earlier, if the OP wants clarification he can ask for it. From alister.nospam.ware at ntlworld.com Mon Sep 22 11:23:55 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Mon, 22 Sep 2014 15:23:55 GMT Subject: Love to get some feedback on my first python app!!! References: Message-ID: On Mon, 22 Sep 2014 16:32:27 +0200, Jean-Michel Pichavant wrote: > ----- Original Message ----- >> From: "Chris Angelico" >> Cc: python-list at python.org Sent: Saturday, 20 September, 2014 4:58:44 >> PM Subject: Re: Love to get some feedback on my first python app!!! > [snip] >> >> #search API rawData = >> urllib.urlopen('http://ajax.googleapis.com/ajax/services/search/ web?v=1.0&q='+encodedQuery).read() >> #loads data from API into json jsonData = json.loads(rawData) >> #extracts the results from API searchResults = >> jsonData['responseData']['results'] >> >> The more normal way to write these would be in present tense, in a more >> imperative style: "Fix some bugs", "Load data", "Extract results". >> (Although these comments are actually quite redundant - all they do is >> tell you what the single next line of code does.) > > I used to belong to the cult "don't repeat yourself" in the comments, > being angry against people who thought I couldn't understand by myself > the simplest line of code. > > But I changed my mind. I've read some code comments over the years and > best ones (imo) where those which where actually repeating themselves. > Golden rules of comments: > > # state what you plan to do doIt() > > For instance: > > cells = ['a', 'b' 'c'] > # print the first cell print cell[1] That is not too bad, "Print Customer name from cell 1" may be better as it would stick out if the data structure changed what is meant by don't state the obvious in comments is stating something like "Increment x" without explaining why. -- "It is hard to overstate the debt that we owe to men and women of genius." -- Robert G. Ingersoll From jeanmichel at sequans.com Mon Sep 22 11:52:22 2014 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 22 Sep 2014 17:52:22 +0200 (CEST) Subject: Love to get some feedback on my first python app!!! In-Reply-To: Message-ID: <1142710437.7070860.1411401142913.JavaMail.root@sequans.com> ----- Original Message ----- > From: "Chris Angelico" > Cc: python-list at python.org > Sent: Monday, 22 September, 2014 4:50:15 PM > Subject: Re: Love to get some feedback on my first python app!!! > > On Tue, Sep 23, 2014 at 12:32 AM, Jean-Michel Pichavant > wrote: > > For instance: > > > > cells = ['a', 'b' 'c'] > > # print the first cell > > print cell[1] > > > > A bug that is easily spotted thanks to the comment. It's all about > > implementation versus intentions. Also note that comment should be > > written for the future self, and most importantly, for the > > current others. > > I do see your point, but there's a serious problem here of code > edits. > It's really easy to zip through and find all occurrences of some name > and change them - and miss the one in the comment. In this particular > case, I'm not actually sure where the bug is: is it in the first line > (should be "cell = ...") or the third ("print cells[1]")? Either way, > the comment doesn't make it any clearer, because the plural rule in > English doesn't always match naming of variables. Also, it's common > in > English to count from 1, but in code to count from 0; so there's > another bug (and this might be the one you thought easily spotted) - > it should either be "cell[0]" in the third line, or "print the 1th > cell" in the second. > > (Plus, there's a comma omitted. That list has two elements, but I > think it's meant to have three. However, I'm guessing that's a > transcription error, or a construction-in-email error, and nothing to > do with what you're saying.) > > Now, compare this similar code: > > cells = ['Chris Angelico', 'rosuav at gmail.com', 142857] > # print the email address > print(cells[2]) > > This says *why* it's doing what it does - what the meaning of the > index is. And it, too, has a clearly visible bug, because when it > prints out an integer, the comment makes it obvious that it's done > the > wrong thing. This is, IMO, much more useful. If the code gets edited > (maybe the name used to be in two fields for First Name and Last > Name, > and then someone realized how bad an idea that is - but forgot to > update the index), the original intention is visible; if it just says > "print out cell #2", it's not so helpful. > > So basically, don't *purely* repeat yourself, but give some info > that's a level behind the code. > > ChrisA Damn you didn't fall into my trap :D. The code I posted had many bugs but one could not be fixed without the comment. Or at least there's an obvious discrepancy between the comment and the code that should catch the reader's attention. Anyway it's seems we agree anyway because your example perfectly illustrate what I was trying to demonstrate: print(cells[2]) is very easy to understand, most of people would say 'no need of any comment'. I think it does require a comment. I find myself writing a comment every 3 or 4 line of code, at least, for what I've read, that's way too much. JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From rosuav at gmail.com Mon Sep 22 12:04:43 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 23 Sep 2014 02:04:43 +1000 Subject: Love to get some feedback on my first python app!!! In-Reply-To: <1142710437.7070860.1411401142913.JavaMail.root@sequans.com> References: <1142710437.7070860.1411401142913.JavaMail.root@sequans.com> Message-ID: On Tue, Sep 23, 2014 at 1:52 AM, Jean-Michel Pichavant wrote: > The code I posted had many bugs but one could not be fixed without the comment. Or at least there's an obvious discrepancy between the comment and the code that should catch the reader's attention. > The obvious discrepancy, sadly, doesn't tell you which one is right. It's like the old days of FAT file systems - DOS would maintain two copies of the eponymous File Allocation Table, but in the event of corruption, it had no way of knowing which was to be trusted. (And I'm not sure anything would ever actually notice differences, other than an explicit CHKDSK.) When you have an intention comment, rather than simply replicating the functionality in human-readable form, you can more easily check that the intention matches the rest of the design. ChrisA From breamoreboy at yahoo.co.uk Mon Sep 22 12:10:24 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 22 Sep 2014 17:10:24 +0100 Subject: Love to get some feedback on my first python app!!! In-Reply-To: References: <42e68de9-7528-46fc-8c74-c0baa1d6199e@googlegroups.com> <9bed8e07-9e22-4131-92e8-f950cb5c0d18@googlegroups.com> Message-ID: On 22/09/2014 12:47, vek.m1234 at gmail.com wrote: > 1. It's feedback not a mathematical proof. What is? > 2. I hope the OP tries what I suggested - it's all entirely optional. Which is? > > @OP > I have no idea what that program does because it's well commented. You aren't using variable and function names to good effect and are resorting to excessive comments. > > Additionally, I think you are mangling your display text but I'm not sure. > textDisplay.insert should be a function that you pass args to. > > def spit_msg(text): > textDisplay.insert(text) > > spit_msg("go away doo doo bird") > > Any time you see repeated text in your program, wrap it in a single func and simplify. > > try: > def create_root_window(): > rather than letting all your funny parts dangle around naked. > Google groups rides again? -- 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 Mon Sep 22 12:16:03 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Mon, 22 Sep 2014 16:16:03 +0000 (UTC) Subject: face detection References: Message-ID: On Mon, 22 Sep 2014 15:29:58 +0530, narayan naik wrote: > good evening sir, > I am doing my M.Tech project on face > detection,I am confused with the face detection algorithm,can you please > tell me the simple and best algorithm. http://www.lmgtfy.com/?q=best+face+detection+algorithm+python -- Denis McMahon, denismfmcmahon at gmail.com From rosuav at gmail.com Mon Sep 22 12:26:40 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 23 Sep 2014 02:26:40 +1000 Subject: Love to get some feedback on my first python app!!! In-Reply-To: References: <42e68de9-7528-46fc-8c74-c0baa1d6199e@googlegroups.com> <9bed8e07-9e22-4131-92e8-f950cb5c0d18@googlegroups.com> Message-ID: On Tue, Sep 23, 2014 at 2:10 AM, Mark Lawrence wrote: > Google groups rides again? Yeah. And now someone from Google Groups has killfiled me. So it's up to you to request/recommend alternatives, s/he won't see me saying so. ChrisA From breamoreboy at yahoo.co.uk Mon Sep 22 12:17:02 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 22 Sep 2014 17:17:02 +0100 Subject: Love to get some feedback on my first python app!!! In-Reply-To: References: <42e68de9-7528-46fc-8c74-c0baa1d6199e@googlegroups.com> <9bed8e07-9e22-4131-92e8-f950cb5c0d18@googlegroups.com> Message-ID: On 22/09/2014 14:35, vek.m1234 at gmail.com wrote: > @Chris, Hi, I don't like your style of posting - please kill file me. > > @Everybody else - I don't like Chris and his style of posting (overuse of the 'troll' word and perceived aggression). I shall be ignoring him for a year (barring an emergency). Good communication demands that I announce this. Please don't misconstrue this as rudeness on my part. If you feel that he is asking something of pertinence, feel free to include it in your posts for a reply. > Laughable as you never give any context. Please equip yourself with a decent tool, there are plenty to choose from. And ignore Chris at your peril, he knows a fair bit about Python. Sure he gets things wrong, but the only person who never gets things wrong is the person who never does anything. -- 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 Sep 22 12:17:54 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 22 Sep 2014 17:17:54 +0100 Subject: Love to get some feedback on my first python app!!! In-Reply-To: References: <42e68de9-7528-46fc-8c74-c0baa1d6199e@googlegroups.com> <9bed8e07-9e22-4131-92e8-f950cb5c0d18@googlegroups.com> Message-ID: On 22/09/2014 14:48, C Smith wrote: > I wouldn't take it personally, just defend your position. I think that > is what he is looking for. We are all adults here (maybe?). You guys > should be able to work it out. A tangential skill to programming is > being able to give and take criticism well, even if you think it > crosses the line. > > On Mon, Sep 22, 2014 at 6:35 AM, wrote: >> @Chris, Hi, I don't like your style of posting - please kill file me. >> >> @Everybody else - I don't like Chris and his style of posting (overuse of the 'troll' word and perceived aggression). I shall be ignoring him for a year (barring an emergency). Good communication demands that I announce this. Please don't misconstrue this as rudeness on my part. If you feel that he is asking something of pertinence, feel free to include it in your posts for a reply. >> -- >> https://mail.python.org/mailman/listinfo/python-list Hells bells if it's not googlegroups it's top posting. What did I do in a past life to deserve this? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rosuav at gmail.com Mon Sep 22 12:58:10 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 23 Sep 2014 02:58:10 +1000 Subject: Love to get some feedback on my first python app!!! In-Reply-To: References: <42e68de9-7528-46fc-8c74-c0baa1d6199e@googlegroups.com> <9bed8e07-9e22-4131-92e8-f950cb5c0d18@googlegroups.com> Message-ID: On Tue, Sep 23, 2014 at 2:17 AM, Mark Lawrence wrote: > And ignore Chris at your peril, he knows a fair bit about Python. Sure he > gets things wrong, but the only person who never gets things wrong is the > person who never does anything. Thanks :) I don't mind being wrong, or being told I'm wrong. Those are some of the best threads we've ever had - lengthy debates by intelligent people who start out with different views, figuring out exactly what the differences are and why there are those differences. Those are the threads that differentiate c.l.p/python-list from Facebook - there's solid content, serious discussion, and stuff that's worth going back to. ChrisA From breamoreboy at yahoo.co.uk Mon Sep 22 12:14:00 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 22 Sep 2014 17:14:00 +0100 Subject: Love to get some feedback on my first python app!!! In-Reply-To: References: <42e68de9-7528-46fc-8c74-c0baa1d6199e@googlegroups.com> Message-ID: On 22/09/2014 14:17, Nicholas Cannon wrote: > Ok I'm confused. Do I need to do better comments? I know the text is not that great but that is my next obstacle I am going to tackle. I mostly need to know where I am going wrong such as what is expectable readable code and what is not and how to fix this. This is good feedback thanks to all of you guys. All I want to do is learn and become better and neater! > So am I. To whom are you replying and about what? I'm not spending my time trying to find out just because you can't be bothered to use a decent tool when posting here. -- 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 Sep 22 12:11:54 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 22 Sep 2014 17:11:54 +0100 Subject: Love to get some feedback on my first python app!!! In-Reply-To: <4e75613a-706a-4441-b94a-49dbedf3df28@googlegroups.com> References: <42e68de9-7528-46fc-8c74-c0baa1d6199e@googlegroups.com> <4e75613a-706a-4441-b94a-49dbedf3df28@googlegroups.com> Message-ID: On 22/09/2014 13:00, vek.m1234 at gmail.com wrote: > https://github.com/Veek/Python/blob/master/IRC/Hexchat/fake_ctcp.py > that's not too bad as far as readability is concerned and it's bereft of all comments {:p > Definitely googlegroups rides again. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From luisjosenovoa at gmail.com Mon Sep 22 12:57:22 2014 From: luisjosenovoa at gmail.com (LJ) Date: Mon, 22 Sep 2014 09:57:22 -0700 (PDT) Subject: Comparison Message-ID: <521ef86a-df52-4a49-8562-6312273a8c07@googlegroups.com> Hi All, Quick question here. In the code I am working on I am apparently doing a lot of dictionary lookups and those are taking a lot of time. I looked at the possibility of changing the structure and I found about the numpy structured arrays. The concrete question is: what would be the difference between using one or the other in terms of performance? meaning looping and performing checks an operations on them? Thanks, From rosuav at gmail.com Mon Sep 22 13:11:09 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 23 Sep 2014 03:11:09 +1000 Subject: Comparison In-Reply-To: <521ef86a-df52-4a49-8562-6312273a8c07@googlegroups.com> References: <521ef86a-df52-4a49-8562-6312273a8c07@googlegroups.com> Message-ID: On Tue, Sep 23, 2014 at 2:57 AM, LJ wrote: > Quick question here. In the code I am working on I am apparently doing a lot of dictionary lookups and those are taking a lot of time. > I looked at the possibility of changing the structure and I found about the numpy structured arrays. > The concrete question is: what would be the difference between using one or the other in terms of performance? meaning looping and performing checks an operations on them? The lookups themselves almost certainly aren't actually taking the time, unless you have some kind of crazy hash collision happening, which is so statistically unlikely that it would have to have come from malice. What's the code doing? What are you trying to accomplish? It's much more likely that you have an algorithmic flaw than a data type inefficiency. ChrisA From luisjosenovoa at gmail.com Mon Sep 22 13:38:42 2014 From: luisjosenovoa at gmail.com (LJ) Date: Mon, 22 Sep 2014 10:38:42 -0700 (PDT) Subject: Comparison In-Reply-To: References: <521ef86a-df52-4a49-8562-6312273a8c07@googlegroups.com> Message-ID: <0be2cb54-4520-4379-a9bb-279cfe134d19@googlegroups.com> On Monday, September 22, 2014 1:12:23 PM UTC-4, Chris Angelico wrote: > On Tue, Sep 23, 2014 at 2:57 AM, LJ wrote: > > > Quick question here. In the code I am working on I am apparently doing a lot of dictionary lookups and those are taking a lot of time. > > > I looked at the possibility of changing the structure and I found about the numpy structured arrays. > > > The concrete question is: what would be the difference between using one or the other in terms of performance? meaning looping and performing checks an operations on them? > > > > The lookups themselves almost certainly aren't actually taking the > > time, unless you have some kind of crazy hash collision happening, > > which is so statistically unlikely that it would have to have come > > from malice. What's the code doing? What are you trying to accomplish? > > It's much more likely that you have an algorithmic flaw than a data > > type inefficiency. > > > > ChrisA Thank you for your reply. Basically what is happening is the following: I have a network in which the nodes are defined as dictionaries using the NetworkX package. Inside each node (each dictionary) I defined a dictionary of dictionaries holding attributes corresponding to different ways in which the node can be reached (this dictionaries I refer to as labels). At some point in my algorithm I am looping through some subset of nodes and through the labels in each node and I perform some "joining" checks with the labels of each node in another subset of nodes. To clarify I check for a feasibility condition in a pairwise manner for every label in one node and every label of another. This nested loop is taking time. I wonder if the fact of defining the labels using numpy instead of dictionaries could imply a faster way to perform this loop. I hope I was clear. Thanks. From rosuav at gmail.com Mon Sep 22 13:45:16 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 23 Sep 2014 03:45:16 +1000 Subject: Comparison In-Reply-To: <0be2cb54-4520-4379-a9bb-279cfe134d19@googlegroups.com> References: <521ef86a-df52-4a49-8562-6312273a8c07@googlegroups.com> <0be2cb54-4520-4379-a9bb-279cfe134d19@googlegroups.com> Message-ID: On Tue, Sep 23, 2014 at 3:38 AM, LJ wrote: > At some point in my algorithm I am looping through some subset of nodes and through the labels in each node and I perform some "joining" checks with the labels of each node in another subset of nodes. To clarify I check for a feasibility condition in a pairwise manner for every label in one node and every label of another. This nested loop is taking time. > Okay, that's where the issue is - you're doing a cross-match, that's going to be comparing every label against every other. You might be able to cache some references to part-way into the tree, depending on how your code is written, but ultimately, you still need to do all of those checks. What's the definition of feasibility? Can you optimize that? Maybe there's a way to do a rough check that cuts down the number you have to do the exact check on. ChrisA From irmen.NOSPAM at xs4all.nl Mon Sep 22 13:47:43 2014 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Mon, 22 Sep 2014 19:47:43 +0200 Subject: Pyrolite, lightweight pickle and pyro client library, seeking a bit of testing help Message-ID: <542060bf$0$2929$e4fe514c@news.xs4all.nl> Hi, I've developed Pyrolite (https://github.com/irmen/Pyrolite), a lightweight client library for Java and .NET to gain access to Python servers running Pyro. As such it also contains a complete pickle and unpickle implementation in these languages. Quite recently I got a pull request to fix a big/little-endianness decoding issue regarding machine floats and doubles in pickled arrays. It was a mistake on my part but it got me thinking: the unit tests of my library should ideally be run on both little- and big-endian machines, because some of the code depends on this. I've only got access to little endian systems myself. So basically I'm looking for some tips here, for instance can Travis-ci.org perhaps help out? Or can someone here with access to a big endian system help me out with running the Java and .NET (Microsoft or Mono) unit test suite of my project on that system? (just a one time request, to verify the current version). Irmen de Jong PS the reason why I'm posting a Java or .NET related issue here is because the core protocol my library handles is a Python invented one ;) From rosuav at gmail.com Mon Sep 22 13:53:59 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 23 Sep 2014 03:53:59 +1000 Subject: Pyrolite, lightweight pickle and pyro client library, seeking a bit of testing help In-Reply-To: <542060bf$0$2929$e4fe514c@news.xs4all.nl> References: <542060bf$0$2929$e4fe514c@news.xs4all.nl> Message-ID: On Tue, Sep 23, 2014 at 3:47 AM, Irmen de Jong wrote: > I've developed Pyrolite (https://github.com/irmen/Pyrolite), a lightweight client > library for Java and .NET to gain access to Python servers running Pyro. As such it also > contains a complete pickle and unpickle implementation in these languages. Does this imply that you send pickle data across the internet and unpickle it? Isn't that rather dangerous? ChrisA From davea at davea.name Mon Sep 22 14:03:07 2014 From: davea at davea.name (Dave Angel) Date: Mon, 22 Sep 2014 14:03:07 -0400 (EDT) Subject: Python advice References: <9b76b07d-db88-4e08-9abe-10df1ac9953e@googlegroups.com> Message-ID: ngangsia akumbo Wrote in message: > I have learned python for some time now. I am developing apps using django. > > I need some advice. > I want to be able to write big programs using python. I have not been able to do that as of now. Define'big'. I could write a 25 line Python program that generates gigabytes of useful data. Or I could write 100,000 lines of assembler that could have been done in 1000 lines of some other language. When you say you haven't been able to do (something), just what has been stopping you? > I need a way forward on what more free ebooks i can get mt hands on so i can accomplish my goals. > > I need some advice. should i go on to learn other languages like java or c++ cos i want to be able to using all these knowledge for games, desktop, mobile and web. You certainly should learn other languages. I used about 35 during my career. But until you've mastered one, c++ and Java will probably be more confusing than helpful. There are others you probably need first, such as html, css, regex. And other skills, such as a debugger, profiler, customizable editor. > > i start learning java and i seem it is more real life. Do you mean because it makes you work harder? I've used both, though not on the same project. And java isn't the tool I'd reach for, for most purposes. > it looks real that python. This sentence isn't. Perhaps you intended a comma after 'real', or some more words at the end. -- DaveA From ckaynor at zindagigames.com Mon Sep 22 14:24:24 2014 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Mon, 22 Sep 2014 11:24:24 -0700 Subject: Love to get some feedback on my first python app!!! In-Reply-To: <1142710437.7070860.1411401142913.JavaMail.root@sequans.com> References: <1142710437.7070860.1411401142913.JavaMail.root@sequans.com> Message-ID: On Mon, Sep 22, 2014 at 8:52 AM, Jean-Michel Pichavant < jeanmichel at sequans.com> wrote: > Anyway it's seems we agree anyway because your example perfectly > illustrate what I was trying to demonstrate: > print(cells[2]) is very easy to understand, most of people would say 'no > need of any comment'. I think it does require a comment. > But the thing that requires the comment is the "2", not the "print" or the "cells". And that comes to a more common issue: any number other than 0 or 1 in code most likely needs a comment (that comment could be merely a variable name). Values of 0 or 1 may need a comment, but there are plenty of cases where they are used quite clearly - its much less likely that other numbers have obvious meaning. Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: From irmen.NOSPAM at xs4all.nl Mon Sep 22 14:23:08 2014 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Mon, 22 Sep 2014 20:23:08 +0200 Subject: Pyrolite, lightweight pickle and pyro client library, seeking a bit of testing help In-Reply-To: References: <542060bf$0$2929$e4fe514c@news.xs4all.nl> Message-ID: <5420690b$0$2833$e4fe514c@news.xs4all.nl> On 22-9-2014 19:53, Chris Angelico wrote: > On Tue, Sep 23, 2014 at 3:47 AM, Irmen de Jong wrote: >> I've developed Pyrolite (https://github.com/irmen/Pyrolite), a lightweight client >> library for Java and .NET to gain access to Python servers running Pyro. As such it also >> contains a complete pickle and unpickle implementation in these languages. > > Does this imply that you send pickle data across the internet and > unpickle it? Isn't that rather dangerous? > > ChrisA Yes it is, good to point this out. This is why Pyro has been using a different (and safe) serializer by default for a while now. You have to plow through the usual security warnings in the docs and make a conscious effort in your code to enable the pickle serializer if you really want/need it. Pyrolite also contains a Java and .NET version of that safe serializer so you should not be using pickle at all when dealing with Pyro, but its implementation is there. And the pickle code can be used independently. Irmen From rosuav at gmail.com Mon Sep 22 14:25:33 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 23 Sep 2014 04:25:33 +1000 Subject: Love to get some feedback on my first python app!!! In-Reply-To: References: <1142710437.7070860.1411401142913.JavaMail.root@sequans.com> Message-ID: On Tue, Sep 23, 2014 at 4:24 AM, Chris Kaynor wrote: > On Mon, Sep 22, 2014 at 8:52 AM, Jean-Michel Pichavant > wrote: >> >> Anyway it's seems we agree anyway because your example perfectly >> illustrate what I was trying to demonstrate: >> print(cells[2]) is very easy to understand, most of people would say 'no >> need of any comment'. I think it does require a comment. > > > But the thing that requires the comment is the "2", not the "print" or the > "cells". And that comes to a more common issue: any number other than 0 or 1 > in code most likely needs a comment (that comment could be merely a variable > name). Values of 0 or 1 may need a comment, but there are plenty of cases > where they are used quite clearly - its much less likely that other numbers > have obvious meaning. Or in this case, replacing the list with a namedtuple is probably more useful. ChrisA From rosuav at gmail.com Mon Sep 22 14:28:44 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 23 Sep 2014 04:28:44 +1000 Subject: Pyrolite, lightweight pickle and pyro client library, seeking a bit of testing help In-Reply-To: <5420690b$0$2833$e4fe514c@news.xs4all.nl> References: <542060bf$0$2929$e4fe514c@news.xs4all.nl> <5420690b$0$2833$e4fe514c@news.xs4all.nl> Message-ID: On Tue, Sep 23, 2014 at 4:23 AM, Irmen de Jong wrote: > This is why Pyro has been using a different (and safe) serializer by default for a while > now. You have to plow through the usual security warnings in the docs and make a > conscious effort in your code to enable the pickle serializer if you really want/need it. Is the safe serializer affected by byte order? If not, you could just mark this off as a known bug, and say "if anyone has a big-endian system to test this on, please help out". It would be another incentive to use the safe serializer rather than pickle. And it'd save you a lot of trouble. :) I would have offered one of my systems for the test, except ... they're all little-endian. I'm all PC-based hardware here (mainly Linux running on Intel CPUs, though there are some variations). ChrisA From jeanmichel at sequans.com Mon Sep 22 13:05:47 2014 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 22 Sep 2014 19:05:47 +0200 (CEST) Subject: Love to get some feedback on my first python app!!! In-Reply-To: Message-ID: <490163235.7079063.1411405547777.JavaMail.root@sequans.com> ---- Original Message ----- > From: "Chris Angelico" > Cc: python-list at python.org > Sent: Monday, 22 September, 2014 6:04:43 PM > Subject: Re: Love to get some feedback on my first python app!!! > > On Tue, Sep 23, 2014 at 1:52 AM, Jean-Michel Pichavant > wrote: > > The code I posted had many bugs but one could not be fixed without > > the comment. Or at least there's an obvious discrepancy between > > the comment and the code that should catch the reader's attention. > > > > The obvious discrepancy, sadly, doesn't tell you which one is right. [snip] > > ChrisA You're right but that's fine and the comment's still doing its job. Either the comment is wrong, or the code is. It doesn't really matter which one, It needs to be investigated and fixed. Otherwise you could say that writing specifications is pointless since specifications can be wrong and when a problem occur you need to figure out if either the code or the specification is responsible. Like a CRC check, sometimes the payload is correct and the error is on the CRC, it's still damn useful. JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From gherron at digipen.edu Mon Sep 22 13:32:35 2014 From: gherron at digipen.edu (Gary Herron) Date: Mon, 22 Sep 2014 10:32:35 -0700 Subject: face detection In-Reply-To: References: Message-ID: <54205D33.9090702@digipen.edu> On 09/22/2014 02:59 AM, narayan naik wrote: > good evening sir, > I am doing my M.Tech project on face > detection,I am confused with the face detection algorithm,can you > please tell me the simple and best algorithm. > > No, sorry, but this newsgroup is about Python (a programming language). I'm not sure where you would find information about face detection, but I'm sure you could find a better forum with a little searching. Gary Herron -- Dr. Gary Herron Department of Computer Science DigiPen Institute of Technology (425) 895-4418 -------------- next part -------------- An HTML attachment was scrubbed... URL: From ckaynor at zindagigames.com Mon Sep 22 15:00:13 2014 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Mon, 22 Sep 2014 12:00:13 -0700 Subject: Python advice In-Reply-To: References: <9b76b07d-db88-4e08-9abe-10df1ac9953e@googlegroups.com> Message-ID: On Mon, Sep 22, 2014 at 11:03 AM, Dave Angel wrote: > > I need a way forward on what more free ebooks i can get mt hands on so i > can accomplish my goals. > > > > I need some advice. should i go on to learn other languages like java or > c++ cos i want to be able to using all these knowledge for games, desktop, > mobile and web. > > You certainly should learn other languages. I used about 35 > during my career. But until you've mastered one, c++ and Java > will probably be more confusing than helpful. There are others > you probably need first, such as html, css, regex. And other > skills, such as a debugger, profiler, customizable editor. A lot of what you should learn will depend on what you want to do. As a rule-of-thumb I'd recommend sticking to one or two high-level languages until you are reasonably comfortable with them, then possibly branching to other languages. As you've already started with Python, I'd continue on it for a while. Possibly throw in Javascript/HTML/CSS for web-development - for server-side code you could look in the to various Python web frameworks, or learn PHP for those. Once you are comfortable with at least one of those, you can consider branching off into other languages as your projects need. A few languages and their major strengths: - Python is pretty good base-line language. It is really good as a glue language to piece together other components, or for IO-bound or user-bound code, but will not preform well enough for many other applications such as games. It is good for short parts of games, but a full next-gen engine would be much too slow if written in pure Python, however Civilization 5 uses Python as its scripting language. There are also libraries available that can provide enough performance to do basic games in Python. - C# is another good base-line language, although its much more limited to Windows (there are ways to run it on Mac and Linux, but not as easily). The main benefit it has is that, if you have Visual Studio, you get a nice UI designer built-in. Overall, this is a decent option for Windows-only GUI applications, and can be expanded with other libraries to other platforms, including many mobile platforms. Some web-servers can also run it as a server-side language. - Javascript is basically a necessity for web-based applications, as it is the only language that is commonly runnable across all browsers. There are, however, compilers that can (with some success) convert other languages to Javascript. (note: Javascript runs in the browser, primarily) - PHP is another commonly used web language, and is widely supported by servers. Anymore, there are also good Python libraries available for server-side webpages, although whether you can use them will depend on the server you are using. For some of the free servers, even PHP may not be supported, and you will only be able to do static sites (no server-side code). - C/C++ are both low level, and therefore generally harder to learn but provides much better performance than many other languages. I'd recommend putting these off until you are more comfortable with other, higher-level languages. - LUA is a commonly used scripting language for games. You'll find many engines have LUA support, as it tends to be very light-weight. I'd only recommend LUA if you want to program in one of those engines. World of Warcraft is one game I know of that has public support for LUA when making UI mods. - Objective-C is one of the main languages used for IOS (Apple) development. - Java is a commonly used language for Andoid development. Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: From random832 at fastmail.us Mon Sep 22 15:34:03 2014 From: random832 at fastmail.us (random832 at fastmail.us) Date: Mon, 22 Sep 2014 15:34:03 -0400 Subject: program to generate data helpful in finding duplicate large files In-Reply-To: References: Message-ID: <1411414443.4182630.170466465.768582FE@webmail.messagingengine.com> On Thu, Sep 18, 2014, at 14:45, Chris Kaynor wrote: > Additionally, you may want to specify binary mode by using > open(file_path, > 'rb') to ensure platform-independence ('r' uses Universal newlines, which > means on Windows, Python will convert "\r\n" to "\n" while reading the > file). Additionally, some platforms will treat binary files differently. Does 'r' not use universal newlines on unix? If not, why not? The only purpose seems to be to allow people to write bad programs and have them work on unix. It makes even less sense in python 3 where opening a file in text mode results in a TextIOWrapper with utf-8 encoding, and therefore can't be used on arbitrary binary files. From ian.g.kelly at gmail.com Mon Sep 22 15:39:47 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 22 Sep 2014 13:39:47 -0600 Subject: Python advice In-Reply-To: References: <9b76b07d-db88-4e08-9abe-10df1ac9953e@googlegroups.com> Message-ID: On Mon, Sep 22, 2014 at 1:00 PM, Chris Kaynor wrote: > Python is pretty good base-line language. It is really good as a glue > language to piece together other components, or for IO-bound or user-bound > code, but will not preform well enough for many other applications such as > games. It is good for short parts of games, but a full next-gen engine would > be much too slow if written in pure Python, however Civilization 5 uses > Python as its scripting language. There are also libraries available that > can provide enough performance to do basic games in Python. Correction: Civilization 4 used Python for scripting. For Civilization 5 they switched to Lua, I believe for performance-related reasons. From ckaynor at zindagigames.com Mon Sep 22 15:47:26 2014 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Mon, 22 Sep 2014 12:47:26 -0700 Subject: program to generate data helpful in finding duplicate large files In-Reply-To: <1411414443.4182630.170466465.768582FE@webmail.messagingengine.com> References: <1411414443.4182630.170466465.768582FE@webmail.messagingengine.com> Message-ID: I went and looked up the PEPs regarding universal new-lines, and it seems it would be platform-independent - all of "\r\n", "\r", and "\n" will always be converted to "\n" in Python, unless explicitly modified on the file object (or Universal newlines are disabled). It still stands that for platform independence, "rb" should be used due to some platforms treating binary files differently. Additionally, and most importantly, for what the OP was doing (determining if files are the same), you almost certainly want to read the raw bytes - especially if some of the files are truly binary (such as *.exe on Windows). Chris On Mon, Sep 22, 2014 at 12:34 PM, wrote: > On Thu, Sep 18, 2014, at 14:45, Chris Kaynor wrote: > > Additionally, you may want to specify binary mode by using > > open(file_path, > > 'rb') to ensure platform-independence ('r' uses Universal newlines, which > > means on Windows, Python will convert "\r\n" to "\n" while reading the > > file). Additionally, some platforms will treat binary files differently. > > Does 'r' not use universal newlines on unix? If not, why not? The only > purpose seems to be to allow people to write bad programs and have them > work on unix. It makes even less sense in python 3 where opening a file > in text mode results in a TextIOWrapper with utf-8 encoding, and > therefore can't be used on arbitrary binary files. > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ckaynor at zindagigames.com Mon Sep 22 17:59:44 2014 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Mon, 22 Sep 2014 14:59:44 -0700 Subject: Python advice In-Reply-To: References: <9b76b07d-db88-4e08-9abe-10df1ac9953e@googlegroups.com> Message-ID: On Mon, Sep 22, 2014 at 12:39 PM, Ian Kelly wrote: > On Mon, Sep 22, 2014 at 1:00 PM, Chris Kaynor > wrote: > > Python is pretty good base-line language. It is really good as a glue > > language to piece together other components, or for IO-bound or > user-bound > > code, but will not preform well enough for many other applications such > as > > games. It is good for short parts of games, but a full next-gen engine > would > > be much too slow if written in pure Python, however Civilization 5 uses > > Python as its scripting language. There are also libraries available that > > can provide enough performance to do basic games in Python. > > Correction: Civilization 4 used Python for scripting. For Civilization > 5 they switched to Lua, I believe for performance-related reasons. > I stand corrected. A quick search shows you are correct, for all of Civ4 using Python, Civ5 using Lua, and the primary reason being performance. -------------- next part -------------- An HTML attachment was scrubbed... URL: From larry at hastings.org Mon Sep 22 18:12:38 2014 From: larry at hastings.org (Larry Hastings) Date: Mon, 22 Sep 2014 23:12:38 +0100 Subject: [python-committers] [RELEASE] Python 3.4.2rc1 is now available In-Reply-To: References: <54202F17.3010008@hastings.org> Message-ID: <54209ED6.30608@hastings.org> On 09/22/2014 03:58 PM, Victor Stinner wrote: > Someone broke test_pydoc. Example: > http://buildbot.python.org/all/builders/AMD64%20FreeBSD%2010.0%203.4/builds/481/steps/test/logs/stdio I broke it while making the release. Known bug, happened before, for 3.4.1rc1. http://bugs.python.org/issue21431 We'll get it right for 3.4.2 final. I don't think we need to respin 3.4.2rc1 / add a 3.4.2rc2 for this. On 09/22/2014 06:02 PM, Terry Reedy wrote: > On 9/22/2014 10:15 AM, Larry Hastings wrote: >> You can download it here: >> >> https://www.python.org/download/releases/3.4.2 > Unfortunately, I cannot. This actually links to > https://www.python.org/download/releases/3.4.1 WFM. I'm guessing this was a CDN caching problem--I forgot to manually purge the cache. Does it work for you now? //arry/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Mon Sep 22 19:06:10 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 22 Sep 2014 19:06:10 -0400 Subject: program to generate data helpful in finding duplicate large files In-Reply-To: <1411414443.4182630.170466465.768582FE@webmail.messagingengine.com> References: <1411414443.4182630.170466465.768582FE@webmail.messagingengine.com> Message-ID: On 9/22/2014 3:34 PM, random832 at fastmail.us wrote: > On Thu, Sep 18, 2014, at 14:45, Chris Kaynor wrote: >> Additionally, you may want to specify binary mode by using >> open(file_path, >> 'rb') to ensure platform-independence ('r' uses Universal newlines, which >> means on Windows, Python will convert "\r\n" to "\n" while reading the >> file). Additionally, some platforms will treat binary files differently. > > Does 'r' not use universal newlines on unix? 'r' in the open mode means 'read', versus 'w' for 'write' and 'a' for 'append'. 'b' means 'binary', versus 't' for 'text'. I am pretty sure universal newlines only applies to text mode, as least in 3.x. -- Terry Jan Reedy From rosuav at gmail.com Mon Sep 22 20:55:00 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 23 Sep 2014 10:55:00 +1000 Subject: Python advice In-Reply-To: References: <9b76b07d-db88-4e08-9abe-10df1ac9953e@googlegroups.com> Message-ID: On Tue, Sep 23, 2014 at 5:00 AM, Chris Kaynor wrote: > As a rule-of-thumb I'd recommend sticking to one or two high-level languages > until you are reasonably comfortable with them, then possibly branching to > other languages. As you've already started with Python, I'd continue on it > for a while. Possibly throw in Javascript/HTML/CSS for web-development - for > server-side code you could look in the to various Python web frameworks, or > learn PHP for those. Let's start with application programming languages... pick up the other languages separately. I'd strengthen the recommendation: As you've already started with Python, and as Python is an excellent language, I'd recommend continuing with it for a good while. Don't bother with PHP. > A few languages and their major strengths: > > Python is pretty good base-line language. It is really good as a glue > language to piece together other components, or for IO-bound or user-bound > code, but will not preform well enough for many other applications such as > games. It is good for short parts of games, but a full next-gen engine would > be much too slow if written in pure Python, however Civilization 5 uses > Python as its scripting language. There are also libraries available that > can provide enough performance to do basic games in Python. Agreed (with the minor correction re Civ 4/5 and Lua, per other posts); but you'd be amazed how much can be done in the "slow language". There are two common models for mixing Python and some lower-level, higher performance language: either you use the high performance language as the main program and then script a few parts in Python to make them customizable, or you use Python as the main program and use the other language to do the heavy lifting via well-defined API calls. The latter is extremely well-suited to heavy-duty mathematical computation - you can do enormous amounts of work with numpy, and all the grunt-work is done in Fortran, even though you just write pure Python code. > C# is another good base-line language, although its much more limited to > Windows (there are ways to run it on Mac and Linux, but not as easily). The > main benefit it has is that, if you have Visual Studio, you get a nice UI > designer built-in. Overall, this is a decent option for Windows-only GUI > applications, and can be expanded with other libraries to other platforms, > including many mobile platforms. Some web-servers can also run it as a > server-side language. I haven't used it extensively, but I'm given to believe that mono means C# is reasonably viable on Mac/Linux these days. You'd have to find an expert to be sure, though. Personally, I don't think C# has anything above other languages, if you're writing for desktop OSes. But mobile is a completely different story, and if you can write one codebase that runs on Windows, Mac, Linux, and whatever phone you're targeting, that's a huge win. Otherwise, though, don't bother learning C#, at least for now. > Javascript is basically a necessity for web-based applications, as it is the > only language that is commonly runnable across all browsers. There are, > however, compilers that can (with some success) convert other languages to > Javascript. (note: Javascript runs in the browser, primarily) JavaScript/ECMAScript is the One Obvious Way to script a web page. It's also one of the easiest languages to sandbox as a means of allowing untrusted people to script your program. (It shares this with Lua, which is a much less powerful language.) Sadly, it's stuck in UTF-16 land, and that's never going to change (for reasons of backward compatibility). Learn JS if you want to do anything even slightly fancy with web pages. > PHP is another commonly used web language, and is widely supported by > servers. Anymore, there are also good Python libraries available for > server-side webpages, although whether you can use them will depend on the > server you are using. For some of the free servers, even PHP may not be > supported, and you will only be able to do static sites (no server-side > code). A few years ago, PHP was the *only* way to write server-side code for cheap web hosting. That's changing, but given how terrible a language PHP is, I would say you're far FAR better off filtering web hosts down to those that let you run Python code (even if that means paying a little more) rather than learning PHP. Don't learn PHP unless you have a really REALLY compelling use-case... maybe there's some existing PHP framework that does 99.995% of what you want, and the remaining .005% just requires a tiny bit of your own PHP code. And even then, keep your eyes open for the possibility of outgrowing that framework. > C/C++ are both low level, and therefore generally harder to learn but > provides much better performance than many other languages. I'd recommend > putting these off until you are more comfortable with other, higher-level > languages. Agreed. The primary job of C is to write high level languages in. :) Secondarily, it's occasionally used for other boring jobs like C compilers, OS kernels, device drivers, and other stuff that early programmers can completely ignore. Eventually, you'll need to learn C, if only to understand why certain things are the way they are at the CPU level (for instance, do you know why 2**31 is such a common limit?), but the more you can avoid actually coding in C, the happier you'll be. C++ has its place, but not all that much of it... or maybe too much of it, I'm not sure which. It's trying to stretch upward into the domain of high level languages, and stretch downward into "C but with a few more features", and I'm not convinced it's doing a good job of balancing the two.domains. > LUA is a commonly used scripting language for games. You'll find many > engines have LUA support, as it tends to be very light-weight. I'd only > recommend LUA if you want to program in one of those engines. World of > Warcraft is one game I know of that has public support for LUA when making > UI mods. Lua is a much simpler language than ECMAScript, incredibly light-weight, and easily sandboxed. It doesn't work with Unicode (I think its string type is eight-bit, so you have to work with encoded bytes), which is a serious downside in my opinion. Learn Lua if you want to work with something that embeds it. Otherwise, don't bother for now. > Objective-C is one of the main languages used for IOS (Apple) development. > > Java is a commonly used language for Andoid development. Learn these if you want to develop for their corresponding phones. Java has other roles, too, but IMO nothing you can't do with Python. And thanks to Jython, you can even use Python to call on Java-specific libraries. So, that's application languages. What about other types of language? * SQL is the one and only database query language you should ever need to bother with. (You might skip SQL too, if you use something like SQLAlchemy, but you certainly won't need any other query language - not in 2014.) It's well worth getting to know SQL at some point; whether you use Python, Pike, C, or any other language for the application, your SQL code will be the same. * HTML5 is the one obvious way to build web pages, these days. Don't bother with XHTML, older versions of the HTML standard, or any of the other tweaks; just put "" at the top of your file and follow the HTML5 standard. Yes, it's not fully stable yet, but the core isn't changing, so you're safe. * bash scripting and bash command lines are the One Obvious Way to execute lots of commands, on any sort of POSIX system. Get to know the shell ecosystem - the nature of bash pipelines and so on, plus the standard POSIX tools. Combining 'find' with some other program is one of the easiest ways to do sweeping changes to a subset of files on your system. * English. Yes, really. It's not a programming language, but your code looks better if all your text strings, comments, variable names, etc are correctly spelled. (Particularly so if they end up as part of a communication standard. I'm looking at you, Referer!) Not every language will be important to every programmer, but I'd say the above four are going to be the most useful to someone who already knows Python. ChrisA From timr at probo.com Mon Sep 22 22:09:45 2014 From: timr at probo.com (Tim Roberts) Date: Mon, 22 Sep 2014 19:09:45 -0700 Subject: very lightweight gui for win32 + python 3.4 References: <20140914151345.4a17399a94aee701b58137e5@gmx.net> Message-ID: Wolfgang Keller wrote: > >> wxPython and Qt are well known but they are not exactly lightweight. > >wxPython not lightweight? > >It's just a wrapper of win32. That's not really accurate. wxWidgets does expose the Win32 APIs, but the wrapping is not all that transparent. And wxPython adds significant functionality on the top of that. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From wuwei23 at gmail.com Mon Sep 22 23:59:26 2014 From: wuwei23 at gmail.com (alex23) Date: Tue, 23 Sep 2014 13:59:26 +1000 Subject: Love to get some feedback on my first python app!!! In-Reply-To: References: <1142710437.7070860.1411401142913.JavaMail.root@sequans.com> Message-ID: On 23/09/2014 4:25 AM, Chris Angelico wrote: > On Tue, Sep 23, 2014 at 4:24 AM, Chris Kaynor wrote: >> But the thing that requires the comment is the "2", not the "print" or the >> "cells". And that comes to a more common issue: any number other than 0 or 1 >> in code most likely needs a comment (that comment could be merely a variable >> name). Values of 0 or 1 may need a comment, but there are plenty of cases >> where they are used quite clearly - its much less likely that other numbers >> have obvious meaning. > > Or in this case, replacing the list with a namedtuple is probably more useful. Depending on the use case, binding a slice to a name can also help clarify things. From nicholascannon1 at gmail.com Tue Sep 23 01:49:58 2014 From: nicholascannon1 at gmail.com (Nicholas Cannon) Date: Mon, 22 Sep 2014 22:49:58 -0700 (PDT) Subject: How to not enable a user to close the root tkinter window In-Reply-To: <6dffdfb3-82b3-4746-8f39-d6bfa727f439@googlegroups.com> References: <6dffdfb3-82b3-4746-8f39-d6bfa727f439@googlegroups.com> Message-ID: <4f95597e-52de-4446-b184-f0e50f698fc5@googlegroups.com> The git hub has not actually been updated yet I am working on somethine else then committing the update. How would I stop the threads though. I'am using the Thread from threading function. From rosuav at gmail.com Tue Sep 23 01:54:42 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 23 Sep 2014 15:54:42 +1000 Subject: How to not enable a user to close the root tkinter window In-Reply-To: <4f95597e-52de-4446-b184-f0e50f698fc5@googlegroups.com> References: <6dffdfb3-82b3-4746-8f39-d6bfa727f439@googlegroups.com> <4f95597e-52de-4446-b184-f0e50f698fc5@googlegroups.com> Message-ID: On Tue, Sep 23, 2014 at 3:49 PM, Nicholas Cannon wrote: > The git hub has not actually been updated yet I am working on somethine else then committing the update. How would I stop the threads though. I'am using the Thread from threading function. > Ah, okay. (Side point: I recommend committing early and often, it makes it much easier to go back and look at stuff later.) The easiest way is to just set a global variable, and then have the thread periodically check that - once it's set, it shuts itself down. ChrisA From kevin.p.dwyer at gmail.com Tue Sep 23 02:22:33 2014 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Tue, 23 Sep 2014 07:22:33 +0100 Subject: Google Appengine Proxy Post method error References: Message-ID: alextrapp at googlemail.com wrote: > So I got the Labnol Google Appengine proxy but it can't handle the Post > method aka error 405. > > I need help adding this method to the script: > > mirror.py = http://pastebin.com/2zRsdi3U > > transform_content.py = http://pastebin.com/Fw7FCncA > > main.html = http://pastebin.com/HTBH3y5T > > All other files are just small files for appengine that don't carry > sufficient code for this. Hope you guys can help. > > Thanks in advance :) Hello, Very broadly speaking, you need to add a post method to the MirrorHandler class, and in that method: - mung the request in a similar fashion to the get method - avoid caching the request (POST requests are not idempotent) - forward the altered request to the destination server - return the response to the original client The labnol google-proxy githubpage lists a twitter account for support contact - http://twitter.com/labnol - so you could try asking there for more help. Also check the docs for webapp2 and and Google App Engine (http://developers.google.com/appengine). Have fun, Kev From wxjmfauth at gmail.com Tue Sep 23 02:22:12 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Mon, 22 Sep 2014 23:22:12 -0700 (PDT) Subject: Python advice In-Reply-To: References: <9b76b07d-db88-4e08-9abe-10df1ac9953e@googlegroups.com> Message-ID: <39cc7608-8ddf-49f6-968f-a6c5cd6b9f35@googlegroups.com> Le lundi 22 septembre 2014 21:01:07 UTC+2, Chris Kaynor a ?crit?: > > > > > A few languages and their major strengths: > Python is pretty good base-line language. It is really good as a glue LUA is a commonly used scripting language for games. You'll find many engines have LUA support, as it tends to be very light-weight. I'd only recommend LUA if you want to program in one of those engines. [...] Well... http://www.luatex.org/index.html Luckily for the end users. And luckily for "TeX". How would it be possible with this absurd Flexible String Representation with does the opposite (memory and performance) of the implementation of the coding schemes endorsed by Unicode(.org)? jmf From jazeltq at 163.com Tue Sep 23 02:10:53 2014 From: jazeltq at 163.com (Li Tianqing) Date: Tue, 23 Sep 2014 14:10:53 +0800 (CST) Subject: After install python2.7.3 from source code, no module named array Message-ID: <75c44e67.6422.148a1224f4b.Coremail.jazeltq@163.com> Hello, Right now, i install python2.7.3 from source code, but when use it to run some script. It raises no module exception. Dose `make` not compile array into builtin? -- Best Li Tianqing -------------- next part -------------- An HTML attachment was scrubbed... URL: From jazeltq at 163.com Tue Sep 23 02:28:59 2014 From: jazeltq at 163.com (Li Tianqing) Date: Tue, 23 Sep 2014 14:28:59 +0800 (CST) Subject: After install python2.7.3 from source code, no module named array Message-ID: <5d590450.6963.148a132e07d.Coremail.jazeltq@163.com> I am sorry, i do not install, i just make, and then use the python under source code. If you run 'make install' then some lib will compile and then will no problem there. Hello, Right now, i install python2.7.3 from source code, but when use it to run some script. It raises no module exception. Dose `make` not compile array into builtin? -- Best Li Tianqing -------------- next part -------------- An HTML attachment was scrubbed... URL: From vek.m1234 at gmail.com Tue Sep 23 03:33:43 2014 From: vek.m1234 at gmail.com (vek.m1234 at gmail.com) Date: Tue, 23 Sep 2014 00:33:43 -0700 (PDT) Subject: After install python2.7.3 from source code, no module named array In-Reply-To: References: Message-ID: <61ed2414-fb10-4145-8f22-6aa513c2d3c1@googlegroups.com> not quite sure what you mean.. python uses 'list' instead of the C/C++ array data type. there are __builtin__ and builtins module in 2.7 and 3.2 and a 'array' module. make install, copies files into the system dir-tree but you can run the interpreter from the build-dir and it should work. From __peter__ at web.de Tue Sep 23 03:59:56 2014 From: __peter__ at web.de (Peter Otten) Date: Tue, 23 Sep 2014 09:59:56 +0200 Subject: Works perfectly (was Re: CSV methodology) References: Message-ID: jayte wrote: > On Tue, 16 Sep 2014 13:22:02 +0200, Peter Otten <__peter__ at web.de> wrote: > >>jayte wrote: >> >>> On Mon, 15 Sep 2014 09:29:02 +0200, Peter Otten <__peter__ at web.de> >>> wrote: > > [...] > >>>> but you can read raw data >>>>with numpy. Something like >>>> >>>>with open(filename, "rb") as f: >>>> a = numpy.fromfile(f, dtype=[ >>>> ("distance", "f16"), >>>> ("iterations", "i2"), >>>> ("zc_x", "i2"), >>>> ("zc_y", "i2"), >>>> ]).reshape(1778, 1000) >>>> >>>>might do, assuming "extended double" takes 16 bytes. >>> >>> Will try. Double extended precision is ten bytes, but I assume >>> changing the "f16" to "f10" would account for that... >> >>Unfortunately it seems that numpy doesn't support "f10" > > Thus far, this appears to work perfectly: > > with open(filename, "rb") as f: > a = numpy.fromfile(f, dtype=[ > ("distance", "f8"), > ("iterations", "u2"), > ("zc_x", "u2"), > ("zc_y", "u2"), > ]) > > file.close(f) > > d = a["distance"] > i = a["iterations"] > x = a["zc_x"] > y = a["zc_y"] > > (except, of course, for the loss of precision) > > "reshape()" does not appear to be necessary; the various variables > d, i, x, y return a len() of 1778000 Assuming adjacent pixels are in the same row after b = a.reshape(h, w).T you can access a pixel as b[x, y] # without the .T (transposition) it would be b[y, x] instead of a[y*w + x] and a square of 9 pixels with b[left:left+3, top:top+3] > Again, thank you very much, > > Jeff From noone at nowhere.net Tue Sep 23 04:16:37 2014 From: noone at nowhere.net (blindanagram) Date: Tue, 23 Sep 2014 09:16:37 +0100 Subject: GCD in Fractions Message-ID: What is the rationale for gcd(x, y) in Fractions returning a negative value when y is negtive? For example gcd(3, -7) returns -1, which means that a co-prime test that would work in many other languages 'if gcd(x, y) == 1' will fail in Python for negative y. And, of course, since -|x| is less than |x|, returning -|x| rather than |x| is not returning the greatest common divisor of x and y when y is negative. From fk26541598fk at gmail.com Tue Sep 23 04:29:27 2014 From: fk26541598fk at gmail.com (Frank Liou) Date: Tue, 23 Sep 2014 01:29:27 -0700 (PDT) Subject: PIL can't read binary Message-ID: <2bae5b6f-a3b9-40d8-a037-a6ff309ba71f@googlegroups.com> I use PIL Image.open() but it show 'list' object has no attribute 'open' this is my code class Image2(): trans = connection.begin() session = Session() ProductId = session.query(ProductEntity.ProductId).filter(ProductEntity.CompanyId=="2").all() Image = session.query(ProductImageGalleryEntity).filter(ProductImageGalleryEntity.ProductId=="20").all() PicFromDataBase = Image[0].ProductImage try: b = Image.open(str(PicFromDataBase)) except Exception as e: sad = e From rosuav at gmail.com Tue Sep 23 04:36:09 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 23 Sep 2014 18:36:09 +1000 Subject: PIL can't read binary In-Reply-To: <2bae5b6f-a3b9-40d8-a037-a6ff309ba71f@googlegroups.com> References: <2bae5b6f-a3b9-40d8-a037-a6ff309ba71f@googlegroups.com> Message-ID: On Tue, Sep 23, 2014 at 6:29 PM, Frank Liou wrote: > I use PIL Image.open() > > but it show 'list' object has no attribute 'open' > > this is my code > > class Image2(): > trans = connection.begin() > session = Session() > ProductId = session.query(ProductEntity.ProductId).filter(ProductEntity.CompanyId=="2").all() > Image = session.query(ProductImageGalleryEntity).filter(ProductImageGalleryEntity.ProductId=="20").all() > PicFromDataBase = Image[0].ProductImage > try: > b = Image.open(str(PicFromDataBase)) > except Exception as e: > sad = e I suspect a lot of this ought to be in a method, probably __init__, rather than raw in the class definition. However, the problem here is that your Image is a list (as indicated by the exception), and you probably want to open just one of its elements - maybe Image[0].open(...). You may also want to iterate over the entire list, which would cope better with the possibility of having none or multiple. ChrisA From felipou at gmail.com Tue Sep 23 05:11:23 2014 From: felipou at gmail.com (felipou at gmail.com) Date: Tue, 23 Sep 2014 02:11:23 -0700 (PDT) Subject: Timedelta constructor with string parameter Message-ID: Hello everyone! I created some code recently to parse a string and create a timedelta from it. Right now it only accepts positive integers, and only hours, minutes and seconds, but I think it could be easily extended to support everything that timedelta accepts. time_delta_regex = re.compile( r'((?P\d+?)h)?((?P\d+?)m)?((?P\d+?)s)?' ) def parseTimeDelta( value ): timedelta_params = value if isinstance( value, basestring ): parts = time_delta_regex.match( value ) if not parts: return None parts = parts.groupdict() timedelta_params = {} for ( name, param ) in parts.iteritems(): if param: timedelta_params[ name ] = int( param ) return datetime.timedelta( **timedelta_params ) parseTimeDelta("5h32m15s") I was thinking this conversion could be very useful to lots of people, and so I thought about proposing it as an enhancement to the standard library. But before doing anything, I thought it would be a good idea to see what people here think. I think this would be a nice addition as a constructor of the timedelta class, but I'm not sure if it would conflict with any existing code. I can't see any downside to including this in the constructor or as a separate function. So, what do you guys think? From info at egenix.com Tue Sep 23 05:17:06 2014 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Tue, 23 Sep 2014 11:17:06 +0200 Subject: =?UTF-8?Q?ANN:_Python_Meeting_D=c3=bcsseldorf_-_30.09.2014?= Message-ID: <54213A92.4010905@egenix.com> [This announcement is in German since it targets a local user group meeting in D?sseldorf, Germany] ________________________________________________________________________ ANK?NDIGUNG Python Meeting D?sseldorf http://pyddf.de/ Ein Treffen von Python Enthusiasten und Interessierten in ungezwungener Atmosph?re. Dienstag, 30.09.2014, 18:00 Uhr Raum 1, 2.OG im B?rgerhaus Stadtteilzentrum Bilk D?sseldorfer Arcaden, Bachstr. 145, 40217 D?sseldorf Diese Nachricht ist auch online verf?gbar: http://www.egenix.com/company/news/Python-Meeting-Duesseldorf-2014-09-30 ________________________________________________________________________ NEUIGKEITEN * Bereits angemeldete Vortr?ge: Charlie Clark "Generator Gotchas" Marc-Andre Lemburg "Python und Fliegen - Speicherbedarf von Python Objekten optimieren" Weiterhin werden wir die Ergebnisse des PyDDF Sprints 2014 vom kommenden Wochenende (http://pyddf.de/sprint2014) pr?sentieren. Weitere Vortr?ge k?nnen gerne noch angemeldet werden: info at pyddf.de * Startzeit und Ort: Wir treffen uns um 18:00 Uhr im B?rgerhaus in den D?sseldorfer Arcaden. Das B?rgerhaus teilt sich den Eingang mit dem Schwimmbad und befindet sich an der Seite der Tiefgarageneinfahrt der D?sseldorfer Arcaden. ?ber dem Eingang steht ein gro?es ?Schwimm?'in Bilk? Logo. Hinter der T?r direkt links zu den zwei Aufz?gen, dann in den 2. Stock hochfahren. Der Eingang zum Raum 1 liegt direkt links, wenn man aus dem Aufzug kommt. Google Street View: http://bit.ly/11sCfiw ________________________________________________________________________ EINLEITUNG Das Python Meeting D?sseldorf ist eine regelm??ige Veranstaltung in D?sseldorf, die sich an Python Begeisterte aus der Region wendet: * http://pyddf.de/ Einen guten ?berblick ?ber die Vortr?ge bietet unser YouTube-Kanal, auf dem wir die Vortr?ge nach den Meetings ver?ffentlichen: * http://www.youtube.com/pyddf/ Veranstaltet wird das Meeting von der eGenix.com GmbH, Langenfeld, in Zusammenarbeit mit Clark Consulting & Research, D?sseldorf: * http://www.egenix.com/ * http://www.clark-consulting.eu/ ________________________________________________________________________ PROGRAMM Das Python Meeting D?sseldorf nutzt eine Mischung aus Open Space und Lightning Talks, wobei die Gewitter bei uns auch schon mal 20 Minuten dauern k?nnen ;-). Lightning Talks k?nnen vorher angemeldet werden, oder auch spontan w?hrend des Treffens eingebracht werden. Ein Beamer mit XGA Aufl?sung steht zur Verf?gung. Folien bitte als PDF auf USB Stick mitbringen. Lightning Talk Anmeldung bitte formlos per EMail an info at pyddf.de ________________________________________________________________________ KOSTENBETEILIGUNG Das Python Meeting D?sseldorf wird von Python Nutzern f?r Python Nutzer veranstaltet. Um die Kosten zumindest teilweise zu refinanzieren, bitten wir die Teilnehmer um einen Beitrag in H?he von EUR 10,00 inkl. 19% Mwst, Sch?ler und Studenten zahlen EUR 5,00 inkl. 19% Mwst. Wir m?chten alle Teilnehmer bitten, den Betrag in bar mitzubringen. ________________________________________________________________________ ANMELDUNG Da wir nur f?r ca. 20 Personen Sitzpl?tze haben, m?chten wir bitten, sich per EMail anzumelden. Damit wird keine Verpflichtung eingegangen. Es erleichtert uns allerdings die Planung. Meeting Anmeldung bitte formlos per EMail an info at pyddf.de ________________________________________________________________________ WEITERE INFORMATIONEN Weitere Informationen finden Sie auf der Webseite des Meetings: http://pyddf.de/ Mit freundlichen Gr??en, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Sep 23 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/ ________________________________________________________________________ 2014-09-27: PyDDF Sprint 2014 ... 4 days to go 2014-09-30: Python Meeting Duesseldorf ... 7 days to go ::::: 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 ned at nedbatchelder.com Tue Sep 23 07:03:58 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 23 Sep 2014 07:03:58 -0400 Subject: PIL can't read binary In-Reply-To: <2bae5b6f-a3b9-40d8-a037-a6ff309ba71f@googlegroups.com> References: <2bae5b6f-a3b9-40d8-a037-a6ff309ba71f@googlegroups.com> Message-ID: On 9/23/14 4:29 AM, Frank Liou wrote: > I use PIL Image.open() > > but it show 'list' object has no attribute 'open' > > this is my code > > class Image2(): > trans = connection.begin() > session = Session() > ProductId = session.query(ProductEntity.ProductId).filter(ProductEntity.CompanyId=="2").all() > Image = session.query(ProductImageGalleryEntity).filter(ProductImageGalleryEntity.ProductId=="20").all() > PicFromDataBase = Image[0].ProductImage > try: > b = Image.open(str(PicFromDataBase)) > except Exception as e: > sad = e Image is the name of the PIL module, but you've reassigned it to be a list. Try this: images = session.query(ProductImageGalleryEntity).filter(ProductImageGalleryEntity.ProductId=="20").all() PicFromDataBase = images[0].ProductImage try: b = Image.open(str(PicFromDataBase)) except Exception as e: sad = e Also, I'll second Chris' point that this code should not be in the body of the class, but in a method, or perhaps just a plain-old function. -- Ned Batchelder, http://nedbatchelder.com From steve+comp.lang.python at pearwood.info Tue Sep 23 07:13:16 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 23 Sep 2014 21:13:16 +1000 Subject: Comparison References: <521ef86a-df52-4a49-8562-6312273a8c07@googlegroups.com> <0be2cb54-4520-4379-a9bb-279cfe134d19@googlegroups.com> Message-ID: <542155cd$0$6599$c3e8da3$5496439d@news.astraweb.com> LJ wrote: > I have a network in which the nodes are defined as dictionaries using the > NetworkX package. Inside each node (each dictionary) I defined a > dictionary of dictionaries holding attributes corresponding to different > ways in which the node can be reached (this dictionaries I refer to as > labels). At some point in my algorithm I am looping through some subset of > nodes and through the labels in each node and I perform some "joining" > checks with the labels of each node in another subset of nodes. To clarify > I check for a feasibility condition in a pairwise manner for every label > in one node and every label of another. This nested loop is taking time. I > wonder if the fact of defining the labels using numpy instead of > dictionaries could imply a faster way to perform this loop. I doubt it very much. Python dicts are extremely fast, and it doesn't sound like your problem is that each dict lookup is slow. It sounds like your problem is that you are doing a lot of them. If you have 100 labels in one node, and 100 labels in the other, and you are doing: for label_a in A: for label_b in B: is_feasible(label_a, label_b) the total number of feasibility checks is 100*100 = 10000, not the 200 that you may be expecting. The bottleneck here is probably your is_feasible check, called many times, not the dict look-ups. But of course we cannot be sure without seeing your code, and we can't be certain without running the profiler and seeing exactly where your bottlenecks are. -- Steven From wolfgang.maier at biologie.uni-freiburg.de Tue Sep 23 07:53:49 2014 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Tue, 23 Sep 2014 13:53:49 +0200 Subject: GCD in Fractions In-Reply-To: References: Message-ID: <54215F4D.80305@biologie.uni-freiburg.de> On 09/23/2014 10:16 AM, blindanagram wrote: > What is the rationale for gcd(x, y) in Fractions returning a negative > value when y is negtive? > I guess it is implemented this way because its main use is in the Fraction constructor. > For example gcd(3, -7) returns -1, which means that a co-prime test that > would work in many other languages 'if gcd(x, y) == 1' will fail in > Python for negative y. > On the other hand, it allows: >>> Fraction(3, -7) Fraction(-3, 7) and: >>> Fraction(3, -7) == Fraction(-3, 7) True Given that the implementation is particularly useful for Fraction() it is debatable whether the function shouldn't be called _gcd instead of gcd, but otherwise it makes sense. > And, of course, since -|x| is less than |x|, returning -|x| rather than > |x| is not returning the greatest common divisor of x and y when y is > negative. > however, you can always use abs on y before passing it to gcd. Wolfgang From wolfgang.maier at biologie.uni-freiburg.de Tue Sep 23 07:53:49 2014 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Tue, 23 Sep 2014 13:53:49 +0200 Subject: GCD in Fractions In-Reply-To: References: Message-ID: <54215F4D.80305@biologie.uni-freiburg.de> On 09/23/2014 10:16 AM, blindanagram wrote: > What is the rationale for gcd(x, y) in Fractions returning a negative > value when y is negtive? > I guess it is implemented this way because its main use is in the Fraction constructor. > For example gcd(3, -7) returns -1, which means that a co-prime test that > would work in many other languages 'if gcd(x, y) == 1' will fail in > Python for negative y. > On the other hand, it allows: >>> Fraction(3, -7) Fraction(-3, 7) and: >>> Fraction(3, -7) == Fraction(-3, 7) True Given that the implementation is particularly useful for Fraction() it is debatable whether the function shouldn't be called _gcd instead of gcd, but otherwise it makes sense. > And, of course, since -|x| is less than |x|, returning -|x| rather than > |x| is not returning the greatest common divisor of x and y when y is > negative. > however, you can always use abs on y before passing it to gcd. Wolfgang From miki.tebeka at gmail.com Tue Sep 23 08:34:19 2014 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Tue, 23 Sep 2014 05:34:19 -0700 (PDT) Subject: "Fuzzy" Counter? Message-ID: <0d28ee82-2240-4f10-9db9-e966c0e62a13@googlegroups.com> Greetings, Before I start writing my own. Is there something like collections.Counter (fore frequencies) that does "fuzzy" matching? Meaning x is considered equal to y if abs(x - y) < epsilon. (x, y and my case will be numpy.array). Thanks, -- Miki From noone at nowhere.net Tue Sep 23 08:48:22 2014 From: noone at nowhere.net (blindanagram) Date: Tue, 23 Sep 2014 13:48:22 +0100 Subject: GCD in Fractions In-Reply-To: References: Message-ID: On 23/09/2014 12:53, Wolfgang Maier wrote: > On 09/23/2014 10:16 AM, blindanagram wrote: >> What is the rationale for gcd(x, y) in Fractions returning a negative >> value when y is negtive? >> > > I guess it is implemented this way because its main use is in the > Fraction constructor. This is not guaranteed once it is exposed as a function that is available to all Python users. >> For example gcd(3, -7) returns -1, which means that a co-prime test that >> would work in many other languages 'if gcd(x, y) == 1' will fail in >> Python for negative y. [snip] > Given that the implementation is particularly useful for Fraction() it > is debatable whether the function shouldn't be called _gcd instead of > gcd, but otherwise it makes sense. As you imply, it would make sense if it hadn't been exposed for more general use. However, I am less sure that it is sensible to have a gcd function exposed for end user use when it conflicts with the function's usual definition. From steve+comp.lang.python at pearwood.info Tue Sep 23 08:50:21 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 23 Sep 2014 22:50:21 +1000 Subject: GCD in Fractions References: Message-ID: <54216c8e$0$29966$c3e8da3$5496439d@news.astraweb.com> blindanagram wrote: > What is the rationale for gcd(x, y) in Fractions returning a negative > value when y is negtive? Good question. Normally, gcd is only defined for non-negative integers. Wolfram Mathworld, for example, doesn't mention negative values at all (as far as I can see): http://mathworld.wolfram.com/GreatestCommonDivisor.html although buried deep in the documentation for Mathematica's GCD function is hidden the fact that it treats GCD(-a, -b) the same as GCD(a, b): http://functions.wolfram.com/IntegerFunctions/GCD/04/02/01/ and sure enough Wolfram Alpha tells me that the GCD of *all* of: (100, 20) (-100, 20) (100, -20) (-100, -20) are equal to +20. On the other hand, Excel and LibreOffice both give an error for the GCD of a negative value, and I've seen versions of gcd() which do the same as fractions.gcd. So I think there is not one single standard way to extend GCD to negative numbers. > For example gcd(3, -7) returns -1, which means that a co-prime test that > would work in many other languages 'if gcd(x, y) == 1' will fail in > Python for negative y. True, but either of: abs(gcd(x, y)) == 1 gcd(x, y) in (1, -1) will work. > And, of course, since -|x| is less than |x|, returning -|x| rather than > |x| is not returning the greatest common divisor of x and y when y is > negative. That's a good argument for gcd if it were in a general maths module, but since it is specifically used for generating fractions, I guess that the developers won't be very convinced by that. -- Steven From __peter__ at web.de Tue Sep 23 09:36:24 2014 From: __peter__ at web.de (Peter Otten) Date: Tue, 23 Sep 2014 15:36:24 +0200 Subject: "Fuzzy" Counter? References: <0d28ee82-2240-4f10-9db9-e966c0e62a13@googlegroups.com> Message-ID: Miki Tebeka wrote: > Before I start writing my own. Is there something like collections.Counter > (fore frequencies) that does "fuzzy" matching? > > Meaning x is considered equal to y if abs(x - y) < epsilon. (x, y and my > case will be numpy.array). The problem I see with that description is that for x, y, z, assumming x eq y y eq z not (x eq z) where eq is the test given above -- should x, y, and z land in the same bin? I'm not really qualified here, but k-means clustering may be a direction to investigate: From python.list at tim.thechases.com Tue Sep 23 09:42:46 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 23 Sep 2014 08:42:46 -0500 Subject: "Fuzzy" Counter? In-Reply-To: <0d28ee82-2240-4f10-9db9-e966c0e62a13@googlegroups.com> References: <0d28ee82-2240-4f10-9db9-e966c0e62a13@googlegroups.com> Message-ID: <20140923084246.31706fb5@bigbox.christie.dr> On 2014-09-23 05:34, Miki Tebeka wrote: > Before I start writing my own. Is there something like > collections.Counter (fore frequencies) that does "fuzzy" matching? > > Meaning x is considered equal to y if abs(x - y) < epsilon. (x, y > and my case will be numpy.array). Not that I know of -- the performance characteristics would differ radically from the O(1) expectations that Counter() gives you since you'd have to compare your value against *every* value in the container[*], and you have the possibility that two items in the container are equidistant yet within EPSILON: EPSILON = 0.51 my_counter[1.0] += 1 my_counter[2.0] += 1 my_counter[1.5] += 1 # which one should be incremented? -tkc [*] This could be mitigated if you had some constraints on your inputs and wanted to do some sort of bucket-hashing, limiting it to a subset of the possible keys From a.nandagoban at traxens.com Tue Sep 23 09:56:41 2014 From: a.nandagoban at traxens.com (Arulnambi Nandagoban) Date: Tue, 23 Sep 2014 15:56:41 +0200 Subject: tcp server as windows service Message-ID: <005a01cfd736$34346ad0$9c9d4070$@traxens.com> Hello all, I developed a multithreaded tcp server with python and I converted into a windows executable using pyinstaller. I would like to run the server as a windows service so that server restarts whenever pc restarts without doing it manually . Help me out with some sample code . -- nambi -------------- next part -------------- An HTML attachment was scrubbed... URL: From elearn2014 at gmail.com Tue Sep 23 10:18:09 2014 From: elearn2014 at gmail.com (luofeiyu) Date: Tue, 23 Sep 2014 22:18:09 +0800 Subject: how to write a html to automatically display the dictionary? Message-ID: <54218121.8060902@gmail.com> x={'f1':1,'f2':2,'f3':3} how can i create the following html file automatically with python to display x ?
f1 f2 f3
1 2 3
From noone at nowhere.net Tue Sep 23 10:37:39 2014 From: noone at nowhere.net (blindanagram) Date: Tue, 23 Sep 2014 15:37:39 +0100 Subject: GCD in Fractions In-Reply-To: <54216c8e$0$29966$c3e8da3$5496439d@news.astraweb.com> References: <54216c8e$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <6qidnUSKb8osGLzJnZ2dnUVZ8jOdnZ2d@brightview.co.uk> On 23/09/2014 13:50, Steven D'Aprano wrote: > blindanagram wrote: > >> What is the rationale for gcd(x, y) in Fractions returning a negative >> value when y is negtive? > > Good question. > > Normally, gcd is only defined for non-negative integers. Wolfram Mathworld, > for example, doesn't mention negative values at all (as far as I can see): > > http://mathworld.wolfram.com/GreatestCommonDivisor.html > > although buried deep in the documentation for Mathematica's GCD function is > hidden the fact that it treats GCD(-a, -b) the same as GCD(a, b): > > http://functions.wolfram.com/IntegerFunctions/GCD/04/02/01/ > > and sure enough Wolfram Alpha tells me that the GCD of *all* of: > > (100, 20) > (-100, 20) > (100, -20) > (-100, -20) > > are equal to +20. On the other hand, Excel and LibreOffice both give an > error for the GCD of a negative value, and I've seen versions of gcd() > which do the same as fractions.gcd. So I think there is not one single > standard way to extend GCD to negative numbers. > >> For example gcd(3, -7) returns -1, which means that a co-prime test that >> would work in many other languages 'if gcd(x, y) == 1' will fail in >> Python for negative y. > > True, but either of: > > abs(gcd(x, y)) == 1 > gcd(x, y) in (1, -1) > > will work. > > >> And, of course, since -|x| is less than |x|, returning -|x| rather than >> |x| is not returning the greatest common divisor of x and y when y is >> negative. > > That's a good argument for gcd if it were in a general maths module, but > since it is specifically used for generating fractions, I guess that the > developers won't be very convinced by that. That's an argument for a private gcd within the fractions module and a a 'normal' version in math. From rosuav at gmail.com Tue Sep 23 10:42:07 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 24 Sep 2014 00:42:07 +1000 Subject: GCD in Fractions In-Reply-To: <6qidnUSKb8osGLzJnZ2dnUVZ8jOdnZ2d@brightview.co.uk> References: <54216c8e$0$29966$c3e8da3$5496439d@news.astraweb.com> <6qidnUSKb8osGLzJnZ2dnUVZ8jOdnZ2d@brightview.co.uk> Message-ID: On Wed, Sep 24, 2014 at 12:37 AM, blindanagram wrote: > That's an argument for a private gcd within the fractions module and a a > 'normal' version in math. Steven's examples show that there's not really much definition of "normal" as regards GCD of negative numbers. ChrisA From joel.goldstick at gmail.com Tue Sep 23 10:44:54 2014 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 23 Sep 2014 10:44:54 -0400 Subject: how to write a html to automatically display the dictionary? In-Reply-To: <54218121.8060902@gmail.com> References: <54218121.8060902@gmail.com> Message-ID: On Tue, Sep 23, 2014 at 10:18 AM, luofeiyu wrote: > x={'f1':1,'f2':2,'f3':3} > how can i create the following html file automatically with python to > display x ? > Generally, you would use a framework like django or others, but you can make your html a string and use format: html = "... " % x['f1'] >
%d
> > > > > > > > > > >
> f1 > > f2 > > f3 >
> 1 > > 2 > > 3 >
> -- > https://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick http://joelgoldstick.com From ian.g.kelly at gmail.com Tue Sep 23 10:48:25 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 23 Sep 2014 08:48:25 -0600 Subject: Python advice In-Reply-To: References: <9b76b07d-db88-4e08-9abe-10df1ac9953e@googlegroups.com> Message-ID: On Mon, Sep 22, 2014 at 6:55 PM, Chris Angelico wrote: > Lua is a much simpler language than ECMAScript, incredibly > light-weight, and easily sandboxed. It doesn't work with Unicode (I > think its string type is eight-bit, so you have to work with encoded > bytes), which is a serious downside in my opinion. Learn Lua if you > want to work with something that embeds it. Otherwise, don't bother > for now. Apart from the Unicode issue, I'm curious what makes you describe it as "much simpler" than ECMAScript. Lua has coroutines built into the language, stricter typing than ES (still not as strict as Python, but at least you don't have to deal with a === operator because the == operator is broken), operator overloading, iterators, block-level scoping, closure construction that binds loop variables the way the programmer expects (unlike both Python and ES), and associative arrays that allow arbitrary keys rather than coercing the keys to strings. > * SQL is the one and only database query language you should ever need > to bother with. (You might skip SQL too, if you use something like > SQLAlchemy, but you certainly won't need any other query language - > not in 2014.) It's well worth getting to know SQL at some point; > whether you use Python, Pike, C, or any other language for the > application, your SQL code will be the same. SQLAlchemy lets you use SQL without actually writing SQL, but I would argue that it's still basically necessary to understand SQL and what the SQLAlchemy calls translate to in order to use it. From steve+comp.lang.python at pearwood.info Tue Sep 23 10:48:16 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 24 Sep 2014 00:48:16 +1000 Subject: Dynamically swapping between two algorithms Message-ID: <54218831$0$29979$c3e8da3$5496439d@news.astraweb.com> I have a certain calculation which can be performed two radically different ways. With the first algorithm, let's call it SHORT, performance is very fast for small values of the argument, but terrible for large values. For the second algorithm, LARGE, performance is quite poor for small values, but excellent for large values. To add to the complexity, I perform this calculation repeatedly, in a loop: value = 1 while True: x = SHORT(value) # Or should I use LARGE? Decisions, decisions... process(x) value += some_increment() if condition: break Luckily, the value never gets smaller. So if I could somehow determine a cut-over point, CUTOFF, I might write my loop like this: value = 1 while True: f = SHORT if value < CUTOFF else LARGE x = f(value) process(x) value += some_increment() if condition: break alas, the CUTOVER point is likely to be machine-dependent. Take it as a given that inserting a fixed CUTOVER point into the source code (say, ``CUTOVER = 123456``) is not likely to be very effective, and dynamically calculating it at import time is impractical. *If* Python was a different language, I would spawn two threads, one using SHORT and the other using LARGE, then which ever completes first, I'd just kill the other. Alas, this won't work because (1) the GIL and (2) you cannot forcibly kill threads, only ask them to die and hope they listen. I am seeking other ideas for dynamically swapping between the two algorithms, based on runtime information. Any thoughts? (1) I can't tell in advance how many loops I will make. (2) Both SHORT and LARGE get slower as the size of their argument increases. This is unavoidable due to the nature of the problem. (3) SHORT starts off relatively speedy, significantly faster than LARGE for the first few tens of thousands of loops. I'm not talking about trivial micro-optimizations here, I'm talking about the difference between 0.1 second for SHORT versus 10 seconds for LARGE. (4) But as the size of the argument increases, SHORT suffers catastrophic quadratic slowdown, while LARGE slows down only linearly. (Give or take.) (5) Consequently, by the time I reach a few million loops, the difference is now between (say) 5 minutes for LARGE versus 15 hours for SHORT. (6) There is no single algorithm which performs acceptably across the entire range of values I'm expecting to process in practice. (7) Leaving the choice up to the caller is not an option. I am the caller. -- Steven From rosuav at gmail.com Tue Sep 23 11:08:01 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 24 Sep 2014 01:08:01 +1000 Subject: Python advice In-Reply-To: References: <9b76b07d-db88-4e08-9abe-10df1ac9953e@googlegroups.com> Message-ID: On Wed, Sep 24, 2014 at 12:48 AM, Ian Kelly wrote: > On Mon, Sep 22, 2014 at 6:55 PM, Chris Angelico wrote: >> Lua is a much simpler language than ECMAScript, incredibly >> light-weight, and easily sandboxed. It doesn't work with Unicode (I >> think its string type is eight-bit, so you have to work with encoded >> bytes), which is a serious downside in my opinion. Learn Lua if you >> want to work with something that embeds it. Otherwise, don't bother >> for now. > > Apart from the Unicode issue, I'm curious what makes you describe it > as "much simpler" than ECMAScript. Lua has coroutines built into the > language, stricter typing than ES (still not as strict as Python, but > at least you don't have to deal with a === operator because the == > operator is broken), operator overloading, iterators, block-level > scoping, closure construction that binds loop variables the way the > programmer expects (unlike both Python and ES), and associative arrays > that allow arbitrary keys rather than coercing the keys to strings. Mainly that's based on a feeling, rather than anything specific; I've worked with both Lua and JS from both ends (although the extent of my experience with embedding Lua is an evaluation exercise only; the project ended up going with ECMAScript via the V8 engine, which was the other major choice), and Lua seems rather less featured. Partly this might be a consequence of using a very full-featured JavaScript implementation (V8), but it felt like embedding Lua meant doing a lot more of the work myself. Also, from the script writer's point of view, Lua's table type seems less powerful than the JS object, although that may be a flawed appearance due to my greater experience with the latter. In any case, it fits into a very specific niche: you learn Lua if you want to script something that offers Lua scripting. That's technically the same as the JavaScript niche, except that there's a really big "something" that everyone wants to script, and that's web browsers. (Plus, node.js means you can write server-side code in JS, though personally I wouldn't recommend it; I've seen nothing that node.js can do that Python with a good framework can't do just as easily, and without UTF-16 baggage.) >> * SQL is the one and only database query language you should ever need >> to bother with. (You might skip SQL too, if you use something like >> SQLAlchemy, but you certainly won't need any other query language - >> not in 2014.) It's well worth getting to know SQL at some point; >> whether you use Python, Pike, C, or any other language for the >> application, your SQL code will be the same. > > SQLAlchemy lets you use SQL without actually writing SQL, but I would > argue that it's still basically necessary to understand SQL and what > the SQLAlchemy calls translate to in order to use it. What I'd say is that you have to understand database design. There are concepts that go beyond the actual language used (figuring out what a table's primary and unique keys are, handling joins, knowing how to trace logical structure through a series of tables, etc) that you're never going to get away from. With a framework like SQLAlchemy, you shouldn't have to worry about things like the esoteric quoting rules of different DBMSes (why, oh why, can't we just stick to the standard - 'quoted string', "identifier", and not use backticks at all??), but you still have to craft a sane database structure. When I say that you won't need any *other* query language, I mean that you're unlikely, in 2014, to use the BTrieve API calls that I worked with in the 1990s to interface with Pastel Accounting, nor the DBase calls that manipulate those fragile .dbf files that oh so easily get damaged if two people try to use them at once, etc, etc, etc. You might use a wrapper around SQL if you choose, but certainly if you know SQL you should be able to handle any database. And that's a Good Thing. ChrisA From rosuav at gmail.com Tue Sep 23 11:24:10 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 24 Sep 2014 01:24:10 +1000 Subject: Dynamically swapping between two algorithms In-Reply-To: <54218831$0$29979$c3e8da3$5496439d@news.astraweb.com> References: <54218831$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Sep 24, 2014 at 12:48 AM, Steven D'Aprano wrote: > (3) SHORT starts off relatively speedy, significantly faster than LARGE for > the first few tens of thousands of loops. I'm not talking about trivial > micro-optimizations here, I'm talking about the difference between 0.1 > second for SHORT versus 10 seconds for LARGE. > > (4) But as the size of the argument increases, SHORT suffers catastrophic > quadratic slowdown, while LARGE slows down only linearly. (Give or take.) > > (5) Consequently, by the time I reach a few million loops, the difference is > now between (say) 5 minutes for LARGE versus 15 hours for SHORT. Are these figures for a single call to SHORT/LARGE, or for a number of calls aggregated? How much extra cost would a bit of timing add? If you're making the decision no more than every 0.1s, you can probably afford to time every call, but if you're doing a thousand iterations a second in the early phases, you don't want to add a time-of-day call every step. Here's a possibility that won't be perfectly optimal, but it'll sort itself out over time: shorttime = -1.0 largetime = 0.0 value = 1 while True: t = time.time() if shorttime < largetime: x = SHORT(value) shorttime = time.time() - t else: x = LARGE(value) largetime = time.time() - t if largetime < shorttime: break process(x) value += some_increment() if condition: break # The SHORT algorithm is never going to be better, so # switch to always using LARGE while not condition: process(x) x = LARGE(value) value += some_increment() What it'll do is try one each way, and then use whichever was quicker. So you waste 10s early on, running the LARGE algorithm when SHORT would have been better, but then it won't use LARGE again until SHORT takes at least 10s. At that point, an Achilles/Tortoise race begins: every time SHORT catches up with LARGE, LARGE takes a leap forward... until LARGE's leap forward is insufficient for it to "catch up with" SHORT, at which point we declare SHORT to have won the 'race' and just run with the LARGE algorithm the whole way. Downside: Will choose poorly if other things kick in during the timing tests. Ideally, this should use a "CPU time used by this process" monitor, but I'm not sure (a) if one is available to Python, and (b) if it's at all portable, so the above just uses time.time(). (If the code is big and the overhead of merging is insignificant, the same could be done with a flag instead of breaking out of the loop and starting another. Take your pick.) ChrisA From emile at fenx.com Tue Sep 23 11:33:02 2014 From: emile at fenx.com (emile) Date: Tue, 23 Sep 2014 08:33:02 -0700 Subject: Dynamically swapping between two algorithms In-Reply-To: <54218831$0$29979$c3e8da3$5496439d@news.astraweb.com> References: <54218831$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: Add a timing harness and use a test interval (N) and call LARGE every Nth loop until LARGE's timing is better than the prior SHORT's run. Emile On 09/23/2014 07:48 AM, Steven D'Aprano wrote: > I have a certain calculation which can be performed two radically different > ways. With the first algorithm, let's call it SHORT, performance is very > fast for small values of the argument, but terrible for large values. For > the second algorithm, LARGE, performance is quite poor for small values, > but excellent for large values. > > To add to the complexity, I perform this calculation repeatedly, in a loop: > > value = 1 > while True: > x = SHORT(value) # Or should I use LARGE? Decisions, decisions... > process(x) > value += some_increment() > if condition: break > > Luckily, the value never gets smaller. So if I could somehow determine a > cut-over point, CUTOFF, I might write my loop like this: > > value = 1 > while True: > f = SHORT if value < CUTOFF else LARGE > x = f(value) > process(x) > value += some_increment() > if condition: break > > alas, the CUTOVER point is likely to be machine-dependent. Take it as a > given that inserting a fixed CUTOVER point into the source code (say, > ``CUTOVER = 123456``) is not likely to be very effective, and dynamically > calculating it at import time is impractical. > > *If* Python was a different language, I would spawn two threads, one using > SHORT and the other using LARGE, then which ever completes first, I'd just > kill the other. Alas, this won't work because (1) the GIL and (2) you > cannot forcibly kill threads, only ask them to die and hope they listen. > > I am seeking other ideas for dynamically swapping between the two > algorithms, based on runtime information. Any thoughts? > > > (1) I can't tell in advance how many loops I will make. > > (2) Both SHORT and LARGE get slower as the size of their argument increases. > This is unavoidable due to the nature of the problem. > > (3) SHORT starts off relatively speedy, significantly faster than LARGE for > the first few tens of thousands of loops. I'm not talking about trivial > micro-optimizations here, I'm talking about the difference between 0.1 > second for SHORT versus 10 seconds for LARGE. > > (4) But as the size of the argument increases, SHORT suffers catastrophic > quadratic slowdown, while LARGE slows down only linearly. (Give or take.) > > (5) Consequently, by the time I reach a few million loops, the difference is > now between (say) 5 minutes for LARGE versus 15 hours for SHORT. > > (6) There is no single algorithm which performs acceptably across the entire > range of values I'm expecting to process in practice. > > (7) Leaving the choice up to the caller is not an option. I am the caller. > > > > From python at mrabarnett.plus.com Tue Sep 23 11:42:59 2014 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 23 Sep 2014 16:42:59 +0100 Subject: Dynamically swapping between two algorithms In-Reply-To: <54218831$0$29979$c3e8da3$5496439d@news.astraweb.com> References: <54218831$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: <54219503.6080201@mrabarnett.plus.com> On 2014-09-23 15:48, Steven D'Aprano wrote: > I have a certain calculation which can be performed two radically different > ways. With the first algorithm, let's call it SHORT, performance is very > fast for small values of the argument, but terrible for large values. For > the second algorithm, LARGE, performance is quite poor for small values, > but excellent for large values. > > To add to the complexity, I perform this calculation repeatedly, in a loop: > > value = 1 > while True: > x = SHORT(value) # Or should I use LARGE? Decisions, decisions... > process(x) > value += some_increment() > if condition: break > > Luckily, the value never gets smaller. So if I could somehow determine a > cut-over point, CUTOFF, I might write my loop like this: > > value = 1 > while True: > f = SHORT if value < CUTOFF else LARGE > x = f(value) > process(x) > value += some_increment() > if condition: break > > alas, the CUTOVER point is likely to be machine-dependent. Take it as a > given that inserting a fixed CUTOVER point into the source code (say, > ``CUTOVER = 123456``) is not likely to be very effective, and dynamically > calculating it at import time is impractical. > > *If* Python was a different language, I would spawn two threads, one using > SHORT and the other using LARGE, then which ever completes first, I'd just > kill the other. Alas, this won't work because (1) the GIL and (2) you > cannot forcibly kill threads, only ask them to die and hope they listen. > > I am seeking other ideas for dynamically swapping between the two > algorithms, based on runtime information. Any thoughts? > > > (1) I can't tell in advance how many loops I will make. > > (2) Both SHORT and LARGE get slower as the size of their argument increases. > This is unavoidable due to the nature of the problem. > > (3) SHORT starts off relatively speedy, significantly faster than LARGE for > the first few tens of thousands of loops. I'm not talking about trivial > micro-optimizations here, I'm talking about the difference between 0.1 > second for SHORT versus 10 seconds for LARGE. > > (4) But as the size of the argument increases, SHORT suffers catastrophic > quadratic slowdown, while LARGE slows down only linearly. (Give or take.) > > (5) Consequently, by the time I reach a few million loops, the difference is > now between (say) 5 minutes for LARGE versus 15 hours for SHORT. > > (6) There is no single algorithm which performs acceptably across the entire > range of values I'm expecting to process in practice. > > (7) Leaving the choice up to the caller is not an option. I am the caller. > How about this: Try both of them initially, and use the faster one until it takes longer than the slower one did initially. Then try both of them again. Repeat. From rgaddi at technologyhighland.invalid Tue Sep 23 12:32:44 2014 From: rgaddi at technologyhighland.invalid (Rob Gaddi) Date: Tue, 23 Sep 2014 09:32:44 -0700 Subject: "Fuzzy" Counter? References: <0d28ee82-2240-4f10-9db9-e966c0e62a13@googlegroups.com> Message-ID: <20140923093244.066bb10b@rg.highlandtechnology.com> On Tue, 23 Sep 2014 05:34:19 -0700 (PDT) Miki Tebeka wrote: > Greetings, > > Before I start writing my own. Is there something like collections.Counter (fore frequencies) that does "fuzzy" matching? > > Meaning x is considered equal to y if abs(x - y) < epsilon. (x, y and my case will be numpy.array). > > Thanks, > -- > Miki You'll probably have to write that yourself. While you're at it, think long and hard about that definition of fuzziness. If you can make it closer to the concept of histogram "bins" you'll get much better performance. If, for instance, you can live with 1.anything being one bin, and 2.anything being the next (even though this puts 1.999 and 2.000 into separate bins) then you can just floor() the number and use the result as the key. If you really need the continuous fuzziness you'll probably have to keep the potential keys sorted and run a binary search against the list of them to find the nearest. This will still run you into some problems based on ordering. For instance, with an epsilon of 0.1, you'd put 2.0 into a bin, then 1.9 into the same bin, then 2.1 into the same bin. If however you put 1.9 into that bin first, then 2.0 would go into that bin, but 2.1 would go into a different one. TL;DR you need to think very hard about your problem definition and what you want to happen before you actually try to implement this. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From wolfgang.maier at biologie.uni-freiburg.de Tue Sep 23 12:38:55 2014 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Tue, 23 Sep 2014 18:38:55 +0200 Subject: GCD in Fractions In-Reply-To: <54216c8e$0$29966$c3e8da3$5496439d@news.astraweb.com> References: <54216c8e$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 09/23/2014 02:50 PM, Steven D'Aprano wrote: > > Normally, gcd is only defined for non-negative integers. Wolfram Mathworld, > for example, doesn't mention negative values at all (as far as I can see): > > http://mathworld.wolfram.com/GreatestCommonDivisor.html > > although buried deep in the documentation for Mathematica's GCD function is > hidden the fact that it treats GCD(-a, -b) the same as GCD(a, b): > > http://functions.wolfram.com/IntegerFunctions/GCD/04/02/01/ > > and sure enough Wolfram Alpha tells me that the GCD of *all* of: > > (100, 20) > (-100, 20) > (100, -20) > (-100, -20) > > are equal to +20. On the other hand, Excel and LibreOffice both give an > error for the GCD of a negative value, and I've seen versions of gcd() > which do the same as fractions.gcd. So I think there is not one single > standard way to extend GCD to negative numbers. > Well, Excel and LibreOffice can hardly be considered the gold standard when it comes to mathematical definitions. I'm no mathematician either, but Wikipedia has this to say about the properties of gcd: http://en.wikipedia.org/wiki/Greatest_common_divisor#Properties fractions.gcd violates several of them, like: #2: gcd(a, 0) = |a|, for a ? 0, since any number is a divisor of 0, and the greatest divisor of a is |a|. >>>fractions.gcd(-7, 0) -7 #8: The gcd is a commutative function: gcd(a, b) = gcd(b, a). >>>fractions.gcd(3, -7) == fractions.gcd(-7, 3) False While at first I thought this to be a rather irrelevant debate over module private vs public naming conventions, I now think the OP is probably right and renaming fractions.gcd to fractions._gcd may be a good idea. Googling for recipes to calculate the gcd using python brings up fractions.gcd as a general answer (like at stackoverflow: http://stackoverflow.com/questions/11175131/code-for-greatest-common-divisor-in-python) and it is not obvious for non-mathematicians to realize that it is NOT a generally acceptable solution. Maybe fractions.gcd could be renamed, but be wrapped or reimplemented correctly somewhere else in the stdlib or even in fractions ? Wolfgang From skip at pobox.com Tue Sep 23 12:39:49 2014 From: skip at pobox.com (Skip Montanaro) Date: Tue, 23 Sep 2014 11:39:49 -0500 Subject: Timedelta constructor with string parameter In-Reply-To: References: Message-ID: On Tue, Sep 23, 2014 at 4:11 AM, wrote: > I created some code recently to parse a string and create a timedelta from > it. Interesting. I notice that dateutil.parser.parse already understands you notation: >>> x = dateutil.parser.parse("5h32m15s") >>> x datetime.datetime(2014, 9, 23, 5, 32, 15) All that would be necessary is some way to tell it to generate a timedelta instead of a datetime. Might be better to feed changes back to the dateutil package maintainers. Skip -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue Sep 23 12:41:04 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 24 Sep 2014 02:41:04 +1000 Subject: "Fuzzy" Counter? In-Reply-To: <20140923093244.066bb10b@rg.highlandtechnology.com> References: <0d28ee82-2240-4f10-9db9-e966c0e62a13@googlegroups.com> <20140923093244.066bb10b@rg.highlandtechnology.com> Message-ID: On Wed, Sep 24, 2014 at 2:32 AM, Rob Gaddi wrote: > You'll probably have to write that yourself. While you're at it, think > long and hard about that definition of fuzziness. If you can make it > closer to the concept of histogram "bins" you'll get much better > performance. If, for instance, you can live with 1.anything being one > bin, and 2.anything being the next (even though this puts 1.999 and > 2.000 into separate bins) then you can just floor() the number and use > the result as the key. Or even check three bins based on that - the floor(), floor()+1, and floor()-1 bins. That way, you're not running into problems at any boundaries, and you still limit the exponential growth of the comparisons. But it's still fundamentally problematic. ChrisA From toby at tobiah.org Tue Sep 23 12:53:40 2014 From: toby at tobiah.org (Tobiah) Date: Tue, 23 Sep 2014 09:53:40 -0700 Subject: how to write a html to automatically display the dictionary? In-Reply-To: References: Message-ID: <5421A594.8030604@tobiah.org> On 09/23/2014 07:18 AM, luofeiyu wrote: > x={'f1':1,'f2':2,'f3':3} > how can i create the following html file automatically with python to display x ? > > > > > > > > > > > > >
> f1 > > f2 > > f3 >
> 1 > > 2 > > 3 >
def tablefy(values): print "" for value in values: print "%s" % value print "" x = {'f1': 1,'f2': 2,'f3': 3} print "" tablefy(x.keys()) tablefy(x.values()) print "
" From felipou at gmail.com Tue Sep 23 13:15:43 2014 From: felipou at gmail.com (Felipe Menezes Machado) Date: Tue, 23 Sep 2014 19:15:43 +0200 Subject: Timedelta constructor with string parameter In-Reply-To: References: Message-ID: On Tue, Sep 23, 2014 at 6:39 PM, Skip Montanaro wrote: > > On Tue, Sep 23, 2014 at 4:11 AM, wrote: > >> I created some code recently to parse a string and create a timedelta >> from it. > > > Interesting. I notice that dateutil.parser.parse already understands you > notation: > > >>> x = dateutil.parser.parse("5h32m15s") > >>> x > datetime.datetime(2014, 9, 23, 5, 32, 15) > > All that would be necessary is some way to tell it to generate a timedelta > instead of a datetime. Might be better to feed changes back to the dateutil > package maintainers. > > Cool, thanks for the tip, I didn't know dateutil yet. I looked at the code for the dateutil.parser.parse function, and under the hood it is so much more than my function does. It accepts many different formats, and also handles timezones. So I'd have to study it a little to think of a way for it to generate timedelta objects instead of datetime ones. But I'll definitely keep that in mind! Felipe -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Tue Sep 23 13:20:43 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 23 Sep 2014 11:20:43 -0600 Subject: GCD in Fractions In-Reply-To: References: <54216c8e$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Sep 23, 2014 at 10:38 AM, Wolfgang Maier wrote: > Maybe fractions.gcd could be renamed, but be wrapped or reimplemented > correctly somewhere else in the stdlib or even in fractions ? +1 I don't think the math module as suggested upthread is the right place, as that module houses wrappers of C functions that operate on floats. I'm also not sure where is better, though. Maybe the reimplemented version should just keep the name fractions.gcd. From stefan_ml at behnel.de Tue Sep 23 13:26:27 2014 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 23 Sep 2014 19:26:27 +0200 Subject: GCD in Fractions In-Reply-To: References: <54216c8e$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: Wolfgang Maier schrieb am 23.09.2014 um 18:38: > While at first I thought this to be a rather irrelevant debate over module > private vs public naming conventions, I now think the OP is probably right > and renaming fractions.gcd to fractions._gcd may be a good idea. Making a public API private is rarely a good idea. It should be enough in this case to document the behaviour. And, believe it or not, it actually is documented: https://docs.python.org/3.5/library/fractions.html#fractions.gcd > Googling for recipes to calculate the gcd using python brings up > fractions.gcd as a general answer (like at stackoverflow: > http://stackoverflow.com/questions/11175131/code-for-greatest-common-divisor-in-python) > and it is not obvious for non-mathematicians to realize that it is NOT a > generally acceptable solution. It is. Certainly for positive numbers, which clearly present the majority of use cases. It's definitely the "normal" use case, wouldn't you say? For negative numbers, the "expected" behaviour seems to be unclear, so the current behaviour is just as good as any, so backwards compatibility concerns clearly win this fight. Stefan From noone at nowhere.net Tue Sep 23 13:31:33 2014 From: noone at nowhere.net (blindanagram) Date: Tue, 23 Sep 2014 18:31:33 +0100 Subject: GCD in Fractions In-Reply-To: References: <54216c8e$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 23/09/2014 18:20, Ian Kelly wrote: > On Tue, Sep 23, 2014 at 10:38 AM, Wolfgang Maier > wrote: >> Maybe fractions.gcd could be renamed, but be wrapped or reimplemented >> correctly somewhere else in the stdlib or even in fractions ? > > +1 > > I don't think the math module as suggested upthread is the right > place, as that module houses wrappers of C functions that operate on > floats. I'm also not sure where is better, though. Maybe the > reimplemented version should just keep the name fractions.gcd. Since the gcd is only used once in fractions anyway, it would be easy to change gcd here with very little impact on the performance of the fractions module (if necessary a local version could be added to work within fractions as it does now). From gordon at panix.com Tue Sep 23 13:34:53 2014 From: gordon at panix.com (John Gordon) Date: Tue, 23 Sep 2014 17:34:53 +0000 (UTC) Subject: how to write a html to automatically display the dictionary? References: Message-ID: In luofeiyu writes: > x={'f1':1,'f2':2,'f3':3} > how can i create the following html file automatically with python to > display x ? You might want to use something other than a dictionary, as the order isn't guaranteed. -- 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 ian.g.kelly at gmail.com Tue Sep 23 13:39:17 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 23 Sep 2014 11:39:17 -0600 Subject: GCD in Fractions In-Reply-To: References: <54216c8e$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Sep 23, 2014 at 11:26 AM, Stefan Behnel wrote: > Wolfgang Maier schrieb am 23.09.2014 um 18:38: >> While at first I thought this to be a rather irrelevant debate over module >> private vs public naming conventions, I now think the OP is probably right >> and renaming fractions.gcd to fractions._gcd may be a good idea. > > Making a public API private is rarely a good idea. It should be enough in > this case to document the behaviour. > > And, believe it or not, it actually is documented: > > https://docs.python.org/3.5/library/fractions.html#fractions.gcd I don't think documentation is sufficient in this case. This is the kind of thing though that is easy to forget about if you haven't read the documentation recently. And with a function like gcd, one generally wouldn't expect to *need* to read the documentation. >> Googling for recipes to calculate the gcd using python brings up >> fractions.gcd as a general answer (like at stackoverflow: >> http://stackoverflow.com/questions/11175131/code-for-greatest-common-divisor-in-python) >> and it is not obvious for non-mathematicians to realize that it is NOT a >> generally acceptable solution. > > It is. Certainly for positive numbers, which clearly present the majority > of use cases. It's definitely the "normal" use case, wouldn't you say? > > For negative numbers, the "expected" behaviour seems to be unclear, so the > current behaviour is just as good as any, so backwards compatibility > concerns clearly win this fight. I'm not convinced it's all that clear. In addition to Mathworld and Wikipedia that were already cited, ProofWiki provides an actual proof that gcd(a, b) = gcd(|a|, |b|), by way of noting that a and |a| have the same factors. From noone at nowhere.net Tue Sep 23 13:43:04 2014 From: noone at nowhere.net (blindanagram) Date: Tue, 23 Sep 2014 18:43:04 +0100 Subject: GCD in Fractions In-Reply-To: References: <54216c8e$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 23/09/2014 18:26, Stefan Behnel wrote: > Wolfgang Maier schrieb am 23.09.2014 um 18:38: >> While at first I thought this to be a rather irrelevant debate over module >> private vs public naming conventions, I now think the OP is probably right >> and renaming fractions.gcd to fractions._gcd may be a good idea. > For negative numbers, the "expected" behaviour seems to be unclear, so the > current behaviour is just as good as any, so backwards compatibility > concerns clearly win this fight. The expected behaviour is not unclear for anyone who takes the mathematical properties of the GCD seriously. It's a shame that Python doesn't. From ian.g.kelly at gmail.com Tue Sep 23 13:40:21 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 23 Sep 2014 11:40:21 -0600 Subject: GCD in Fractions In-Reply-To: References: <54216c8e$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Sep 23, 2014 at 11:39 AM, Ian Kelly wrote: > I'm not convinced it's all that clear. In addition to Mathworld and > Wikipedia that were already cited, ProofWiki provides an actual proof > that gcd(a, b) = gcd(|a|, |b|), by way of noting that a and |a| have > the same factors. I forgot to include the link: https://proofwiki.org/wiki/GCD_for_Negative_Integers From shagunkhare at gmail.com Tue Sep 23 13:54:21 2014 From: shagunkhare at gmail.com (SK) Date: Tue, 23 Sep 2014 10:54:21 -0700 (PDT) Subject: NumPy, SciPy, & Python 3X Installation/compatibility issues In-Reply-To: <1267f900-27e8-46c5-839e-81bfafa533a5@googlegroups.com> References: <1267f900-27e8-46c5-839e-81bfafa533a5@googlegroups.com> Message-ID: Hi EK, Did you figure out questions 1, 2 and 3? SciPy (0.14.0) on installation asks me for Python 2.7. First day on Python here, I am really struggling :/ Thanks, SK On Saturday, May 10, 2014 7:07:33 PM UTC+2, esa... at gmail.com wrote: > Hi All-- > > > > Let me state at the start that I am new to Python. I am moving away from Fortran and Matlab to Python and I use all different types of numerical and statistical recipes in my work. I have been reading about NumPy and SciPy and could not find any definitive answers to my questions, below. I had run into many mostly installation problems that I could never get NumPy or SciPy to work with Python 3.3 or newer. I am using Windows7 64 bit OS. > > A few questions: > > 1. What are the latest versions of NumPy and SciPy that are compatible with Python 3.3 or newer and Windows7 64 bit? > > 2. What is the best source to download and install them on my computer? > > 3. Are they all installable on my OS w/o any major problems/addition? > > 4. In the long run, would it be better to use UNIX instead of Windows, if I were to use Python for all of my research? > > Thanks in advance. EK From stefan_ml at behnel.de Tue Sep 23 13:55:57 2014 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 23 Sep 2014 19:55:57 +0200 Subject: GCD in Fractions In-Reply-To: References: <54216c8e$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: blindanagram schrieb am 23.09.2014 um 19:43: > On 23/09/2014 18:26, Stefan Behnel wrote: >> Wolfgang Maier schrieb am 23.09.2014 um 18:38: >>> While at first I thought this to be a rather irrelevant debate over module >>> private vs public naming conventions, I now think the OP is probably right >>> and renaming fractions.gcd to fractions._gcd may be a good idea. >> For negative numbers, the "expected" behaviour seems to be unclear, so the >> current behaviour is just as good as any, so backwards compatibility >> concerns clearly win this fight. > > The expected behaviour is not unclear for anyone who takes the > mathematical properties of the GCD seriously. It's a shame that Python > doesn't. May I ask how you get from one little function in the well-defined scope of a data type module (which is not named "math" or "integers" or "natural" or anything like it) to the extrapolation that Python doesn't take mathematical properties serious? If the scope of that function's applicability does not match what you want in your specific use case, then by all means, don't use it for your specific use case. Stefan From malaclypse2 at gmail.com Tue Sep 23 14:03:36 2014 From: malaclypse2 at gmail.com (Jerry Hill) Date: Tue, 23 Sep 2014 14:03:36 -0400 Subject: NumPy, SciPy, & Python 3X Installation/compatibility issues In-Reply-To: References: <1267f900-27e8-46c5-839e-81bfafa533a5@googlegroups.com> Message-ID: On Tue, Sep 23, 2014 at 1:54 PM, SK wrote: > Hi EK, > Did you figure out questions 1, 2 and 3? SciPy (0.14.0) on installation asks me for Python 2.7. First day on Python here, I am really struggling :/ > Thanks, > SK Did you download the SciPy installer for python 3.3? I see it listed for download on the sourceforge site here: http://sourceforge.net/projects/scipy/files/scipy/0.14.0/scipy-0.14.0-win32-superpack-python3.3.exe/download There are also versions for python 3.4, 3.2, 2.7 and 2.6, so you have to make sure you get the one that matches the version of python you're using. -- Jerry From stefan_ml at behnel.de Tue Sep 23 14:09:23 2014 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 23 Sep 2014 20:09:23 +0200 Subject: GCD in Fractions In-Reply-To: References: <54216c8e$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: Ian Kelly schrieb am 23.09.2014 um 19:39: > On Tue, Sep 23, 2014 at 11:26 AM, Stefan Behnel wrote: >> Wolfgang Maier schrieb am 23.09.2014 um 18:38: >>> While at first I thought this to be a rather irrelevant debate over module >>> private vs public naming conventions, I now think the OP is probably right >>> and renaming fractions.gcd to fractions._gcd may be a good idea. >> >> Making a public API private is rarely a good idea. It should be enough in >> this case to document the behaviour. >> >> And, believe it or not, it actually is documented: >> >> https://docs.python.org/3.5/library/fractions.html#fractions.gcd > > I don't think documentation is sufficient in this case. This is the > kind of thing though that is easy to forget about if you haven't read > the documentation recently. And with a function like gcd, one > generally wouldn't expect to *need* to read the documentation. Interesting. I would definitely consult the documentation first thing if I were considering to pass negative values into a gcd function - into any implementation, even if I had been the very author myself, just two months back. I might even take a look at the source to make sure the docs are correct and up to date, and to look for comments that give further insights. But maybe that's just me. Stefan From mailman at hanez.org Tue Sep 23 14:53:48 2014 From: mailman at hanez.org (Johannes Findeisen) Date: Tue, 23 Sep 2014 20:53:48 +0200 Subject: tcp server as windows service In-Reply-To: <005a01cfd736$34346ad0$9c9d4070$@traxens.com> References: <005a01cfd736$34346ad0$9c9d4070$@traxens.com> Message-ID: <20140923205348.27c23e98@hanez.org> Hi, On Tue, 23 Sep 2014 15:56:41 +0200 Arulnambi Nandagoban wrote: > Hello all, > > > > I developed a multithreaded tcp server with python and I converted into a > windows executable using pyinstaller. > > I would like to run the server as a windows service so that server restarts > whenever pc restarts without > > doing it manually . Help me out with some sample code . Take a look at this post: https://stackoverflow.com/questions/32404/is-it-possible-to-run-a-python-script-as-a-service-in-windows-if-possible-how Read the comments below the solution to add your script to the Windows services list. I didn't do windows development but it seems very easy to do. Regards, Johannes From tjreedy at udel.edu Tue Sep 23 15:21:03 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 23 Sep 2014 15:21:03 -0400 Subject: Dynamically swapping between two algorithms In-Reply-To: <54218831$0$29979$c3e8da3$5496439d@news.astraweb.com> References: <54218831$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 9/23/2014 10:48 AM, Steven D'Aprano wrote: > I have a certain calculation which can be performed two radically different > ways. With the first algorithm, let's call it SHORT, performance is very > fast for small values of the argument, but terrible for large values. For > the second algorithm, LARGE, performance is quite poor for small values, > but excellent for large values. > > To add to the complexity, I perform this calculation repeatedly, in a loop: > > value = 1 > while True: > x = SHORT(value) # Or should I use LARGE? Decisions, decisions... > process(x) > value += some_increment() > if condition: break > > Luckily, the value never gets smaller. So if I could somehow determine a > cut-over point, CUTOFF, I might write my loop like this: > > value = 1 > while True: > f = SHORT if value < CUTOFF else LARGE > x = f(value) > process(x) > value += some_increment() > if condition: break > > alas, the CUTOVER point is likely to be machine-dependent. Take it as a > given that inserting a fixed CUTOVER point into the source code (say, > ``CUTOVER = 123456``) is not likely to be very effective, and dynamically > calculating it at import time is impractical. > > *If* Python was a different language, I would spawn two threads, one using > SHORT and the other using LARGE, then which ever completes first, I'd just > kill the other. Alas, this won't work because (1) the GIL and (2) you > cannot forcibly kill threads, only ask them to die and hope they listen. > > I am seeking other ideas for dynamically swapping between the two > algorithms, based on runtime information. Any thoughts? > > > (1) I can't tell in advance how many loops I will make. > > (2) Both SHORT and LARGE get slower as the size of their argument increases. > This is unavoidable due to the nature of the problem. > > (3) SHORT starts off relatively speedy, significantly faster than LARGE for > the first few tens of thousands of loops. I'm not talking about trivial > micro-optimizations here, I'm talking about the difference between 0.1 > second for SHORT versus 10 seconds for LARGE. > > (4) But as the size of the argument increases, SHORT suffers catastrophic > quadratic slowdown, while LARGE slows down only linearly. (Give or take.) One possibility is to apply both algorithms to a few values below any plausible cutoff value, fit curves (line and quadratic), and find intersection of extrapolated cutoff. Possible calculate a few more values to verify and refine extrapolation. > (5) Consequently, by the time I reach a few million loops, the difference is > now between (say) 5 minutes for LARGE versus 15 hours for SHORT. > > (6) There is no single algorithm which performs acceptably across the entire > range of values I'm expecting to process in practice. > > (7) Leaving the choice up to the caller is not an option. I am the caller. > > > > -- Terry Jan Reedy From breamoreboy at yahoo.co.uk Tue Sep 23 15:30:46 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 23 Sep 2014 20:30:46 +0100 Subject: GCD in Fractions In-Reply-To: References: <54216c8e$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 23/09/2014 18:43, blindanagram wrote: > On 23/09/2014 18:26, Stefan Behnel wrote: >> Wolfgang Maier schrieb am 23.09.2014 um 18:38: >>> While at first I thought this to be a rather irrelevant debate over module >>> private vs public naming conventions, I now think the OP is probably right >>> and renaming fractions.gcd to fractions._gcd may be a good idea. >> For negative numbers, the "expected" behaviour seems to be unclear, so the >> current behaviour is just as good as any, so backwards compatibility >> concerns clearly win this fight. > > The expected behaviour is not unclear for anyone who takes the > mathematical properties of the GCD seriously. It's a shame that Python > doesn't. > All you need do is raise an issue on the bug tracker, provide a patch to code, test and docs and the job is done. -- 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 Tue Sep 23 15:31:39 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 23 Sep 2014 15:31:39 -0400 Subject: GCD in Fractions In-Reply-To: References: Message-ID: On 9/23/2014 4:16 AM, blindanagram wrote: > What is the rationale for gcd(x, y) in Fractions returning a negative > value when y is negtive? > For example gcd(3, -7) returns -1, Since the doc says "the result will have the same sign as b", this is intentinal. However, I consider this a *design* bug. Both -1 and +1 are common divisors, and 1 is the greatest. So I consider the previous line "Calculate the Greatest Common Divisor of a and b" to be incorrect. > which means that a co-prime test that > would work in many other languages 'if gcd(x, y) == 1' will fail in > Python for negative y. > > And, of course, since -|x| is less than |x|, returning -|x| rather than > |x| is not returning the greatest common divisor of x and y when y is > negative. > -- Terry Jan Reedy From ldanielburr at gmail.com Tue Sep 23 15:47:02 2014 From: ldanielburr at gmail.com (ldanielburr at gmail.com) Date: Tue, 23 Sep 2014 12:47:02 -0700 (PDT) Subject: SOAPpy: Expected to find node type 'Element' with name 'CountriesFetchingRequest'; Found node type 'Element' with name 'FetchCountries' In-Reply-To: <257bc927-4ada-4020-8b9c-7781d0802bbc@googlegroups.com> References: <257bc927-4ada-4020-8b9c-7781d0802bbc@googlegroups.com> Message-ID: <1db5ea76-840e-475f-a8b4-1e1539f8d709@googlegroups.com> On Sunday, September 21, 2014 9:31:46 PM UTC-5, vek.... at gmail.com wrote: > I'm messing with SOAP, trying to write a small library to handle stuff I buy from Aramex (shipper). I'm learning XML/SOAP and I'm familiar with RPC from C (Stevens) but no other relevant experience. If this is incredibly dumb just ignore it since I'll probably figure it out eventually. > > > > I'm trying to get a list of countries by calling the CoutriesFetchingRequest method - this is documented here: > > http://www.aramex.com/developers/aramex-apis/47442/Location-Services-API > > http://www.aramex.com/content/uploads/109/232/46790/aramex-location-api-manual.pdf > > > > It takes as its arguments a 'ClientInfo' data-structure and 'Code' which is a string. > > > > There is also a 'FetchCountries' method with an 'input' and 'output' something. > > However python was more clear, print server.show_methods(): > > > > Method Name: FetchCountries > > In #0: parameters ((u'http://ws.aramex.net/ShippingAPI/v1/', u'CountriesFetchingRequest')) > > > > > > The trouble is I don't understand how to call 'CoutriesFetchingRequest' or pass it to FetchCountries. Could someone clarify? > > > > > > The WSDL for Aramex has this: > > http://www.aramex.com/content/uploads/109/232/46790/location-api-wsdl.zip > > > > > > > > > > > > > > > > > > > > > > My python code: > > #!/usr/bin/python > > import xml, fpconst, logging > > from SOAPpy import WSDL > > from suds.client import Client > > > > logging.basicConfig(level=logging.INFO) > > logging.getLogger('suds.client').setLevel(logging.DEBUG) > > > > foo = { 'AccountCountryCode' : 'JO', 'AccountEntity' : 'AMM', 'AccountNumber' : '20016', 'AccountPin' : '331421', 'UserName' : 'testingxxx at aramex.com', 'Password' : 'R123456789$r', 'Version' : 'v1.0', 'Source' : '', 'Transaction' : { 'Reference1' : '001', 'Reference2' : '002', 'Reference3' : '003', 'Reference4' : '004', 'Reference5' : '005' } } > > > > wsdl_file = '/home/veek/location-api-wsdl/Location-API-WSDL.wsdl' > > > > server = WSDL.Proxy(wsdl_file) > > print server.methods.keys() > > print dir(server) > > print server.show_methods() > > callInfo = server.methods['FetchCountries'] > > print type(callInfo) > > print dir(callInfo) > > > > for arg in callInfo.inparams: > > print arg.name.ljust(15), arg.type > > server.namespace = 'http://ws.aramex.net/ShippingAPI/v1/' > > x = server.FetchCountries.CountriesFetchingRequest(foo) > > > > The output i get is: > > [u'FetchCountries', u'FetchCountry', u'ValidateAddress', u'FetchCities', u'FetchOffices'] > > ['__doc__', '__getattr__', '__init__', '__module__', '__str__', 'methods', 'show_methods', 'soapproxy', 'wsdl'] > > Method Name: FetchCountries > > > > In #0: parameters ((u'http://ws.aramex.net/ShippingAPI/v1/', u'CountriesFetchingRequest')) > > > > Out #0: parameters ((u'http://ws.aramex.net/ShippingAPI/v1/', u'CountriesFetchingResponse')) > > > > > > > > None > > > > ['__doc__', '__init__', '__module__', 'addInHeaderInfo', 'addInParameter', 'addOutHeaderInfo', 'addOutParameter', 'documentation', 'encodingStyle', 'getInHeaders', 'getInParameters', 'getOutHeaders', 'getOutParameters', 'getReturnParameter', 'inheaders', 'inparams', 'location', 'methodName', 'namespace', 'outheaders', 'outparams', 'retval', 'setReturnParameter', 'soapAction', 'style', 'transport', 'use'] > > parameters (u'http://ws.aramex.net/ShippingAPI/v1/', u'CountriesFetchingRequest') > > > > > > > > SOAPpy.Types.faultType: > Give pysimplesoap a try; you can point it at the wsdl endpoint, and it will provide you a client that lets you call methods in about as obvious a manner as you can reasonably hope for, given the mess that is SOAP. See https://code.google.com/p/pysimplesoap/wiki/SoapClient for some examples. From denismfmcmahon at gmail.com Tue Sep 23 16:20:46 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Tue, 23 Sep 2014 20:20:46 +0000 (UTC) Subject: how to write a html to automatically display the dictionary? References: <5421A594.8030604@tobiah.org> Message-ID: On Tue, 23 Sep 2014 09:53:40 -0700, Tobiah wrote: > On 09/23/2014 07:18 AM, luofeiyu wrote: >> how can i create the following html >> f3 >> No here? >> >> 1 ... >> >> 3 >> >> What is the above doing there? >> >> > [code] Although your solution will produce valid html, it doesn't produce the specified output. ;) -- Denis McMahon, denismfmcmahon at gmail.com From denismfmcmahon at gmail.com Tue Sep 23 16:53:42 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Tue, 23 Sep 2014 20:53:42 +0000 (UTC) Subject: how to write a html to automatically display the dictionary? References: Message-ID: On Tue, 23 Sep 2014 17:34:53 +0000, John Gordon wrote: > In luofeiyu > writes: > >> x={'f1':1,'f2':2,'f3':3} >> how can i create the following html file automatically with python to >> display x ? > > You might want to use something other than a dictionary, as the order > isn't guaranteed. Assuming you want them in order of the key field: from string import * x={'f1':1,'f2':2,'f3':3} y = [ (a,x[a]) for a in x.keys() ] y.sort( cmp=lambda a,b: cmp(a[0],b[0]) ) table = ( "\n" + "\n".join(["\n" + "\n".join(["".format(z[i]) for z in y]) + "\n" for i in range(len(y[0]))]) + "\n
{}
" ) print table -- Denis McMahon, denismfmcmahon at gmail.com From illusiontechniques at gmail.com Tue Sep 23 16:54:54 2014 From: illusiontechniques at gmail.com (C Smith) Date: Tue, 23 Sep 2014 13:54:54 -0700 Subject: Dynamically swapping between two algorithms In-Reply-To: References: <54218831$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: Once the runtime of SHORT starts to increase by a certain threshold, Such as 2x, 4x, or 16x its last runtime? The other ideas already proposed sound better, but I am wondering if it would work. On Tue, Sep 23, 2014 at 12:21 PM, Terry Reedy wrote: > On 9/23/2014 10:48 AM, Steven D'Aprano wrote: >> >> I have a certain calculation which can be performed two radically >> different >> ways. With the first algorithm, let's call it SHORT, performance is very >> fast for small values of the argument, but terrible for large values. For >> the second algorithm, LARGE, performance is quite poor for small values, >> but excellent for large values. >> >> To add to the complexity, I perform this calculation repeatedly, in a >> loop: >> >> value = 1 >> while True: >> x = SHORT(value) # Or should I use LARGE? Decisions, decisions... >> process(x) >> value += some_increment() >> if condition: break >> >> Luckily, the value never gets smaller. So if I could somehow determine a >> cut-over point, CUTOFF, I might write my loop like this: >> >> value = 1 >> while True: >> f = SHORT if value < CUTOFF else LARGE >> x = f(value) >> process(x) >> value += some_increment() >> if condition: break >> >> alas, the CUTOVER point is likely to be machine-dependent. Take it as a >> given that inserting a fixed CUTOVER point into the source code (say, >> ``CUTOVER = 123456``) is not likely to be very effective, and dynamically >> calculating it at import time is impractical. >> >> *If* Python was a different language, I would spawn two threads, one using >> SHORT and the other using LARGE, then which ever completes first, I'd just >> kill the other. Alas, this won't work because (1) the GIL and (2) you >> cannot forcibly kill threads, only ask them to die and hope they listen. >> >> I am seeking other ideas for dynamically swapping between the two >> algorithms, based on runtime information. Any thoughts? >> >> >> (1) I can't tell in advance how many loops I will make. >> >> (2) Both SHORT and LARGE get slower as the size of their argument >> increases. >> This is unavoidable due to the nature of the problem. >> >> (3) SHORT starts off relatively speedy, significantly faster than LARGE >> for >> the first few tens of thousands of loops. I'm not talking about trivial >> micro-optimizations here, I'm talking about the difference between 0.1 >> second for SHORT versus 10 seconds for LARGE. >> >> (4) But as the size of the argument increases, SHORT suffers catastrophic >> quadratic slowdown, while LARGE slows down only linearly. (Give or take.) > > > One possibility is to apply both algorithms to a few values below any > plausible cutoff value, fit curves (line and quadratic), and find > intersection of extrapolated cutoff. Possible calculate a few more values > to verify and refine extrapolation. > > >> (5) Consequently, by the time I reach a few million loops, the difference >> is >> now between (say) 5 minutes for LARGE versus 15 hours for SHORT. >> >> (6) There is no single algorithm which performs acceptably across the >> entire >> range of values I'm expecting to process in practice. >> >> (7) Leaving the choice up to the caller is not an option. I am the caller. >> >> >> >> > > > -- > Terry Jan Reedy > > -- > https://mail.python.org/mailman/listinfo/python-list From juan0christian at gmail.com Tue Sep 23 17:32:34 2014 From: juan0christian at gmail.com (Juan Christian) Date: Tue, 23 Sep 2014 18:32:34 -0300 Subject: Flask and Python 3 Message-ID: I'm following a tutorial about Flask using Python 3.4.1, but I'm getting an error with a dead simple example: generator.py: from flask import Flask, render_template app = Flask(__name__) @app.route('/') def index(): return 'Hello World' @app.route('/blog/post/') def post(): return render_template('post.html', post_content = "Hello, World (from a template)") if __name__ == '__main__': app.run(port = 8000) ------------------------ base.html: {% block head %} Test {% endlbock head %} {% block content %}{% endlbock content %} ------------------------ post.html: {% extends "base.html" %} {% block content %}
{{ post_content }}
{% endblock content %} ------------------------ I typed everything correct,acessing http://localhost:8000 works, but http://localhost:8000/blog/post/ gives me ' 500 Internal Server Error '. Why? Python 3.4.1 Flask (0.10.1) itsdangerous (0.24) Jinja2 (2.7.3) MarkupSafe (0.23) pip (1.5.6) setuptools (5.8) Werkzeug (0.9.6) -------------- next part -------------- An HTML attachment was scrubbed... URL: From noone at nowhere.net Tue Sep 23 17:38:08 2014 From: noone at nowhere.net (blindanagram) Date: Tue, 23 Sep 2014 22:38:08 +0100 Subject: GCD in Fractions In-Reply-To: References: <54216c8e$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 23/09/2014 18:55, Stefan Behnel wrote: > blindanagram schrieb am 23.09.2014 um 19:43: >> On 23/09/2014 18:26, Stefan Behnel wrote: >>> Wolfgang Maier schrieb am 23.09.2014 um 18:38: >>>> While at first I thought this to be a rather irrelevant debate over module >>>> private vs public naming conventions, I now think the OP is probably right >>>> and renaming fractions.gcd to fractions._gcd may be a good idea. >>> For negative numbers, the "expected" behaviour seems to be unclear, so the >>> current behaviour is just as good as any, so backwards compatibility >>> concerns clearly win this fight. >> >> The expected behaviour is not unclear for anyone who takes the >> mathematical properties of the GCD seriously. It's a shame that Python >> doesn't. > > May I ask how you get from one little function in the well-defined scope of > a data type module (which is not named "math" or "integers" or "natural" or > anything like it) to the extrapolation that Python doesn't take > mathematical properties serious? Firstly I have to choose between two possibilities: (a) that the name of the function has been deliberately chosen to imply that it calculates the mathematical function known as the 'greatest commmon divisor'; or (b) that the initials 'gcd' have been chosen by pure chance and the association between this function and the 'greatest commmon divisor' has arisen from pure coincidence. Of these, I find (a) overwhelmingly more likely. Seccondly (as others here have pointed out), the mathematical properties of the greatest common divisor are well defined for both positive and negative integers. But the Python function called gcd doesn't have some of these properties. I hence conclude that Python doesn't take the mathematical properties of the greatest common divisor seriously since it doesn't ensure that its version of this function has these properties. From noone at nowhere.net Tue Sep 23 17:48:26 2014 From: noone at nowhere.net (blindanagram) Date: Tue, 23 Sep 2014 22:48:26 +0100 Subject: GCD in Fractions In-Reply-To: References: <54216c8e$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 23/09/2014 20:30, Mark Lawrence wrote: > On 23/09/2014 18:43, blindanagram wrote: >> On 23/09/2014 18:26, Stefan Behnel wrote: >>> Wolfgang Maier schrieb am 23.09.2014 um 18:38: >>>> While at first I thought this to be a rather irrelevant debate over >>>> module >>>> private vs public naming conventions, I now think the OP is probably >>>> right >>>> and renaming fractions.gcd to fractions._gcd may be a good idea. >>> For negative numbers, the "expected" behaviour seems to be unclear, >>> so the >>> current behaviour is just as good as any, so backwards compatibility >>> concerns clearly win this fight. >> >> The expected behaviour is not unclear for anyone who takes the >> mathematical properties of the GCD seriously. It's a shame that Python >> doesn't. >> > All you need do is raise an issue on the bug tracker, provide a patch to > code, test and docs and the job is done. Thank you for your helpful comment. I will happily do this if after discussion here there is a reasonable level of support and encouragement for such an action. However, there is at least one person here who takes the view that backward compatibility outranks mathematical correctness and I don't want to find that 'I am banging my head against a brick wall' if this is likely to be the stance that Python developers take. From gordon at panix.com Tue Sep 23 17:48:56 2014 From: gordon at panix.com (John Gordon) Date: Tue, 23 Sep 2014 21:48:56 +0000 (UTC) Subject: Flask and Python 3 References: Message-ID: In Juan Christian writes: > @app.route('/') > def index(): > return 'Hello World' As posted, your code is not indented. Is this literally how your code looks? > {% block content %}{% endlbock content %} "endlbock" is certainly a typo. > I typed everything correct,acessing http://localhost:8000 works, but > http://localhost:8000/blog/post/ gives me ' 500 Internal Server Error '. > Why? Have you looked in the http server error log for an explanatory error message? -- 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 juan0christian at gmail.com Tue Sep 23 17:57:00 2014 From: juan0christian at gmail.com (Juan Christian) Date: Tue, 23 Sep 2014 18:57:00 -0300 Subject: Flask and Python 3 In-Reply-To: References: Message-ID: On Tue, Sep 23, 2014 at 6:48 PM, John Gordon wrote: > > > @app.route('/') > > def index(): > > return 'Hello World' > > As posted, your code is not indented. Is this literally how your code > looks? > > The mail screwed the indentation, it's indented in the file. > > {% block content %}{% endlbock content %} > > "endlbock" is certainly a typo. Oh my Gooooodd... Yes, that's it, working 100% now. Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From larry.martell at gmail.com Tue Sep 23 18:01:34 2014 From: larry.martell at gmail.com (Larry Martell) Date: Tue, 23 Sep 2014 16:01:34 -0600 Subject: Best way to deal with different data types in a list comprehension Message-ID: I have some code that I inherited: ' '.join([self.get_abbrev()] + [str(f['value') for f in self.filters if f.has_key('value')]).strip() This broke today when it encountered some non-ascii data. I changed the str(f['value']) line to f['value'].encode('utf-8'), which works fine, except when f['value'] is not a string (it could be anything). Without rewriting this without the list comprehension, how can I write this to deal with both strings and non-strings? From miguelglafuente at gmail.com Tue Sep 23 18:05:52 2014 From: miguelglafuente at gmail.com (Rock Neurotiko) Date: Wed, 24 Sep 2014 00:05:52 +0200 Subject: Best way to deal with different data types in a list comprehension In-Reply-To: References: Message-ID: Maybe there are a different way, but you can do this: ' '.join([self.get_abbrev()] + [str(f['value').encode('utf-8') if type(f['value']) is str else str(f['value'] for f in self.filters if f.has_key('value')]).strip() 2014-09-24 0:01 GMT+02:00 Larry Martell : > I have some code that I inherited: > > ' '.join([self.get_abbrev()] + > [str(f['value') > for f in self.filters > if f.has_key('value')]).strip() > > > This broke today when it encountered some non-ascii data. > > I changed the str(f['value']) line to f['value'].encode('utf-8'), > which works fine, except when f['value'] is not a string (it could be > anything). > > Without rewriting this without the list comprehension, how can I write > this to deal with both strings and non-strings? > -- > https://mail.python.org/mailman/listinfo/python-list > -- Miguel Garc?a Lafuente - Rock Neurotiko Do it, the devil is in the details. The quieter you are, the more you are able to hear. Happy Coding. Code with Passion, Decode with Patience. If we make consistent effort, based on proper education, we can change the world. El contenido de este e-mail es privado, no se permite la revelacion del contenido de este e-mail a gente ajena a ?l. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ckaynor at zindagigames.com Tue Sep 23 18:17:22 2014 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Tue, 23 Sep 2014 15:17:22 -0700 Subject: Best way to deal with different data types in a list comprehension In-Reply-To: References: Message-ID: On Tue, Sep 23, 2014 at 3:01 PM, Larry Martell wrote: > I have some code that I inherited: > > ' '.join([self.get_abbrev()] + > [str(f['value') > for f in self.filters > if f.has_key('value')]).strip() > > This broke today when it encountered some non-ascii data. > One option would be to do the processing in unicode, and convert to utf-8 only when needed: u' '.join([self.get_abbrev()] + [unicode(f['value') for f in self.filters if f.has_key('value')]).strip() If needed, add a .encode('utf-8') to the end. > > I changed the str(f['value']) line to f['value'].encode('utf-8'), > which works fine, except when f['value'] is not a string (it could be > anything). > > Without rewriting this without the list comprehension, how can I write > this to deal with both strings and non-strings? > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From irmen.NOSPAM at xs4all.nl Tue Sep 23 18:16:50 2014 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Wed, 24 Sep 2014 00:16:50 +0200 Subject: Pyrolite, lightweight pickle and pyro client library, seeking a bit of testing help In-Reply-To: References: <542060bf$0$2929$e4fe514c@news.xs4all.nl> <5420690b$0$2833$e4fe514c@news.xs4all.nl> Message-ID: <5421f152$0$2932$e4fe514c@news2.news.xs4all.nl> On 22-9-2014 20:28, Chris Angelico wrote: > On Tue, Sep 23, 2014 at 4:23 AM, Irmen de Jong wrote: >> This is why Pyro has been using a different (and safe) serializer by default for a while >> now. You have to plow through the usual security warnings in the docs and make a >> conscious effort in your code to enable the pickle serializer if you really want/need it. > > Is the safe serializer affected by byte order? If not, you could just > mark this off as a known bug, and say "if anyone has a big-endian > system to test this on, please help out". It would be another > incentive to use the safe serializer rather than pickle. And it'd save > you a lot of trouble. :) The safe serializer is this one: https://github.com/irmen/serpent and it is a text based protocol, so no, it is not affected by byte order. It uses Python literal expressions as understood by ast.literal_eval(). Note that the endianness bug in my pickle implementation was fixed by the pull request so it is no longer a known bug. But I still would like to be able to run the test suite on both endianness platforms (or let someone else try it for me :-) ) > > I would have offered one of my systems for the test, except ... > they're all little-endian. I'm all PC-based hardware here (mainly > Linux running on Intel CPUs, though there are some variations). Heh, yes; I used to have a PowerPC G4 mac mini (a big endian platform), but that machine got replaced by an Intel based one (little endian, as all the other computers I have access to). Ah well. Irmen From larry.martell at gmail.com Tue Sep 23 18:20:06 2014 From: larry.martell at gmail.com (Larry Martell) Date: Tue, 23 Sep 2014 18:20:06 -0400 Subject: Best way to deal with different data types in a list comprehension In-Reply-To: References: Message-ID: On Tue, Sep 23, 2014 at 6:05 PM, Rock Neurotiko wrote: > 2014-09-24 0:01 GMT+02:00 Larry Martell : >> >> I have some code that I inherited: >> >> ' '.join([self.get_abbrev()] + >> [str(f['value') >> for f in self.filters >> if f.has_key('value')]).strip() >> >> >> This broke today when it encountered some non-ascii data. >> >> I changed the str(f['value']) line to f['value'].encode('utf-8'), >> which works fine, except when f['value'] is not a string (it could be >> anything). >> >> Without rewriting this without the list comprehension, how can I write >> this to deal with both strings and non-strings? > Maybe there are a different way, but you can do this: > > ' '.join([self.get_abbrev()] + > [str(f['value').encode('utf-8') if type(f['value']) is str else > str(f['value'] > for f in self.filters > if f.has_key('value')]).strip() Thanks for the reply, but please don't top post. This worked for me: '.join([self.get_abbrev()] + [f['value'].encode('utf-8') if type(f['value']) is unicode else str(f['value']) for f in self.filters if f.has_key('value')]).strip() From breamoreboy at yahoo.co.uk Tue Sep 23 18:52:54 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 23 Sep 2014 23:52:54 +0100 Subject: GCD in Fractions In-Reply-To: References: <54216c8e$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 23/09/2014 22:48, blindanagram wrote: > On 23/09/2014 20:30, Mark Lawrence wrote: >> On 23/09/2014 18:43, blindanagram wrote: >>> On 23/09/2014 18:26, Stefan Behnel wrote: >>>> Wolfgang Maier schrieb am 23.09.2014 um 18:38: >>>>> While at first I thought this to be a rather irrelevant debate over >>>>> module >>>>> private vs public naming conventions, I now think the OP is probably >>>>> right >>>>> and renaming fractions.gcd to fractions._gcd may be a good idea. >>>> For negative numbers, the "expected" behaviour seems to be unclear, >>>> so the >>>> current behaviour is just as good as any, so backwards compatibility >>>> concerns clearly win this fight. >>> >>> The expected behaviour is not unclear for anyone who takes the >>> mathematical properties of the GCD seriously. It's a shame that Python >>> doesn't. >>> >> All you need do is raise an issue on the bug tracker, provide a patch to >> code, test and docs and the job is done. > > Thank you for your helpful comment. I will happily do this if after > discussion here there is a reasonable level of support and encouragement > for such an action. > > However, there is at least one person here who takes the view that > backward compatibility outranks mathematical correctness and I don't > want to find that 'I am banging my head against a brick wall' if this is > likely to be the stance that Python developers take. > From https://docs.python.org/devguide/experts.html Mark Dickinson and Raymond Hettinger are listed as the maintainers of the fractions module. If they're not lurking here I'd guess the simplest way to contact them is via the bug tracker. That also gives the official mechanism as to whether or not an enhancement request such as this is accepted or rejected and the rationale behind the decision. For example it is feasible that the current behaviour would be deprecated in Python 3.5 and changed in 3.6 to match your needs. I don't have enough knowledge of the maths to say one way or another, but I'm certain that others will chip in with their comments. Best of luck anyway :) -- 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 Tue Sep 23 19:06:25 2014 From: elearn2014 at gmail.com (luofeiyu) Date: Wed, 24 Sep 2014 07:06:25 +0800 Subject: how to write a html to automatically display the dictionary? In-Reply-To: References: <54218121.8060902@gmail.com> Message-ID: <5421FCF1.2060409@gmail.com> how can i create the proper html file with /Jinjia/2 or other temple? Joel Goldstick wrote: Generally, you would use a framework like django or others. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Tue Sep 23 19:46:41 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 23 Sep 2014 19:46:41 -0400 Subject: Flask and Python 3 In-Reply-To: References: Message-ID: On 9/23/2014 5:57 PM, Juan Christian wrote: > On Tue, Sep 23, 2014 at 6:48 PM, John Gordon > wrote: > > > @app.route('/') > > def index(): > > return 'Hello World' > > As posted, your code is not indented. Is this literally how your code > looks? > > The mail screwed the indentation, it's indented in the file. Did you use tabs? They are more likely to disappear than spaces. -- Terry Jan Reedy From ned at nedbatchelder.com Tue Sep 23 19:55:52 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 23 Sep 2014 19:55:52 -0400 Subject: how to write a html to automatically display the dictionary? In-Reply-To: References: Message-ID: On 9/23/14 4:53 PM, Denis McMahon wrote: > from string import * You aren't using any names from string, so you can skip this line. > > x={'f1':1,'f2':2,'f3':3} > y = [ (a,x[a]) for a in x.keys() ] > y.sort( cmp=lambda a,b: cmp(a[0],b[0]) ) This is more easily done as: y = sorted(x.items()) .items() returns a sequence of (key, value) pairs, and tuples are sorted lexicographically, so the first elements are compared first, then the second, etc. -- Ned Batchelder, http://nedbatchelder.com From jon+usenet at unequivocal.co.uk Tue Sep 23 20:33:38 2014 From: jon+usenet at unequivocal.co.uk (Jon Ribbens) Date: Wed, 24 Sep 2014 00:33:38 +0000 (UTC) Subject: Flask and Python 3 References: Message-ID: On 2014-09-23, Juan Christian wrote: > if __name__ == '__main__': > app.run(port = 8000) app.run(port=8000, debug=True) might've made the problem easier to find. From juan0christian at gmail.com Tue Sep 23 21:23:07 2014 From: juan0christian at gmail.com (Juan Christian) Date: Tue, 23 Sep 2014 22:23:07 -0300 Subject: Flask and Python 3 In-Reply-To: References: Message-ID: On Tue, Sep 23, 2014 at 8:46 PM, Terry Reedy wrote: > > Did you use tabs? They are more likely to disappear than spaces. Yes, I use tabs. On Tue, Sep 23, 2014 at 9:33 PM, Jon Ribbens wrote: > > app.run(port=8000, debug=True) might've made the problem easier to find. > I didn't learn debug with Flask yet. Only in the next videos. -------------- next part -------------- An HTML attachment was scrubbed... URL: From vek.m1234 at gmail.com Tue Sep 23 22:48:15 2014 From: vek.m1234 at gmail.com (Veek M) Date: Wed, 24 Sep 2014 09:18:15 +0630 Subject: SOAPpy: Expected to find node type 'Element' with name 'CountriesFetchingRequest'; Found node type 'Element' with name 'FetchCountries' References: <257bc927-4ada-4020-8b9c-7781d0802bbc@googlegroups.com> Message-ID: dieter wrote: > I have no experience with "SOAPpy", but with "suds" (another Python > SAOP client). A "suds" client exposes two attributes "factory" *miaows happily* From miki.tebeka at gmail.com Wed Sep 24 00:57:50 2014 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Tue, 23 Sep 2014 21:57:50 -0700 (PDT) Subject: "Fuzzy" Counter? In-Reply-To: References: <0d28ee82-2240-4f10-9db9-e966c0e62a13@googlegroups.com> Message-ID: <599ba7b9-1df3-44d4-bceb-fb477ae5cb10@googlegroups.com> On Tuesday, September 23, 2014 4:37:10 PM UTC+3, Peter Otten wrote: > x eq y > y eq z > not (x eq z) > > where eq is the test given above -- should x, y, and z land in the same bin? Yeah, I know the counting depends on the order of items. But I'm OK with that. From miki.tebeka at gmail.com Wed Sep 24 01:01:51 2014 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Tue, 23 Sep 2014 22:01:51 -0700 (PDT) Subject: "Fuzzy" Counter? In-Reply-To: <20140923093244.066bb10b@rg.highlandtechnology.com> References: <0d28ee82-2240-4f10-9db9-e966c0e62a13@googlegroups.com> <20140923093244.066bb10b@rg.highlandtechnology.com> Message-ID: <1a63fb8d-e0b8-4385-acbc-ddb6bf1f0f7d@googlegroups.com> On Tuesday, September 23, 2014 7:33:06 PM UTC+3, Rob Gaddi wrote: > While you're at it, think > long and hard about that definition of fuzziness. If you can make it > closer to the concept of histogram "bins" you'll get much better > performance. The problem for me here is that I can't determine the number of bins in advance. I'd like to get frequencies. I guess every "new" (don't have any previous equal item) can be a bin. > TL;DR you need to think very hard about your problem definition and > what you want to happen before you actually try to implement this. Always a good advice :) I'm actually implementing algorithm for someone else (in the bio world where I know very little about). From elearn2014 at gmail.com Tue Sep 23 21:29:23 2014 From: elearn2014 at gmail.com (luofeiyu) Date: Wed, 24 Sep 2014 09:29:23 +0800 Subject: how to display the result in table with jinkoa2 temple? Message-ID: <54221E73.8050504@gmail.com> import sqlite3 db=r'F:\workspace\china\data\china.sqlite' con=sqlite3.connect(db) cur=con.cursor() res=cur.execute('select ??,????,????,????,?????? from profile limit 20').fetchall() the result is a list. >>> for row in res: ... print(row) ... ('600000', '??', '187?', 39340.0, 30.0) ('600004', '????', '11.5?', 4499.0, 23.0) ('600005', '????', '101?', 38857.0, 24.0) ('600006', '????', '20.0?', 10290.0, 20.0) ('600007', '???', '10.1?', 2332.0, 19.0) ('600008', '????', '22.0?', 6515.0, 20.0) ('600009', '????', '19.3?', 5472.0, 18.0) ('600010', '????', '80.0?', 31389.0, 19.0) ('600011', '????', '141?', 37729.0, 29.0) ('600012', '????', '16.6?', 2106.0, 14.0) ('600015', '??', '89.0?', 25200.0, 34.0) ('600016', '??', '340?', 54927.0, 32.0) ('600017', '????', '30.8?', 5340.0, 21.0) ('600018', '????', '228?', 19842.0, 20.0) ('600019', '????', '165?', 37487.0, 23.0) ('600020', '????', '22.5?', 2959.0, 32.0) ('600021', '????', '21.4?', 6673.0, 22.0) ('600022', '????', '64.4?', 31738.0, 20.0) ('600023', '????', '118?', 10142.0, 14.0) ('600026', '????', '34.0?', 7536.0, 21.0) >>> i want to display it in html table . html_str='' for row in res: html_str=html_str+'' for col in row: html_str=html_str+'' html_str=html_str+'' html_str=html_str+'
'+str(col).replace('\s','') html_str=html_str+'
' myhtml=open('f:\\test.html','w') myhtml.write(html_str) myhtml.close() when i open 'f:\\test.html' in chrome , how can i change my code more elegantly with temple jinjia2 to do the same display ? -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: ibbiefdi.png Type: image/png Size: 19642 bytes Desc: not available URL: From dieter at handshake.de Wed Sep 24 03:44:26 2014 From: dieter at handshake.de (dieter) Date: Wed, 24 Sep 2014 09:44:26 +0200 Subject: Dynamically swapping between two algorithms References: <54218831$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87zjdpea3p.fsf@handshake.de> Steven D'Aprano writes: > ... > *If* Python was a different language, I would spawn two threads, one using > SHORT and the other using LARGE, then which ever completes first, I'd just > kill the other. Alas, this won't work because (1) the GIL The GIL does not prevent this scenario. The two threads will not really run in parallel but interleaved - but this should not be a big problem. > and (2) you > cannot forcibly kill threads, only ask them to die and hope they listen. You can kill threads (though you will need a "C" level function for this) as long as they execute Python code. And it is your code: you can make your threads be listening, from time to time in the computation. From jeanmichel at sequans.com Wed Sep 24 05:27:24 2014 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 24 Sep 2014 11:27:24 +0200 (CEST) Subject: how to write a html to automatically display the dictionary? In-Reply-To: <5421FCF1.2060409@gmail.com> Message-ID: <1554094191.7296518.1411550844759.JavaMail.root@sequans.com> ----- Original Message ----- > From: "luofeiyu" > To: "Joel Goldstick" , python-list at python.org > Sent: Wednesday, 24 September, 2014 1:06:25 AM > Subject: Re: how to write a html to automatically display the dictionary? > > > how can i create the proper html file with Jinjia 2 or other temple? > template :) I'm surprised you didn't figure it out by looking at jinja2 examples in their documentation. python 2.7 : from jinja2 import Template template = Template(''' {% for k in x.keys()%}{%endfor%}{% for k in x.values()%}{%endfor%}
{{k}}
{{k}}
''') with open('foo.html', 'w') as myFile: myFile.write(template.render(x={'f1':1,'f2':2,'f3':3})) Regards, JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From elearn2014 at gmail.com Wed Sep 24 05:32:02 2014 From: elearn2014 at gmail.com (luofeiyu) Date: Wed, 24 Sep 2014 17:32:02 +0800 Subject: why can't open the file with browser? Message-ID: <54228F92.90409@gmail.com> | import webbrowser webbrowser.open('f:\\test.html') why the file f:\\test.html is opened by notepad ,not by my firefox or chrome? | -------------- next part -------------- An HTML attachment was scrubbed... URL: From robin at reportlab.com Wed Sep 24 05:53:06 2014 From: robin at reportlab.com (Robin Becker) Date: Wed, 24 Sep 2014 10:53:06 +0100 Subject: import reloading Message-ID: <54229482.6040104@chamonix.reportlab.co.uk> I'm tryng to bring some outdated ihooks code into the modern world. I notice that module loaders are supposed to re-use an existing module if it is already in sys.modules. Is a loader supposed to reset all the reused module's attributes and reset the __dict__ or does it just run the code from the module in hte __dict__? -- Robin Becker From breamoreboy at yahoo.co.uk Wed Sep 24 06:42:59 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 24 Sep 2014 11:42:59 +0100 Subject: GCD in Fractions In-Reply-To: References: <54216c8e$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 23/09/2014 23:52, Mark Lawrence wrote: > On 23/09/2014 22:48, blindanagram wrote: >> On 23/09/2014 20:30, Mark Lawrence wrote: >>> On 23/09/2014 18:43, blindanagram wrote: >>> All you need do is raise an issue on the bug tracker, provide a patch to >>> code, test and docs and the job is done. >> >> Thank you for your helpful comment. I will happily do this if after >> discussion here there is a reasonable level of support and encouragement >> for such an action. >> >> However, there is at least one person here who takes the view that >> backward compatibility outranks mathematical correctness and I don't >> want to find that 'I am banging my head against a brick wall' if this is >> likely to be the stance that Python developers take. >> > > From https://docs.python.org/devguide/experts.html Mark Dickinson and > Raymond Hettinger are listed as the maintainers of the fractions module. > If they're not lurking here I'd guess the simplest way to contact them > is via the bug tracker. That also gives the official mechanism as to > whether or not an enhancement request such as this is accepted or > rejected and the rationale behind the decision. For example it is > feasible that the current behaviour would be deprecated in Python 3.5 > and changed in 3.6 to match your needs. I don't have enough knowledge > of the maths to say one way or another, but I'm certain that others will > chip in with their comments. Best of luck anyway :) > Somebody got there first http://bugs.python.org/issue22477 -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From mdickinson at enthought.com Wed Sep 24 07:14:59 2014 From: mdickinson at enthought.com (Mark Dickinson) Date: Wed, 24 Sep 2014 11:14:59 +0000 (UTC) Subject: GCD in Fractions References: <54216c8e$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: Mark Lawrence yahoo.co.uk> writes: > Somebody got there first http://bugs.python.org/issue22477 I think there's good reason to suspect that Brian Gladman and blindanagram are one and the same. :-) >>> sorted("BrianGladman".lower()) == sorted("blindanagram") True From skip at pobox.com Wed Sep 24 07:31:20 2014 From: skip at pobox.com (Skip Montanaro) Date: Wed, 24 Sep 2014 06:31:20 -0500 Subject: why can't open the file with browser? In-Reply-To: <54228F92.90409@gmail.com> References: <54228F92.90409@gmail.com> Message-ID: Maybe it's supposed to be file://localhost/test.html ? Just a guess, as I don't use Windows. Skip On Wed, Sep 24, 2014 at 4:32 AM, luofeiyu wrote: > > import webbrowser > webbrowser.open('f:\\test.html') > > why the file f:\\test.html is opened by notepad ,not by my firefox or chrome? > > > > > -- > https://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Wed Sep 24 07:44:10 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 24 Sep 2014 21:44:10 +1000 Subject: GCD in Fractions References: <54216c8e$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5422ae8b$0$29980$c3e8da3$5496439d@news.astraweb.com> blindanagram wrote: > Seccondly (as others here have pointed out), the mathematical properties > of the greatest common divisor are well defined for both positive and > negative integers. You keep saying that, but it simply is not true. Different people use different definitions. Some refuse to allow negative arguments at all. Some insist that the GCD must be positive. Others allow it to be negative. GCD is well-defined for **positive integers only**. Mathworld emphasises "positive integers" in their definition, repeating the phrase THREE times in the first paragraph: The greatest common divisor, sometimes also called the highest common divisor (Hardy and Wright 1979, p. 20), of two positive integers a and b is the largest divisor common to a and b. For example, GCD(3,5)=1, GCD(12,60)=12, and GCD(12,90)=6. The greatest common divisor GCD(a,b,c,...) can also be defined for three or more positive integers as the largest divisor shared by all of them. Two or more positive integers that have greatest common divisor 1 are said to be relatively prime to one another, often simply just referred to as being "relatively prime." http://mathworld.wolfram.com/GreatestCommonDivisor.html The rest of the page avoids mentioning anything about negative values. There are five graphs on the page, all five are limited to only positive values. Mathworld does show one thing that suggests an interpretation for the GCD of negative values: The GCD is distributive GCD(ma,mb)=mGCD(a,b) which tells us that: GCD(-x, -y) = -GCD(x, y) And yet, Mathematica has: GCD(-x, -y) = GCD(x, y) the very opposite of what Mathworld says, despite coming from the same people. http://functions.wolfram.com/IntegerFunctions/GCD/04/02/01/ The Collins Dictionary of Mathematics (second edition, 2002) says: highest common factor, greatest common factor, or greatest common divisor (abbrev hcf, gcf, gcd) n, an integer d that exactly divides (sense 2) two given integers a and b, and is such that if c divides a and b, then c divides d; this definition extends to finite sets of integers and to integral domains. For example, the highest common factor of 12, 60 and 84 is 12. Yet again, we have no clear definition for negative values. Here's an example using Euclid's algorithm to calculate the GCD of negative numbers, and sure enough, you get a negative result: https://answers.yahoo.com/question/index?qid=20111021023909AA8bCjB Wikipedia, on the other hand, defines GCD: In mathematics, the greatest common divisor (gcd), also known as the greatest common factor (gcf), highest common factor (hcf), or greatest common measure (gcm), of two or more integers (when at least one of them is not zero), is the largest positive integer that divides the numbers without a remainder. https://en.wikipedia.org/wiki/Greatest_common_divisor So: - Mathworld says that GCD of two negative numbers is a negative number; - but Mathematica says that GCD of two negative numbers is a positive; - Wikipedia agrees with Mathematica and disagrees with Mathworld; - Euclid's algorithm returns negative values for the GCD of two negatives; - Collins Dictionary gives a definition which is met by either positive or negative results. -- Steven From davea at davea.name Wed Sep 24 07:54:58 2014 From: davea at davea.name (Dave Angel) Date: Wed, 24 Sep 2014 07:54:58 -0400 (EDT) Subject: import reloading References: <54229482.6040104@chamonix.reportlab.co.uk> Message-ID: Robin Becker Wrote in message: > I'm tryng to bring some outdated ihooks code into the modern world. > > I notice that module loaders are supposed to re-use an existing module if it is > already in sys.modules. > No, the loader is required to reuse the existing module. > Is a loader supposed to reset all the reused module's attributes and reset the > __dict__ or does it just run the code from the module in hte __dict__? > Nothing gets reset or run. It simply reuses the existing module object. There are ways to fool the loader, for example by having a module visible in more than one file system path. The most common of these bugs is a module that tries to import the script that's started it all. Because that initial script is named __main__ internally, if you try to import it by filename you end up with two instances. -- DaveA From davea at davea.name Wed Sep 24 08:12:15 2014 From: davea at davea.name (DaveA) Date: Wed, 24 Sep 2014 08:12:15 -0400 Subject: why can't open the file with browser? Message-ID: > import webbrowser > webbrowser.open('f:\\test.html') > why the file f:\\test.html is opened by notepad? > ,not by my firefox or chrome? The default protocol in a browser is http. If you're not running a server on your local machine, ?you need to specify a different protocol. ?Try file:///f:/test.html I also don't run Windows any more so I might have the drive letter part wrong. -- DaveA -------- Original message -------- From: luofeiyu Date:09/24/2014 5:32 AM (GMT-05:00) To: python-list at python.org Subject: why can't open the file with browser? import webbrowser webbrowser.open('f:\\test.html') why the file f:\\test.html is opened by notepad ,not by my firefox or chrome? -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Wed Sep 24 08:22:54 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 24 Sep 2014 22:22:54 +1000 Subject: why can't open the file with browser? In-Reply-To: <54228F92.90409@gmail.com> References: <54228F92.90409@gmail.com> Message-ID: On Wed, Sep 24, 2014 at 7:32 PM, luofeiyu wrote: > import webbrowser webbrowser.open('f:\\test.html') why the file > f:\\test.html is opened by notepad ,not by my firefox or chrome? It looks to me as if your default association is set to Notepad rather than a web browser. Try opening one of the browsers' settings pages and making it your default browser. In Chrome, that's chrome://settings/ and it's near the bottom; in Firefox, go to Tools|Options, Advanced, and it's on the General tab. (They might check on startup and offer to make themselves default, which would save you some trouble.) ChrisA From gandalf at shopzeus.com Wed Sep 24 08:37:37 2014 From: gandalf at shopzeus.com (=?ISO-8859-2?Q?Nagy_L=E1szl=F3_Zsolt?=) Date: Wed, 24 Sep 2014 14:37:37 +0200 Subject: Receiving large files with @tornado.web.stream_request_body Message-ID: <5422BB11.40001@shopzeus.com> I was using tornado 3 before. I see that file streaming was included in version 4. This is something I need for posting large files. I have a problem receiving multiple files with a single POST request. Client side could be something like this:
First file:
Second file:
Third file:
Suppose the user has seleted 3 large ISO files, I would like to stream them into files on the server side. This is what I was trying: @tornado.web.stream_request_body class PostFilesHandler(tornado.web.RequestHandler): def post(self): for postfile in self.request.files: print("File info:",postfile) # There is no postfile["body"] here!!! def prepare(self): self.temp_file = tempfile.NamedTemporaryFile(delete=False) def data_received(self, chunk): self.temp_file.write(chunk) # This is great but which file is this??? The problem is obvious: the data_received method receives raw data, but how do I tell when data body for a file ends and another begins? How can I save the body of all posted files into different named temp files, and then access them from from the post() method? The main reason for using this is to limit memory usage. Some files might be GB sized and I don't want to store them in memory. Can please someone point me to a working example? Thanks Laszlo -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. From steve+comp.lang.python at pearwood.info Wed Sep 24 09:16:53 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 24 Sep 2014 23:16:53 +1000 Subject: Best way to deal with different data types in a list comprehension References: Message-ID: <5422c446$0$29978$c3e8da3$5496439d@news.astraweb.com> Larry Martell wrote: > I have some code that I inherited: > > ' '.join([self.get_abbrev()] + > [str(f['value') > for f in self.filters > if f.has_key('value')]).strip() > > > This broke today when it encountered some non-ascii data. It's already broken. It gives a Syntax Error part way through: py> ' '.join([self.get_abbrev()] + ... [str(f['value') File "", line 2 [str(f['value') ^ SyntaxError: invalid syntax Please copy and paste the actual code, don't retype it. This is my guess of what you actually have, reformatted to make it more clear (at least to me): ' '.join( [self.get_abbrev()] + [str(f['value']) for f in self.filters if f.has_key('value')] ).strip() I *think* that the call to strip() is redundant. Hmmm... perhaps not, if the self.get_abbrev() begins with whitespace, or the last f['value'] ends with whitespace. You should consider removing that call to .strip(), but for now I'll assume it actually is useful and leave it in. First change: assuming the filters are dicts, do the test this way: ' '.join( [self.get_abbrev()] + [str(f['value']) for f in self.filters if 'value' in f] ).strip() Now, the *right* way to fix your problem is to convert the whole application to use unicode strings everywhere instead of byte strings. I'm guessing you are using Python 2.6 or 2.7. You say it broke when given some non-ascii data, but that's extremely ambiguous. {23: 42} is non-ascii data. What exactly do you have, and where did it come from? My *guess* is that you had a Unicode string, containing characters which cannot be converted to ASCII. py> str(u'??') Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128) > I changed the str(f['value']) line to f['value'].encode('utf-8'), Hmmm, I'm not sure that's a good plan: py> u'??'.encode('utf-8') '\xce\xa9\xcf\x80' Do you really want to find arbitrary bytes floating through your strings? A better strategy is to convert the program to use unicode strings internally, and only convert to byte strings when you read and write to files. But assuming you don't have the time or budget for that sort of re-write, here's a minimal chance which might do the job: u' '.join( [self.get_abbrev()] + [unicode(f['value']) for f in self.filters if 'value' in f] ).strip() That works correctly for random objects and ASCII byte strings: py> unicode([1, 2, 3]) u'[1, 2, 3]' py> unicode('bytes') u'bytes' Alas, it will fail for non-ASCII byte strings: py> unicode('bytes \xFF') Traceback (most recent call last): File "", line 1, in UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 6: ordinal not in range(128) Here's a version which prefers byte-strings, but should be able to handle everything you throw at it: ' '.join( [self.get_abbrev()] + [ (x.encode('utf-8') if isinstance(x, unicode) else x) for x in (f['value'] for f in self.filters if 'value' in f) ] ).strip() Note the use of a generator expression inside the list comp. -- Steven From noone at nowhere.net Wed Sep 24 09:25:42 2014 From: noone at nowhere.net (blindanagram) Date: Wed, 24 Sep 2014 14:25:42 +0100 Subject: GCD in Fractions In-Reply-To: <5422ae8b$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <54216c8e$0$29966$c3e8da3$5496439d@news.astraweb.com> <5422ae8b$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 24/09/2014 12:44, Steven D'Aprano wrote: > blindanagram wrote: [snip] > - Mathworld says that GCD of two negative numbers is a negative number; > > - but Mathematica says that GCD of two negative numbers is a positive; > > - Wikipedia agrees with Mathematica and disagrees with Mathworld; After looking at these (and several other) on-line mathematical sites, I realised that I would have to go back to long standing mathemmatical references to find how the gcd is defined by those that explicitly cover the greatest common divisor for negative integers (I did this before raising the issue here). All four that I have so far looked at have definitions that lead to gcd(a, b) for integers being equal to gcd(|a|, |b|). I hope to visit a University library shortly to review more. Does anyone know of such a reference that uses a definition that conflicts with gcd(a, b) for integers being equal to gcd(|a|, |b|)? From robin at reportlab.com Wed Sep 24 09:34:30 2014 From: robin at reportlab.com (Robin Becker) Date: Wed, 24 Sep 2014 14:34:30 +0100 Subject: import reloading In-Reply-To: References: <54229482.6040104@chamonix.reportlab.co.uk> Message-ID: <5422C866.8010506@chamonix.reportlab.co.uk> On 24/09/2014 12:54, Dave Angel wrote: > Robin Becker Wrote in message: >........... >> Is a loader supposed to reset all the reused module's attributes and reset the >> __dict__ or does it just run the code from the module in hte __dict__? >> > > Nothing gets reset or run. It simply reuses the existing module object. > I find that a bit weird. In fact as a test I created a testmod.py ####### A=3 print('A=%r' % A) ####### then in python3.4 Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:24:06) [MSC v.1600 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import testmod A=3 >>> testmod.A 3 >>> #I externally changed testmod.py to read >>> #a=4 >>> #print('a=%r' % a) >>> import imp >>> imp.reload(testmod) a=4 >>> testmod.A 3 >>> testmod.a 4 >>> so you are right the old module variables are still there. Presumably any functions/classes etc etc that don't get overwritten will also continue to exist. > There are ways to fool the loader, for example by having a module > visible in more than one file system path. > The most common of > these bugs is a module that tries to import the script that's > started it all. Because that initial script is named __main__ > internally, if you try to import it by filename you end up with > two instances. > > -- Robin Becker From nomail at invalid.com Wed Sep 24 09:30:55 2014 From: nomail at invalid.com (ast) Date: Wed, 24 Sep 2014 15:30:55 +0200 Subject: brackets at the end of a method name Message-ID: <5422c791$0$2941$426a74cc@news.free.fr> Hi Once a file is opened with: f=open("foo.txt", "r") we have some methods associated with file f f.read() f.readline() .. f.close() f.name f.mode I dont understand why sometimes there are brackets () at the end of the method name (ie close())and sometimes no (ie name) I thought that maybe methods with () could have a parameter passed to, for example f.close(parameter) but it is not the case. This is documentation about close(), there is no parameter. close() Close the current file and forget everything we know about it (including the filename and the current line number). thx From anddamNOPSAM+gruppi at brapi.net Wed Sep 24 09:37:01 2014 From: anddamNOPSAM+gruppi at brapi.net (Andrea D'Amore) Date: Wed, 24 Sep 2014 15:37:01 +0200 Subject: brackets at the end of a method name References: <5422c791$0$2941$426a74cc@news.free.fr> Message-ID: On 2014-09-24 13:30:55 +0000, ast said: > we have some methods associated with file f > [?] > f.close() > f.name print(type(f.close)) print(type(f.name)) Spot the difference. -- Andrea From nomail at invalid.com Wed Sep 24 09:42:22 2014 From: nomail at invalid.com (ast) Date: Wed, 24 Sep 2014 15:42:22 +0200 Subject: brackets at the end of a method name In-Reply-To: References: <5422c791$0$2941$426a74cc@news.free.fr> Message-ID: <5422ca41$0$2921$426a74cc@news.free.fr> "Andrea D'Amore" a ?crit dans le message de news:lvuhdu$c6q$1 at virtdiesel.mng.cu.mi.it... > On 2014-09-24 13:30:55 +0000, ast said: > >> we have some methods associated with file f >> [?] >> f.close() >> f.name > > print(type(f.close)) > print(type(f.name)) > > Spot the difference. > > -- > Andrea > f.name is an attribute and f.close a method ! How stupid am i thx From elearn2014 at gmail.com Wed Sep 24 09:55:30 2014 From: elearn2014 at gmail.com (luofeiyu) Date: Wed, 24 Sep 2014 21:55:30 +0800 Subject: how to make return(self.res) not to output the content of list ? Message-ID: <5422CD52.8060501@gmail.com> There is a file named analyse.py in the D:\Python34\Lib\site-packages. import sqlite3,os,jinja2 db = r'F:\workspace\china\data\china.sqlite' con = sqlite3.connect(db) cur = con.cursor() class status(): def grow(self): self.res=cur.execute('select ??,????,????,????,? ????? from profile limit 10').fetchall() def display(self): template = jinja2.Template(''' {% for row in res %} {% for col in row -%} {% endfor %} {% endfor %}
{{ col}}
''') with open('f:\\test.html', 'w') as f: f.write(template.render(res=self.res)) import webbrowser webbrowser.open('f:\\test.html') when i open python3.4 console to input the code: import analyse x=analyse.status() x.grow() x.display() i get when i add return(self.res) in grow method to make analyse.py into the following: import sqlite3,os,jinja2 db = r'F:\workspace\china\data\china.sqlite' con = sqlite3.connect(db) cur = con.cursor() class status(): def grow(self): self.res=cur.execute('select ??,????,????,????,? ????? from profile limit 10').fetchall() return(self.res) def display(self): template = jinja2.Template(''' {% for row in res %} {% for col in row -%} {% endfor %} {% endfor %}
{{ col}}
''') with open('f:\\test.html', 'w') as f: f.write(template.render(res=self.res)) import webbrowser webbrowser.open('f:\\test.html') now again input the code: import analyse x=analyse.status() x.grow() the x.grow() will output [('600000', '??', '187?', 39340.0, 30.0), ('600004', '????', '11.5?', 4499.0, 23.0), ('600005', '????', '101?', 38857.0, 24.0), ('600006', '????', '20.0?', 10290.0, 20.0), ('600007', '???', '10.1?', 2332.0, 19.0), ('600008', '????', '22.0?', 6515.0, 20.0), ('600009', '????', '19.3?', 5472.0, 18.0), ('600010', '????', '80.0?', 31389.0, 19.0), ('600011', '????', '141?', 37729.0, 29.0), ('600012', '????', '16.6?', 2106.0, 14.0)] now what i want to do is : 1.keep return(self.res) in grow method. 2.it is my target that when run the code: import analyse x=analyse.status() x.grow() there is nothing output in my console , to make return(self.res) not to output the content of list , how can i do ? -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: jjdehdhi.png Type: image/png Size: 12871 bytes Desc: not available URL: From davea at davea.name Wed Sep 24 09:58:13 2014 From: davea at davea.name (Dave Angel) Date: Wed, 24 Sep 2014 09:58:13 -0400 (EDT) Subject: import reloading References: <54229482.6040104@chamonix.reportlab.co.uk> <5422C866.8010506@chamonix.reportlab.co.uk> Message-ID: Robin Becker Wrote in message: > On 24/09/2014 12:54, Dave Angel wrote: >> Robin Becker Wrote in message: >>........... >>> Is a loader supposed to reset all the reused module's attributes and reset the >>> __dict__ or does it just run the code from the module in hte __dict__? >>> >> >> Nothing gets reset or run. It simply reuses the existing module object. >> > I find that a bit weird. In fact as a test I created a testmod.py > > ####### > A=3 > print('A=%r' % A) > ####### > > then in python3.4 > > Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:24:06) [MSC v.1600 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> import testmod > A=3 > >>> testmod.A > 3 > >>> #I externally changed testmod.py to read > >>> #a=4 > >>> #print('a=%r' % a) > >>> import imp > >>> imp.reload(testmod) > a=4 > > >>> testmod.A > 3 > >>> testmod.a > 4 > >>> > > > so you are right the old module variables are still there. Presumably any > functions/classes etc etc that don't get overwritten will also continue to exist. > > Please don't misquote me. I have no idea why testmod.A gave you a number at all. Must be a bug in reload. Anyway I talked only about import. imp.reload is an abomination useful only to occasionally save time in an interactive session. import, on the other hand, had better continue to be consistent. Many modules are imported dozens of times in a typical application, and you wouldn't want multiple instances of them. -- DaveA From kwpolska at gmail.com Wed Sep 24 10:09:43 2014 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Wed, 24 Sep 2014 16:09:43 +0200 Subject: Flask and Python 3 In-Reply-To: References: Message-ID: On Wed, Sep 24, 2014 at 3:23 AM, Juan Christian wrote: > I didn't learn debug with Flask yet. Only in the next videos. Learning from videos is the worst thing you can do. Use the official flask documentation at http://flask.pocoo.org/docs/0.10/quickstart/ ? it?s much friendlier than a video. Also, there is nothing to ?learn? ? just change the line, and you will have more helpful errors. -- Chris ?Kwpolska? Warrick PGP: 5EAAEA16 stop html mail | always bottom-post | only UTF-8 makes sense From ian.g.kelly at gmail.com Wed Sep 24 10:26:46 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 24 Sep 2014 08:26:46 -0600 Subject: GCD in Fractions In-Reply-To: <5422ae8b$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <54216c8e$0$29966$c3e8da3$5496439d@news.astraweb.com> <5422ae8b$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Sep 24, 2014 at 5:44 AM, Steven D'Aprano wrote: > The Collins Dictionary of Mathematics (second edition, 2002) says: > > highest common factor, greatest common factor, or greatest > common divisor (abbrev hcf, gcf, gcd) > > n, an integer d that exactly divides (sense 2) two given > integers a and b, and is such that if c divides a and b, > then c divides d; this definition extends to finite sets > of integers and to integral domains. For example, the > highest common factor of 12, 60 and 84 is 12. > > Yet again, we have no clear definition for negative values. Well, this definition would imply that gcd(a, b) should always return *two* results, one positive and one negative. I don't think anybody wants that. It would make more sense to standardize on one of them, and if we take sqrt as an example, then the result should be positive. > Here's an example using Euclid's algorithm to calculate the GCD of negative > numbers, and sure enough, you get a negative result: > > https://answers.yahoo.com/question/index?qid=20111021023909AA8bCjB This depends entirely on your implementation of the modulo operation, which is an issue of computing since the operator is not used in mathematics. The algorithm itself only specifies at each step to solve the equation R_{n-2} = Q * R_{n-1} + R_{n}, such that |R_{n}| < |R_{n-1}|. For any given input there can be many possible solutions, both positive and negative, regardless of the signs of the inputs, and it doesn't matter which solution you choose. So one could implement Euclid's algorithm to return either a positive or negative result for any arbitrary pair of integers. From gandalf at shopzeus.com Wed Sep 24 10:31:28 2014 From: gandalf at shopzeus.com (=?ISO-8859-1?Q?Nagy_L=E1szl=F3_Zsolt?=) Date: Wed, 24 Sep 2014 16:31:28 +0200 Subject: Receiving large files with @tornado.web.stream_request_body In-Reply-To: <5422BB11.40001@shopzeus.com> References: <5422BB11.40001@shopzeus.com> Message-ID: <5422D5C0.8040404@shopzeus.com> @tornado.web.stream_request_body > class PostFilesHandler(tornado.web.RequestHandler): > def post(self): > for postfile in self.request.files: > print("File info:",postfile) # There is no > postfile["body"] here!!! > > def prepare(self): > self.temp_file = tempfile.NamedTemporaryFile(delete=False) > > def data_received(self, chunk): > self.temp_file.write(chunk) # This is great but which file is > this??? > > I have found out that the raw post data is stored there. Extracting file contents from that raw file is possible. However, the provisional email.contentmanager class does not provide methods for extracting streams from a mime message. Which is bad, because nobody wants to load a huge mime message into memory (for example, a DVD iso file...) -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. From pgollakota at gmail.com Wed Sep 24 10:44:06 2014 From: pgollakota at gmail.com (Praveen Gollakota) Date: Wed, 24 Sep 2014 07:44:06 -0700 (PDT) Subject: ThreadPoolExecutor - callback guaranteed to run in same thread as the submitted function? Message-ID: Hello, In the ThreadPoolExecutor (TPE), is the callback always guaranteed to run in the same thread as the submitted function? For example, I tested this with the following code. I ran it many times and it seemed like `func` and `callback` always ran in the same thread. import concurrent.futures import random import threading import time executor = concurrent.futures.ThreadPoolExecutor(max_workers=3) def func(x): time.sleep(random.random()) return threading.current_thread().name def callback(future): time.sleep(random.random()) x = future.result() cur_thread = threading.current_thread().name if (cur_thread != x): print(cur_thread, x) print('main thread: %s' % threading.current_thread()) for i in range(10000): future = executor.submit(func, i) future.add_done_callback(callback) However, it seemed to fail when I removed the `time.sleep(random.random())` statements, i.e. at least a few `func` functions and `callbacks` **did not** run in the same thread. For a project that I am working on, the callback must always run on the same thread as the submitted function, so I wanted to be sure that this is guaranteed by TPE. (And also the results of the test without the random sleep seemed puzzling). I looked at the source code for executors (see https://hg.python.org/cpython/file/6d44906344f4/Lib/concurrent/futures/_base.py#l297) and it does not seem like we switch the thread to the main thread before we run the callback. But just wanted to be sure. Any insight would be appreciated! Thanks, Praveen From a.nandagoban at traxens.com Wed Sep 24 10:49:21 2014 From: a.nandagoban at traxens.com (Arulnambi Nandagoban) Date: Wed, 24 Sep 2014 16:49:21 +0200 Subject: Python as Windows Service In-Reply-To: <1570DB93-532A-4A9D-A5DF-20F3D6DEE3B8@Gmail.com> References: <460EC810-C983-43FB-90AF-315D5DF5174B@Gmail.com> <000f01cfd7c7$64caa6a0$2e5ff3e0$@traxens.com> <1570DB93-532A-4A9D-A5DF-20F3D6DEE3B8@Gmail.com> Message-ID: <006c01cfd806$ba875b30$2f961190$@traxens.com> De : Gmail [mailto:mrjean1 at gmail.com] Envoy? : Wednesday, September 24, 2014 2:41 PM ? : Arulnambi Nandagoban Objet : Re: Python as Windows Service Also, this may work for you NSSM installs an existing app as a service. /Jean On Sep 24, 2014, at 3:16 AM, "Arulnambi Nandagoban" wrote: De : MrJean1 [mailto:mrjean1 at gmail.com] Envoy? : Tuesday, September 23, 2014 5:55 PM ? : a.nandagoban at traxens.com Objet : Python as Windows Service Here's one, simple example There are more, just search for "Python Windows Service" for example. /Jean Thank you !!! -- Nambi Thank you again !!! I managed to run the server as as service with help of sample code provided in From ian.g.kelly at gmail.com Wed Sep 24 10:56:18 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 24 Sep 2014 08:56:18 -0600 Subject: "Fuzzy" Counter? In-Reply-To: <1a63fb8d-e0b8-4385-acbc-ddb6bf1f0f7d@googlegroups.com> References: <0d28ee82-2240-4f10-9db9-e966c0e62a13@googlegroups.com> <20140923093244.066bb10b@rg.highlandtechnology.com> <1a63fb8d-e0b8-4385-acbc-ddb6bf1f0f7d@googlegroups.com> Message-ID: On Tue, Sep 23, 2014 at 11:01 PM, Miki Tebeka wrote: > On Tuesday, September 23, 2014 7:33:06 PM UTC+3, Rob Gaddi wrote: > >> While you're at it, think >> long and hard about that definition of fuzziness. If you can make it >> closer to the concept of histogram "bins" you'll get much better >> performance. > The problem for me here is that I can't determine the number of bins in advance. I'd like to get frequencies. I guess every "new" (don't have any previous equal item) can be a bin. Then your result depends on the order of your input, which is usually not a good thing. Why would you need to determine the *number* of bins in advance? You just need to determine where they start and stop. If for example your epsilon is 0.5, you could determine the bins to be at [-0.5, 0.5); [0.5, 1.5); [1.5, 2.5); ad infinitum. Then for each actual value you encounter, you could calculate the appropriate bin, creating it first if it doesn't already exist. From ian.g.kelly at gmail.com Wed Sep 24 12:05:00 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 24 Sep 2014 10:05:00 -0600 Subject: how to make return(self.res) not to output the content of list ? In-Reply-To: <5422CD52.8060501@gmail.com> References: <5422CD52.8060501@gmail.com> Message-ID: On Wed, Sep 24, 2014 at 7:55 AM, luofeiyu wrote: > > now what i want to do is : > 1.keep return(self.res) in grow method. > 2.it is my target that when run the code: > > import analyse > x=analyse.status() > x.grow() > > there is nothing output in my console , to make return(self.res) not to output the content of list , > how can i do ? You could write a separate method that just calls self.grow() and does not return the result, and call that method instead from the interactive interpreter. -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Wed Sep 24 12:13:23 2014 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 24 Sep 2014 18:13:23 +0200 Subject: GCD in Fractions In-Reply-To: References: <54216c8e$0$29966$c3e8da3$5496439d@news.astraweb.com> <5422ae8b$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: blindanagram schrieb am 24.09.2014 um 15:25: > On 24/09/2014 12:44, Steven D'Aprano wrote: > >> blindanagram wrote: > [snip] >> - Mathworld says that GCD of two negative numbers is a negative number; >> >> - but Mathematica says that GCD of two negative numbers is a positive; >> >> - Wikipedia agrees with Mathematica and disagrees with Mathworld; > > After looking at these (and several other) on-line mathematical sites, I > realised that I would have to go back to long standing mathemmatical > references to find how the gcd is defined by those that explicitly cover > the greatest common divisor for negative integers (I did this before > raising the issue here). > > All four that I have so far looked at have definitions that lead to > gcd(a, b) for integers being equal to gcd(|a|, |b|). I hope to visit a > University library shortly to review more. Does anyone know of such a > reference that uses a definition that conflicts with gcd(a, b) for > integers being equal to gcd(|a|, |b|)? Steven has already given sources that suggest that the result of gcd() should be positive. Just like he gave sources that suggest the opposite. So, the question is not how or where to find even more sources, or to decide which of those sources is "more right" than the others, the question is whether such a shaky ground is a reasonable foundation for breaking other people's code. We have an open tracker ticket now on changing *something* about the current situation. Let's just add some new functionality somewhere if people really want it (as in "need it for their code", not just "want it for purity reasons" or "sleep better when they know it's out there"), but please, everyone, stop complaining about "fractions.gcd" not catering for your needs. It does what it's there for, even if the name is more public or more generic than you might want. There are other ways to fix the actual problem and move on. Stefan From __peter__ at web.de Wed Sep 24 12:33:56 2014 From: __peter__ at web.de (Peter Otten) Date: Wed, 24 Sep 2014 18:33:56 +0200 Subject: how to make return(self.res) not to output the content of list ? References: <5422CD52.8060501@gmail.com> Message-ID: luofeiyu wrote: > There is a file named analyse.py in the D:\Python34\Lib\site-packages. > > > import sqlite3,os,jinja2 > db = r'F:\workspace\china\data\china.sqlite' > con = sqlite3.connect(db) > cur = con.cursor() > > class status(): > def grow(self): > self.res=cur.execute('select ??,????,????,????,? > ????? from profile limit 10').fetchall() > > def display(self): > template = jinja2.Template(''' > > {% for row in res %} > > {% for col in row -%} > > {% endfor %} > > {% endfor %} >
{{ col}}
> ''') > with open('f:\\test.html', 'w') as f: > f.write(template.render(res=self.res)) > import webbrowser > webbrowser.open('f:\\test.html') > > > when i open python3.4 console to input the code: > import analyse > x=analyse.status() > x.grow() > x.display() > > i get > > > when i add return(self.res) in grow method to make analyse.py into the > following: > > import sqlite3,os,jinja2 > db = r'F:\workspace\china\data\china.sqlite' > con = sqlite3.connect(db) > cur = con.cursor() > > class status(): > def grow(self): > self.res=cur.execute('select ??,????,????,????,? > ????? from profile limit 10').fetchall() > return(self.res) > def display(self): > template = jinja2.Template(''' > > {% for row in res %} > > {% for col in row -%} > > {% endfor %} > > {% endfor %} >
{{ col}}
> ''') > with open('f:\\test.html', 'w') as f: > f.write(template.render(res=self.res)) > import webbrowser > webbrowser.open('f:\\test.html') > > > now again input the code: > import analyse > x=analyse.status() > x.grow() > the x.grow() will output > > [('600000', '??', '187?', 39340.0, 30.0), > ('600004', '????', '11.5?', 4499.0, 23.0), > ('600005', '????', '101?', 38857.0, 24.0), > ('600006', '????', '20.0?', 10290.0, 20.0), > ('600007', '???', '10.1?', 2332.0, 19.0), > ('600008', '????', '22.0?', 6515.0, 20.0), > ('600009', '????', '19.3?', 5472.0, 18.0), > ('600010', '????', '80.0?', 31389.0, 19.0), > ('600011', '????', '141?', 37729.0, 29.0), > ('600012', '????', '16.6?', 2106.0, 14.0)] > > now what i want to do is : > 1.keep return(self.res) in grow method. > 2.it is my target that when run the code: > > import analyse > x=analyse.status() > x.grow() > > there is nothing output in my console , to make return(self.res) not to > output the content of list , > how can i do ? You can set the display hook: >>> [1, 2, 3] [1, 2, 3] >>> import sys >>> sys.displayhook = lambda obj: None >>> [1, 2, 3] >>> From breamoreboy at yahoo.co.uk Wed Sep 24 12:34:37 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 24 Sep 2014 17:34:37 +0100 Subject: GCD in Fractions In-Reply-To: References: <54216c8e$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 24/09/2014 12:14, Mark Dickinson wrote: > Mark Lawrence yahoo.co.uk> writes: >> Somebody got there first http://bugs.python.org/issue22477 > > I think there's good reason to suspect that Brian Gladman and > blindanagram are one and the same. :-) > >>>> sorted("BrianGladman".lower()) == sorted("blindanagram") > True > Is that considered proof that I still reign supreme as the most unobservant person on the planet? :) -- 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 Sep 24 12:41:49 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 24 Sep 2014 17:41:49 +0100 Subject: why can't open the file with browser? In-Reply-To: References: <54228F92.90409@gmail.com> Message-ID: On 24/09/2014 13:22, Chris Angelico wrote: > On Wed, Sep 24, 2014 at 7:32 PM, luofeiyu wrote: >> import webbrowser webbrowser.open('f:\\test.html') why the file >> f:\\test.html is opened by notepad ,not by my firefox or chrome? > > It looks to me as if your default association is set to Notepad rather > than a web browser. Try opening one of the browsers' settings pages > and making it your default browser. In Chrome, that's > chrome://settings/ and it's near the bottom; in Firefox, go to > Tools|Options, Advanced, and it's on the General tab. (They might > check on startup and offer to make themselves default, which would > save you some trouble.) > > ChrisA > From https://docs.python.org/3/library/webbrowser.html#module-webbrowser "Note that on some platforms, trying to open a filename using this function, may work and start the operating system?s associated program. However, this is neither supported nor portable." So it looks like a case of changing the file association through control panel or similar. I'll leave the OP to find out how to do that as an exercise. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From random832 at fastmail.us Wed Sep 24 12:49:36 2014 From: random832 at fastmail.us (random832 at fastmail.us) Date: Wed, 24 Sep 2014 12:49:36 -0400 Subject: GCD in Fractions In-Reply-To: References: <54216c8e$0$29966$c3e8da3$5496439d@news.astraweb.com> <5422ae8b$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1411577376.707183.171298849.4D1CC1A4@webmail.messagingengine.com> On Wed, Sep 24, 2014, at 10:26, Ian Kelly wrote: > This depends entirely on your implementation of the modulo operation, > which is an issue of computing since the operator is not used in > mathematics. Wikipedia suggests that "remainders from Euclidean division" should be used. In Euclidean division, the remainder is always positive. (whereas either C or Python allows the modulo to be negative, in different situations: in python [round quotient down] the modulo has the same sign as b, whereas in C [round quotient to zero] the modulo has the same sign as a). def mod(a, b): r = a % b return r + abs(b) if r < 0 else r def gcd(a, b): if b == 0: return a else: return gcd(b, mod(a, b)) This appears to give a negative result when: a < 0 and b == 0, obviously. A is returned as the gcd. a == 0 and b < 0. B is returned as the gcd |a| is exactly divisible by |b| and b < 0. B is returned as the gcd. However, it still lacks the symmetry of gcd(a, b) == gcd(b, a) in some cases. For example, gcd(-2, 6) is 2, whereas gcd(6, -2) is -2. From rosuav at gmail.com Wed Sep 24 12:54:12 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 25 Sep 2014 02:54:12 +1000 Subject: String representations of numbers and approximate equality Message-ID: Yes, it's another "how can I see if two numbers are approximately equal" thread, but this time I have a concrete definition of "approximately equal"... and they're Decimals, not floats. I have a number of files (this is an ongoing thing) in which there are two columns of numbers. One of them should be equal to the other times some factor which the program knows from elsewhere. All the numbers are represented as strings of ASCII decimal digits, possibly including a U+002E decimal point. Something like this: # (these are calculated on factor 30) ["0.75", "22.5"] ["0.80", "24"] ["4.73", "142"] The definition of valid is that, within the rounding they've been given, the values are correct. The first two are strictly correct; the third would be 141.9 with full accuracy but 142 is deemed good enough. But this should fail: ["0.1", "10"] 0.1 * 30 should be 3, not 10; and 10 / 30 should be 0.333, not 0.1; therefore this is wrong. This is a san-check for human-entered data, so sloppiness is necessary. I just want to have a chance to catch obvious typos and such. In theory, I think, a decimal.Decimal context should be able to do what I want here - but I'm not particularly familiar with it. Performance isn't critical, so stupid techniques that work on the actual string representation would be fine too. In general, the numbers will be fairly small. Maybe 3-4 digits before the decimal point, and probably not more than 2-3 after. Not sure if that makes things any easier or not. All advice appreciated! ChrisA From noone at nowhere.net Wed Sep 24 13:05:22 2014 From: noone at nowhere.net (blindanagram) Date: Wed, 24 Sep 2014 18:05:22 +0100 Subject: GCD in Fractions In-Reply-To: References: <54216c8e$0$29966$c3e8da3$5496439d@news.astraweb.com> <5422ae8b$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 24/09/2014 17:13, Stefan Behnel wrote: > blindanagram schrieb am 24.09.2014 um 15:25: >> On 24/09/2014 12:44, Steven D'Aprano wrote: [snip] > We have an open tracker ticket now on changing *something* about the > current situation. Let's just add some new functionality somewhere if > people really want it (as in "need it for their code", not just "want it > for purity reasons" or "sleep better when they know it's out there"), but > please, everyone, stop complaining about "fractions.gcd" not catering for > your needs. It does what it's there for, even if the name is more public or > more generic than you might want. There are other ways to fix the actual > problem and move on. This has never been about my need to use fractions.gcd since I don't even use it (I have my own implementation). From noone at nowhere.net Wed Sep 24 13:31:59 2014 From: noone at nowhere.net (blindanagram) Date: Wed, 24 Sep 2014 18:31:59 +0100 Subject: GCD in Fractions In-Reply-To: References: <54216c8e$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 24/09/2014 17:34, Mark Lawrence wrote: > On 24/09/2014 12:14, Mark Dickinson wrote: >> Mark Lawrence yahoo.co.uk> writes: >>> Somebody got there first http://bugs.python.org/issue22477 >> >> I think there's good reason to suspect that Brian Gladman and >> blindanagram are one and the same. :-) >> >>>>> sorted("BrianGladman".lower()) == sorted("blindanagram") >> True >> > Is that considered proof that I still reign supreme as the most > unobservant person on the planet? :) I am afraid not - you are far from alone :-) I have used this alias for quite a few years now on sci.crypt without people realising who 'owns' it (there are reasons why people on sci.crypt might discover this). From tjreedy at udel.edu Wed Sep 24 13:42:04 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 24 Sep 2014 13:42:04 -0400 Subject: GCD in Fractions In-Reply-To: <5422ae8b$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <54216c8e$0$29966$c3e8da3$5496439d@news.astraweb.com> <5422ae8b$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 9/24/2014 7:44 AM, Steven D'Aprano wrote: > blindanagram wrote: > >> Seccondly (as others here have pointed out), the mathematical properties >> of the greatest common divisor are well defined for both positive and >> negative integers. > > You keep saying that, but it simply is not true. Different people use > different definitions. Some refuse to allow negative arguments at all. Some > insist that the GCD must be positive. Others allow it to be negative. [convincing evidence of the above snipped] The negative of the greatest common divisor is the least common divisor (when the range includes negative integers). If a 'gcd' is allowed to be negative, one must re-interpret 'gcd' as abbreviating 'greatest-magnitude common divisor'. It then might be better called 'gmcd'. -- Terry Jan Reedy From jhibschman at gmail.com Wed Sep 24 14:09:12 2014 From: jhibschman at gmail.com (Johann Hibschman) Date: Wed, 24 Sep 2014 14:09:12 -0400 Subject: GCD in Fractions References: <54216c8e$0$29966$c3e8da3$5496439d@news.astraweb.com> <5422ae8b$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano writes: > blindanagram wrote: > >> Seccondly (as others here have pointed out), the mathematical properties >> of the greatest common divisor are well defined for both positive and >> negative integers. > > You keep saying that, but it simply is not true. Different people use > different definitions. Some refuse to allow negative arguments at all. Some > insist that the GCD must be positive. Others allow it to be negative. I can't find a good source for allowing it to be negative, though. Clearly, the primary use of the function is on the positive integers, with the negatives being an extension. > Mathworld does show one thing that suggests an interpretation for the GCD of > negative values: > > The GCD is distributive > GCD(ma,mb)=mGCD(a,b) > > which tells us that: > > GCD(-x, -y) = -GCD(x, y) > > And yet, Mathematica has: > > GCD(-x, -y) = GCD(x, y) > > the very opposite of what Mathworld says, despite coming from the same > people. This is most likely simply them dropping the constraint that m must be non-negative. Wikipedia, for example, specifies it under "Properties." > The Collins Dictionary of Mathematics (second edition, 2002) says: > > highest common factor, greatest common factor, or greatest > common divisor (abbrev hcf, gcf, gcd) > > n, an integer d that exactly divides (sense 2) two given > integers a and b, and is such that if c divides a and b, > then c divides d; this definition extends to finite sets > of integers and to integral domains. For example, the > highest common factor of 12, 60 and 84 is 12. > > Yet again, we have no clear definition for negative values. As pointed out, this definition always yields two values (positive and negative), even for positive a and b, so there's nothing special for negative a or b. Typically, I've seen this augmented with "choose the positive one" to get a single value. > Here's an example using Euclid's algorithm to calculate the GCD of negative > numbers, and sure enough, you get a negative result: The algorithm is pretty irrelevant here. gcd's not defined by a particular algorithm to calculate it. >From everything that I've seen, mathematicians consider the gcd to be always positive. Now, that's not saying that fraction should implement the mathematical gcd, if it doesn't need it. That should be its own argument, though; it doesn't help to add false doubt about what the gcd of negative numbers should be. Cheers, Johann From milsonmun at gmail.com Wed Sep 24 15:33:05 2014 From: milsonmun at gmail.com (Milson Munakami) Date: Wed, 24 Sep 2014 12:33:05 -0700 (PDT) Subject: Syntax error in python unittest script Message-ID: <2c76f6c8-bb13-44e9-8da8-62a08e067b3a@googlegroups.com> Hi, I am learning to use unittest with python and walkthrough with this example http://agiletesting.blogspot.com/2005/01/python-unit-testing-part-1-unittest.html so my test script is like this: import json import urllib #import time #from util import * import httplib #import sys #from scapy.all import * import unittest import os, sys, socket, struct, select, time from threading import Thread import logging import traceback class testFirewall( unittest.TestCase ): def setUp(self): """ set up data used in the tests. setUp is called before each test function execution. """ self.controllerIp="127.0.0.1" self.switches = ["00:00:00:00:00:00:00:01"] self.startTime_ = time.time() self.failed = False self.reportStatus_ = True self.name_ = "Firewall" self.log = logging.getLogger("unittest") def tearDown(self): if self.failed: return duration = time.time() - self.startTime_ self.cleanup(True) if self.reportStatus_: self.log.info("=== Test %s completed normally (%d sec)", self.name_, duration def cleanup(self, success): sys.excepthook = sys.__excepthook__ try: return except NameError: self.log.error("Exception hit during cleanup, bypassing:\n%s\n\n" % traceback.format_exc()) pass else: fail("Expected a NameError") def testStatusFirewall(self): command = "http://%s:8080/wm/firewall/module/status/json" % self.controllerIp x = urllib.urlopen(command).read() parsedResult = json.loads(x) return parsedResult['result'] def suite(): suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(testFirewall)) return suite if __name__ == '__main__': logging.basicConfig(filename='/tmp/testfirewall.log', level=logging.DEBUG, format='%(asctime)s %(levelname)s %(name)s %(message)s') logger=logging.getLogger(__name__) suiteFew = unittest.TestSuite() suiteFew.addTest(testFirewall("testStatusFirewall")) unittest.TextTestRunner(verbosity=2).run(suiteFew) #unittest.main() #unittest.TextTestRunner(verbosity=2).run(suite()) while running it in console using python .py It gives me errror File "TestTest.py", line 44 def cleanup(self, success): ^ SyntaxError: invalid syntax I guess it is due to time module but as you can see I already had import time. what can be the reason if I comment those line containing the time it works. But i need to keep track of duration Please help and suggest. Thanks, Milson From juan0christian at gmail.com Wed Sep 24 15:39:52 2014 From: juan0christian at gmail.com (Juan Christian) Date: Wed, 24 Sep 2014 16:39:52 -0300 Subject: Flask and Python 3 In-Reply-To: References: Message-ID: On Wednesday, September 24, 2014, Chris ?Kwpolska? Warrick < kwpolska at gmail.com> wrote: > Learning from videos is the worst thing you can do. Use the official > flask documentation at http://flask.pocoo.org/docs/0.10/quickstart/ ? > it?s much friendlier than a video. > > Also, there is nothing to ?learn? ? just change the line, and you will > have more helpful errors. > That's the way I always learned everything. I watch some video courses, read a book and read the official documentation altogether. My way can't work for you, but for me it's excellent. And you don't even know which video/course I'm talking about, so it's gross to tell that "videos are the worst thing"... Anyway, the problem was solved, I already learned lots of new things and I'm practicing them. -------------- next part -------------- An HTML attachment was scrubbed... URL: From emile at fenx.com Wed Sep 24 15:40:06 2014 From: emile at fenx.com (Emile van Sebille) Date: Wed, 24 Sep 2014 12:40:06 -0700 Subject: Syntax error in python unittest script In-Reply-To: <2c76f6c8-bb13-44e9-8da8-62a08e067b3a@googlegroups.com> References: <2c76f6c8-bb13-44e9-8da8-62a08e067b3a@googlegroups.com> Message-ID: On 9/24/2014 12:33 PM, Milson Munakami wrote: > def tearDown(self): > if self.failed: > return > duration = time.time() - self.startTime_ > self.cleanup(True) > if self.reportStatus_: > self.log.info("=== Test %s completed normally (%d sec)", self.name_, duration The method above doesn't end cleanly (you need to add a close paren to the last line at least) Emile > def cleanup(self, success): From __peter__ at web.de Wed Sep 24 15:41:05 2014 From: __peter__ at web.de (Peter Otten) Date: Wed, 24 Sep 2014 21:41:05 +0200 Subject: Syntax error in python unittest script References: <2c76f6c8-bb13-44e9-8da8-62a08e067b3a@googlegroups.com> Message-ID: Milson Munakami wrote: > if self.reportStatus_: > self.log.info("=== Test %s completed normally (%d sec)", self.name_, duration The info() call is missing the closing parenthesis > def cleanup(self, success): > sys.excepthook = sys.__excepthook__ > > It gives me errror > > File "TestTest.py", line 44 > def cleanup(self, success): > ^ > SyntaxError: invalid syntax To find a syntax error it is often a good idea to look into the code that precedes the line that the compiler complains about. From davea at davea.name Wed Sep 24 15:56:00 2014 From: davea at davea.name (Dave Angel) Date: Wed, 24 Sep 2014 15:56:00 -0400 (EDT) Subject: String representations of numbers and approximate equality References: Message-ID: Chris Angelico Wrote in message: > Yes, it's another "how can I see if two numbers are approximately > equal" thread, but this time I have a concrete definition of > "approximately equal"... and they're Decimals, not floats. > > I have a number of files (this is an ongoing thing) in which there are > two columns of numbers. One of them should be equal to the other times > some factor which the program knows from elsewhere. All the numbers > are represented as strings of ASCII decimal digits, possibly including > a U+002E decimal point. Something like this: > > # (these are calculated on factor 30) > ["0.75", "22.5"] > ["0.80", "24"] > ["4.73", "142"] > > The definition of valid is that, within the rounding they've been > given, the values are correct. The first two are strictly correct; the > third would be 141.9 with full accuracy but 142 is deemed good enough. > But this should fail: > Your definition is not nearly as concrete as you think. Is the first number considered to be exact, and we'll only check the second? Will the factor always be an int, and thus exact? When the desired second number is exactly halfway between two values, is rounding down as acceptable as up? (Eg, exact answer 142.75, acceptable 142.7 and 142.8) Once you're sure of the goal, it's a question of whether the decimal package can handle it. I would be inclined to do it in two stages. Drop all the periods and convert each to int (long). Multiply and Add 5**n, where n is related to the length of the target. Convert to string, padded with lots of zeroes. See if the exact string begins with the target. If not, they're not close enough. If the first part passes, you just have to check the position of the decimal point. Or you could check the implementation of round. If you pick the right value for round, you could do an exact comparison. Alternatively, if you're just looking to catch typos, it could be simpler. Or if you put constraints on the numbers involved. -- DaveA From milsonmun at gmail.com Wed Sep 24 16:06:46 2014 From: milsonmun at gmail.com (Milson Munakami) Date: Wed, 24 Sep 2014 13:06:46 -0700 (PDT) Subject: Syntax error in python unittest script In-Reply-To: <2c76f6c8-bb13-44e9-8da8-62a08e067b3a@googlegroups.com> References: <2c76f6c8-bb13-44e9-8da8-62a08e067b3a@googlegroups.com> Message-ID: <7807b4fc-fde2-41ea-a1d8-23bb93a50b8c@googlegroups.com> On Wednesday, September 24, 2014 1:33:35 PM UTC-6, Milson Munakami wrote: > Hi, > > > > I am learning to use unittest with python and walkthrough with this example > > http://agiletesting.blogspot.com/2005/01/python-unit-testing-part-1-unittest.html > > > Thanks > so my test script is like this: > > import json > > import urllib > > #import time > > #from util import * > > import httplib > > #import sys > > #from scapy.all import * > > import unittest > > > > import os, sys, socket, struct, select, time > > from threading import Thread > > > > import logging > > import traceback > > > > > > > > class testFirewall( unittest.TestCase ): > > def setUp(self): > > """ > > > > set up data used in the tests. > > > > setUp is called before each test function execution. > > > > """ > > > > self.controllerIp="127.0.0.1" > > self.switches = ["00:00:00:00:00:00:00:01"] > > self.startTime_ = time.time() > > self.failed = False > > self.reportStatus_ = True > > self.name_ = "Firewall" > > self.log = logging.getLogger("unittest") > > > > def tearDown(self): > > if self.failed: > > return > > duration = time.time() - self.startTime_ > > self.cleanup(True) > > if self.reportStatus_: > > self.log.info("=== Test %s completed normally (%d sec)", self.name_, duration > > > > def cleanup(self, success): > > sys.excepthook = sys.__excepthook__ > > try: > > return > > except NameError: > > self.log.error("Exception hit during cleanup, bypassing:\n%s\n\n" % traceback.format_exc()) > > pass > > else: > > > > fail("Expected a NameError") > > > > > > def testStatusFirewall(self): > > command = "http://%s:8080/wm/firewall/module/status/json" % self.controllerIp > > x = urllib.urlopen(command).read() > > parsedResult = json.loads(x) > > return parsedResult['result'] > > > > > > def suite(): > > > > suite = unittest.TestSuite() > > > > suite.addTest(unittest.makeSuite(testFirewall)) > > > > return suite > > > > if __name__ == '__main__': > > logging.basicConfig(filename='/tmp/testfirewall.log', level=logging.DEBUG, > > format='%(asctime)s %(levelname)s %(name)s %(message)s') > > logger=logging.getLogger(__name__) > > > > suiteFew = unittest.TestSuite() > > > > suiteFew.addTest(testFirewall("testStatusFirewall")) > > > > unittest.TextTestRunner(verbosity=2).run(suiteFew) > > > > #unittest.main() > > > > #unittest.TextTestRunner(verbosity=2).run(suite()) > > > > > > while running it in console using python .py > > > > It gives me errror > > > > File "TestTest.py", line 44 > > def cleanup(self, success): > > ^ > > SyntaxError: invalid syntax > > > > I guess it is due to time module but as you can see I already had import time. > > > > what can be the reason if I comment those line containing the time it works. > > > > But i need to keep track of duration > > > > Please help and suggest. > > > > Thanks, > > Milson From breamoreboy at yahoo.co.uk Wed Sep 24 16:28:49 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 24 Sep 2014 21:28:49 +0100 Subject: Syntax error in python unittest script In-Reply-To: <7807b4fc-fde2-41ea-a1d8-23bb93a50b8c@googlegroups.com> References: <2c76f6c8-bb13-44e9-8da8-62a08e067b3a@googlegroups.com> <7807b4fc-fde2-41ea-a1d8-23bb93a50b8c@googlegroups.com> Message-ID: On 24/09/2014 21:06, Milson Munakami wrote: [snipped all the usual garbage] 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 gandalf at shopzeus.com Wed Sep 24 16:41:24 2014 From: gandalf at shopzeus.com (=?ISO-8859-1?Q?Nagy_L=E1szl=F3_Zsolt?=) Date: Wed, 24 Sep 2014 22:41:24 +0200 Subject: Receiving large files with @tornado.web.stream_request_body In-Reply-To: <5422D5C0.8040404@shopzeus.com> References: <5422BB11.40001@shopzeus.com> <5422D5C0.8040404@shopzeus.com> Message-ID: <54232C74.7040707@shopzeus.com> 2014.09.24. 16:31 keltez?ssel, Nagy L?szl? Zsolt ?rta: > @tornado.web.stream_request_body >> class PostFilesHandler(tornado.web.RequestHandler): >> def post(self): >> for postfile in self.request.files: >> print("File info:",postfile) # There is no >> postfile["body"] here!!! >> >> def prepare(self): >> self.temp_file = tempfile.NamedTemporaryFile(delete=False) >> >> def data_received(self, chunk): >> self.temp_file.write(chunk) # This is great but which file is >> this??? >> >> > I have found out that the raw post data is stored there. Extracting > file contents from that raw file is possible. However, the provisional > email.contentmanager class does not provide methods for extracting > streams from a mime message. Which is bad, because nobody wants to > load a huge mime message into memory (for example, a DVD iso file...) I wrote my own solution in the meantime, that can parse any large POST request into temporary files without using too much memory. If anyone is interested I can post it here. -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. From tjreedy at udel.edu Wed Sep 24 17:39:38 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 24 Sep 2014 17:39:38 -0400 Subject: Syntax error in python unittest script In-Reply-To: <2c76f6c8-bb13-44e9-8da8-62a08e067b3a@googlegroups.com> References: <2c76f6c8-bb13-44e9-8da8-62a08e067b3a@googlegroups.com> Message-ID: On 9/24/2014 3:33 PM, Milson Munakami wrote: > I am learning to use unittest with python [way too long example] > File "TestTest.py", line 44 > def cleanup(self, success): > ^ > SyntaxError: invalid syntax A common recommendation is to find the *minimal* example that exhibits the problem. (Start with commenting out everything after the code in the traceback, then at least half the code before it. Etc.) That means that removing or commenting out a single statememt and the problem disappears. In compound statements, you may need to insert 'pass' to not create a new problem. If you had done that, you would have reduced your code to something like class testFirewall( unittest.TestCase ): def tearDown(self): if self.reportStatus_: self.log.info("=== Test %s completed normally (%d sec)", self.name_, duration def cleanup(self, success): sys.excepthook = sys.__excepthook__ At that point, replacing "self.log.info(..." with "pass" would have made it clear that the problem was with the replaced statement. -- Terry Jan Reedy From rbeaudoin at comcast.net Wed Sep 24 19:19:36 2014 From: rbeaudoin at comcast.net (Robert E. Beaudoin) Date: Wed, 24 Sep 2014 19:19:36 -0400 Subject: GCD in Fractions References: <54216c8e$0$29966$c3e8da3$5496439d@news.astraweb.com> <5422ae8b$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 09/24/14 09:25, blindanagram wrote: > On 24/09/2014 12:44, Steven D'Aprano wrote: > >> blindanagram wrote: > [snip] >> - Mathworld says that GCD of two negative numbers is a negative number; >> >> - but Mathematica says that GCD of two negative numbers is a positive; >> >> - Wikipedia agrees with Mathematica and disagrees with Mathworld; > > After looking at these (and several other) on-line mathematical sites, I > realised that I would have to go back to long standing mathemmatical > references to find how the gcd is defined by those that explicitly cover > the greatest common divisor for negative integers (I did this before > raising the issue here). > > All four that I have so far looked at have definitions that lead to > gcd(a, b) for integers being equal to gcd(|a|, |b|). I hope to visit a > University library shortly to review more. Does anyone know of such a > reference that uses a definition that conflicts with gcd(a, b) for > integers being equal to gcd(|a|, |b|)? > I doubt you'll find an advanced mathematical text that has such a definition. I think most abstract algebra texts would give a definition equivalent to saying that for any integers n and m the ideal generated by n and m is equal to the principal ideal generated by gcd(n,m); that is the heart of the matter mathematically, and this definition generalizes to other so-called "principal ideal domains" than the integers. (Don't want to Google for "ideal" and "principal ideal"? OK: an ideal is a subset of the integers closed under addition of any two of its elements, and under multiplication of any of its elements by any integer; a set of integers generates an ideal if that ideal is the intersection of all ideals containing that set, and a principal ideal is an ideal generated by a singleton set. For more elaboration, though, I'm going to point you at the internet, or better, some of those advanced texts in the library.) After working through what the definitions of ideals and principal ideals imply for the the definition above of gcd, you get the statement that k is the (or, better, a) gcd of n and m if and only if k divides n and m, and any other integer that divides both n and m divides k. The upshot is that, mathematically, gcd is only defined up to a change of sign, which helps explain why references may disagree with each other. Some authors may impose the restriction than gcd(n,m) >= 0 for all n and m (which does have the advantage that then "greatest" really means greatest and not just "greatest absolute value"), but that isn't really a necessary part of the definition as far as the mathematically important properties of gcd are concerned. All that the abstract algebra requires is that |gcd(n,m)| = |gcd(|n|,|m|)|. So implementations of gcd that sometimes return a negative value are not, it seems to me, mathematically broken, though they might violate the principle of least surprise. for-whatever-it's-worth'ly-yrs, R. Beaudoin From drsalists at gmail.com Wed Sep 24 19:41:16 2014 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 24 Sep 2014 16:41:16 -0700 Subject: String representations of numbers and approximate equality In-Reply-To: References: Message-ID: On Wed, Sep 24, 2014 at 9:54 AM, Chris Angelico wrote: > Yes, it's another "how can I see if two numbers are approximately > equal" thread, but this time I have a concrete definition of > "approximately equal"... and they're Decimals, not floats. > > I have a number of files (this is an ongoing thing) in which there are > two columns of numbers. One of them should be equal to the other times > some factor which the program knows from elsewhere. All the numbers > are represented as strings of ASCII decimal digits, possibly including > a U+002E decimal point. Something like this: > > # (these are calculated on factor 30) > ["0.75", "22.5"] > ["0.80", "24"] > ["4.73", "142"] > > The definition of valid is that, within the rounding they've been > given, the values are correct. The first two are strictly correct; the > third would be 141.9 with full accuracy but 142 is deemed good enough. > But this should fail: > > ["0.1", "10"] > > 0.1 * 30 should be 3, not 10; and 10 / 30 should be 0.333, not 0.1; > therefore this is wrong. tolerance = decimal.Decimal('0.1') # I hesitate to call it epsilon if abs(decimal1 - decimal2) <= tolerance: print('They are close') else: print('They are different') From shawn at skrite.net Wed Sep 24 19:57:13 2014 From: shawn at skrite.net (Shawn Bright) Date: Wed, 24 Sep 2014 16:57:13 -0700 (PDT) Subject: cannot run a ruby script from a python script. Message-ID: <8c24ba60-9f0c-4b29-8c3e-64139af3a676@googlegroups.com> hello all. i have a linux computer that i use to run a GUI (wxGTK) program. In this program, there is a call to run an external ruby script. command = "ruby run_my_command.rb &" os.system(command) however, when it runs, i get this in the terminal sh: 1: ruby: not found i had considered that the path to the executable was messed up or somesuch, but when i just run python in the interpreter, it works fine. also, i have another computer with identical hardware, same OS, same package versions that it does work on also. This machine is to be a backup. Another note: When i run which ruby i get the path to the ruby executable. If i use that in my code, it will run, however, it will not be able to find any of the modules that i need for the ruby script to import. example command = "/path/to/ruby run_my_command.rb &" os.system(command) will run the ruby script, but the ruby script will not be able to import any of it's modules. thanks for any tips on this. From elearn2014 at gmail.com Wed Sep 24 20:11:18 2014 From: elearn2014 at gmail.com (luofeiyu) Date: Thu, 25 Sep 2014 08:11:18 +0800 Subject: how to make return(self.res) not to output the content of list ? In-Reply-To: References: <5422CD52.8060501@gmail.com> Message-ID: <54235DA6.7060702@gmail.com> `sys.displayhook = lambda obj: None ` will block everything to be displayed on the interactive python console . i rewrite my code as the following : import sqlite3,os,jinja2 db = r'data.sqlite' con = sqlite3.connect(db) cur = con.cursor() class status(): def __init__(): import sys sys.displayhook=mydisplay def mydisplay(x): if (x is not the result of an method grow of class status ) : x #how to do in python code? else : pass def grow(self): self.res= a data ananlyse process return(self.res) def display(self): #to display it in the html table how to fulfill the mydisplay function in python code to make x.grow() in the following not to output the list of self.res?? import analyse x=analyse.status() x.grow() From elearn2014 at gmail.com Wed Sep 24 20:15:07 2014 From: elearn2014 at gmail.com (luofeiyu) Date: Thu, 25 Sep 2014 08:15:07 +0800 Subject: how to make return(self.res) not to output the content of list ? In-Reply-To: References: <5422CD52.8060501@gmail.com> Message-ID: <54235E8B.4040106@gmail.com> You could write a separate method that just calls self.grow() and does not return the result, and call that method instead from the interactive interpreter. how can i change your meaning into python code? There is my code structure. class status(): def grow(self): self.res= a data ananlyse process return(self.res) def display(self): #to display it in the html table From cs at zip.com.au Wed Sep 24 20:44:28 2014 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 25 Sep 2014 10:44:28 +1000 Subject: cannot run a ruby script from a python script. In-Reply-To: <8c24ba60-9f0c-4b29-8c3e-64139af3a676@googlegroups.com> References: <8c24ba60-9f0c-4b29-8c3e-64139af3a676@googlegroups.com> Message-ID: <20140925004428.GA57587@cskk.homeip.net> On 24Sep2014 16:57, Shawn Bright wrote: >i have a linux computer that i use to run a GUI (wxGTK) program. In this program, there is a call to run an external ruby script. > >command = "ruby run_my_command.rb &" >os.system(command) > >however, when it runs, i get this in the terminal >sh: 1: ruby: not found > >i had considered that the path to the executable was messed up or somesuch, but when i just run python in the interpreter, it works fine. > >also, i have another computer with identical hardware, same OS, same package versions that it does work on also. This machine is to be a backup. > >Another note: When i run which ruby i get the path to the ruby executable. If i use that in my code, it will run, however, it will not be able to find any of the modules that i need for the ruby script to import. For your edification: modify your command to be this: command = "which ruby; echo $PATH; ruby run_my_command.rb &" and see if the output says what you expect. From the behaviour you describe I would expect that the GUI program, when it fails, is not being invoked from your command line but from some menu or suchlike. Further, I would guess that the invoking program (window manager, whatever) does not have ruby in its $PATH. This same effect obtains when you use the full path to ruby (usually a bad idea because your script may not work on another system where ruby is somewhere different) because like $PATH, the ruby search path also lacks the directories where the modules reside. When you run it from your command prompt or from the python interpreter your environment is already set up with this extra information. Cheers, Cameron Simpson C makes it easy for you to shoot yourself in the foot. C++ makes that harder, but when you do, it blows away your whole leg. - Bjarne Stroustrup From cs at zip.com.au Wed Sep 24 20:39:09 2014 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 25 Sep 2014 10:39:09 +1000 Subject: how to make return(self.res) not to output the content of list ? In-Reply-To: <54235E8B.4040106@gmail.com> References: <54235E8B.4040106@gmail.com> Message-ID: <20140925003909.GA48517@cskk.homeip.net> On 25Sep2014 08:15, luofeiyu wrote: >You could write a separate method that just calls self.grow() and does >not return the result, and call that method instead from the >interactive interpreter. luofeiyu: please take care to include the attribution line. The text above is from Ian Kelly, but you do not show that. Attribution is important: it both gives credit and also lets people know who said what. On 25Sep2014 08:15, luofeiyu wrote: >how can i change your meaning into python code? Well, I'd not do it that way. I would just make .grow() not return self.res. Basicly, if a function returns None (which it does when it does not have an explicit return command), the python interpreter prints no output. So I would just write .grow() like this: def grow(self): self.res= a data ananlyse process Let the caller access self.res directly afterwards if they want to. For Ian's suggestion, write a trivial method like this: def grow_but_be_silent(self): self.grow() Cumbersome, but it would do what you seem to ask for. Cheers, Cameron Simpson Drive Agressively Rash Magnificently - Nankai Leathers From rosuav at gmail.com Wed Sep 24 21:38:27 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 25 Sep 2014 11:38:27 +1000 Subject: String representations of numbers and approximate equality In-Reply-To: References: Message-ID: On Thu, Sep 25, 2014 at 5:56 AM, Dave Angel wrote: > Your definition is not nearly as concrete as you think. Is the > first number considered to be exact, and we'll only check the > second? Will the factor always be an int, and thus > exact? Apologies: the definition is concrete, just under-specified in the post. No, both numbers are inexact; most notably, one third of the factor might be involved - both of these should be correct: ["1.333", "40"] ["1.33", "40"] But if it's easier to assume that one or t'other must be exact, that's fine too - I can just run the check twice, once each way. > When the desired second number is exactly halfway between two > values, is rounding down as acceptable as up? > (Eg, exact answer 142.75, acceptable 142.7 and 142.8) Yes, either would be accepted. > Once you're sure of the goal, it's a question of whether the > decimal package can handle it. I would be inclined to do it in > two stages. Drop all the periods and convert each to int (long). > Multiply and Add 5**n, where n is related to the length of the > target. Convert to string, padded with lots of zeroes. > > > See if the exact string begins with the target. If not, they're > not close enough. > > If the first part passes, you just have to check the position of > the decimal point. > > Or you could check the implementation of round. If you pick the > right value for round, you could do an exact comparison. > > > Alternatively, if you're just looking to catch typos, it could > be simpler. Or if you put constraints on the numbers > involved. It is just to catch typos. I don't mind if it misses some cases, not a big deal. Thanks for the suggestion. I'll see how that looks in code. ChrisA From rosuav at gmail.com Wed Sep 24 21:46:07 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 25 Sep 2014 11:46:07 +1000 Subject: Flask and Python 3 In-Reply-To: References: Message-ID: On Thu, Sep 25, 2014 at 5:39 AM, Juan Christian wrote: > That's the way I always learned everything. I watch some video courses, read > a book and read the official documentation altogether. > > My way can't work for you, but for me it's excellent. And you don't even > know which video/course I'm talking about, so it's gross to tell that > "videos are the worst thing"... It doesn't matter which video/course you were talking about. Chris was talking about the *format* of videos. And I agree with him. ChrisA From ikorot01 at gmail.com Wed Sep 24 22:52:18 2014 From: ikorot01 at gmail.com (Igor Korot) Date: Wed, 24 Sep 2014 19:52:18 -0700 Subject: Which module I'm missing? Message-ID: Hi, ALL, I got a suggestion to install eric for my developmental needs. Unfortunately, it looks like my Linux distribution have a bug as running eric throws an exception. [code] igor at IgorDellGentoo ~/plaso-build/liblnk-20140905 $ eric5 An unhandled exception occurred. Please report the problem using the error reporting dialog or via email to . A log has been written to "/home/igor/.eric5/eric5_error.log". Error information: -------------------------------------------------------------------------------- 2014-09-21, 07:56:26 -------------------------------------------------------------------------------- : No module named 'DebugClients.Python3.coverage' -------------------------------------------------------------------------------- File "/usr/lib64/python3.3/site-packages/eric5/eric5.py", line 268, in main() File "/usr/lib64/python3.3/site-packages/eric5/eric5.py", line 245, in main from UI.UserInterface import UserInterface File "/usr/lib64/python3.3/site-packages/eric5/UI/UserInterface.py", line 34, in from QScintilla.MiniEditor import MiniEditor File "/usr/lib64/python3.3/site-packages/eric5/QScintilla/MiniEditor.py", line 26, in from .SearchReplaceWidget import SearchReplaceWidget File "/usr/lib64/python3.3/site-packages/eric5/QScintilla/SearchReplaceWidget.py", line 16, in from .Editor import Editor File "/usr/lib64/python3.3/site-packages/eric5/QScintilla/Editor.py", line 35, in from DataViews.PyCoverageDialog import PyCoverageDialog File "/usr/lib64/python3.3/site-packages/eric5/DataViews/PyCoverageDialog.py", line 22, in from DebugClients.Python3.coverage.misc import CoverageException -------------------------------------------------------------------------------- Version Numbers: Python 3.3.3 Qt 4.8.5 PyQt4 4.10.3 sip 4.15.3 QScintilla 2.7.2 WebKit 534.34 eric5 5.3.6 (rev 1d360120e928) Platform: linux 3.3.3 (default, May 29 2014, 03:55:37) [GCC 4.7.3] -------------------------------------------------------------------------------- Distribution Info: /etc/os-release NAME=Gentoo ID=gentoo PRETTY_NAME="Gentoo/Linux" ANSI_COLOR="1;32" HOME_URL="http://www.gentoo.org/" SUPPORT_URL="http://www.gentoo.org/main/en/support.xml" BUG_REPORT_URL="https://bugs.gentoo.org/" /etc/gentoo-release Gentoo Base System release 2.2 igor at IgorDellGentoo ~/plaso-build/liblnk-20140905 $ emerge -pv eric These are the packages that would be merged, in order: Calculating dependencies... done! [ebuild R ] dev-util/eric-5.3.6:5 USE="spell" LINGUAS="ru -cs -de -en -es -fr -it -tr -zh_CN" 0 kB Total: 1 package (1 reinstall), Size of downloads: 0 kB igor at IgorDellGentoo ~/plaso-build/liblnk-20140905 $ eselect python list Available Python interpreters: [1] python2.7 * [2] python3.3 [/code] So my question is: which module I need to install? Thank you. From tim_grove at sil.org Wed Sep 24 23:15:53 2014 From: tim_grove at sil.org (Timothy W. Grove) Date: Thu, 25 Sep 2014 04:15:53 +0100 Subject: Automatic Crash Reporting Message-ID: <542388E9.3000808@sil.org> Can anyone recommend a good automatic crash reporting module that would work nicely with a python3/pyqt4 application? Thanks. Tim From dieter at handshake.de Thu Sep 25 02:14:26 2014 From: dieter at handshake.de (dieter) Date: Thu, 25 Sep 2014 08:14:26 +0200 Subject: ThreadPoolExecutor - callback guaranteed to run in same thread as the submitted function? References: Message-ID: <874mvwtef1.fsf@handshake.de> Praveen Gollakota writes: > In the ThreadPoolExecutor (TPE), is the callback always guaranteed to run in the same thread as the submitted function? To answer question of this type (yourself), you may look at the relevant source code. I am quite sure that the "submitted function" will be executed in one of the threads from the thread pool. I have not looked at the "ThreadPoolExecutor" code. The easiest thing would be to run the callback in the same thread as the submitted function. However, it could facilitate use of the "ThreadPoolExecutor" (less locking) when the synchronisation were done inside the "ThreadPoolExecutor" and the callbacks were executed in a single thread (likely the one which has set up the "ThreadPoolExecutor"). A look at the source should tell the details. From wxjmfauth at gmail.com Thu Sep 25 02:20:00 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 24 Sep 2014 23:20:00 -0700 (PDT) Subject: String representations of numbers and approximate equality In-Reply-To: References: Message-ID: <82a86410-5b0f-4742-be00-69e0e8f94e52@googlegroups.com> Le jeudi 25 septembre 2014 01:41:42 UTC+2, Dan Stromberg a ?crit?: > On Wed, Sep 24, 2014 at 9:54 AM, Chris Angelico wrote: > > > Yes, it's another "how can I see if two numbers are approximately > > > equal" thread, but this time I have a concrete definition of > > > "approximately equal"... and they're Decimals, not floats. > > > > > > I have a number of files (this is an ongoing thing) in which there are > > > two columns of numbers. One of them should be equal to the other times > > > some factor which the program knows from elsewhere. All the numbers > > > are represented as strings of ASCII decimal digits, possibly including > > > a U+002E decimal point. Something like this: > > > > > > # (these are calculated on factor 30) > > > ["0.75", "22.5"] > > > ["0.80", "24"] > > > ["4.73", "142"] > > > > > > The definition of valid is that, within the rounding they've been > > > given, the values are correct. The first two are strictly correct; the > > > third would be 141.9 with full accuracy but 142 is deemed good enough. > > > But this should fail: > > > > > > ["0.1", "10"] > > > > > > 0.1 * 30 should be 3, not 10; and 10 / 30 should be 0.333, not 0.1; > > > therefore this is wrong. > > > > tolerance = decimal.Decimal('0.1') # I hesitate to call it epsilon > > > > if abs(decimal1 - decimal2) <= tolerance: > > print('They are close') > > else: > > print('They are different') Basically yes, but... In the present case, what counts is the confidence interval of a calculation, not the the precision of the numbers used for the calculation. >>> def z(x, y): ... x, y = float(x), float(y) ... err = 0.05 * y ... fac = 30 ... if y - err <= x * fac < y + err: ... return 'good enough' ... else: ... return 'bad' ... >>> z('0.1', '10') 'bad' >>> z('0.1', '3') 'good enough' >>> z('4.73', '142') 'good enough' >>> z('4.729999', '142') 'good enough' >>> z('4.7300001', '142') 'good enough' >>> z('4.73', '140') 'good enough' From dieter at handshake.de Thu Sep 25 02:24:25 2014 From: dieter at handshake.de (dieter) Date: Thu, 25 Sep 2014 08:24:25 +0200 Subject: Which module I'm missing? References: Message-ID: <87zjdorzdy.fsf@handshake.de> Igor Korot writes: > I got a suggestion to install eric for my developmental needs. > Unfortunately, it looks like my Linux distribution have a bug as > running eric throws an exception. > > [code] > igor at IgorDellGentoo ~/plaso-build/liblnk-20140905 $ eric5 > An unhandled exception occurred. Please report the problem > using the error reporting dialog or via email to > . > A log has been written to "/home/igor/.eric5/eric5_error.log". > > Error information: > -------------------------------------------------------------------------------- > 2014-09-21, 07:56:26 > -------------------------------------------------------------------------------- > : > No module named 'DebugClients.Python3.coverage' This tells you that "DebugClients.Python3.coverage" could not be imported. The real problem might be "DebugClients" or "DebugClients.Python3" or "DebugClients.Python2.coverage". To find out, import those packages/modules in an interactive Python interpreter session in turn. The first failing import indicates the real problem. If "DebugClients" is the culprit, then either the package is not installed or not covered by "sys.path" (the envvar "PYTHONPATH"). You might try "locate DebugClients" to see whether "DebugClients" is somewhere on your file system. The installation instructions for "eric" might tell you something about package or configuration dependencies. From ian.g.kelly at gmail.com Thu Sep 25 02:39:30 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 25 Sep 2014 00:39:30 -0600 Subject: ThreadPoolExecutor - callback guaranteed to run in same thread as the submitted function? In-Reply-To: References: Message-ID: On Wed, Sep 24, 2014 at 8:44 AM, Praveen Gollakota wrote: > However, it seemed to fail when I removed the `time.sleep(random.random())` statements, i.e. at least a few `func` functions and `callbacks` **did not** run in the same thread. > > For a project that I am working on, the callback must always run on the same thread as the submitted function, so I wanted to be sure that this is guaranteed by TPE. (And also the results of the test without the random sleep seemed puzzling). The documentation for Future.add_done_callback says: "If the future has already completed or been cancelled, fn will be called immediately." Checking the code, the callback is simply called from the submitting thread in this case. This makes sense as the thread that completed the future has already moved onto something else and may not be readily available or even identifiable. From __peter__ at web.de Thu Sep 25 02:44:39 2014 From: __peter__ at web.de (Peter Otten) Date: Thu, 25 Sep 2014 08:44:39 +0200 Subject: how to make return(self.res) not to output the content of list ? References: <5422CD52.8060501@gmail.com> <54235DA6.7060702@gmail.com> Message-ID: luofeiyu wrote: > `sys.displayhook = lambda obj: None ` will block everything to be > displayed on the interactive python console . > > i rewrite my code as the following : > > import sqlite3,os,jinja2 > db = r'data.sqlite' > con = sqlite3.connect(db) > cur = con.cursor() > > class status(): > def __init__(): > import sys > sys.displayhook=mydisplay > > def mydisplay(x): > if (x is not the result of an method grow of class status ) : x > #how to do in python code? else : pass > > def grow(self): > self.res= a data ananlyse process > return(self.res) > > def display(self): > #to display it in the html table > > > > how to fulfill the mydisplay function in python code to make x.grow() in > the following not to output the list of self.res?? > > > import analyse > x=analyse.status() > x.grow() Have grow() return a list subclass with the empty string as its repr(): >>> class GrowMethodResult(list): ... def __repr__(self): return "" ... >>> def grow(): ... return GrowMethodResult([1,2,3]) ... >>> grow() >>> From ikorot01 at gmail.com Thu Sep 25 03:03:09 2014 From: ikorot01 at gmail.com (Igor Korot) Date: Thu, 25 Sep 2014 00:03:09 -0700 Subject: Which module I'm missing? In-Reply-To: <87zjdorzdy.fsf@handshake.de> References: <87zjdorzdy.fsf@handshake.de> Message-ID: Thanx Dieter. On 9/24/14, dieter wrote: > Igor Korot writes: >> I got a suggestion to install eric for my developmental needs. >> Unfortunately, it looks like my Linux distribution have a bug as >> running eric throws an exception. >> >> [code] >> igor at IgorDellGentoo ~/plaso-build/liblnk-20140905 $ eric5 >> An unhandled exception occurred. Please report the problem >> using the error reporting dialog or via email to >> . >> A log has been written to "/home/igor/.eric5/eric5_error.log". >> >> Error information: >> -------------------------------------------------------------------------------- >> 2014-09-21, 07:56:26 >> -------------------------------------------------------------------------------- >> : >> No module named 'DebugClients.Python3.coverage' > > This tells you that "DebugClients.Python3.coverage" could not > be imported. The real problem might be "DebugClients" > or "DebugClients.Python3" or "DebugClients.Python2.coverage". > To find out, import those packages/modules in an interactive > Python interpreter session in turn. The first failing import > indicates the real problem. > > If "DebugClients" is the culprit, then either the package is > not installed or not covered by "sys.path" (the envvar "PYTHONPATH"). > You might try "locate DebugClients" to see whether "DebugClients" is > somewhere > on your file system. > > The installation instructions for "eric" might tell you something > about package or configuration dependencies. > > -- > https://mail.python.org/mailman/listinfo/python-list > From karina.pinter at exxonmobil.com Thu Sep 25 04:07:08 2014 From: karina.pinter at exxonmobil.com (Pinter, Karina /C) Date: Thu, 25 Sep 2014 10:07:08 +0200 Subject: Python Imaging Library 1.x - 64bit setup file for Python 2.7.2. Message-ID: Dear Team, I am working as a software analyst at ExxonMobil. I received a software request for Python Imaging Library 1.x and the user needs a 64bit setup file for Python 2.7.2. Can I download it somewhere? Thanks in advance. Best Regards, Karina Pinter ExxonMobil BSC Hungary Kft. Software Analyst EMIT / IT Operations / Customer Infrastructure / IT Asset Management H-1139 Budapest, V?ci ?t 81-85. Phone: +36 1 298 5361 [cid:image001.png at 01CFD8A8.777C8BB0] -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image001.png Type: image/png Size: 9238 bytes Desc: image001.png URL: From marko at pacujo.net Thu Sep 25 05:46:55 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 25 Sep 2014 12:46:55 +0300 Subject: ThreadPoolExecutor - callback guaranteed to run in same thread as the submitted function? References: Message-ID: <871tr06nhs.fsf@elektro.pacujo.net> Ian Kelly : > The documentation for Future.add_done_callback says: "If the future > has already completed or been cancelled, fn will be called > immediately." That sounds really bad. There should be a guarantee that the callback is not called from the same thread before returning from Future.add_done_callback. Otherwise, the caller may have a really difficult time handling preemption and avoiding deadlocks at the same time. Example (pseudocode): def callback(self): with self.lock: ... def xyz(self, f): with self.lock: ... f.add_done_callback(self.callback) The code will deadlock if the callback is invoked immediately. Marko From vincent.vande.vyvre at telenet.be Thu Sep 25 06:08:36 2014 From: vincent.vande.vyvre at telenet.be (Vincent Vande Vyvre) Date: Thu, 25 Sep 2014 12:08:36 +0200 Subject: Python Imaging Library 1.x - 64bit setup file for Python 2.7.2. In-Reply-To: References: Message-ID: <5423E9A4.4060909@telenet.be> Le 25/09/2014 10:07, Pinter, Karina /C a ?crit : > > Dear Team, > > I am working as a software analyst at ExxonMobil. I received a > software request for Python Imaging Library 1.x and the user needs a > 64bit setup file for Python 2.7.2. Can I download it somewhere? > > Thanks in advance. > > */Best Regards,/* > > */ > Karina Pinter/** > **/ExxonMobil BSC Hungary Kft./* > /Software Analyst/ > /EMIT / IT Operations / Customer Infrastructure / IT Asset Management/*//* > > /H-1139 Budapest, V?ci ?t 81-85. Phone/: +36 1 298 5361 > > cid:image001.png at 01CEF5B8.F78ACF20 > > > for Windows I presume, have a look here: http://www.lfd.uci.edu/~gohlke/pythonlibs/#pillow From 4kir4.1i at gmail.com Thu Sep 25 06:56:21 2014 From: 4kir4.1i at gmail.com (Akira Li) Date: Thu, 25 Sep 2014 14:56:21 +0400 Subject: GCD in Fractions References: <54216c8e$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87d2akufxm.fsf@gmail.com> Mark Lawrence writes: > On 24/09/2014 12:14, Mark Dickinson wrote: >> Mark Lawrence yahoo.co.uk> writes: >>> Somebody got there first http://bugs.python.org/issue22477 >> >> I think there's good reason to suspect that Brian Gladman and >> blindanagram are one and the same. :-) >> >>>>> sorted("BrianGladman".lower()) == sorted("blindanagram") >> True >> > > Is that considered proof that I still reign supreme as the most > unobservant person on the planet? :) It might mean that you are *too observant* because I've noticed that the order of the letters is different just now. http://english.stackexchange.com/questions/8628/is-it-true-that-only-the-positions-of-the-first-and-last-letter-in-a-word-matter [spoiler: it is not true in general but brains can do a lot of "error-correction" subconsciously] -- Akira From rosuav at gmail.com Thu Sep 25 07:03:08 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 25 Sep 2014 21:03:08 +1000 Subject: GCD in Fractions In-Reply-To: <87d2akufxm.fsf@gmail.com> References: <54216c8e$0$29966$c3e8da3$5496439d@news.astraweb.com> <87d2akufxm.fsf@gmail.com> Message-ID: On Thu, Sep 25, 2014 at 8:56 PM, Akira Li <4kir4.1i at gmail.com> wrote: > It might mean that you are *too observant* because I've noticed that > the order of the letters is different just now. > > http://english.stackexchange.com/questions/8628/is-it-true-that-only-the-positions-of-the-first-and-last-letter-in-a-word-matter > > [spoiler: it is not true in general but brains can do a lot of > "error-correction" subconsciously] It's definitely not true, and has been frequently debunked. But brains do error-correct, and not just on the order of letters. I spend a lot of time on MUDs, where the typographical quality is comparable to IRC; those of you who hang out on #python can probably attest to the same thing. When people type quickly, they make errors... and they're often the same errors (one hand not on the home keys, two letters transposed, omitted letters, etc). Those of us who hang out there tend to get familiar enough with the errors to autocorrect them - and sometimes not even notice them :) ChrisA From pradeepatjob at gmail.com Thu Sep 25 08:28:35 2014 From: pradeepatjob at gmail.com (pradeepatjob at gmail.com) Date: Thu, 25 Sep 2014 05:28:35 -0700 (PDT) Subject: how to execute the following command using python Message-ID: <27d70eda-ea9d-40d7-a00e-1b9f943df8cd@googlegroups.com> Hi group, I am trying to mount a remote network to my Ubuntu system. The remote machine keeps on changes or it is given by the user whoever wants to use my script. so , user enters what to mount. I found following command and it is running successfully when I execute using shell. the command: echo -e 'ubuntumachinepassword/\nremotemachinepasword' | sudo --stdin sshfs root at remoteip:/remotesystem/folder/ /localmountpoint / -o workaround=rename -o password_stdin -o allow_other but when i used this in os.system(abovecommad) i was not successfull. any help on this? thanks & regards Pradeep Kumar From davea at davea.name Thu Sep 25 08:40:28 2014 From: davea at davea.name (Dave Angel) Date: Thu, 25 Sep 2014 08:40:28 -0400 (EDT) Subject: String representations of numbers and approximate equality References: Message-ID: Chris Angelico Wrote in message: > On Thu, Sep 25, 2014 at 5:56 AM, Dave Angel wrote: >> Your definition is not nearly as concrete as you think. Is the >> first number considered to be exact, and we'll only check the >> second? Will the factor always be an int, and thus >> exact? > > Apologies: the definition is concrete, just under-specified in the post. > > No, both numbers are inexact; most notably, one third of the factor > might be involved - both of these should be correct: > > ["1.333", "40"] > ["1.33", "40"] > > But if it's easier to assume that one or t'other must be exact, that's > fine too - I can just run the check twice, once each way. > You could assume that the one with more significant digits is the exact one. Another approach is to see if twiddling the last digit gets you from too high to too low. I used this approach to check a trig package I wrote in '75. An answer was close enough if twiddling the last digit changed the result value from too high to too low, or if twiddling the last digit of the argument did. I needed to go both ways because the curve sometimes had a slope greater than one. Oh, and don't forget to set the precision of Decimal to a couple more than the sum of the digits. -- DaveA From rosuav at gmail.com Thu Sep 25 08:42:19 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 25 Sep 2014 22:42:19 +1000 Subject: how to execute the following command using python In-Reply-To: <27d70eda-ea9d-40d7-a00e-1b9f943df8cd@googlegroups.com> References: <27d70eda-ea9d-40d7-a00e-1b9f943df8cd@googlegroups.com> Message-ID: On Thu, Sep 25, 2014 at 10:28 PM, wrote: > echo -e 'ubuntumachinepassword/\nremotemachinepasword' | sudo --stdin sshfs root at remoteip:/remotesystem/folder/ /localmountpoint / -o workaround=rename -o password_stdin -o allow_other > This implies that you're embedding two passwords in the script, in clear text. I suggest not doing this - it's actually easier that way. All you need to do is permit passwordless access: first to sudo, then to the remote machine. Passwordless sudo access can be done either globally or for this one specific password, via the sudoers file. You can find out how to do that on the internet; it's not a Python issue. Passwordless SSH (including sshfs) is usually done with a key pair - look up ssh-keygen and the authorized_keys file (you put your public key into that file, and access is granted without a password). Again, plenty of info about that on the internet. (Side point: I strongly recommend NOT granting access via the root login. Even if you know what you're doing, even if you think you've locked it down to just SFTP, even if you think it's granting read-only access, I still say mounting root at anything is a dangerous thing to do. And if you haven't locked it down, and are giving root shell access to anyone who knows a password that's stored in clear text in a script... you definitely shouldn't be doing that.) Once you have that, all you need is to run this: sudo sshfs root at remoteip:/remotesystem/folder /localmountpoint -o allow_other and you might not even need "-o allow_other". Everything should just work by itself - that's what I do with the Yosemite Project, with an additional feature of automating the authorized_keys management (based on IP address ranges that are permitted access). ChrisA From rosuav at gmail.com Thu Sep 25 08:46:07 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 25 Sep 2014 22:46:07 +1000 Subject: String representations of numbers and approximate equality In-Reply-To: References: Message-ID: On Thu, Sep 25, 2014 at 10:40 PM, Dave Angel wrote: > Another approach is to see if twiddling the last digit gets you > from too high to too low. I used this approach to check a trig > package I wrote in '75. An answer was close enough if twiddling > the last digit changed the result value from too high to too low, > or if twiddling the last digit of the argument did. I needed to > go both ways because the curve sometimes had a slope greater than > one. Ooh, that sounds clean. So, something like this: if x * FACTOR > y: reduce_last_digit_of_x if x * FACTOR > y: error otherwise do the opposite check ? That's pretty doable. ChrisA From shawn at skrite.net Thu Sep 25 09:14:30 2014 From: shawn at skrite.net (Shawn Bright) Date: Thu, 25 Sep 2014 06:14:30 -0700 (PDT) Subject: cannot run a ruby script from a python script. In-Reply-To: <8c24ba60-9f0c-4b29-8c3e-64139af3a676@googlegroups.com> References: <8c24ba60-9f0c-4b29-8c3e-64139af3a676@googlegroups.com> Message-ID: On Wednesday, September 24, 2014 6:57:34 PM UTC-5, Shawn Bright wrote: > hello all. > > > > i have a linux computer that i use to run a GUI (wxGTK) program. In this program, there is a call to run an external ruby script. > > > > command = "ruby run_my_command.rb &" > > os.system(command) > > > > however, when it runs, i get this in the terminal > > sh: 1: ruby: not found > > > > i had considered that the path to the executable was messed up or somesuch, but when i just run python in the interpreter, it works fine. > > > > also, i have another computer with identical hardware, same OS, same package versions that it does work on also. This machine is to be a backup. > > > > Another note: When i run which ruby i get the path to the ruby executable. If i use that in my code, it will run, however, it will not be able to find any of the modules that i need for the ruby script to import. > > > > example > > > > command = "/path/to/ruby run_my_command.rb &" > > os.system(command) > > > > will run the ruby script, but the ruby script will not be able to import any of it's modules. > > > > > > thanks for any tips on this. I tried this with the same results. I am executing the GUI program from a terminal. It is a data engine that only really can serve our company so no reason to create menu entries for it and such. It did try to execute the ruby code, but could not. Thanks for your help. From ian.g.kelly at gmail.com Thu Sep 25 10:16:05 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 25 Sep 2014 08:16:05 -0600 Subject: ThreadPoolExecutor - callback guaranteed to run in same thread as the submitted function? In-Reply-To: <871tr06nhs.fsf@elektro.pacujo.net> References: <871tr06nhs.fsf@elektro.pacujo.net> Message-ID: On Thu, Sep 25, 2014 at 3:46 AM, Marko Rauhamaa wrote: > Ian Kelly : > >> The documentation for Future.add_done_callback says: "If the future >> has already completed or been cancelled, fn will be called >> immediately." > > That sounds really bad. > > There should be a guarantee that the callback is not called from the > same thread before returning from Future.add_done_callback. Otherwise, > the caller may have a really difficult time handling preemption and > avoiding deadlocks at the same time. > > Example (pseudocode): > > def callback(self): > with self.lock: > ... > > def xyz(self, f): > with self.lock: > ... > f.add_done_callback(self.callback) > > The code will deadlock if the callback is invoked immediately. Easily solved using a re-entrant lock. Alternatively, one could use synchronization to make sure the future can't complete until all callbacks have been added. That would have the benefit of keeping the callback processing on the same thread as the future, as the OP wanted. From gandalf at shopzeus.com Thu Sep 25 10:33:50 2014 From: gandalf at shopzeus.com (=?ISO-8859-1?Q?Nagy_L=E1szl=F3_Zsolt?=) Date: Thu, 25 Sep 2014 16:33:50 +0200 Subject: Python as Windows Service In-Reply-To: <006c01cfd806$ba875b30$2f961190$@traxens.com> References: <460EC810-C983-43FB-90AF-315D5DF5174B@Gmail.com> <000f01cfd7c7$64caa6a0$2e5ff3e0$@traxens.com> <1570DB93-532A-4A9D-A5DF-20F3D6DEE3B8@Gmail.com> <006c01cfd806$ba875b30$2f961190$@traxens.com> Message-ID: <542427CE.4060800@shopzeus.com> > *De :*Gmail [mailto:mrjean1 at gmail.com] > *Envoy? :* Wednesday, September 24, 2014 2:41 PM > *? :* Arulnambi Nandagoban > *Objet :* Re: Python as Windows Service > > Also, this may work for you > > > > > > NSSM installs an existing app as a service. > > > //Jean/ > By the way, do we have support for creating a Windows Service for Python 3 already? I know it was not working about 6 months ago. Does pywin32 (PythonService.exe ?) still lack this feautue? -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. -------------- next part -------------- An HTML attachment was scrubbed... URL: From marko at pacujo.net Thu Sep 25 10:47:54 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 25 Sep 2014 17:47:54 +0300 Subject: ThreadPoolExecutor - callback guaranteed to run in same thread as the submitted function? References: <871tr06nhs.fsf@elektro.pacujo.net> Message-ID: <87sijf69k5.fsf@elektro.pacujo.net> Ian Kelly : > On Thu, Sep 25, 2014 at 3:46 AM, Marko Rauhamaa wrote: >> Example (pseudocode): >> >> def callback(self): >> with self.lock: >> ... >> >> def xyz(self, f): >> with self.lock: >> ... >> f.add_done_callback(self.callback) >> >> The code will deadlock if the callback is invoked immediately. > > Easily solved using a re-entrant lock. Not easily. Your state transition might not be complete at the time of the preemption. Many such issues can be resolved by moving the preemptive function calls to the end of the critical section, but that is not always possible, easy or taken into account. If preemption needs to be prepared for, the real solution is: def xyz(self, f): with self.lock: ... def add_callback(): f.add_done_callback(self.callback) self.executor.schedule(add_callback) which is ugly, of course. > Alternatively, one could use synchronization to make sure the future > can't complete until all callbacks have been added. That would have > the benefit of keeping the callback processing on the same thread as > the future, as the OP wanted. You can still keep the callback in the same thread if your executor is tied to the the same thread as the calling function. That's the classic event loop. The executor API should be independent of the implementation (single vs multithreaded), but it should be able to guarantee that it never makes callbacks preemptively. Marko From zachary.ware+pylist at gmail.com Thu Sep 25 10:53:21 2014 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Thu, 25 Sep 2014 09:53:21 -0500 Subject: Python as Windows Service In-Reply-To: <542427CE.4060800@shopzeus.com> References: <460EC810-C983-43FB-90AF-315D5DF5174B@Gmail.com> <000f01cfd7c7$64caa6a0$2e5ff3e0$@traxens.com> <1570DB93-532A-4A9D-A5DF-20F3D6DEE3B8@Gmail.com> <006c01cfd806$ba875b30$2f961190$@traxens.com> <542427CE.4060800@shopzeus.com> Message-ID: On Thu, Sep 25, 2014 at 9:33 AM, Nagy L?szl? Zsolt wrote: > By the way, do we have support for creating a Windows Service for Python 3 > already? I know it was not working about 6 months ago. Does pywin32 > (PythonService.exe ?) still lack this feautue? I can confirm that a Windows service can be created using the latest py2exe (which supports Python 3.3+) with Python 3.4 and pywin32 build 219. I assume that pythonservice.exe would also work, but I haven't tried it on its own. -- Zach From ian.g.kelly at gmail.com Thu Sep 25 11:40:34 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 25 Sep 2014 09:40:34 -0600 Subject: ThreadPoolExecutor - callback guaranteed to run in same thread as the submitted function? In-Reply-To: <87sijf69k5.fsf@elektro.pacujo.net> References: <871tr06nhs.fsf@elektro.pacujo.net> <87sijf69k5.fsf@elektro.pacujo.net> Message-ID: On Thu, Sep 25, 2014 at 8:47 AM, Marko Rauhamaa wrote: > Ian Kelly : > >> On Thu, Sep 25, 2014 at 3:46 AM, Marko Rauhamaa wrote: >>> Example (pseudocode): >>> >>> def callback(self): >>> with self.lock: >>> ... >>> >>> def xyz(self, f): >>> with self.lock: >>> ... >>> f.add_done_callback(self.callback) >>> >>> The code will deadlock if the callback is invoked immediately. >> >> Easily solved using a re-entrant lock. > > Not easily. Your state transition might not be complete at the time of > the preemption. Many such issues can be resolved by moving the > preemptive function calls to the end of the critical section, but that > is not always possible, easy or taken into account. Fair enough. In the simple example above, I see no harm in simply moving the add_done_callback call outside (after) the "with self.lock" block altogether. I can imagine more complex examples where the call is further down the stack and harder to isolate from the lock, although I would argue that's probably a code smell. > If preemption needs to be prepared for, the real solution is: > > > def xyz(self, f): > with self.lock: > ... > def add_callback(): > f.add_done_callback(self.callback) > self.executor.schedule(add_callback) > > which is ugly, of course. YMMV, but I think I would prefer to make the executor.schedule call be the callback: def callback(self, f): with self.lock: ... def xyz(self, f): with self.lock: ... f.add_done_callback( functools.partial(self.executor.schedule, self.callback)) From rosuav at gmail.com Thu Sep 25 12:04:40 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 26 Sep 2014 02:04:40 +1000 Subject: ThreadPoolExecutor - callback guaranteed to run in same thread as the submitted function? In-Reply-To: References: <871tr06nhs.fsf@elektro.pacujo.net> <87sijf69k5.fsf@elektro.pacujo.net> Message-ID: On Fri, Sep 26, 2014 at 1:40 AM, Ian Kelly wrote: > Fair enough. In the simple example above, I see no harm in simply > moving the add_done_callback call outside (after) the "with self.lock" > block altogether. I can imagine more complex examples where the call > is further down the stack and harder to isolate from the lock, > although I would argue that's probably a code smell. I'd definitely call it code smell. What happens with this? with lock: def inner(): do_more_work() f.add_done_callback(inner) The lock's possibly released before the callback happens, or possibly not, but either way, the code *looks* as if it's all happening inside the "with lock" block. Recipe for confusion IMO. ChrisA From kwpolska at gmail.com Thu Sep 25 13:28:30 2014 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Thu, 25 Sep 2014 19:28:30 +0200 Subject: Flask and Python 3 In-Reply-To: References: Message-ID: On Wed, Sep 24, 2014 at 9:39 PM, Juan Christian wrote: > On Wednesday, September 24, 2014, Chris ?Kwpolska? Warrick > wrote: >> >> Learning from videos is the worst thing you can do. Use the official >> flask documentation at http://flask.pocoo.org/docs/0.10/quickstart/ ? >> it?s much friendlier than a video. >> >> Also, there is nothing to ?learn? ? just change the line, and you will >> have more helpful errors. > > > That's the way I always learned everything. I watch some video courses, read > a book and read the official documentation altogether. > > My way can't work for you, but for me it's excellent. And you don't even > know which video/course I'm talking about, so it's gross to tell that > "videos are the worst thing"... It doesn?t matter. Here, have some wisdom, as provided by the top Google hit for ?video tutorials suck?: https://news.ycombinator.com/item?id=4565615 The thing is, it?s text. I suppose I could use some text-to-speech software to provide you with a video tutorial version of that. -- Chris ?Kwpolska? Warrick PGP: 5EAAEA16 stop html mail | always bottom-post | only UTF-8 makes sense From breamoreboy at yahoo.co.uk Thu Sep 25 13:48:10 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 25 Sep 2014 18:48:10 +0100 Subject: Python Imaging Library 1.x - 64bit setup file for Python 2.7.2. In-Reply-To: References: Message-ID: On 25/09/2014 09:07, Pinter, Karina /C wrote: > Dear Team, > > I am working as a software analyst at ExxonMobil. I received a software > request for Python Imaging Library 1.x and the user needs a 64bit setup > file for Python 2.7.2. Can I download it somewhere? > > Thanks in advance. > > */Best Regards,/* > > */ > Karina Pinter/** > **/ExxonMobil BSC Hungary Kft./* > /Software Analyst/ > /EMIT / IT Operations / Customer Infrastructure / IT Asset Management/*//* > > /H-1139 Budapest, V?ci ?t 81-85. Phone/: +36 1 298 5361 > > cid:image001.png at 01CEF5B8.F78ACF20 > Are you aware that PIL is no longer supported? However a friendly fork is available see https://pypi.python.org/pypi/Pillow/2.5.3 where right at the bottom of a long page you'll find Pillow-2.5.3.win-amd64-py2.7.exe -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From juan0christian at gmail.com Thu Sep 25 14:18:21 2014 From: juan0christian at gmail.com (Juan Christian) Date: Thu, 25 Sep 2014 15:18:21 -0300 Subject: Flask and Python 3 In-Reply-To: References: Message-ID: On Thu, Sep 25, 2014 at 2:28 PM, Chris ?Kwpolska? Warrick < kwpolska at gmail.com> wrote: > > It doesn?t matter. Here, have some wisdom, as provided by the top > Google hit for ?video tutorials suck?: > https://news.ycombinator.com/item?id=4565615 > Using your link, the first comment from user 'arocks': " If you have been into teaching you would realize that there are different kinds of learners. Some prefer verbal material, others prefer more visual, while some others like written material. The vast majority however prefer a combination of the above. While you can pour over tutorials on how to use Emacs; just watching a video of a power user using Emacs gives you a different impression. It is really a completely different experience. Sometimes it is faster to produce a set of video tutorials than to prepare well-written documentation. Hence they make a call. However, I agree that written documentation is the best medium for long term (i.e. smaller, searchable etc) So, rather than asking for one medium of instruction to stop, I would rather encourage the plurality. Let the end-user pick and choose whatever he/she likes. " As the guy said, and many others in the comments agree, "rather than asking for one medium of instruction to stop, I would rather encourage the plurality.", and indeed, I prefer plurality, I DO use the official doc, I don't only see video-tutorials. You don't know me, you don't know my learning process, so stop imposing what YOU think is right, because what's right for YOU won't necessarily be for others. No matter what you say, it won't change, don't try to standardize the learning process, you nor anyone can do this. > The thing is, it?s text. I suppose I could use some text-to-speech > software to provide you with a video tutorial version of that. No, you can't, if you think a video tutorial is only that, I'm afraid to tell that you only saw terrible courses/tutorials in your life. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu Sep 25 14:23:03 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 26 Sep 2014 04:23:03 +1000 Subject: Flask and Python 3 In-Reply-To: References: Message-ID: On Fri, Sep 26, 2014 at 4:18 AM, Juan Christian wrote: > On Thu, Sep 25, 2014 at 2:28 PM, Chris ?Kwpolska? Warrick > wrote: >> >> It doesn?t matter. Here, have some wisdom, as provided by the top >> Google hit for ?video tutorials suck?: >> https://news.ycombinator.com/item?id=4565615 > > > Using your link, the first comment from user 'arocks': > > " So, rather than asking for one medium of instruction to stop, I would rather > encourage the plurality. Let the end-user pick and choose whatever he/she > likes. " > > > As the guy said, and many others in the comments agree, "rather than asking > for one medium of instruction to stop, I would rather encourage the > plurality.", and indeed, I prefer plurality, I DO use the official doc, I > don't only see video-tutorials. You don't know me, you don't know my > learning process, so stop imposing what YOU think is right, because what's > right for YOU won't necessarily be for others. No matter what you say, it > won't change, don't try to standardize the learning process, you nor anyone > can do this. Actually, what most of the comments are agreeing on is that videos need their transcripts. Without them, they suck. Most videos don't have any sort of transcript. Ergo, most videos suck. ChrisA From kwpolska at gmail.com Thu Sep 25 14:26:14 2014 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Thu, 25 Sep 2014 20:26:14 +0200 Subject: Flask and Python 3 In-Reply-To: References: Message-ID: On Thu, Sep 25, 2014 at 8:18 PM, Juan Christian wrote: >> The thing is, it?s text. I suppose I could use some text-to-speech >> software to provide you with a video tutorial version of that. > > > No, you can't, if you think a video tutorial is only that, I'm afraid to > tell that you only saw terrible courses/tutorials in your life. Go on, show me a good video tutorial. One that is quick to consume, and one I can come back to at any time I please (within reasonable bounds). I can just open a text-based tutorial and use my browser?s search capabilities (or a Table of Contents or an index in an analog book) to find the precise bit of knowledge I need. You can?t easily do that with video tutorials. Also, video tutorials for code (as well as analog books) lack a very important feature: copy-paste. Nobody likes retyping large passages of code. Especially because it?s error-prone. -- Chris ?Kwpolska? Warrick PGP: 5EAAEA16 stop html mail | always bottom-post | only UTF-8 makes sense From juan0christian at gmail.com Thu Sep 25 14:35:32 2014 From: juan0christian at gmail.com (Juan Christian) Date: Thu, 25 Sep 2014 15:35:32 -0300 Subject: Flask and Python 3 In-Reply-To: References: Message-ID: On Thu, Sep 25, 2014 at 3:23 PM, Chris Angelico wrote: > Actually, what most of the comments are agreeing on is that videos > need their transcripts. Without them, they suck. Most videos don't > have any sort of transcript. Ergo, most videos suck. I'm not talking about "360p 3min kid's tutorial form Youtube" here, when I say video tutorial, it's implied that every video that I talked about have 1. The source-code (if programming/code related), 2. The transcripts and in some cases even 3. PDF version of the video. In this topic my code went wrong because I did it on my own, and not crtlc/crtlv from the original source-code, and it was a stupid typo error On Thu, Sep 25, 2014 at 3:26 PM, Chris ?Kwpolska? Warrick < kwpolska at gmail.com> wrote: > Also, video tutorials for code (as well as analog books) lack a very > important feature: copy-paste. Nobody likes retyping large passages > of code. Especially because it?s error-prone. Coursera, edX, digitaltutors, tv.adobe, tutsplus and many other sites. But, doesn't matter, if the person watching them is close minding and blindly hate any type of video tutorial, all these sites, no matter how good they are will suck for this person... Any, I think you two fled the point here. I didn't create this topic in order to talk about "video vs text", if you guy want to continue this waste of time, create a topic and talk everything you want. I'm done here, as I said, PLURALITY is the key thing, don't try to impose what you think is right and wrong. Bye. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu Sep 25 13:46:38 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 26 Sep 2014 03:46:38 +1000 Subject: Flask and Python 3 In-Reply-To: References: Message-ID: On Fri, Sep 26, 2014 at 3:28 AM, Chris ?Kwpolska? Warrick wrote: > It doesn?t matter. Here, have some wisdom, as provided by the top > Google hit for ?video tutorials suck?: > https://news.ycombinator.com/item?id=4565615 """The online video medium may be great for bloggers, but when I'm seeking information, everything else is a distraction.""" Not sure what "bloggers" means here. I blog in plain text, because I believe it's the best medium for anything of importance. If you're going to write something and then stand by it, and expect people to respond with serious debate, text is by far the best way to convey your point, if for one reason: quotability. Go ahead, make a video response, and quote something someone else said! Easy, isn't it? No? Hmm. Would you prefer to try quoting something from a text blog? http://rosuav.blogspot.com/ Maybe you're offended by my stance on the Bible. Or maybe you think Alice's Adventures In Down-Under-Land are worth talking about. Or perhaps you think my review of The Merry Widow is unfair to your sister's cousin's aunt who was in the cast. You can grab some of my text, surround it with quote characters, copy and paste the link to my blog, and make your own point. In five seconds, if you're used to it. Even if you're really familiar with your tools, I doubt very much that you can quote a video that quickly. ChrisA From bv4bv4bv4 at gmail.com Thu Sep 25 16:04:56 2014 From: bv4bv4bv4 at gmail.com (bv4bv4bv4 at gmail.com) Date: Thu, 25 Sep 2014 13:04:56 -0700 (PDT) Subject: The Description of the Barrier Between Two Seas Message-ID: <5f26d90e-1529-4bf7-a178-4ab0fd947774@googlegroups.com> The Description of the Barrier Between Two Seas Oceanographers, in the wake of the scientific progress in this age, have discovered the barrier between two seas. They have found that a barrier separates two neighboring seas. The barrier moves between them, and it is called by scientists "a front" compared to the front between two armies. By virtue of this barrier each sea retains its own characteristics which Allah (SWT) has assigned to it and which are suitable for the organisms living in that environment. Because of this barrier, the two neighboring seas mingle so slowly that the amount of water that passes from one sea to the other acquires the characteristics of the other sea while crossing the barrier which overturns the waters crossing from one sea to the other, keeping each sea with its own characteristics. The gradual progress of human knowledge about the fact of the differences between seawater masses and the existence of barriers between them : Oceanographers discovered that there were certain differences between water samples taken from various seas in 1284 AH/1873 AD, by the British Marine Scientific Expedition of the Challenger Voyage. It was discovered that masses of sea water vary in their composition, in respect of salinity, water temperature, density and types of marine organisms. The data were obtained from 362 oceanographic stations. The report of the expedition filled 29,500 pages in 50 volumes and took 23 years to complete. One of the great achievements of scientific exploration, the expedition also showed how little man knew about the sea. After 1933 AD another American expedition set out in the Mexican Gulf and installed hundreds of sea stations to study the characteristics of seas. It found out that a large number of stations in a certain area gave similar information about the characteristics of the water in that area, whether in respect of salinity, density, temperature, marine organisms or solubility of oxygen in water, while another group of stations in another area gave a different set of data about that area. So, oceanographers concluded that there were two distinctive seas with different characteristics, and not just limited samples as the Expedition of Challenger showed. Man installed hundreds of marine stations to study the characteristics of various seas. Scientists have found out that the differences in these characteristics distinguished one sea from another. But why do these seas not mix and become homogeneous in spite of the effect of tide and ebb that moves sea water twice a day, and causes seas to move forward and backward turbulently, besides other factors that cause sea water to be in continuous movement and turbulence, such as surface and internal waves and sea currents? The answer appeared for the first time in scientific books in 1361 AH/1942 AD. Extensive studies of marine characteristics revealed that there are water barriers separating neighboring seas and maintaining the distinctive properties of each sea with respect to density, salinity, marine life, temperature and solubility of oxygen in water. There are large waves, strong currents, and tides in the Mediterranean Sea and the Atlantic Ocean. Mediterranean Sea water enters the Atlantic by Gibraltar. But their temperature, salinity, and densities do not change, because of the barrier that separates them. After 1962 AD there was known the role of sea barriers in modifying the properties of the water masses that pass from one sea to another, to prevent one sea from overwhelming the other. So salty seas retain their own properties and boundaries by virtue of these barriers. A field study comparing the waters of Oman Gulf and those of the Arabian Gulf has shown the difference between them regarding their chemical properties, the prevalent vegetation and the barrier separating them. About a hundred years of research and study has been required to discover the fact of the existence of barriers between sea water masses and their role in making each sea retain its own properties. Hundred of researchers took part and numerous precise scientific instruments and equipment were used to achieve that. Fourteen centuries ago the Holy Qur'an revealed this fact. Allah (SWT) says: (He has let free (MARAJA) the two sees meeting together. Between them is a barrier that they do not transgress. Then which of the Blessings of your Lord will you both (Jinn and men) deny? Out of them both come out pearls and carol." (LV: 19-22) Allah (SWT) also says: "And He made a barrier between the two seas.)(XXVII: 61) Linguistic meanings and the commentators' sayings: Maraja (let free): Ibn Faris said: "'maraja': The consonants m, r and j form a root indicating a movement of going and coming and turbulence." Al-Bahrayn (the two seas): Al-Asfahani said: "Some say that the word "bahr" (sea) is usually used to mean salt water rather than fresh water." Ibn Manzursaid: "'Bahr' is more frequently used to describe salt water than fresh water." If the word "bahr" is used without qualification it means salt water; otherwise, it means the thing qualified." The Holy Qur'an uses "nahr" (river) to indicate abundant running fresh water, while it uses "bahr" (sea) to indicate salt water. Allah (SWT) says: (And He has made the ships to be of service to you that they may sail through the sea by His Command; and He has made rivers (also) to be of service to you.)(XIV: 32) In the hadith, "bahr" (sea) is also used to mean salt water. Allah's Messenger (Peace be upon him) was asked by a man who said: "O Allah's Messenger! We travel by sea and carry with us a little fresh water. If we should use it forwudu (ablution) we would get thirsty. May we use seawater for wudu? Allah' Messenger (Peace be upon him) said:"Its water is pure and its dead (animals) are lawful (to eat)." Al-Barzakh: It is the barrier. Most commentatorssuggest that it is invisible. Al-baghi: Ibn Manzur said: "'Al-Baghi' means transgression, exceeding the limits." Al-Jawhari and Al-Asfahani said the same. Al-Marjan: Ibn Al-Jawzi said: "Al-Qadi Abu Ya'li says that Al-Marjan is a kind of bar-like pearls. Al-Zajjajsaid: "Al-Marjan is white, very white." Ibn Mas'ud said: "Al-Marjan is red beads." Abu Hayyan said that to some people Al-Marjan is red stone. Al-Qurtubi said: "It is said that Al-Marjan is the big pearls. The same is also said by 'Ali and Ibn 'Abbas (May Allah bestow His Mercy on them both). The small pieces of Marjan are the small pearls. It is also reported on their authority the opposite: the big pieces are called pearls and the smaller are called Marjan. Al-Dahhak and Qatadah said the same." Al-Alusi said: "If we take into consideration the connotation of brilliance and glitter which the Arabic word "pearls" carries, and the connotation of movement and mixing that the word "Marjan" carries, we can say that "pearls" is used for big pieces and "Marjan" for small ones." Anyhow, Marjan is a kind of ornament that is found in various colors: white and red. It may be in big or small pieces. It is bar-like stone. In the Verse it is something other than pearls, for the conjunction "and" implies talking bout two different things. Marjan (carol), however, is found in salt seas only. The Verse shows us the minute secrets which oceanography has revealed only recently. They describe the meeting between salt seas. Following is the evidence to that: First: The Verse uses the word "bahrayn" (two seas) without any qualification. This means that salt seas are intended here. Second: The Verses in Surat Al-Rahman show that the two seas yield pearls and "Marjan"(carol). It has become evident that Marjan is found in salt seas only. This indicates that the Verse is referring to two salt seas. Allah (SWT) says: "Out of them both come out pearls and carol," i.e. out of each of them. Who knew in the past that salt seas differ in many respects in spite of their apparent similarity to the observer? (They all taste salt, look blue, have waves, contain fish, etc.) How can they differ although they meet each other? We know that when two amounts of water are mixed in a container they get homogenous. How can seas remain differentiated even in the presence of the factors of mixing, such as the ebb and flow of the sea, currents and storms? The Verse mentions the meeting of two salt seas that differ from one another. If the two seas were similar to one another, they would be one sea. However, differentiating between them in the Qur'anic utterance implies the difference between them although they are both salt. (He has let free (Maraja) the two seas meeting together) means that the two seas are mixed; they are in the state of backward and forward movements, of mixing and turbulence at the site of the meeting, as is understood from the literal meaning of "Maraja". This is the fact that science has discovered, that is to say, the barrier is described as being zigzag or wavy and shifting in position during the various seasons because of the tide and winds. This Verse by itself implies the presence of so much mixing and merging between these seas as would deprive them of their distinctive properties. But Allah (SWT), the All-Knower, shows in the following Verse that "between them is a barrier which they do not transgress", i.e. In spite of this state of merging and turbulence that characterizes the seas there is a barrier between them preventing them from transgressing or exceeding their limits. This is what man has discovered as a result of the advances achieved in his sciences and instruments. It has been found that a third water mass separates the two seas and it has such properties as are different from those of each of the two seas separated by it. Yet, in spite of the presence of the barrier, the waters of the two adjacent seas mix very slowly without one sea encroaching upon the other through carrying over its own properties to it, for the barrier zone is a region for changing the water crossing from one sea to the other so that it gradually acquires the properties of the sea that is going to enter and loses the properties of the sea it has come form. Thus neither of the two seas transgresses by carrying its own properties to the other, although they mix during the process of meeting. How truthful is Allah's Saying: (He has let free (maraja) the two seas meeting together. Between them is a barrier which they do not transgress.) Most commentators suggest that the barrier that separates the two seas referred to here is an invisible barrier created by Allah. Some commentators find it difficult to reconcile the idea of the seas being merging and the presence of a barrier at the same time, for the presence of a barrier entails the prevention of merging. So the mention of merging (maraja) entails the absence of a barrier. This apparent contradiction has been resolved by discovering the secrets of the seas. The Miraculous Aspects of the Previous Verses: We can conclude the following from the discussion above: The Holy Qur'an, which was revealed more than 14 centuries ago, includes very precise pieces of information and knowledge about marine phenomena that have been discovered only recently by means of very sophisticated equipment. An instance in this respect is the existence of water barriers between seas. Allah (SWT) says: (He has let free (maraja) the two seas meeting together. Between them is a barrier which they do not transgress.) The historical development of Oceanography shows that no precise information had been available on seas before Challenger Expedition (in 1873 AD), let alone at the time when the Holy Qur'an was being revealed 14 centuries ago to an illiterate Prophet that lived in a desert environment and never traveled by sea. Oceanography has witnessed no advances except in the last two centuries, particularly in the latter half of the twentieth century. Prior to that a sea was considered as something fearful and mysterious. Myths and superstitions were fabricated about it. Sea voyagers were only interested in their own safety and how to find the correct routes during their long journeys. Man discovered that salt seas are different only in the thirties of the twentieth century, after thousands of marine stations had been established by researchers to analyze samples of sea water to measure the differences between the degrees of temperature, salinity, density and oxygen dissolubility in the sea water recorded at all those stations, and then realize that salt seas are different. Man did not know anything about the barrier that separates between salt seas till the establishment of the aforesaid stations, and after spending a long time tracing these wavy moving barriers that change their geographical locations with the change of seasons. Man did not know that the water masses of the two seas are separated by a water barrier and are mixed at the same time till he started studying with his ships and equipment the water movement in the meeting region of the seas and analyzing the water masses in those regions. Man did not apply this rule to all seas that meet together except after vast scientific surveying, investigation and verification of this phenomenon, which occurs between each pair of adjacent seas in the world. Now then, did Allah's Messenger (Peace be upon him) own stations and equipment for analyzing water and the ability to trace the movement of various water masses? Did he carry out a comprehensive surveying process, although he never sailed the sea and lived at a time when superstitions were prevalent, particularly in the field of seas? Were, at the time of Allah's Messenger (Peace be upon him) such researches, instruments and studies as are available for the oceanographers of today who have discovered all these secrets by means of research and study? This knowledge, which the Qur'an came with, included a precise description of the subtlest secrets at a time when humanity could never have known them, which indicates that its source is Divine, as Allah (SWT) says: (Say: "the (Qur'an) was sent down by Him Who knows the secret (that is) in the heavens and the earth: Verily He is Oft-Forgiving, Most Merciful.) (XXV: 6) It also indicates that the one to whom the Book was sent down was a Messenger inspired. Allah (SWT) but says the Truth in the Verse: (Soon will We show Our Signs in the Universe and in their own selves, until it becomes manifest to them that this the Truth. Is it not sufficient that your Lord does witness all things?) http://www.quran-m.com/firas/en1/index.php/universe/253-the-description-of-the-barrier-between-two-seas.html Thank you From rosuav at gmail.com Thu Sep 25 19:55:51 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 26 Sep 2014 09:55:51 +1000 Subject: Flask and Python 3 In-Reply-To: References: Message-ID: On Fri, Sep 26, 2014 at 4:35 AM, Juan Christian wrote: > when I say video tutorial, it's implied that every video that I talked about > have 1. The source-code (if programming/code related), 2. The transcripts > and in some cases even 3. PDF version of the video. I've almost never seen videos that have all of that - and certainly not enough to *imply* that about the term. ChrisA From cs at zip.com.au Thu Sep 25 20:30:42 2014 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 26 Sep 2014 10:30:42 +1000 Subject: Dynamically swapping between two algorithms In-Reply-To: <54218831$0$29979$c3e8da3$5496439d@news.astraweb.com> References: <54218831$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20140926003042.GA26619@cskk.homeip.net> On 24Sep2014 00:48, Steven D'Aprano wrote: >I have a certain calculation which can be performed two radically different >ways. With the first algorithm, let's call it SHORT, performance is very >fast for small values of the argument, but terrible for large values. For >the second algorithm, LARGE, performance is quite poor for small values, >but excellent for large values. > >To add to the complexity, I perform this calculation repeatedly, in a loop: > >value = 1 >while True: > x = SHORT(value) # Or should I use LARGE? Decisions, decisions... > process(x) > value += some_increment() > if condition: break > >Luckily, the value never gets smaller. So if I could somehow determine a >cut-over point, CUTOFF, I might write my loop like this: > >value = 1 >while True: > f = SHORT if value < CUTOFF else LARGE > x = f(value) > process(x) > value += some_increment() > if condition: break > >alas, the CUTOVER point is likely to be machine-dependent. Take it as a >given that inserting a fixed CUTOVER point into the source code (say, >``CUTOVER = 123456``) is not likely to be very effective, and dynamically >calculating it at import time is impractical. I have two suggestions. The first suggestion presumes multiple CPUs, and is a bit of a brute force hack. If the total runtime domain for SHORT (total runtime for when SHORT is better) is small compared to the domain for LARGE it may be worthwhile. FIRST SUGGESTION Run SHORT and LARGE in subprocesses, flat out. When either stops, kill the other. Once LARGE is the first to stop, do not bother with SHORT any more. FIRST SUGGESTION Chris Angelico's approach looks pretty cool, but seems unstable (in choices) initially. Are the input values predictable? Or a fixed sequences? I am wondering if there's any scope for gathering all the values (or all the values up to comfortably past the unknown cutover point) before running SHORT or LARGE at all? I was thinking bisecting to find the CUTOFF, but the cost of the wrong algorithm for values well over the CUTOFF would be nasty. Alternatively: Did you say SHORT becomes quadratic in cost as it grows and LARGE roughtly linear? Pretend they really are purely quadratic and linear respectively. Then you could start with both SHORT and LARGE for your first value. Run SHORT and LARGE. Measure the elapsed time for each. Compute their ratio. I think you should be able to estimate the cutover point as the point where the two curves intersect. Run the SHORT algorithm until them. Then run both. Remeasure. Re-estimate. Repeat until definitely LARGE domain (estimate points into the past, maybe with an error margin). Then just use LARGE. Thoughts? Cheers, Cameron Simpson From fabiofz at gmail.com Thu Sep 25 21:25:27 2014 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Thu, 25 Sep 2014 22:25:27 -0300 Subject: PyDev 3.8.0 Released Message-ID: What is PyDev? --------------------------- PyDev is an open-source Python IDE on top of Eclipse for Python, Jython and IronPython development. It comes with goodies such as code completion, syntax highlighting, syntax analysis, code analysis, refactor, debug, interactive console, etc. Details on PyDev: http://pydev.org Details on its development: http://pydev.blogspot.com What is LiClipse? --------------------------- LiClipse is a PyDev standalone with goodies such as support for Multiple cursors, theming and a number of other languages such as Django Templates, Kivy Language, Mako Templates, Html, Javascript, etc. It's also a commercial counterpart which helps supporting the development of PyDev. Details on LiClipse: http://brainwy.github.io/liclipse/ Release Highlights: ------------------------------- * **Important**: PyDev requires Eclipse 3.8 or 4.3 onwards and Java 7! For older versions, keep using PyDev 2.x (use LiClipse: http://brainwy.github.io/liclipse for a PyDev standalone with all requirements bundled). * **Debugger** * It's now possible to **attach debugger to running process in Windows and Linux** (open debug perspective > PyDev > Attach to Process) * pep8 upgraded to 1.5.7 * Fixed issue in dialog shown when PyDev editor is opened which could lead to closing the IDE. * Selecting PyQT API version using sip.setapi no longer fails in debug mode (PyDev-452). * Code completion tries to get docstring definition from class before evaluating property (PyDev-412). * Internal error error when parsing file with wrong syntax: java.lang.ClassCastException for invalid dict (PyDev-411). * runfile was restored in pydevconsole (Ctrl+Alt+Enter is working again). * **Variables** and **Expressions** views working again when debugging interactive console (PyDev-446). * Pressing Shift to debug with Ctrl+F9 test runner now properly works in Linux (PyDev-444). * Fixed interpreter configuration when the interpreter prints something before actually running interpreterInfo.py (PyDev-448). * Fixed NullPointerException when debugging file without extension. Cheers, -- Fabio Zadrozny ------------------------------------------------------ Software Developer LiClipse http://brainwy.github.io/liclipse PyDev - Python Development Environment for Eclipse http://pydev.org http://pydev.blogspot.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Thu Sep 25 23:11:43 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 25 Sep 2014 20:11:43 -0700 Subject: Dynamically swapping between two algorithms In-Reply-To: <54218831$0$29979$c3e8da3$5496439d@news.astraweb.com> References: <54218831$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5424D96F.40205@stoneleaf.us> On 09/23/2014 07:48 AM, Steven D'Aprano wrote: > > alas, the CUTOVER point is likely to be machine-dependent. Take it as a > given that inserting a fixed CUTOVER point into the source code (say, > ``CUTOVER = 123456``) is not likely to be very effective, and dynamically > calculating it at import time is impractical. Have your setup script do some timings to figure out where CUTOFF is on any particular machine. You can then store it in a .conf file, or directly modify the source file with the value, or ... -- ~Ethan~ From steve+comp.lang.python at pearwood.info Fri Sep 26 02:45:06 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 26 Sep 2014 16:45:06 +1000 Subject: "Fuzzy" Counter? References: <0d28ee82-2240-4f10-9db9-e966c0e62a13@googlegroups.com> <20140923093244.066bb10b@rg.highlandtechnology.com> <1a63fb8d-e0b8-4385-acbc-ddb6bf1f0f7d@googlegroups.com> Message-ID: <54250b73$0$12983$c3e8da3$5496439d@news.astraweb.com> Ian Kelly wrote: > On Tue, Sep 23, 2014 at 11:01 PM, Miki Tebeka > wrote: >> On Tuesday, September 23, 2014 7:33:06 PM UTC+3, Rob Gaddi wrote: >> >>> While you're at it, think >>> long and hard about that definition of fuzziness. If you can make it >>> closer to the concept of histogram "bins" you'll get much better >>> performance. >> The problem for me here is that I can't determine the number of bins in >> advance. I'd like to get frequencies. I guess every "new" (don't have any >> previous equal item) can be a bin. > > Then your result depends on the order of your input, which is usually > not a good thing. > > Why would you need to determine the *number* of bins in advance? You > just need to determine where they start and stop. If for example your > epsilon is 0.5, you could determine the bins to be at [-0.5, 0.5); > [0.5, 1.5); [1.5, 2.5); ad infinitum. Then for each actual value you > encounter, you could calculate the appropriate bin, creating it first > if it doesn't already exist. That has the unfortunate implication that: 0.500000001 and 1.499999999 (delta = 0.999999998) are considered equal, but: 1.500000001 and 1.499999999 (delta = 0.000000002) are considered unequal. -- Steven From shivaji_tn at yahoo.com Fri Sep 26 02:46:15 2014 From: shivaji_tn at yahoo.com (Gmane) Date: Fri, 26 Sep 2014 06:46:15 +0000 (UTC) Subject: https://www.python.org/ seems to be down Message-ID: https://www.python.org/ seems to be down when I last checked on 06:45 UTC on 26th Sep 2014. Anybody else experiencing this problem? From miguelglafuente at gmail.com Fri Sep 26 02:51:37 2014 From: miguelglafuente at gmail.com (Rock Neurotiko) Date: Fri, 26 Sep 2014 08:51:37 +0200 Subject: https://www.python.org/ seems to be down In-Reply-To: References: Message-ID: 2014-09-26 8:46 GMT+02:00 Gmane : > https://www.python.org/ http://www.downforeveryoneorjustme.com/python.org -- Miguel Garc?a Lafuente - Rock Neurotiko Do it, the devil is in the details. The quieter you are, the more you are able to hear. Happy Coding. Code with Passion, Decode with Patience. If we make consistent effort, based on proper education, we can change the world. El contenido de este e-mail es privado, no se permite la revelacion del contenido de este e-mail a gente ajena a ?l. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Fri Sep 26 02:52:48 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 26 Sep 2014 16:52:48 +1000 Subject: https://www.python.org/ seems to be down In-Reply-To: References: Message-ID: On Fri, Sep 26, 2014 at 4:46 PM, Gmane wrote: > https://www.python.org/ seems to be down when I last checked on 06:45 UTC on > 26th Sep 2014. > Anybody else experiencing this problem? Working for me. Are you getting DNS failure, HTTP failure, SSL certificate issues, or what? ChrisA From shivaji_tn at yahoo.com Fri Sep 26 03:05:36 2014 From: shivaji_tn at yahoo.com (Gmane) Date: Fri, 26 Sep 2014 07:05:36 +0000 (UTC) Subject: https://www.python.org/ seems to be down References: Message-ID: Chris Angelico gmail.com> writes: > > On Fri, Sep 26, 2014 at 4:46 PM, Gmane > yahoo.com.dmarc.invalid> wrote: > > https://www.python.org/ seems to be down when I last checked on 06:45 UTC on > > 26th Sep 2014. > > Anybody else experiencing this problem? > > Working for me. Are you getting DNS failure, HTTP failure, SSL > certificate issues, or what? > > ChrisA > I am getting the following error in my Firefox browser (OpenSuse OS): Secure Connection Failed An error occurred during a connection to www.python.org. The OCSP response is not yet valid (contains a date in the future). (Error code: sec_error_ocsp_future_response) The page you are trying to view cannot be shown because the authenticity of the received data could not be verified. Please contact the web site owners to inform them of this problem. Alternatively, use the command found in the help menu to report this broken site. Shiva From miguelglafuente at gmail.com Fri Sep 26 03:14:46 2014 From: miguelglafuente at gmail.com (Rock Neurotiko) Date: Fri, 26 Sep 2014 09:14:46 +0200 Subject: https://www.python.org/ seems to be down In-Reply-To: References: Message-ID: 2014-09-26 9:05 GMT+02:00 Gmane : > Chris Angelico gmail.com> writes: > > I am getting the following error in my Firefox browser (OpenSuse OS): > > Secure Connection Failed > > An error occurred during a connection to www.python.org. The OCSP response > is not yet valid (contains a date in the future). (Error code: > sec_error_ocsp_future_response) > > The page you are trying to view cannot be shown because the > authenticity > of the received data could not be verified. > Please contact the web site owners to inform them of this problem. > Alternatively, use the command found in the help menu to report this broken > site. > > Shiva > > -- > https://mail.python.org/mailman/listinfo/python-list > Check your local date, usually that happens when you don't have it right. -- Miguel Garc?a Lafuente - Rock Neurotiko Do it, the devil is in the details. The quieter you are, the more you are able to hear. Happy Coding. Code with Passion, Decode with Patience. If we make consistent effort, based on proper education, we can change the world. El contenido de este e-mail es privado, no se permite la revelacion del contenido de este e-mail a gente ajena a ?l. -------------- next part -------------- An HTML attachment was scrubbed... URL: From c_dddd at 163.com Fri Sep 26 02:54:22 2014 From: c_dddd at 163.com (Dang Zhiqiang) Date: Fri, 26 Sep 2014 14:54:22 +0800 (CST) Subject: https://www.python.org/ seems to be down In-Reply-To: References: Message-ID: <6fa13a91.19a5d.148b0bd34bf.Coremail.c_dddd@163.com> Working for me, In beijing is OK. At 2014-09-26 14:46:15, "Gmane" wrote: >https://www.python.org/ seems to be down when I last checked on 06:45 UTC on >26th Sep 2014. >Anybody else experiencing this problem? > >-- >https://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From calderon.christian760 at gmail.com Fri Sep 26 01:45:56 2014 From: calderon.christian760 at gmail.com (Christian Calderon) Date: Thu, 25 Sep 2014 22:45:56 -0700 Subject: joining thread hangs unexpectedly Message-ID: I am working on a personal project that helps minecraft clients connect to minecraft servers using tor hidden services. I am handling the client connection in a separate thread, but when I try to join the threads they hang. The problem is in the file called hiddencraft.py, in the function main at the end, in the finally clause at the bottom. Can anyone tell me what I am doing wrong? https://github.com/ChrisCalderon/hiddencraft -------------- next part -------------- An HTML attachment was scrubbed... URL: From shivaji_tn at yahoo.com Fri Sep 26 03:25:21 2014 From: shivaji_tn at yahoo.com (Gmane) Date: Fri, 26 Sep 2014 07:25:21 +0000 (UTC) Subject: https://www.python.org/ seems to be down References: Message-ID: Hi, Thanks - that was the problem....incorrect system date/time. The system date time and hardware date time were off. Adjusted the system time to use one of the online time servers and then used hwclock --systohc (as a root user) to set the hardware clock. But it is weird that the data from a website fails to render because of incorrect system date. Thanks, Shiva From miguelglafuente at gmail.com Fri Sep 26 03:31:25 2014 From: miguelglafuente at gmail.com (Rock Neurotiko) Date: Fri, 26 Sep 2014 09:31:25 +0200 Subject: https://www.python.org/ seems to be down In-Reply-To: References: Message-ID: 2014-09-26 9:25 GMT+02:00 Gmane : > Hi, > > Thanks - that was the problem....incorrect system date/time. The system > date time and hardware date time were off. Adjusted the system time to use > one of the online time servers and then used hwclock --systohc (as a root > user) to set the hardware clock. > > But it is weird that the data from a website fails to render because of > incorrect system date. > > Thanks, > Shiva > > -- > https://mail.python.org/mailman/listinfo/python-list > Doesn't fails the render of the data, fails the verification of the SSL certificate, all certificates have an start and end date, if you are not in that range, your browser don't verify it (that's to prevent malicious SSL certs). -- Miguel Garc?a Lafuente - Rock Neurotiko Do it, the devil is in the details. The quieter you are, the more you are able to hear. Happy Coding. Code with Passion, Decode with Patience. If we make consistent effort, based on proper education, we can change the world. El contenido de este e-mail es privado, no se permite la revelacion del contenido de este e-mail a gente ajena a ?l. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Fri Sep 26 03:37:14 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 26 Sep 2014 17:37:14 +1000 Subject: https://www.python.org/ seems to be down In-Reply-To: References: Message-ID: On Fri, Sep 26, 2014 at 5:31 PM, Rock Neurotiko wrote: > Doesn't fails the render of the data, fails the verification of the SSL > certificate, all certificates have an start and end date, if you are not in > that range, your browser don't verify it (that's to prevent malicious SSL > certs). Precisely. Normally, if you get an error about the date range, the best thing to do is check the cert's validity dates; if it looks like it ought to be valid, check your system date :) ChrisA From wolfgang.maier at biologie.uni-freiburg.de Fri Sep 26 03:47:11 2014 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Fri, 26 Sep 2014 09:47:11 +0200 Subject: any way to tell at runtime whether a callable is implemented in Python or C ? Message-ID: Hi, is there any reliable and inexpensive way to inspect a callable from running Python code to learn whether it is implemented in Python or C before calling into it ? Thanks, Wolfgang From stefan_ml at behnel.de Fri Sep 26 03:59:52 2014 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 26 Sep 2014 09:59:52 +0200 Subject: any way to tell at runtime whether a callable is implemented in Python or C ? In-Reply-To: References: Message-ID: Wolfgang Maier schrieb am 26.09.2014 um 09:47: > is there any reliable and inexpensive way to inspect a callable from > running Python code to learn whether it is implemented in Python or C > before calling into it ? Not really. Both can have very different types and very different interfaces. There are types, classes, functions, methods, objects with a dedicated __call__() method, ... Any of them can be implemented in Python or C (or other native languages, or a mix of more than one language). What's your use case? There might be other ways to achieve what you want. Stefan From miki.tebeka at gmail.com Fri Sep 26 04:23:56 2014 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Fri, 26 Sep 2014 01:23:56 -0700 (PDT) Subject: "Fuzzy" Counter? In-Reply-To: References: <0d28ee82-2240-4f10-9db9-e966c0e62a13@googlegroups.com> <20140923093244.066bb10b@rg.highlandtechnology.com> <1a63fb8d-e0b8-4385-acbc-ddb6bf1f0f7d@googlegroups.com> Message-ID: Greetings, On Wednesday, September 24, 2014 5:57:15 PM UTC+3, Ian wrote: > Then your result depends on the order of your input, which is usually > not a good thing. As stated in previous reply - I'm OK with that. > Why would you need to determine the *number* of bins in advance? You > just need to determine where they start and stop. If for example your > epsilon is 0.5, you could determine the bins to be at [-0.5, 0.5); > [0.5, 1.5); [1.5, 2.5); ad infinitum. Then for each actual value you > encounter, you could calculate the appropriate bin, creating it first > if it doesn't already exist. I see what you mean. I thought you mean histogram like bins where you usually state the number of bins in advance. From rosuav at gmail.com Fri Sep 26 04:42:39 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 26 Sep 2014 18:42:39 +1000 Subject: any way to tell at runtime whether a callable is implemented in Python or C ? In-Reply-To: References: Message-ID: On Fri, Sep 26, 2014 at 5:47 PM, Wolfgang Maier wrote: > Hi, > is there any reliable and inexpensive way to inspect a callable from running > Python code to learn whether it is implemented in Python or C before calling > into it ? I'm not sure you can say for absolute certain, but the presence of a __code__ attribute is strongly suggestive that there's Python code behind the function. That might be good enough for your purposes. ChrisA From jeanmichel at sequans.com Fri Sep 26 05:56:05 2014 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 26 Sep 2014 11:56:05 +0200 (CEST) Subject: Flask and Python 3 In-Reply-To: Message-ID: <14096496.7663135.1411725365381.JavaMail.root@sequans.com> ----- Original Message ----- > From: "Chris Angelico" > Cc: "Python" > Sent: Friday, 26 September, 2014 1:55:51 AM > Subject: Re: Flask and Python 3 > > On Fri, Sep 26, 2014 at 4:35 AM, Juan Christian > wrote: > > when I say video tutorial, it's implied that every video that I > > talked about > > have 1. The source-code (if programming/code related), 2. The > > transcripts > > and in some cases even 3. PDF version of the video. > > I've almost never seen videos that have all of that - and certainly > not enough to *imply* that about the term. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list Though I'm never using videos to learn, they probably can benefit some people. Ask you this question : is there a major difference between videos and presentations, if not how can we justify the money spent on Pycons over the years ? JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From rustompmody at gmail.com Fri Sep 26 07:21:38 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 26 Sep 2014 04:21:38 -0700 (PDT) Subject: Flask and Python 3 In-Reply-To: References: Message-ID: <11dcecc1-4fbd-45e6-94f8-1bb6e336d5f3@googlegroups.com> On Friday, September 26, 2014 3:26:34 PM UTC+5:30, Jean-Michel Pichavant wrote: > Though I'm never using videos to learn, they probably can benefit some people. > > Ask you this question : is there a major difference between videos and presentations, if not how can we justify the money spent on Pycons over the years ? There is all sorts of buzz nowadays about left-vs-right brain and correspondingly how combined visual+textual (aka right+left) may be better than using only one approach. Google throws up stuff like: http://www.inspiration.com/sites/default/files/documents/Detailed-Summary.pdf To the OP: You dont invite chiding because of using videos but because of comments like: > I didn't learn debug with Flask yet. Only in the next videos. From ned at nedbatchelder.com Fri Sep 26 07:41:40 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 26 Sep 2014 07:41:40 -0400 Subject: Flask and Python 3 In-Reply-To: References: Message-ID: On 9/25/14 2:26 PM, Chris ?Kwpolska? Warrick wrote: > On Thu, Sep 25, 2014 at 8:18 PM, Juan Christian > wrote: >>> The thing is, it?s text. I suppose I could use some text-to-speech >>> software to provide you with a video tutorial version of that. >> >> >> No, you can't, if you think a video tutorial is only that, I'm afraid to >> tell that you only saw terrible courses/tutorials in your life. > > Go on, show me a good video tutorial. One that is quick to consume, > and one I can come back to at any time I please (within reasonable > bounds). I can just open a text-based tutorial and use my browser?s > search capabilities (or a Table of Contents or an index in an analog > book) to find the precise bit of knowledge I need. You can?t easily > do that with video tutorials. > > Also, video tutorials for code (as well as analog books) lack a very > important feature: copy-paste. Nobody likes retyping large passages > of code. Especially because it?s error-prone. > Chris, you are trying to convince the OP that videos are a bad way to learn, after the OP has told you that it is his part of his preferred way to learn. Seriously? Do you really think you know what is best for everyone? Different people learn in different ways, and there could be a large generational component at work here. It's clear that you prefer text content to video content. I do too. Lots of people do. But videos are popular also. Can't we just stick to trying to help people with Python, and let them make other decisions for themselves? -- Ned Batchelder, http://nedbatchelder.com From stefan_ml at behnel.de Fri Sep 26 08:12:25 2014 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 26 Sep 2014 14:12:25 +0200 Subject: any way to tell at runtime whether a callable is implemented in Python or C ? In-Reply-To: References: Message-ID: Chris Angelico schrieb am 26.09.2014 um 10:42: > On Fri, Sep 26, 2014 at 5:47 PM, Wolfgang Maier wrote: >> is there any reliable and inexpensive way to inspect a callable from running >> Python code to learn whether it is implemented in Python or C before calling >> into it ? > > I'm not sure you can say for absolute certain, but the presence of a > __code__ attribute is strongly suggestive that there's Python code > behind the function. That might be good enough for your purposes. Cython implemented native functions have a "__code__" attribute, too. Their current "__code__.co_code" attribute is empty (no bytecode), but I wouldn't rely on that for all times either. Stefan From vijnaana at gmail.com Fri Sep 26 08:54:48 2014 From: vijnaana at gmail.com (vijnaana at gmail.com) Date: Fri, 26 Sep 2014 05:54:48 -0700 (PDT) Subject: PyCli : Need some reference to good books or tutorials on pycli Message-ID: <48e1bd9f-a2c6-4c97-a971-0653e44a29c0@googlegroups.com> Hi Folks, I need to develop a CLI (PyCli or similar)on Linux. To be more specific to develop Quagga(open source routing software) like commands using python instead of C. Need some good reference material for the same. P.S google didn't help Thank You! Vij From ian.g.kelly at gmail.com Fri Sep 26 09:47:30 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 26 Sep 2014 07:47:30 -0600 Subject: joining thread hangs unexpectedly In-Reply-To: References: Message-ID: On Thu, Sep 25, 2014 at 11:45 PM, Christian Calderon wrote: > I am working on a personal project that helps minecraft clients connect to > minecraft servers using tor hidden services. I am handling the client > connection in a separate thread, but when I try to join the threads they > hang. The problem is in the file called hiddencraft.py, in the function main > at the end, in the finally clause at the bottom. Can anyone tell me what I > am doing wrong? > > https://github.com/ChrisCalderon/hiddencraft You're creating a separate Queue for each thread but when you store each one in the queue_ variable you're replacing the previous one, so when you go to kill them you only ever send the die command to the last thread created. From torriem at gmail.com Fri Sep 26 10:58:43 2014 From: torriem at gmail.com (Michael Torrie) Date: Fri, 26 Sep 2014 08:58:43 -0600 Subject: PyCli : Need some reference to good books or tutorials on pycli In-Reply-To: <48e1bd9f-a2c6-4c97-a971-0653e44a29c0@googlegroups.com> References: <48e1bd9f-a2c6-4c97-a971-0653e44a29c0@googlegroups.com> Message-ID: <54257F23.3060705@gmail.com> On 09/26/2014 06:54 AM, vijnaana at gmail.com wrote: > Hi Folks, > > I need to develop a CLI (PyCli or similar)on Linux. > To be more specific to develop Quagga(open source routing software) like > commands using python instead of C. > > Need some good reference material for the same. > > P.S google didn't help Wait, are you asking about making a command-line interface in Python? If so, then there are a number of aspects you can google for: - command line argument parsing. See python docs on argparse - A read/eval print loop using custom keywords and syntax, if you want your program to be interactive. - you'll need to use readline to handle line editing - something to parse line input. PyParsing perhaps. Or some other lexical parser, or manually do the parsing you need to do with .split() or regular expressions. - possibly curses for doing screen output, though print() is probably sufficient. Except for pyparsing everything is in the standard library. From torriem at gmail.com Fri Sep 26 10:45:58 2014 From: torriem at gmail.com (Michael Torrie) Date: Fri, 26 Sep 2014 08:45:58 -0600 Subject: PyCli : Need some reference to good books or tutorials on pycli In-Reply-To: <48e1bd9f-a2c6-4c97-a971-0653e44a29c0@googlegroups.com> References: <48e1bd9f-a2c6-4c97-a971-0653e44a29c0@googlegroups.com> Message-ID: <54257C26.2040706@gmail.com> On 09/26/2014 06:54 AM, vijnaana at gmail.com wrote: > Hi Folks, > > I need to develop a CLI (PyCli or similar)on Linux. > To be more specific to develop Quagga(open source routing software) like > commands using python instead of C. > > Need some good reference material for the same. > > P.S google didn't help I don't doubt that. I don't understand what you're asking either. Can you be more specific? I've never heard of "PyCli." What is it? From jeanmichel at sequans.com Fri Sep 26 11:45:17 2014 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 26 Sep 2014 17:45:17 +0200 (CEST) Subject: PyCli : Need some reference to good books or tutorials on pycli In-Reply-To: <48e1bd9f-a2c6-4c97-a971-0653e44a29c0@googlegroups.com> Message-ID: <492011913.7724098.1411746317650.JavaMail.root@sequans.com> ----- Original Message ----- > From: vijnaana at gmail.com > To: python-list at python.org > Sent: Friday, 26 September, 2014 2:54:48 PM > Subject: PyCli : Need some reference to good books or tutorials on pycli > > Hi Folks, > > I need to develop a CLI (PyCli or similar)on Linux. > To be more specific to develop Quagga(open source routing software) > like > commands using python instead of C. > > Need some good reference material for the same. > > P.S google didn't help > > Thank You! > Vij Have you considered using ipython ? I have built a CLI on top of that and it's pretty easy and effective, and it requires almost no dev. The following code is untested but it should give you an idea of what I mean. cli.py: import IPython import yourApi # explict exposure foo = yourApi.foo bar = yourApi.bar # or you can expose all the content of yourApi api = yourApi # delete unwanted names del yourApi del IPython # start the interactive CLI IPython.frontend.terminal.embed.InteractiveShellEmbed(banner1='Hello Word', exit_msg='bbye')() Regards, JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From ian.g.kelly at gmail.com Fri Sep 26 12:10:19 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 26 Sep 2014 10:10:19 -0600 Subject: any way to tell at runtime whether a callable is implemented in Python or C ? In-Reply-To: References: Message-ID: On Fri, Sep 26, 2014 at 6:12 AM, Stefan Behnel wrote: > Chris Angelico schrieb am 26.09.2014 um 10:42: >> On Fri, Sep 26, 2014 at 5:47 PM, Wolfgang Maier wrote: >>> is there any reliable and inexpensive way to inspect a callable from running >>> Python code to learn whether it is implemented in Python or C before calling >>> into it ? >> >> I'm not sure you can say for absolute certain, but the presence of a >> __code__ attribute is strongly suggestive that there's Python code >> behind the function. That might be good enough for your purposes. > > Cython implemented native functions have a "__code__" attribute, too. Their > current "__code__.co_code" attribute is empty (no bytecode), but I wouldn't > rely on that for all times either. Meanwhile, Python classes and objects with __call__ methods have no __code__ attribute. From ethan at stoneleaf.us Fri Sep 26 12:20:12 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 26 Sep 2014 09:20:12 -0700 Subject: "Fuzzy" Counter? In-Reply-To: <20140923093244.066bb10b@rg.highlandtechnology.com> References: <0d28ee82-2240-4f10-9db9-e966c0e62a13@googlegroups.com> <20140923093244.066bb10b@rg.highlandtechnology.com> Message-ID: <5425923C.4020205@stoneleaf.us> On 09/23/2014 09:32 AM, Rob Gaddi wrote: > On Tue, 23 Sep 2014 05:34:19 -0700 (PDT) Miki Tebeka wrote: >> >> Before I start writing my own. Is there something like collections.Counter (fore frequencies) that does "fuzzy" matching? >> >> Meaning x is considered equal to y if abs(x - y) < epsilon. (x, y and my case will be numpy.array). > > You'll probably have to write that yourself. While you're at it, think > long and hard about that definition of fuzziness. If you can make it > closer to the concept of histogram "bins" you'll get much better > performance. You might want to take a look at the reference implementation for PEP 455 [1]. If you can decide on a method to transform your keys (such as taking the floor, or the half, or something like that), then that should work as is. -- ~Ethan~ [1] http://legacy.python.org/dev/peps/pep-0455/ From detlev at die-offenbachs.de Fri Sep 26 13:09:03 2014 From: detlev at die-offenbachs.de (Detlev Offenbach) Date: Fri, 26 Sep 2014 19:09:03 +0200 Subject: [PyQt] Automatic Crash Reporting In-Reply-To: <542388E9.3000808@sil.org> References: <542388E9.3000808@sil.org> Message-ID: <108599733.RTPZhBJjzn@saturn> Hi, I did this myself for the eric IDE. Depending upon your needs it is really simple. Just check the eric5.py main script. (http://eric-ide.python-projects.org) Detlev On Thursday 25 September 2014, 04:15:53 Timothy W. Grove wrote: > Can anyone recommend a good automatic crash reporting module that would > work nicely with a python3/pyqt4 application? Thanks. > > Tim > _______________________________________________ > PyQt mailing list PyQt at riverbankcomputing.com > http://www.riverbankcomputing.com/mailman/listinfo/pyqt-- *Detlev Offenbach* detlev at die-offenbachs.de -------------- next part -------------- An HTML attachment was scrubbed... URL: From random832 at fastmail.us Fri Sep 26 13:57:33 2014 From: random832 at fastmail.us (random832 at fastmail.us) Date: Fri, 26 Sep 2014 13:57:33 -0400 Subject: "Fuzzy" Counter? In-Reply-To: <599ba7b9-1df3-44d4-bceb-fb477ae5cb10@googlegroups.com> References: <0d28ee82-2240-4f10-9db9-e966c0e62a13@googlegroups.com> <599ba7b9-1df3-44d4-bceb-fb477ae5cb10@googlegroups.com> Message-ID: <1411754253.1883471.172174641.2965E45D@webmail.messagingengine.com> On Wed, Sep 24, 2014, at 00:57, Miki Tebeka wrote: > On Tuesday, September 23, 2014 4:37:10 PM UTC+3, Peter Otten wrote: > > x eq y > > y eq z > > not (x eq z) > > > > where eq is the test given above -- should x, y, and z land in the same bin? > Yeah, I know the counting depends on the order of items. But I'm OK with > that. It doesn't just depend on the order. If you put x and z in first (creating two "bins"), then which one does y go in after? From tjreedy at udel.edu Fri Sep 26 14:20:43 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 26 Sep 2014 14:20:43 -0400 Subject: Flask and Python 3 In-Reply-To: References: Message-ID: On 9/26/2014 7:41 AM, Ned Batchelder wrote: > Can't we just stick to trying to help people with Python, and let them > make other decisions for themselves? I agree. The OP should watch the video on debugging, and the off-topic discussion of video versus text should end. -- Terry Jan Reedy From rgaddi at technologyhighland.invalid Fri Sep 26 14:30:16 2014 From: rgaddi at technologyhighland.invalid (Rob Gaddi) Date: Fri, 26 Sep 2014 11:30:16 -0700 Subject: "Fuzzy" Counter? References: <0d28ee82-2240-4f10-9db9-e966c0e62a13@googlegroups.com> <20140923093244.066bb10b@rg.highlandtechnology.com> <1a63fb8d-e0b8-4385-acbc-ddb6bf1f0f7d@googlegroups.com> Message-ID: <20140926113016.3f6a7628@rg.highlandtechnology.com> On Tue, 23 Sep 2014 22:01:51 -0700 (PDT) Miki Tebeka wrote: > On Tuesday, September 23, 2014 7:33:06 PM UTC+3, Rob Gaddi wrote: > > > While you're at it, think > > long and hard about that definition of fuzziness. If you can make it > > closer to the concept of histogram "bins" you'll get much better > > performance. > The problem for me here is that I can't determine the number of bins in advance. I'd like to get frequencies. I guess every "new" (don't have any previous equal item) can be a bin. > > > TL;DR you need to think very hard about your problem definition and > > what you want to happen before you actually try to implement this. > Always a good advice :) I'm actually implementing algorithm for someone else (in the bio world where I know very little about). See, THERE's your problem. You've got a scientist trying to make prescriptions for an engineering problem. He's given you a fuzzy description of the sort of thing he's trying to do. Your job is to turn that fuzzy description into a concrete, actual algorithm before you even write a single line of code, which means understanding what the data is, and what the desired result of that data is. Because the thing you keep trying to do, with all of its order dependencies fundamentally CANNOT be right, regardless of what the squishy scientist tells you. The "histogram" bin solution that everyone keeps trying to steer you towards is almost certainly what you really want. Epsilon is your resolution. You cannot resolve any information below your resolution limit. Yes, 1.49 and 1.51 wind up in different bins, whereas 1.51 and 2.49 are in the same one, but that's what it means to have a resolution of 1; you can't say anything about whether any given count in the "2, plus or minus a bit" bin is very nearly 1 or very nearly 3. This doesn't require you to know the number of bins in advance, you can just create and fill them as needed. That said, you're trying to solve a physical problem, and so it has physical limits. Your biologist should be able to give you an order of magnitude estimate of how many "bins" you're expecting, and what the ultimate shape is expected to look like. Normally distributed? Wildly bimodal? Is the overall span of data going to span 10 epsilon or 10,000 epsilon? If there are going to be a ton of bins, you may be better served by putting 1/3 of a count into bins n-1, n, and n+1 rather than just in bin n; it's the equivalent of squinting a bit when you look at the bins. But you have to understand the problem to solve it. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From tjreedy at udel.edu Fri Sep 26 14:42:45 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 26 Sep 2014 14:42:45 -0400 Subject: any way to tell at runtime whether a callable is implemented in Python or C ? In-Reply-To: References: Message-ID: On 9/26/2014 12:10 PM, Ian Kelly wrote: > On Fri, Sep 26, 2014 at 6:12 AM, Stefan Behnel wrote: >>> On Fri, Sep 26, 2014 at 5:47 PM, Wolfgang Maier wrote: >>>> is there any reliable and inexpensive way to inspect a callable from running >>>> Python code to learn whether it is implemented in Python or C before calling >>>> into it ? Implementation languages are not part of the language definition and are not limited to Python and C. Some CPython extension modules have used Fortran (perhaps with a very thin C layer). One way I can think of: apply inspect.signature. If it fails, the function is not coded in Python. If it succeeds, pass a correct number of args but invalid types/values (float('nan') for instance), catch the exception, and see if the traceback contains a line of Python code from the function. (But I am not sure what happens if the function was coded in Python but the code is not available.) As someone already asked, why? >> Cython implemented native functions have a "__code__" attribute, too. Their >> current "__code__.co_code" attribute is empty (no bytecode), but I wouldn't >> rely on that for all times either. > > Meanwhile, Python classes and objects with __call__ methods have no > __code__ attribute. Also, Python functions can call C functions, and many builtin functions take Python functions as arguments. -- Terry Jan Reedy From random832 at fastmail.us Fri Sep 26 15:10:43 2014 From: random832 at fastmail.us (random832 at fastmail.us) Date: Fri, 26 Sep 2014 15:10:43 -0400 Subject: "Fuzzy" Counter? In-Reply-To: <20140926113016.3f6a7628@rg.highlandtechnology.com> References: <0d28ee82-2240-4f10-9db9-e966c0e62a13@googlegroups.com> <20140923093244.066bb10b@rg.highlandtechnology.com> <1a63fb8d-e0b8-4385-acbc-ddb6bf1f0f7d@googlegroups.com> <20140926113016.3f6a7628@rg.highlandtechnology.com> Message-ID: <1411758643.1901648.172197529.1EB8F967@webmail.messagingengine.com> On Fri, Sep 26, 2014, at 14:30, Rob Gaddi wrote: > The "histogram" bin solution that everyone keeps trying to steer you > towards is almost certainly what you really want. Epsilon is your > resolution. You cannot resolve any information below your resolution > limit. Yes, 1.49 and 1.51 wind up in different bins, whereas 1.51 and > 2.49 are in the same one, but that's what it means to have a resolution > of 1; you can't say anything about whether any given count in the "2, > plus or minus a bit" bin is very nearly 1 or very nearly 3. You could "antialias" the values, though. 1.49 results in a value that is 51% in the "1" bin, and 49% in the "2" bin. count[1] += 0.51, count[2] += 0.49. You could even spread each value across a larger number of smaller bins. From rgaddi at technologyhighland.invalid Fri Sep 26 15:36:46 2014 From: rgaddi at technologyhighland.invalid (Rob Gaddi) Date: Fri, 26 Sep 2014 12:36:46 -0700 Subject: "Fuzzy" Counter? References: <0d28ee82-2240-4f10-9db9-e966c0e62a13@googlegroups.com> <20140923093244.066bb10b@rg.highlandtechnology.com> <1a63fb8d-e0b8-4385-acbc-ddb6bf1f0f7d@googlegroups.com> <20140926113016.3f6a7628@rg.highlandtechnology.com> Message-ID: <20140926123646.57aa9288@rg.highlandtechnology.com> On Fri, 26 Sep 2014 15:10:43 -0400 random832 at fastmail.us wrote: > On Fri, Sep 26, 2014, at 14:30, Rob Gaddi wrote: > > The "histogram" bin solution that everyone keeps trying to steer you > > towards is almost certainly what you really want. Epsilon is your > > resolution. You cannot resolve any information below your resolution > > limit. Yes, 1.49 and 1.51 wind up in different bins, whereas 1.51 and > > 2.49 are in the same one, but that's what it means to have a resolution > > of 1; you can't say anything about whether any given count in the "2, > > plus or minus a bit" bin is very nearly 1 or very nearly 3. > > You could "antialias" the values, though. 1.49 results in a value that > is 51% in the "1" bin, and 49% in the "2" bin. count[1] += 0.51, > count[2] += 0.49. You could even spread each value across a larger > number of smaller bins. Right, but there's still that stateless determination of which bin (or bins) 1.49 goes in. The history of the bins is irrelevant, which is the important part. -- 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 Fri Sep 26 18:06:51 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 26 Sep 2014 23:06:51 +0100 Subject: Microsoft Visual C++ Compiler for Python 2.7 Message-ID: I thought that Windows users who don't follow Python-dev might be interested in this announcement https://mail.python.org/pipermail/python-dev/2014-September/136499.html, the rest of you can look away now :) -- 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 Fri Sep 26 18:55:54 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Fri, 26 Sep 2014 18:55:54 -0400 Subject: Want to win a 500 tablet? Message-ID: I am taking "An Introduction to Interactive Programming in Python" at coursera.org. From their announcments page: Week one of the video contest is open For those of you that are interested in helping your peers, the student video tutorial competition is an excellent opportunity. The week one submission thread is up in the "student video tutorial forum." Feel free to browse the current tutorials or make your own. The deadline for submission of this week's videos is 23:00 UTC on Thursday. The overall winner of this competition will receive a $500 tablet computer so give it a try if you are interested! From Seymore4Head at Hotmail.invalid Fri Sep 26 19:03:20 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Fri, 26 Sep 2014 19:03:20 -0400 Subject: Want to win a 500 tablet? References: Message-ID: On Fri, 26 Sep 2014 18:55:54 -0400, Seymore4Head wrote: >I am taking "An Introduction to Interactive Programming in Python" at >coursera.org. From their announcments page: > >Week one of the video contest is open > >For those of you that are interested in helping your peers, the >student video tutorial competition is an excellent opportunity. The >week one submission thread is up in the "student video tutorial >forum." Feel free to browse the current tutorials or make your own. >The deadline for submission of this week's videos is 23:00 UTC on >Thursday. The overall winner of this competition will receive a $500 >tablet computer so give it a try if you are interested! BTW this was the most informative tutorial I found. https://www.youtube.com/watch?v=LpTzLnryDq8 From python.list at tim.thechases.com Fri Sep 26 17:07:56 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 26 Sep 2014 16:07:56 -0500 Subject: pip install virtualenvwrapper complaining there's no module named "core" Message-ID: <20140926160756.717fff6c@bigbox.christie.dr> I'm at a bit of a loss trying to figure out where this mysterious "core" module is. FWIW, this is a hosted server where "python" is 2.4, but 2.6 is available if named. Full steps were as follows: 1) Pull down "get-pip.py" as directed wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py 2) Okay, "raw.github.com" serves a cert that wget doesn't like because the cert is assigned to just "github.com" (grumble) wget --no-check-certificate https://raw.github.com/pypa/pip/master/contrib/get-pip.py 3) Run it, specifying that I want things to get installed in my home/user directory: python2.6 get-pip.py --user 4) Okay, let's get me some virutalenv (works fine) pip2.6 install --user virtualenv 5) Okay, let's get me some virutalenvwrapper pip2.6 install --user virtualenvwrapper This is where things fall over (~/.pip/pip.log output below) with the inability to import a module named "core". Where am I going wrong, or what am I missing? I have a nagging feeling that it's either a 2.4-vs-2.6 conflict, or possibly some PYTHONPATH (currently unset) issue that I missed. -tkc ---------------------------------------------------------- Downloading/unpacking virtualenvwrapper Running setup.py (path:/tmp/pip_build_tim/virtualenvwrapper/setup.py) egg_info for package virtualenvwrapper Installed /tmp/pip_build_tim/virtualenvwrapper/pbr-0.10.0-py2.6.egg Searching for pip Reading http://pypi.python.org/simple/pip/ Best match: pip 1.5.6 Downloading https://pypi.python.org/packages/source/p/pip/pip-1.5.6.tar.gz#md5=01026f87978932060cc86c1dc527903e Processing pip-1.5.6.tar.gz Running pip-1.5.6/setup.py -q bdist_egg --dist-dir /tmp/easy_install-CcQHLI/pip-1.5.6/egg-dist-tmp-8B3Dq1 warning: no files found matching 'pip/cacert.pem' warning: no files found matching '*.html' under directory 'docs' warning: no previously-included files matching '*.rst' found under directory 'docs/_build' no previously-included directories found matching 'docs/_build/_sources' Installed /tmp/pip_build_tim/virtualenvwrapper/pip-1.5.6-py2.6.egg /usr/local/lib/python2.6/site-packages/setuptools-0.6c9-py2.6.egg/setuptools/dist.py:245: UserWarning: Module pbr was already imported from /tmp/easy_install-7dd_Tz/pbr-0.10.0/pbr/__init__.py, but /tmp/pip_build_tim/virtualenvwrapper/pbr-0.10.0-py2.6.egg is being added to sys.path Traceback (most recent call last): File "", line 17, in File "/tmp/pip_build_tim/virtualenvwrapper/setup.py", line 7, in pbr=True, File "/usr/local/lib/python2.6/distutils/core.py", line 113, in setup _setup_distribution = dist = klass(attrs) File "build/bdist.linux-i686/egg/setuptools/dist.py", line 223, in __init__ File "/usr/local/lib/python2.6/distutils/dist.py", line 270, in __init__ self.finalize_options() File "build/bdist.linux-i686/egg/setuptools/dist.py", line 256, in finalize_options File "build/bdist.linux-i686/egg/pkg_resources.py", line 1913, in load ImportError: No module named core Complete output from command python setup.py egg_info: Installed /tmp/pip_build_tim/virtualenvwrapper/pbr-0.10.0-py2.6.egg Searching for pip Reading http://pypi.python.org/simple/pip/ Best match: pip 1.5.6 Downloading https://pypi.python.org/packages/source/p/pip/pip-1.5.6.tar.gz#md5=01026f87978932060cc86c1dc527903e Processing pip-1.5.6.tar.gz Running pip-1.5.6/setup.py -q bdist_egg --dist-dir /tmp/easy_install-CcQHLI/pip-1.5.6/egg-dist-tmp-8B3Dq1 warning: no files found matching 'pip/cacert.pem' warning: no files found matching '*.html' under directory 'docs' warning: no previously-included files matching '*.rst' found under directory 'docs/_build' no previously-included directories found matching 'docs/_build/_sources' Installed /tmp/pip_build_tim/virtualenvwrapper/pip-1.5.6-py2.6.egg /usr/local/lib/python2.6/site-packages/setuptools-0.6c9-py2.6.egg/setuptools/dist.py:245: UserWarning: Module pbr was already imported from /tmp/easy_install-7dd_Tz/pbr-0.10.0/pbr/__init__.py, but /tmp/pip_build_tim/virtualenvwrapper/pbr-0.10.0-py2.6.egg is being added to sys.path Traceback (most recent call last): File "", line 17, in File "/tmp/pip_build_tim/virtualenvwrapper/setup.py", line 7, in pbr=True, File "/usr/local/lib/python2.6/distutils/core.py", line 113, in setup _setup_distribution = dist = klass(attrs) File "build/bdist.linux-i686/egg/setuptools/dist.py", line 223, in __init__ File "/usr/local/lib/python2.6/distutils/dist.py", line 270, in __init__ self.finalize_options() File "build/bdist.linux-i686/egg/setuptools/dist.py", line 256, in finalize_options File "build/bdist.linux-i686/egg/pkg_resources.py", line 1913, in load ImportError: No module named core ---------------------------------------- Cleaning up... Command python setup.py egg_info failed with error code 1 in /tmp/pip_build_tim/virtualenvwrapper Storing debug log for failure in /home/tim/.pip/pip.log From davea at davea.name Fri Sep 26 21:30:55 2014 From: davea at davea.name (Dave Angel) Date: Fri, 26 Sep 2014 21:30:55 -0400 (EDT) Subject: Microsoft Visual C++ Compiler for Python 2.7 References: Message-ID: Mark Lawrence Wrote in message: > I thought that Windows users who don't follow Python-dev might be > interested in this announcement > https://mail.python.org/pipermail/python-dev/2014-September/136499.html, > the rest of you can look away now :) > > -- > My fellow Pythonistas, ask not what our language can do for you, ask > what you can do for our language. > > Mark Lawrence > > Not Found The requested URL /pipermail/python-dev/2014-Sep tember/136499.html, was not found on this server. -- DaveA From ethan at stoneleaf.us Fri Sep 26 22:17:31 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 26 Sep 2014 19:17:31 -0700 Subject: Microsoft Visual C++ Compiler for Python 2.7 In-Reply-To: References: Message-ID: <54261E3B.8000909@stoneleaf.us> On 09/26/2014 06:30 PM, Dave Angel wrote: > > Not Found Worked fine for me. -- ~Ethan~ From Seymore4Head at Hotmail.invalid Fri Sep 26 23:49:43 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Fri, 26 Sep 2014 23:49:43 -0400 Subject: Leap year Message-ID: Still practicing. Since this is listed as a Pseudocode, I assume this is a good way to explain something. That means I can also assume my logic is fading with age. http://en.wikipedia.org/wiki/Leap_year#Algorithm Me trying to look at the algorithm, it would lead me to try something like: if year % 4 !=0: return False elif year % 100 !=0: return True elif year % 400 !=0: return False **** Since it is a practice problem I have the answer: def is_leap_year(year): return ((year % 4) == 0 and ((year % 100) != 0 or (year % 400) == 0)) I didn't have any problem when I did this: if year % 400 == 0: print ("Not leap year") elif year % 100 == 0: print ("Leap year") elif year % 4 == 0: print ("Leap year") else: print ("Not leap year") From gheskett at wdtv.com Sat Sep 27 00:08:01 2014 From: gheskett at wdtv.com (Gene Heskett) Date: Sat, 27 Sep 2014 00:08:01 -0400 Subject: Leap year In-Reply-To: References: Message-ID: <201409270008.01946.gheskett@wdtv.com> On Friday 26 September 2014 23:49:43 Seymore4Head did opine And Gene did reply: > Still practicing. Since this is listed as a Pseudocode, I assume this > is a good way to explain something. That means I can also assume my > logic is fading with age. > http://en.wikipedia.org/wiki/Leap_year#Algorithm > > Me trying to look at the algorithm, it would lead me to try something > like: > if year % 4 !=0: > return False > elif year % 100 !=0: > return True > elif year % 400 !=0: > return False > > **** Since it is a practice problem I have the answer: > def is_leap_year(year): > return ((year % 4) == 0 and ((year % 100) != 0 or (year % 400) == 0)) > > I didn't have any problem when I did this: > > if year % 400 == 0: > print ("Not leap year") > elif year % 100 == 0: > print ("Leap year") > elif year % 4 == 0: > print ("Leap year") > else: > print ("Not leap year") Which is, except for language syntax to state it, exactly the same as is quoted for this problem in the original K&R C manual. Is there anything new? Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page US V Castleman, SCOTUS, Mar 2014 is grounds for Impeaching SCOTUS From rosuav at gmail.com Sat Sep 27 00:54:40 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 27 Sep 2014 14:54:40 +1000 Subject: Microsoft Visual C++ Compiler for Python 2.7 In-Reply-To: References: Message-ID: On Sat, Sep 27, 2014 at 11:30 AM, Dave Angel wrote: > Not Found > > The requested URL /pipermail/python-dev/2014-Sep > tember/136499.html, was not found on this server. Someone forgot to be careful of posting URLs with punctuation near them... Trim off the comma and it'll work: https://mail.python.org/pipermail/python-dev/2014-September/136499.html ChrisA From i at introo.me Fri Sep 26 07:13:08 2014 From: i at introo.me (Shiyao Ma) Date: Fri, 26 Sep 2014 19:13:08 +0800 Subject: Understanding co_lnotab Message-ID: When reading the notes on co_lnotab I totally got lost at this line:https://hg.python.org/cpython/file/fd0c02c3df31/Objects/lnotab_notes.txt#l31 It says,"In case #b, there's no way to know from looking at the table later how many were written." No way to know "what" is written? And why no way to know "how many" times? Regards -- ????????????????http://introo.me? From pestrella at gmail.com Fri Sep 26 14:15:19 2014 From: pestrella at gmail.com (Paula Estrella) Date: Fri, 26 Sep 2014 15:15:19 -0300 Subject: tkinter and gtk problem Message-ID: Hello, we are working on ubuntu 12.04 LTS; we use gtk to take screenshots and we added a simple interface to select a file using tkFileDialog but it doesn't work; is it possible that tkinter and gtk are incompatible? a test script to open a file with tkFileDialog works fine but if we import gtk even if we don't use it, the dialog box doesn't respond to mouse events anymore; if we comment the import gtk it does work .... Anyone knows what might be going on or how to solve that? Thanks a lot! Paula -------------- next part -------------- An HTML attachment was scrubbed... URL: From vicezik at gmail.com Fri Sep 26 14:53:32 2014 From: vicezik at gmail.com (Abohfu venant zinkeng) Date: Fri, 26 Sep 2014 11:53:32 -0700 Subject: Storage Cost Calculation Message-ID: - Hard drives have been the secondary storage of choice on computers for many years. They have improved in speed, in capacity, and in cost for over 50 years. It's interesting to look at how the prices have dropped, or, conversely, how much storage your money will buy now as compared to many years ago. This improvement is an example of *Moore's Law* This site was written by a person (in 2009) who had considered this amazing trend. He collected a lot of data about hard drive capacity and price. The formula he extrapolated by using the data he found is *cost per gigabyte = 10-0.2502(year-1980) + 6.304* where *year* is the year for which the extrapolated cost was desired. This formula is based on data from 1980 to 2010. Your program should develop a table of costs, based on the user's inputs of the starting and ending years and the formula. The table should produce columns as seen below, The column Year is the year, starting at the point the user says to start at, and going to the ending year, stopping there. The size of the step in the table is also specified by the user. The user inputs are all integers. Your program can assume that. *NOTE:* The "ending year, stopping there" phrase is a bit ambiguous. If you want to use the ending year as the stop value in a range function, that is fine. If you want to add one to the ending year and use that as the stop value, that is also ok. *In the tables below, end year plus one was used.* Tab characters can be used. *Sample Run:* Big Blue Hard Drive Storage Cost Enter the starting year: 1992 Enter the ending year: 2015 What step size for the table? 4 Hard Drive Storage Costs Table Start Year = 1992 End Year = 2015 Year Cost Per Gigabyte ($) 1992 2002.627 1996 199.894 2000 19.953 2004 1.992 2008 0.199 2012 0.02 *Another Run:* Big Blue Hard Drive Storage Cost Enter the starting year: 1998 Enter the ending year: 2010 What step size for the table? 2 Hard Drive Storage Costs Table Start Year = 1998 End Year = 2010 Year Cost Per Gigabyte ($) 1998 63.154 2000 19.953 2002 6.304 2004 1.992 2006 0.629 2008 0.199 2010 0.063 - QUESTION - Could someone help me with a design and a python program to implement that design to solve the above problem? -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sat Sep 27 02:04:28 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 27 Sep 2014 16:04:28 +1000 Subject: Storage Cost Calculation In-Reply-To: References: Message-ID: On Sat, Sep 27, 2014 at 4:53 AM, Abohfu venant zinkeng wrote: > QUESTION > > Could someone help me with a design and a python program to implement that > design to solve the above problem? We are not going to do your homework for you. ChrisA From rosuav at gmail.com Sat Sep 27 02:08:47 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 27 Sep 2014 16:08:47 +1000 Subject: tkinter and gtk problem In-Reply-To: References: Message-ID: On Sat, Sep 27, 2014 at 4:15 AM, Paula Estrella wrote: > Hello, we are working on ubuntu 12.04 LTS; we use gtk to take screenshots > and we added a simple interface to select a file using tkFileDialog but it > doesn't work; is it possible that tkinter and gtk are incompatible? a test > script to open a file with tkFileDialog works fine but if we import gtk even > if we don't use it, the dialog box doesn't respond to mouse events anymore; > if we comment the import gtk it does work .... > > Anyone knows what might be going on or how to solve that? Interesting. I've never tried to use two GUI toolkits at once. Can you just use GTK to bring up a file dialog? ChrisA From dieter at handshake.de Sat Sep 27 03:33:02 2014 From: dieter at handshake.de (dieter) Date: Sat, 27 Sep 2014 09:33:02 +0200 Subject: tkinter and gtk problem References: Message-ID: <87k34ph61d.fsf@handshake.de> Paula Estrella writes: > Hello, we are working on ubuntu 12.04 LTS; we use gtk to take screenshots > and we added a simple interface to select a file using tkFileDialog but it > doesn't work; is it possible that tkinter and gtk are incompatible? a test > script to open a file with tkFileDialog works fine but if we import gtk > even if we don't use it, the dialog box doesn't respond to mouse events > anymore; if we comment the import gtk it does work .... UI toolkits (like "tk" and "gtk") usually use a so called event loop which gets information about user interaction events (e.g. keyboard/mouse events) and dispatches appropriate application callbacks. When you use two (or more) such toolkits in the same application, you need a special event loop which multiplexes the events to the various toolkits. The implementation of such a multiplexing event loop might be difficult (and likely will be dependent on the UI toolkits to be integrated). Therefore, if possible, try to avoid combining multiple UI toolkits in the same application. From davea at davea.name Sat Sep 27 05:07:11 2014 From: davea at davea.name (Dave Angel) Date: Sat, 27 Sep 2014 05:07:11 -0400 (EDT) Subject: Leap year References: Message-ID: Seymore4Head Wrote in message: > Still practicing. Since this is listed as a Pseudocode, I assume this > is a good way to explain something. That means I can also assume my > logic is fading with age. > http://en.wikipedia.org/wiki/Leap_year#Algorithm > > > I didn't have any problem when I did this: > > if year % 400 == 0: > print ("Not leap year") > elif year % 100 == 0: > print ("Leap year") > elif year % 4 == 0: > print ("Leap year") > else: > print ("Not leap year") > But the first two prints are incorrect, so I'm not sure what you mean by "didn't have any problem." Incidentally, it's usually easier to test a function that does one thing. So if you replace all those prints with appropriate return True or return False, then it's easy to exhaustively compare two variations. -- DaveA From michael at stroeder.com Sat Sep 27 06:06:16 2014 From: michael at stroeder.com (=?ISO-8859-1?Q?Michael_Str=F6der?=) Date: Sat, 27 Sep 2014 12:06:16 +0200 Subject: ANN: python-ldap 2.4.17 Message-ID: Find a new release of python-ldap: http://pypi.python.org/pypi/python-ldap/2.4.17 python-ldap provides an object-oriented API to access LDAP directory servers from Python programs. It mainly wraps the OpenLDAP 2.x libs for that purpose. Additionally it contains modules for other LDAP-related stuff (e.g. processing LDIF, LDAP URLs and LDAPv3 schema). Project's web site: http://www.python-ldap.org/ Ciao, Michael. ---------------------------------------------------------------- Released 2.4.17 2014-09-27 Changes since 2.4.16: Lib/ * New hook syncrepl_refreshdone() in ldap.syncrepl.SyncReplConsumer (thanks to Petr Spacek and Chris Mikkelson) Modules/ * Added support for getting file descriptor of connection with ldap.OPT_DESC From skip.montanaro at gmail.com Sat Sep 27 07:14:31 2014 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Sat, 27 Sep 2014 06:14:31 -0500 Subject: Storage Cost Calculation In-Reply-To: References: Message-ID: On Sep 27, 2014 1:06 AM, "Chris Angelico" wrote: > > We are not going to do your homework for you. Perhaps it was a take home test... What then? :-) Skip -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sat Sep 27 07:18:31 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 27 Sep 2014 21:18:31 +1000 Subject: Storage Cost Calculation In-Reply-To: References: Message-ID: On Sat, Sep 27, 2014 at 9:14 PM, Skip Montanaro wrote: > On Sep 27, 2014 1:06 AM, "Chris Angelico" wrote: >> > >> We are not going to do your homework for you. > > Perhaps it was a take home test... What then? :-) Then we are not going to do his take home test for you. I feel like I'm using a Hungarian phrasebook here... ChrisA From larry.martell at gmail.com Sat Sep 27 07:41:46 2014 From: larry.martell at gmail.com (Larry Martell) Date: Sat, 27 Sep 2014 07:41:46 -0400 Subject: Storage Cost Calculation In-Reply-To: References: Message-ID: On Sat, Sep 27, 2014 at 7:18 AM, Chris Angelico wrote: > On Sat, Sep 27, 2014 at 9:14 PM, Skip Montanaro > wrote: > > On Sep 27, 2014 1:06 AM, "Chris Angelico" wrote: > >> > > > >> We are not going to do your homework for you. > > > > Perhaps it was a take home test... What then? :-) > > Then we are not going to do his take home test for you. > > I feel like I'm using a Hungarian phrasebook here... > My hovercraft is full is eels. -------------- next part -------------- An HTML attachment was scrubbed... URL: From larry.martell at gmail.com Sat Sep 27 07:43:15 2014 From: larry.martell at gmail.com (Larry Martell) Date: Sat, 27 Sep 2014 07:43:15 -0400 Subject: Storage Cost Calculation In-Reply-To: References: Message-ID: On Sat, Sep 27, 2014 at 7:18 AM, Chris Angelico wrote: > On Sat, Sep 27, 2014 at 9:14 PM, Skip Montanaro > wrote: > > On Sep 27, 2014 1:06 AM, "Chris Angelico" wrote: > >> > > > >> We are not going to do your homework for you. > > > > Perhaps it was a take home test... What then? :-) > > Then we are not going to do his take home test for you. > > I feel like I'm using a Hungarian phrasebook here... > My hovercraft is full of eels. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ned at nedbatchelder.com Sat Sep 27 08:08:58 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 27 Sep 2014 08:08:58 -0400 Subject: Understanding co_lnotab In-Reply-To: References: Message-ID: On 9/26/14 7:13 AM, Shiyao Ma wrote: > When reading the notes on co_lnotab > > I totally got lost at this > line:https://hg.python.org/cpython/file/fd0c02c3df31/Objects/lnotab_notes.txt#l31 > > It says,"In case #b, there's no way to know > from looking at the table later how many were written." > > > No way to know "what" is written? > And why no way to know "how many" times? > I'm not sure what that sentence means, and I've written code that uses co_lnotab. I think they are trying to explain the difficulties with abandoned approaches. Don't worry about that. Look at the code in the comment there to see how to interpret the bytes in co_lnotab. Here's the code in coverage.py that reads it: https://bitbucket.org/ned/coveragepy/src/a69ae93817be94e400df257e1b1e41cf37c9b146/coverage/parser.py?at=default#cl-377 if that helps. Just out of curiosity, what are you writing, it sounds interesting! :) --Ned. > > Regards > > -- Ned Batchelder, http://nedbatchelder.com From skip.montanaro at gmail.com Sat Sep 27 08:34:20 2014 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Sat, 27 Sep 2014 07:34:20 -0500 Subject: Understanding co_lnotab In-Reply-To: References: Message-ID: On Sat, Sep 27, 2014 at 7:08 AM, Ned Batchelder wrote: > Just out of curiosity, what are you writing, it sounds interesting! :) Ned would say that. I think he has an unusual fondness for static code analysis tools. :-) Skip -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Sat Sep 27 10:30:02 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 27 Sep 2014 08:30:02 -0600 Subject: Storage Cost Calculation In-Reply-To: References: Message-ID: On Fri, Sep 26, 2014 at 12:53 PM, Abohfu venant zinkeng wrote: > This site was written by a person (in 2009) who had considered this amazing > trend. He collected a lot of data about hard drive capacity and price. The > formula he extrapolated by using the data he found is > > cost per gigabyte = 10-0.2502(year-1980) + 6.304 > where year is the year for which the extrapolated cost was desired. This > formula is based on data from 1980 to 2010. A nice illustration in the perils of extrapolation. Per the formula, hard drives should be $0.006 per gigabyte now. I don't see anything on newegg.com for less than $0.03 per gigabyte; the best deals appear to be at the 2 TB level. And we're only 4 years out of the data range. It also seems odd to quantify technical advancement in a way that is easily affected by fluctuations in the strength of the US dollar. From python at mrabarnett.plus.com Sat Sep 27 11:41:55 2014 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 27 Sep 2014 16:41:55 +0100 Subject: Storage Cost Calculation In-Reply-To: References: Message-ID: <5426DAC3.8060902@mrabarnett.plus.com> On 2014-09-27 15:30, Ian Kelly wrote: > On Fri, Sep 26, 2014 at 12:53 PM, Abohfu venant zinkeng > wrote: >> This site was written by a person (in 2009) who had considered this >> amazing trend. He collected a lot of data about hard drive capacity >> and price. The formula he extrapolated by using the data he found >> is >> >> cost per gigabyte = 10-0.2502(year-1980) + 6.304 where year is the >> year for which the extrapolated cost was desired. This formula is >> based on data from 1980 to 2010. > > A nice illustration in the perils of extrapolation. Per the formula, > hard drives should be $0.006 per gigabyte now. I don't see anything > on newegg.com for less than $0.03 per gigabyte; the best deals appear > to be at the 2 TB level. And we're only 4 years out of the data > range. > > It also seems odd to quantify technical advancement in a way that is > easily affected by fluctuations in the strength of the US dollar. > I once did a calculation of my own about the cost of RAM. In 1981 the BBC Micro was released. There were 2 versions, model A with 16K and model B was 32K. The price difference was ?100, so that's ?100 for 16K of RAM. Today you can get 16GB of RAM for about the same price. If you'd wanted that much RAM 30 years ago, it would've cost you ?100m! From Seymore4Head at Hotmail.invalid Sat Sep 27 13:01:28 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Sat, 27 Sep 2014 13:01:28 -0400 Subject: Storage Cost Calculation References: Message-ID: On Fri, 26 Sep 2014 11:53:32 -0700, Abohfu venant zinkeng wrote: > > QUESTION > > - > > Could someone help me with a design and a python program to >implement that design to solve the above problem? As a side note, it would be handy to compare HD cost to CD cost. I am still trying to get my own personal copy of the Internet. From rosuav at gmail.com Sat Sep 27 13:12:28 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 28 Sep 2014 03:12:28 +1000 Subject: Storage Cost Calculation In-Reply-To: References: Message-ID: On Sun, Sep 28, 2014 at 3:01 AM, Seymore4Head wrote: > As a side note, it would be handy to compare HD cost to CD cost. > I am still trying to get my own personal copy of the Internet. If you set your sights a bit lower, Google might be able to help. They pretty much have their own copy of the World Wide Web, indexed and cached. I've no idea how many dollars they annually spend on hard drives, but probably it uses SI prefixes most of the world has never heard of... ChrisA From ian.g.kelly at gmail.com Sat Sep 27 13:21:53 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 27 Sep 2014 11:21:53 -0600 Subject: Storage Cost Calculation In-Reply-To: References: Message-ID: On Sat, Sep 27, 2014 at 11:12 AM, Chris Angelico wrote: > On Sun, Sep 28, 2014 at 3:01 AM, Seymore4Head > wrote: >> As a side note, it would be handy to compare HD cost to CD cost. >> I am still trying to get my own personal copy of the Internet. > > If you set your sights a bit lower, Google might be able to help. They > pretty much have their own copy of the World Wide Web, indexed and > cached. I've no idea how many dollars they annually spend on hard > drives, but probably it uses SI prefixes most of the world has never > heard of... http://what-if.xkcd.com/63/ From rosuav at gmail.com Sat Sep 27 13:27:59 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 28 Sep 2014 03:27:59 +1000 Subject: Storage Cost Calculation In-Reply-To: References: Message-ID: On Sun, Sep 28, 2014 at 3:21 AM, Ian Kelly wrote: >> If you set your sights a bit lower, Google might be able to help. They >> pretty much have their own copy of the World Wide Web, indexed and >> cached. I've no idea how many dollars they annually spend on hard >> drives, but probably it uses SI prefixes most of the world has never >> heard of... > > http://what-if.xkcd.com/63/ Yes, I've seen that. Probably the most readable financial figures that anyone's ever put together. :) ChrisA From milsonmun at gmail.com Sat Sep 27 19:25:34 2014 From: milsonmun at gmail.com (Milson Munakami) Date: Sat, 27 Sep 2014 16:25:34 -0700 (PDT) Subject: Python unittesting method call issue Message-ID: I am trying to set the precondition for the test first prior to test other test cases. But as you can see in my code the precondition print command is not fired! Can you explain the cause and solution how to fire the code with in that method i.e. SetPreConditionFirewall() with setup variable self. in this fucntion. Here is my code: import json import urllib #import time #from util import * import httplib #import sys #from scapy.all import * import unittest import os, sys, socket, struct, select, time from threading import Thread import logging import traceback class testFirewallS1( unittest.TestCase ): def setUp(self): self.controllerIp="127.0.0.1" def tearDown(self): if self.failed: return duration = time.time() - self.startTime_ self.cleanup(True) if self.reportStatus_: self.log.info("=== Test %s completed normally (%d sec)", self.name_, duration) def cleanup(self, success): sys.excepthook = sys.__excepthook__ try: return except NameError: self.log.error("Exception hit during cleanup, bypassing:\n%s\n\n" % traceback.format_exc()) pass else: fail("Expected a NameError") def SetPreConditionFirewall(self): command = "http://%s:8080/wm/firewall/module/enable/json" % self.controllerIp urllib.urlopen(command).read() print self.controllerIp print "Test Pre-condition setting here" #Precondition Test def testPreConditionFirewall(self): print "Test pass" def suite(): suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(testFirewallS1)) return suite if __name__ == '__main__': suiteFew = unittest.TestSuite() testFirewallS1("SetPreConditionFirewall") suiteFew.addTest(testFirewallS1("testPreConditionFirewall")) #Testing the Test Cases Begins Here unittest.TextTestRunner(verbosity=2).run(suiteFew) How can I do access that method on __main__ and how can that method can access the setup variable. Thanks From rosuav at gmail.com Sat Sep 27 19:42:35 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 28 Sep 2014 09:42:35 +1000 Subject: Python unittesting method call issue In-Reply-To: References: Message-ID: On Sun, Sep 28, 2014 at 9:25 AM, Milson Munakami wrote: > I am trying to set the precondition for the test first prior to test other test cases. But as you can see in my code the precondition print command is not fired! Can you explain the cause and solution how to fire the code with in that method i.e. SetPreConditionFirewall() with setup variable self. in this fucntion. Here is my code: > The first thing to do is to cut down your code - for instance, what happens if you remove the urlopen call and just have the print in there? (And while you're at it, I think suite() is completely superfluous.) You should be able to get your code down to being identical to a working example, except for one difference, and then you'll be able to either spot the issue yourself, or ask for very specific help. ChrisA From ian.g.kelly at gmail.com Sat Sep 27 20:27:27 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 27 Sep 2014 18:27:27 -0600 Subject: Python unittesting method call issue In-Reply-To: References: Message-ID: On Sat, Sep 27, 2014 at 5:25 PM, Milson Munakami wrote: > I am trying to set the precondition for the test first prior to test other test cases. But as you can see in my code the precondition print command is not fired! Can you explain the cause and solution how to fire the code with in that method i.e. SetPreConditionFirewall() with setup variable self. in this fucntion. Here is my code: The method doesn't run because you never called it, and the name has no special meaning to unittest, so unittest is not going to call it for you. The method that gets called prior to each test is setUp. So if you want SetPreConditionFirewall to be called before each test, then call it from setUp. From harmonoisemusic at gmail.com Sat Sep 27 21:07:23 2014 From: harmonoisemusic at gmail.com (Gregory Johannes-Kinsbourg) Date: Sun, 28 Sep 2014 02:07:23 +0100 Subject: Question about uninstallation. Message-ID: <22CC0B3F-BD80-475A-A452-7DC03DF75200@gmail.com> Hello, This whole world of Python language is completely new to me (never programmed before in my life) - anyway sort of besides the point. Anyway, I?ve sort of been learning ?all over the place?, that is to say that ill read something do it and then find out i should have done something else first. Anyway, I?ve basically ended up installing both Python 2 & 3 (I?m on OS X 10.10 btw) and first of all was curious to know if they will clash with each when being used in terminal and how do i safely remove 3 (figure i?ll learn 2 first, then re-install 3). According to the manual I should remove the files from the application folder (fair enough) but also the framework (surely I should leave that for python 2?) Thanks in advance for the response you can provide me. Kind regards, Greg. From rosuav at gmail.com Sat Sep 27 21:13:37 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 28 Sep 2014 11:13:37 +1000 Subject: Question about uninstallation. In-Reply-To: <22CC0B3F-BD80-475A-A452-7DC03DF75200@gmail.com> References: <22CC0B3F-BD80-475A-A452-7DC03DF75200@gmail.com> Message-ID: On Sun, Sep 28, 2014 at 11:07 AM, Gregory Johannes-Kinsbourg wrote: > Anyway, I?ve basically ended up installing both Python 2 & 3 (I?m on OS X 10.10 btw) and first of all was curious to know if they will clash with each when being used in terminal and how do i safely remove 3 (figure i?ll learn 2 first, then re-install 3). According to the manual I should remove the files from the application folder (fair enough) but also the framework (surely I should leave that for python 2?) > They shouldn't clash. You'll invoke one as python2 and the other as python3. However, as Yosemite hasn't been released yet, you may find that you have problems that nobody's run into yet. To get a better understanding of Python, separately from any OS X issues, you may want to make yourself a Linux computer to test on - it's usually not hard to install a virtualization system and create a Linux machine inside your Mac (or just get an actual physical machine). There have been some issues with OS X and Python, in various versions; not being a Mac person myself, I can't say what the least problematic version is. ChrisA From steve+comp.lang.python at pearwood.info Sat Sep 27 21:14:16 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 28 Sep 2014 11:14:16 +1000 Subject: Storage Cost Calculation References: Message-ID: <542760e9$0$13012$c3e8da3$5496439d@news.astraweb.com> MRAB wrote: > In 1981 the BBC Micro was released. There were 2 versions, model A with > 16K and model B was 32K. The price difference was ?100, so that's ?100 > for 16K of RAM. That doesn't follow. The model A might have been ?1 (in which case you could get 16K for ?1) or it might have been ?10000. All your calculation shows is that model B was ?100 more expensive. There are three more-or-less equally valid statistics you could have used to calculate the price of RAM: the average, minimum, or maximum. With only two data points, it doesn't matter whether you use the mean or median to calculate the average. Of the three, the minimum is probably the most useful. > Today you can get 16GB of RAM for about the same price. Funny that you say that. I just googled for "price of RAM", and the very first result talks about how much the price of RAM has *increased* recently: Other components show similar increases ? Kingston 8GB packs have gone from $66 to $79, and Corsair's 16GB RAM packs are up to $150, from $130. A year ago, 16GB of DDR3-1600 from Corsair was $67, which gives you some idea of just how much prices have already risen. ... Aaaaand my browser just crashed and I can't be bothered restarting it, so you can do your own googling if you want the source :-) -- Steven From rosuav at gmail.com Sat Sep 27 21:37:41 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 28 Sep 2014 11:37:41 +1000 Subject: Storage Cost Calculation In-Reply-To: <542760e9$0$13012$c3e8da3$5496439d@news.astraweb.com> References: <542760e9$0$13012$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Sep 28, 2014 at 11:14 AM, Steven D'Aprano wrote: > MRAB wrote: > >> In 1981 the BBC Micro was released. There were 2 versions, model A with >> 16K and model B was 32K. The price difference was ?100, so that's ?100 >> for 16K of RAM. > > That doesn't follow. The model A might have been ?1 (in which case you could > get 16K for ?1) or it might have been ?10000. All your calculation shows is > that model B was ?100 more expensive. > > There are three more-or-less equally valid statistics you could have used to > calculate the price of RAM: the average, minimum, or maximum. With only two > data points, it doesn't matter whether you use the mean or median to > calculate the average. Of the three, the minimum is probably the most > useful. The RAM was presumably the only difference between the two models, so as long as Model A cost at least ?100 (which seems likely; a bit of quick Googling suggests that it may have been of the order of ?400), a ?100 difference can plausibly be called the price of the RAM. ChrisA From steve+comp.lang.python at pearwood.info Sat Sep 27 22:19:11 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 28 Sep 2014 12:19:11 +1000 Subject: Python unittesting method call issue References: Message-ID: <54277020$0$12977$c3e8da3$5496439d@news.astraweb.com> Milson Munakami wrote: > I am trying to set the precondition for the test first prior to test other > test cases. But as you can see in my code the precondition print command > is not fired! Can you explain the cause and solution how to fire the code > with in that method i.e. SetPreConditionFirewall() with setup variable > self. in this fucntion. Here is my code: Unfortunately, your code has many issues. See comments below, interleaved between the lines of code: [snip imports] > class testFirewallS1( unittest.TestCase ): > def setUp(self): > self.controllerIp="127.0.0.1" > def tearDown(self): > if self.failed: > return I cannot see that self.failed is defined anywhere, so your tearDown method will fail every single time a test runs. > duration = time.time() - self.startTime_ I cannot see that self.startTime_ is defined anywhere either. > self.cleanup(True) > if self.reportStatus_: Nor self.reportStatus_. > self.log.info("=== Test %s completed normally (%d sec)", > self.name_, duration) And the same for self.log, self.name_. > def cleanup(self, success): > sys.excepthook = sys.__excepthook__ I don't know why you are doing this. Your code never changes the excepthook, so why are you restoring it? It seems unnecessary. > try: > return > except NameError: A bare return cannot possibly fail. It certainly won't fail with NameError, so your "except NameError" clause is dead code and will never run. > self.log.error("Exception hit during cleanup, > bypassing:\n%s\n\n" % traceback.format_exc()) > pass But if it did run, the "pass" here is pointless and unnecessary. > else: > fail("Expected a NameError") This code will never run, since you've already returned out of the method. It is dead code. If you want to raise an exception, the right way is with the "raise" keyword: raise NameError not to invent some fake name which you hope will fail. > def SetPreConditionFirewall(self): > command = "http://%s:8080/wm/firewall/module/enable/json" % self.controllerIp > urllib.urlopen(command).read() > print self.controllerIp > print "Test Pre-condition setting here" Here you have a test method, which the unittest framework will automatically detect, if you allow it. But later, you explicitly provide a method name for the test suite to run, so there is a conflict: will the unittest framework call your explicitly named method, or your test* methods, or both? I'm afraid I don't know that answer to that, but I expect that the solution is to use one, or the other, not both. > #Precondition Test > def testPreConditionFirewall(self): > print "Test pass" > > def suite(): > suite = unittest.TestSuite() > suite.addTest(unittest.makeSuite(testFirewallS1)) > return suite I'm not sure why you are manually instantiating TestSuite here, instead of allowing unittest to do so on your behalf. But since you never actually call suite(), it doesn't matter, it doesn't get used. > if __name__ == '__main__': > suiteFew = unittest.TestSuite() > testFirewallS1("SetPreConditionFirewall") Here you create a testFirewallS1 instance, but it is immediately garbage collected since you don't do anything with it. > suiteFew.addTest(testFirewallS1("testPreConditionFirewall")) Again, I'm not sure why you are bothering to manually create test suites. Can you explain what you are trying to do? > #Testing the Test Cases Begins Here > unittest.TextTestRunner(verbosity=2).run(suiteFew) > > How can I do access that method on __main__ and how can that method can > access the setup variable. What method on __main__? I don't understand your question. In my opinion, I don't see anything that requires you to manually instantiate the test suites. I think you should let the unittest framework handle all the grunt work. Start by defining one or more test suites, by inheriting from TestCase, then let unittest auto-detect and auto-run them. The simplest way is to just name your tests "testFoo" (for any value of Foo). class TestFirewallS1(unittest.TestCase): # Write your setUp and tearDown methods, if you need them. # Make sure you initialise all the attributes you need. The best # place for that is in the setUp method. def setUp(self): self.variable = "World" # Now write your tests. Prefix them with the word "test". def test_this(self): # Write a self-contained test. It can call any helper methods # you like, access any instance attributes you have. result = self.helper() + self.variable self.assertEqual(result, "HelloWorld!") # Methods not starting with "test" are not special. def helper(self, arg=None): return "Hello" # And another test. def test_that(self): x = 100*3 # Do some calculation. self.assertNotEqual(x, -1) class TestFirewallS2(unittest.TestCase): def test_stuff(self): self.assertTrue(isinstance(self, unittest.TestCase)) if __name__ == '__main__': unittest.main() The framework will: - discover the test suites (classes that inherit from TestCase); - do test discovery (methods beginning with the word "test"); - instantiate each test suite; - run the tests; - run the setUp method (if any) before each test; - run the tearDown method (if any) after each test; - collect the results and display them. unittest.main() will check the commandline to see if you passed "--verbose" as an argument: python path/to/your/test_file.py --verbose or you can force it in your code: unittest.main(verbosity=2) -- Steven From steve+comp.lang.python at pearwood.info Sat Sep 27 22:47:05 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 28 Sep 2014 12:47:05 +1000 Subject: Storage Cost Calculation References: <542760e9$0$13012$c3e8da3$5496439d@news.astraweb.com> Message-ID: <542776aa$0$13001$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > The RAM was presumably the only difference between the two models, so > as long as Model A cost at least ?100 (which seems likely; a bit of > quick Googling suggests that it may have been of the order of ?400), a > ?100 difference can plausibly be called the price of the RAM. Hah! I read MRAB as saying the *RAM* came in two models, "Model A RAM" and "Model B RAM". I wondered why they didn't just say "16K" versus "32K", but it was the 1980s, who knows why people did anything back then... But no, you can't put the ?100 difference down to the price of the RAM even if RAM were the only difference between the two model Micros. There's not enough information to tell how much of that ?100 represents the cost of RAM, and how much is pure profit on the part of the vendor, Acorn. In fact, there were considerable differences apart from RAM: The Model B supported more graphics modes, had a six-pin DIN connector for a monitor (both the A and B had UHF output for connecting to a television, but only the B supported a dedicated monitor), had support for an optional floppy disk controller and even an optional hard drive controller. It also had RS-232 and Centronics parallel interfaces, a 20-pin "user port" for I/O, and even support for a second CPU! The Model A didn't support any of those. http://www.theregister.co.uk/Print/2011/11/30/bbc_micro_model_b_30th_anniversary/ At the time, the BBC Micro memory was (I think) expandable: the Model B could be upgraded to 128K of memory, double what Bill Gates allegedly said was the most anyone would ever need. (He probably didn't say that.) So what we need is to find out what an upgrade would have cost. http://www.progettoemma.net/mess/system.php?machine=bbca -- Steven From rosuav at gmail.com Sat Sep 27 23:35:48 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 28 Sep 2014 13:35:48 +1000 Subject: Storage Cost Calculation In-Reply-To: <542776aa$0$13001$c3e8da3$5496439d@news.astraweb.com> References: <542760e9$0$13012$c3e8da3$5496439d@news.astraweb.com> <542776aa$0$13001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Sep 28, 2014 at 12:47 PM, Steven D'Aprano wrote: > Chris Angelico wrote: > >> The RAM was presumably the only difference between the two models, so >> as long as Model A cost at least ?100 (which seems likely; a bit of >> quick Googling suggests that it may have been of the order of ?400), a >> ?100 difference can plausibly be called the price of the RAM. > > Hah! I read MRAB as saying the *RAM* came in two models, "Model A RAM" > and "Model B RAM". I wondered why they didn't just say "16K" versus "32K", > but it was the 1980s, who knows why people did anything back then... > > But no, you can't put the ?100 difference down to the price of the RAM even > if RAM were the only difference between the two model Micros. There's not > enough information to tell how much of that ?100 represents the cost of > RAM, and how much is pure profit on the part of the vendor, Acorn. In fact, > there were considerable differences apart from RAM: I don't care about "pure profit on the part of the vendor" - that's part of the end-user cost of RAM. But if my presumption is incorrect, there's no way to put a price on just the RAM. ChrisA From steve+comp.lang.python at pearwood.info Sun Sep 28 00:39:28 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 28 Sep 2014 14:39:28 +1000 Subject: Storage Cost Calculation References: <542760e9$0$13012$c3e8da3$5496439d@news.astraweb.com> <542776aa$0$13001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <54279101$0$12976$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > On Sun, Sep 28, 2014 at 12:47 PM, Steven D'Aprano > wrote: [...] >> But no, you can't put the ?100 difference down to the price of the RAM >> even if RAM were the only difference between the two model Micros. >> There's not enough information to tell how much of that ?100 represents >> the cost of RAM, and how much is pure profit on the part of the vendor, >> Acorn. In fact, there were considerable differences apart from RAM: > > I don't care about "pure profit on the part of the vendor" - that's > part of the end-user cost of RAM. No, it's part of the end-user cost of the BBC Micro model B. What we want to know is the cost in 1981 of buying a 16K memory chip, without the rest of the computer. Even that's not necessarily a good indication, since there are all sorts of things which could distort the price. Historically, both IBM and Apple are well known for (ab)using monopoly power to keep the price of spare parts extremely high. If (say) Acorn charged ?85 for a 16KB memory chip, while other manufacturers charged ?15, we wouldn't want to treat Acorn's prices as "the cost of RAM in 1981". We want to compare typical, competitive prices, not RTBO ("Rip The Bastards Off") prices. I used to work for a company that made and sold electronic sensor taps. There were four components: a spout, a solenoid, a transformer, and a sensor. If you bought the four components individually, as spare parts, it would cost you about twice as much as buying the entire kit. Some of that reflects the fact that there's about the same amount of overhead (ordering, billing, storage, packing, delivery...) whether it's a $300 kit or a $30 spout, but most of it reflects monopoly power. When selling the kit, we were competing with other brands of electronic and hands-free taps. When selling the parts, we had a monopoly on the parts: other brands of parts wouldn't fit our taps, and our parts wouldn't fit theirs. I don't quite remember the exact figures, but markup on the entire unit was about 30%, and markup on the parts were about 100-200%, I think. And this is partly why, for a long time, Apple spare parts were so much more expensive than non-Apple spares that wouldn't fit in your Macintosh. You had a choice of RAM from three or four manufacturers for your PC, and no choice at all for your Mac. (I don't know if this is still the case now, I haven't used a Mac seriously since System 7.) > But if my presumption is incorrect, > there's no way to put a price on just the RAM. My point exactly :-) -- Steven From ian.g.kelly at gmail.com Sun Sep 28 01:04:43 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 27 Sep 2014 23:04:43 -0600 Subject: Storage Cost Calculation In-Reply-To: <542776aa$0$13001$c3e8da3$5496439d@news.astraweb.com> References: <542760e9$0$13012$c3e8da3$5496439d@news.astraweb.com> <542776aa$0$13001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Sep 27, 2014 at 8:47 PM, Steven D'Aprano wrote: > http://www.theregister.co.uk/Print/2011/11/30/bbc_micro_model_b_30th_anniversary/ > > At the time, the BBC Micro memory was (I think) expandable: the Model B > could be upgraded to 128K of memory, double what Bill Gates allegedly said > was the most anyone would ever need. (He probably didn't say that.) So what > we need is to find out what an upgrade would have cost. Actually it was 640K in the alleged Bill Gates quote, although I do believe that quote has pretty much been debunked. It was allegedly stated in 1981, but there doesn't seem to be any evidence of it circulating prior to about 1992. Gates himself denies ever having said it, and maintains that he in fact held the opposite opinion. From d.joshi84 at gmail.com Sun Sep 28 01:21:59 2014 From: d.joshi84 at gmail.com (Unix SA) Date: Sun, 28 Sep 2014 11:06:59 +0545 Subject: please suggest me best way to learn REST API call with CLI Message-ID: Hello, I am intermediate to python and i am familier with OOP, but sometime i lost some where looking at OOP in class and objects .... :( I am looking at https://github.com/pulp/pulp .. basically it uses okaara to generate CLI and calls API. so for example if i run "pulp-admin -u admin -p admin rpm repo list" it produces list of all repositories ... now i want to write similar thing .. but without producing all repository i just want to list single repo and below is the API for that .. http://pulp-dev-guide.readthedocs.org/en/pulp-2.2/integration/rest-api/repo/retrieval.html Not sure what's the best way to write it ... i want to do in OO way.. i know how to use requests/httplib module and generate data and produce output ......... but i am not able to build URL ... can someone help to suggest best way to learn and write it ? Regards, DJ -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Sun Sep 28 02:22:16 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 28 Sep 2014 16:22:16 +1000 Subject: Leap year References: Message-ID: <5427a919$0$12982$c3e8da3$5496439d@news.astraweb.com> Seymore4Head wrote: > Still practicing. Since this is listed as a Pseudocode, I assume this > is a good way to explain something. That means I can also assume my > logic is fading with age. > http://en.wikipedia.org/wiki/Leap_year#Algorithm > > Me trying to look at the algorithm, it would lead me to try something > like: > if year % 4 !=0: > return False > elif year % 100 !=0: > return True > elif year % 400 !=0: > return False You can only have the "return" statement inside a function, not in top-level code, and that looks like top-level code. So you need to start with something like: def is_leapyear(year): if year % 4 != 0: return False ... > **** Since it is a practice problem I have the answer: > def is_leap_year(year): > return ((year % 4) == 0 and ((year % 100) != 0 or (year % 400) == 0)) Or in English: - years which are divisible by 4 are leap years, *unless* they are also divisible by 100, in which case they aren't leap years, *except* that years divisible by 400 are leap years. Converting to Python code: def is_leap_year(year): return ( # Years which are divisible by 4 (year % 4 == 0) # and not divisible by 100 and (year % 100 != 0) # unless divisible by 400 or (year % 400 == 0) ) > I didn't have any problem when I did this: > > if year % 400 == 0: > print ("Not leap year") > elif year % 100 == 0: > print ("Leap year") > elif year % 4 == 0: > print ("Leap year") > else: > print ("Not leap year") You might not have had any problems, but neither did you get the right answers. According to your code, 2000 is not a leap year (since 2000 % 400 equals 0) but in reality it is. On the other hand, your code says 1900 was a leap year, which it was not. The lesson here is, code isn't working until you've actually tested it, and to test it sufficiently you need to check the corner cases, not just the obvious ones. -- Steven From dieffedue at gmx.com Sun Sep 28 09:49:40 2014 From: dieffedue at gmx.com (STEFAN CUMESCU) Date: Sun, 28 Sep 2014 06:49:40 -0700 (PDT) Subject: A 14 ANNI VENNI STUPRATO DA AVVOCATO DANIELE MINOTTI DI RAPALLO E GENOVA: UN FIGLIO DI PUTTANA PEDOFILO DI GIRI MAFIOSI E NAZIFASCISTI. DI SUE GANGS FAN ANCHE PARTE I BASTARDI PEDERASTA GIULIANO FERRARA DE IL FOGLIO E PAOLO BARRAI ("MERDATO" LIBERO)! Message-ID: <6b9a8f9f-a9fc-4ef4-88fe-2c2bb64c345e@googlegroups.com> A 14 ANNI VENNI STUPRATO DA AVVOCATO DANIELE MINOTTI DI RAPALLO E GENOVA: UN FIGLIO DI PUTTANA PEDOFILO DI GIRI MAFIOSI E NAZIFASCISTI. DI SUE GANGS FAN ANCHE PARTE I BASTARDI PEDERASTA GIULIANO FERRARA DE IL FOGLIO E PAOLO BARRAI ("MERDATO" LIBERO)! 1 Ciao tuti e scusate di mio italiano. Io sono rumeno e non me nascondo: me chiamo Stefan Cumescu. Io ora tengo 19 anni. Quindi, 5 anni fa tenevo 14 anni). E bene, cinqua anni fa avvocato di giri nazifascisti misti a Cosa Nostra, Camorra, Ndrangheta Daniele Minotti di Rapallo e Ganova, mi diede tre grammi di cocaina, mi fece svenire e mentre ero mas di morto che vivo, me sodomizzo'. Vi era anche pancione pieno di merda Giuliano Ferrara a guardare. Me sodomizzo' lui insieme ad altri sei di suoi giri fascisti e mafiosi. Ho anche prove di questo. Io, ora, Stefan Cumescu di Genova, quartiere Caruggi, facio il muratore, basta droga, basta prostituirsi. Guadanio un decimo di quanto guadaniavo prima e lavoro il triplo di quanto prima. Ma preferisco di questo, sento la mia vita uno poco di maggiore securo. Ma avvocato di Hitler, Vallanzasca e Satana, avvocato figlio di puttana di Silvio Berlusconi e Giuliano Ferrara, nazista e mafioso Daniele Minotti con studio a Genova e Rapallo, davvero fa parte di setta di pedofili assassini molto pericolosi. Ciao. Stefan. Posti Scrito Io vedevo in giro uno belo testo che parlava di tuto questo... ma ora non vedo tanto di piu' in giro lo stesso testo. Alora sai cosa facio? Di mia iniciativa facio cut and copy e provo di riproporlo io. Ciao da Stefan Cumescu e ri scusa di mio italiano... ma presto volio di fare corsi di sera di miliorarlo. Ciao. 2 OCHO AD AVVOCATO "BERLUSCONIANISSIMAMENTE", MEGA RICICLA CASH MAFIOSO, NAZIFASCISTA, ASSASSINO E PEDOFILOMOSESSUALE: DANIELE MINOTTI ( PURE SU FACEBOOK) DI RAPALLO E GENOVA! TUTTI SANNO DI SUE "FESTE" SATANISTISSIME "ATTE A SODOMIZZARE ZINGARELLI DI 6-8 ANNI (A SANREMO, CON DON RICCARDO SEPPIA E COL TANTE VOLTE CONDANNATO A GALERA, PAOLO BARRAI DEL CRIMINALISSIMO BLOG MERCATO "MERDATO" LIBERO.. MA NON SOLO... E FRA POCO.. TUTTI I NOMI E COGNOMI)!!! OCCHIO, PLS, ALL'AVVOCATO PIU' INFIMAMENTE NAZISTA, MEGA LAVA CASH MAFIOSO, MANDANTE DI OMICIDI E "SUICIDATE", E COME SE NON BASTASSE, ACCLARATO PEDOFILOMOSESSUALE, CHE ESISTA ( IL VOMITO VA' SULLA PARTE "PEDOFILO", PIU' CHE OMOSESSUALE, ANCHE SE IL MEGA SODOMIZZATORE DI BAMBINI, DANIELE MINOTTI, LO E' ENTRAMBE LE COSE; OLTRE AD ESSERE UN VERMINOSO CODARDO: METTEVA DELLE SUE FOTO CON FACCE DA ASSOLUTO PERICOLOSISSIMO MANICACO SESSUALE, SU TUTTA INTERNET... ED OVVIAMENTE, ORA, DOPO CHE LE ABBIAM FATTE NOTARE SU MIGLIAIA DI SITI, DA TOPO DI FOGNA, DETTE FOTO LE HA FATTE SUBITO IMBOSCARE)! COME SE NON BASTASSE, PURE FREQUENTISSIMO MANDANTE DI "SUICIDATE" ED OMICIDI: DANIELE MINOTTI DI GENOVA E RAPALLO. Criminalissimo Studio Legale pro Mafia, Camorra, Ndrangheta e Neonazisti assassini, di noto pedofilomosessuale Daniele Minotti :: Genova - Rapallo Via della Libert?, 4/10 - 16035 - Rapallo (GE) (Tribunale di Chiavari) Via XX Settembre, 3/13 - 16121 - Genova RICICLANTE DA ANNI CASH KILLER DEGLI EMANUELLO DI COSA NOSTRA, BASATI A GENOVA. http://www.ilsecoloxix.it/p/genova/2011/05/19/AOJ0cAV-rischio_gronda_arresti.shtml O DEI FEROCI SICARI DELLA NDRANGHETA: I RAMPINO. SEMPRE BASATI A GENOVA. http://www.ilsecoloxix.it/p/genova/2013/06/05/APjJUSgF-ndrangheta_terra_liguria.shtml BASTARDO VERO, PEDERASTA PERVERTITO DANIELE MINOTTI DI GENOVA E RAPALLO: TUTTI SANNO DELLE ORGE PEDOFILE CHE FACEVA CON DON RICCARDO SEPPIA A SANREMO. FRA SIMBOLI DEMONIACI E TERRIFICANTI SODOMIZZAZIONI DI BAMBINI DI 6-8 ANNI ( E AHIME.. FATEMI SDRAMMATIZZARE, PLS... ANCHE 6-8 ANI). BAMBINI ZINGARELLI! D'ALTRONDE, TOPI DI FOGNA CODARDI E SPIETATI COME IL CRIMINALISSIMO AVVOCATO DANIELE MINOTTI DI GENOVA CHE ALTRO AVREBBERO POTUTO RACCATTARE? IL TUTTO FRA CHILI DI COCAINA, MEGA CASH MAFIOSO, E SCIOCCANTISSIMAMENTE, DOZZINE DI TESSERE FASCIOCAMORRISTE DI FORZA ITALIA, FRATELLI D'ITALIA, CASA POUND, FIAMMA TRICOLORE E LEGA NORD. IL DAVVERO "AVVOCATO DEL DIAVOLO", IL BASTARDO MASSONE NAZISTA, IL VERME MASSO-NAZISTA ( MERDA ASSASSINA P2ISTICA PER INTENDERCI), MEGA LAVA CASH MAFIOSO, MANDANTE DI "SUICIDATE" ED OMICIDI A RAFFICA, SEMPRE INC.LANTE BAMBINI O POCO PIU' CHE BAMBINI, DANIELE MINOTTI DI GENOVA E RAPALLO, D'ALTRONDE, I PEDOFILOMOSESSUALI O PEDOFILI IN GENERE LI AMA, SE NE SENTE STRA PARTE, LI DIFENDE. NON CI CREDETE??? VOLETE FARE GLI STRUZZI, CHE PER FRATELLANZA MASSO-N-AZIFASCISTA, PREFERISCONO METTERE LA TESTA DOVE GIRANO I VERMI, SOTTO TERRA??? GIVE A LOOK RIGHT NOW, THEN, PLS:http://www.ansa.it/liguria/notizie/2014/06/20/adescava-minori-sul-web-condannato_36c57304-90aa-4c7f-8463-c7d610ed10dd.html http://iltirreno.gelocal.it/massa/cronaca/2013/04/19/news/casolare-a-luci-rosse-il-pm-7-anni-e-mezzo-all-ex-dipendente-nca-1.6917147 3 E SE GOOGLATE " DANIELE MINOTTI PEDOPORNOGRAFIA" VEDRETE CHE IN TUTTI I SUOI ARTICOLI, SOTTILISSIMAMENTE ( E MANCO TANTO, SOTTILISSIMAMENTE) DIFENDE I PEDOFILI, MINIMIZZA O ELUDE LE LORO ABERRANTI, SPEZZA VITE, COLPE! LI SUPPORTA: OVVIO, E' UN VERME SODOMIZZA BAMBINI LUI IN PRIMO! DA RINCHIUDERE IN GALERA O MANICOMIO CRIMINALE SUBITO: AVRA' GIA' UCCISO E FATTO SCOMPARIRE QUALCHE BIMBO CHE HA INCULATO! O PRESTO LO FARA'! QUI SALVIAMO VITE DI PICCOLISSIME CREATURE CON QUESTI SCRITTI!!! SALVIAMO IL MONDO!!! MA TORNIAMO ORA A STO, PURE TERRORISTA NERO ( ED IN NERO), COME CITATO, FREQUENTE MANDANTE DI OMICIDI, "SUICIDATE" O TERRIFICANTI ISTIGAZIONI AL SUICIDIO: DANIELE MINOTTI DI RAPALLO E GENOVA. DA TANTISSIMI ANNI, VIA VARI CODARDI NICKS, MINACCIANTE MORTE E FACENTE KILLING STALKING A GENIO, SORT OF RE MIDA ED EROE CIVILE MICHELE NISTA, SU CERTISSIMO ORDINE DI AL CAPONE MISTO AD ADOLF HITLER: SILVIO BERLUSCONI ( VIA SUOI CA-N-AZISTI GIULIANO FERRARA, MAURIZIO BELPIETRO, DANIELA GARNERO "SANTANCHE'" E/O ALTRI TOPASTRI DI FOGNA CON SVASTICA AL BRACCIO, DEL CASO). IN QUANTO IL SEMPRE VINCENTISSIMO MICHELE NISTA DIEDE AL CANCRO DEL MONDO INTERO, SILVIO BERLUSCONI, GIUSTAMENTE, DEL DITTATORE, DURANTE UNA TELEFONATA I DUE EBBERO MOLTI ANNI FA. A SEGUITO DI QUESTO, IL COLLETTO LERCISSIMAMENTE INTRISO DI MAFIA, CAMORRA, NDRANGHETA, NAZIFASCISMO, PEDOFILIA, SUOI ORDINI DI OMICIDI E STRAGI, SILVIO BERLUSCONI, FECE DI TUTTO PER DISTRUGGERE LA POSIZIONE DI MICHELE NISTA DI QUASI NUMERO UNO DELLA BORSA DI MILANO, NEGLI ANNI 90. COI METODI PIU' CRIMINALI E VIGLIACCHI POSSIBILE! NON RIUSCENDOLO A DISTRUGGERE PROFESSIONALMENTE ( ESSENDO MICHELE NISTA IN FIUTO BORSISTICO, POLITICO ED INVESTIGATIVO, MOLTO PROBABILMENTE, IL NUMERO UNO DI TUTTO IL PIANETA TERRA), CI RIUSCI' "SOLO" AMMAZZANDOGLI IL PADRE ( CON BASTARDISSIMAMENTE ASSASSINO "METODO FERRULLI") E CERCANDO POI DI UCCIDERE MICHELE, "SOLO" ALTRE 4 VOLTE ( FACENDOGLI SPARIRE I FRENI ANDANDO IN AUTOSTRADA AD OLTRE 120 KM ALL'ORA, PER " SOLO" 3 VOLTE, STESSO MODO CON CUI SILVIO BERLUSCONI FECE AMMAZZARE I GENITORI DI CLEMENTINA FORLEO https://it.answers.yahoo.com/question/index?qid=20100118105650AAhOMTQ RIPETENDO LO STESSO, POI, CON CLEMENTINA FORLEO STESSA http://www.leiweb.it/celebrity/personaggi-news/10_a_clementina-forleo-strani-incidenti.shtml http://straker-61.blogspot.be/2009/12/il-giudice-forleo-coinvolto-in-un.html E IN UN QUARTO CASO, ATTRAVERSO UN AGGUATO FISICO, PREPARATO IN OGNI DETTAGLIO, DA POI FAR PASSARE PER MALORE, COME ACCADUTO COL GRANDE PAPA' DI MICHELE: NOTO " ASSASSINO BERLUSCONIANISSIMO "METODO FERRULLI" http://ricerca.repubblica.it/repubblica/archivio/repubblica/2014/07/06/da-aldrovandi-a-ferrulli-la-stessa-follia-degli-agenti16.html)! VIA VARIE OVRA E GESTAPO PUBBLICHE E PRIVATE DEL, NON SI DICE MAI ABBASTANZA, MEGA MANDANTE DI OMICIDI E STRAGI, BASTARDISSIMO, SPIETATO ASSASSINO SILVIO BERLUSCONI ( NON PER NIENTE LO STESSO VOLEVA " DISARTICOLARE CON TRAUMA", OSSIA U-C-C-I-D-E-N-D-O E FACENDO SEMBRARE IL TUTTO, FINTISSIMI INCIDENTI, INFARTI O SUICIDI, CHI NON SOTTO LE SUE SUOLE ALTE COME QUELLE DEI PAGLIACCI SU TRAMPOLI, A CUI ASSOMIGLIA IN TUTTO http://www.grnet.it/news/95-news/852-segreto-di-stato-sulle-schedature-illegali-berlusconi-salva-pollari-a-pompa.html ... MA TORNEREMO SU QUESTO CON MILIONI DI BLOGS, DOVESSIMO MORIRE DI INFARTO SU UNA TASTIERA, OGGI STESSO). PASSIAMO DI NUOVO, ORA, PLEASE, A UNO DEI SICARI KILLER DI SILVIO BERLUSCONI: L'AVVOCATO OMICIDA E PEDOFILOMOSESSUALE DANIELE MINOTTI (OLTRE CHE NAZI E MEGALAVA EURO MAFIOSI)! 4 INCITA I VERMI DI ESTREMISSIMA DESTRA COME LUI, DI TUTTO IL MONDO, I KAMERADEN KILLER DEI TEA PARTIES, AD UCCIDERE, PRIMA CIVILMENTE E PROFESSIONALMENTE, POI, SE NON "ABBASTANZA INTIMIDITI', DEL TUTTO, CHIUNQUE CRITICHI "TROPPO" I SUO LIDER MAXIMI (LIDER MAXIMI IN TUTTO, SPECIE IN PEDOFILIA, FASCIOCAMORRA ED ORDINI DI OMICIDI E STRAGI): SILVIO BERLUSCONI E LICIO GELLI (CITATI NAZIMAFIOSI DEI TEA PARTIES DI CUI E' STRA PARTE, L'INCULA BAMBINI DANIELE MINOTTI DI GENOVA E RAPALLO, INSIEME AD ALTRO VERME CRIMINALISSIMO: GIACOMO ZUCCO, OVVIAMENTE, PURE LUI, MEGA LAVA SOLDI DI COSA NOSTRA, CAMORRA E NDRANGHETA, SPECIE VIA BITCOINS, ED ESSENDO "BERLUSCONES CLASSIC E NON SPECIAL", PURE LUI NOTO PEDOFILOMOSESSUALE)! CON IL QUALE CONDIVIDE PURE, UNA, DA VOMITARE ANCHE LA BILE, TESSERA DEI PEDERASTA CHE "SON ORGOGLIOSI DI FAR SESSO CON BAMBINI", QUELLA DELL'ORGOGLIO PEDOFILO, OSSIA QUELLA DEI "North American Man-Boy Amore Association" http://www.today.it/rassegna/giornata-orgoglio-pedofilo.html STO PUTRIDISSIMO TOPO DI FOGNA DI DANIELE MINOTTI DEL FORO DI CHIAVARI ( ALTRA SDRAMMATIZZAZIONE, PLS: CHIAVARI, SI, E' DI CERTO LA COSA PIU' BELLA AL MONDO, MA ANCHE LA PIU' BRUTTA, QUANDO LO SI FA DEPRAVATISSIMAMENTE CON I BAMBINI, COME FA SEMPRE STO ESCREMENTOSO PEDERASTA DI DANIELE MINOTTI DI RAPALLO E GENOVA) E' OVVIAMENTE PURE UN BASTARDO RAZZISTA. AUSPICA LA MORTE SOCIALE, " MA ANCHE NON SOLO.. ANCHE TOTALISSIMA" ... DI CHIUNQUE NATO SOTTO LA VERMINOSAMENTE PIDUISTICA AREZZO (DA DOVE VENGONO, NON PER NIENTE, PURE LA BAGASCIONA PREFERITA DA LICIO GELLI, MARIA ELENA BOSCHI.. E SUO PADRE, PORCO SCHIFOSO BANCHIERE DI COSA NOSTRA, CAMORRA E NDRANGHETA, PIER LUIGI BOSCHI DI BANCA ETRURIA... CHE CON LE LORO "RIFORME IMPOSTE DA HITLERIANISSIMA WILLA WANDA", PORTERANNO IL PAESE A NUOVE SVASTICHE, A NUOVI REGIMI ASSASSINISSIMAMENTE DI ESTREMA DESTRA, UNITI AD OVVIA BANCAROTTA E GUERRA CIVILE). COLLABORA, NON PER NIENTE, CON IL VERME ASSASSINO DANIELE MINOTTI DI RAPALLO E GENOVA, IL NOTO AVANZO DI GALERA, CAPO DEL KU KLUK KLAN, ANZI, KAPO' DEL " KU KLUK KLAN PADANO", OVVIAMENTE, ACCLARATO PEDOFILOMOSESSUALE TANTO QUANTO: PAOLO BARRAI. DELL' IMMENSAMENTE CRIMINALE BLOG MERCATO LIBERO = MERDATO LIBERO ( CON CUI, NON PER NIENTE, NON FA ALTRO CHE RICICLARE, VIA MERDOSAMENTE CRIMINALI BITCOINS, SOLDI DI COSA NOSTRA, CAMORRA, NDRANGHETA, COME FRUTTO DI LADRATE E MEGA CORRUZIONE DI LL, LEGA LADRONA, ED EX PDL, POPOLO DI LADRONI, INSIEME AL PRIMA MENZIONATO NOTO SUPER RICICLA SOLDI MAFIOSI: GIACOMO ZUCCO DEI TEA PARTIES... IL TUTTO VIA NAZIMAFIOSA PANAMA O BITCOINS STESSI http://www.ticinonews.ch/ticino/159874/lugano-panama-tre-processi-per-riciclaggio http://www.corriere.it/esteri/14_gennaio_13/panama-polizia-scopre-7-milioni-dollari-doppiofondo-otto-valigie-b0196cb8-7c5a-11e3-bc95-3898e25f75f1.shtml http://www.liberainformazione.org/2013/04/16/panama-segreto-bancario-e-narcotraffico/ http://www.repubblica.it/economia/finanza/2014/01/28/news/bitcoin_arresti_traffico_droga-77128457/ http://www.repubblica.it/economia/2014/07/09/news/bitcoin_terrorismo_riciclaggio-91119086/ ECCO UN POST CHE DIMOSTRA LA LERCISSIMA ARROGANZA NAZINDRANGHETISTA, NAZIMAFIOSA, NAZICAMORRISTA DEI MEGA LAVA CASH ASSASSINO, NONCH? ACCLARATI SCHIFOSI PEDOFILI DI FORZA ITALIA: PAOLO BARRAI, GIACOMO ZUCCO E DANIELE MINOTTI! MA CHE MOSTRA ANCHE QUANTO SIA IDIOTA, CANE IN BORSA, BRUCIA RISPARMI A RAFFICA, L'AVANZO DI GALERA PAOLO BARRAI, CHE PREVEDEVA QUI, IL BIT COIN A ANDANTE DA 700 A 70.000, MENTRE VALE 500 CIRCA! OLE'! http://ilpunto-borsainvestimenti.blogspot.be/2014/03/bitcoin-con-giacomo-zucco-stiamo-ridendo.html). TRATTASI DI VERI E PROPRI AL CAPONE MISTI AD ADOLF HITLER DELLA POLITICA (NERA E SPECIALMENTE "IN NERO")! E FINANZA! 5 CHE IMBOSCANO MEGA VALIGIE PIENE DI CONTANTE KILLER ( http://ilpunto-borsainvestimenti.blogspot.be/2014/08/il-contante-come-strumento-di-marketing.html), PRESSO CRIMINALISSIMA FINTER BANK LUGANO DI COLLETTI MALAVITOSI TANTO QUANTO: FILIPPO CRIPPA E GIOVANNI DAI CAS! A VOI IL "BANCHIERE TOPO DI FOGNA" FILIPPO M CRIPPA DI FZB FINTER ZURICH BANK LUGANO http://www.linkedin.com/pub/filippo-m-crippa/a/a09/826 A VOI IL BANCHIERE AMATISSIMO DA TUTTI I SICARI MAFIOSI DI QUESTO PIANETA: GIOVANNI DEI CAS DI FZB FINTER ZURICH BANK LUGANOhttp://www.linkedin.com/pub/giovanni-dei-cas/2/262/654 MA QUESTI MEGA RICICLAGGI DI CASH SUPER ASSASSINO, AVVENGONO ANCHE PRESSO SCHIFOSISSIMAMENTE CRIMINALE FINECO DI ALTRO BANCHIERE, NOTORIAMENTE AMATISSIMO DA COSA NOSTRA, CAMORRA E NDRANGHETA: ALESSANDRO FOTI DI FINECO BANK, BEN APPUNTO https://www.unicreditgroup.eu/it/governance/management/alessandro-foti.html COMPLICI DI STO TOPO DI FOGNA ASSASSINO E PEDOFILOMOSESSUALE, AVVOCATO DANIELE MINOTTI DI RAPALLO E GENOVA, SONO TANTISSIMI. TUTTI OVVIAMENTE DEI GIRI MAFIOSI E FASCISTI DI SILVIO BERLUSCONI! COLLABORA CON LUI UN EX "BAMBINI DI SATANA", MEGA RICICLA SOLDI ASSASSINI PRESSO BANCA CARIM RIMINI: GABRIELE SILVAGNI. COME ANCHE UN EX "BESTIE DI SATANA", FACCENDIERE MALAVITOSO: MATTEO PARDU DI LA SPEZIA http://www.linkedin.com/pub/matteo-pardu/20/588/906 OLTRE CHE UNA VERME CHE MEGA TRUFFA VIA WEB E FA SEMPRE PERDERE TUTTI I RISPARMI DI OGNI BOCCALONE DA LUI ACCALAPPIATO, BASTARDISSIMO CRIMINALE FEDERICO IZZI DI ROMA. NOTO COME ZIO ROMOLO! VICINO AD ENRICO NICOLETTI, NOTO MALAVITOSO BANCHIERE DELLA BANCA DELLA MAGLIANA http://www.agoravox.it/Arrestato-Enrico-Nicoletti-il.html E AI CRUDELISSIMI ASSASSINI "CASALESI", VIA, NOTORIAMENTE, MEGA OMICIDA FAMIGLIA CAMORRISTA DEI BARDELLINO http://www.ilfattoquotidiano.it/2011/12/10/affari-politici-camorra-formia-avamposto-laziale-casalesi/176674/ PRESSO FORMIA E LATINA ( NON PER NIENTE, DI LATINA, SONO ANCHE I CRIMINALI SCARSI, "SCARSI" IN UMANITA' IN PRIMIS: I SCARSI SONO UNA FAMIGLIA DI DELINQUENTI MOSTRUOSI, SOCI DI QUESTO AL CAPONE DELLA FINANZA, BRUCIA RISPARMI A TONNELLATE, AVANZO DI GALERA FEDERICO IZZI "ZIO ROMOLO"... E PARLO DEL NOTO PEDOFILO, STRAPPA E VENDI ORGANI DI BAMBINI, GINECOLOGO ASSASSINO ALESSANDRO SCARSI, GIA' VARIE VOLTE FINITO IN GALERA http://archiviostorico.corriere.it/2003/febbraio/15/Ginecologo_sfruttatore_co_10_0302151733.shtml E SUO FIGLIO, MEGA RICICLA SOLDI DI CAMORRA, NDRANGHETA E MAFIA: ANDREA SCARSI DI BANCA IFIGEST http://it.linkedin.com/pub/andrea-scarsi/9/4a/67a). VI SONO COME COMPLICI ANCHE DUE LERCIE BALDRACCHE NAZIFASCISTE: ELISA COGNO E PIERA CLERICO DI FRUIMEX ALBA. TRATTASI DI BATTONE PIENE DI SIFILIDE (LA PRIMA FIGLIA DELLA SECONDA) CHE FACEVANO CENTINAIA DI ORGE AD (H)AR(D)CORE (INSIEME.. BAGASCIONE MADRE E FIGLIA... CHE SCHIFO... PUAH) E RICICLANO "BERLUSCONIANISSIMAMENTE" MONTAGNE DI CASH ASSASSINO, VIA LORO SUPER MALAVITOSA FRUIMEX DI ALBA http://it.linkedin.com/pub/elisa-alba-elisa-fruimex/1b/25b/212 COME SCHIFOSO COMPLICE E' ANCHE UN TERRORISTA DI ESTREMISSIMA DESTRA, UNA MERDACCIA DI SERVIZI SEGRETI DEVIATISSIMI, ANCHE LUI, NOTO PEDOFILO ASSASSINO: MAURIZIO BARBERO DI ALBA, PURE, E DI TECHNOSKY MONTESETTEPANI http://it.linkedin.com/pub/maurizio-barbero/8/197/a52 PER NON DIRE POI DEL VERME MEGA RICICLATORE DI SOLDI MAFIOSI GIANPIERO SAMORI', SUPER ATTIVO DA DECENNI A FAR CRIMINI ECONOMICI A PALLONE A CURACAO, PER FRANCESCO CORALLO E SILVIO BERLUSCONI: ALIAS COSA NOSTRA, CAMORRA E NDRANGHETA COME AL SOLITO! http://www.corriere.it/politica/12_novembre_19/affari-samori-tra-san-marino-curacao-gerevini_b46c36fc-3213-11e2-942f-a1cc3910a89d.shtml http://ronaldwederfoort.blogspot.fr/2014/01/curacao-italian-sicilian-mafia.html A FRA NON MOLTO PER OCEANI DI ALTRI DETTAGLI. 6 PS1 STO AVANZO DI GALERA, AVVOCATO NAZINDRANGHETISTA DANIELE MINOTTI DEL TRIBUNALE DI CHIAVARI, FACEVA ANCHE DA COLLANTE FRA IL SUO CAMERATA PAESANO, LADRO, MEGA CORROTTO, E SPIETAMENTE MANDANTE DI OMICIDI, CLAUDIO SCAJOLA, E LA NDRANGHETA. http://www.repubblica.it/politica/2014/05/10/news/il_patto_scajola-matacena_cos_la_ndrangheta_fece_crescere_forza_italia-85725761/ ERA L'ORGANIZZATORE, LA BASTARDISSIMA MENTE DI QUESTO CODARDO, OMICIDA, MA-F-ASCISTA ATTACCO NEI CONFRONTI DI POVERI SENZA TETTO A GENOVA https://www.youtube.com/watch?v=aZIwPGqUfvE ERA "AMICO INTIMO" DEL KILLER DI SILVIO FANELLA, OVVIAMENTE, "NAZIGENOVESE" COME LUI: GIOVANNI BATTISTA CENITI! CON CUI NON PER NIENTE CONDIVIDEVA TRAME MEGA KILLER, ANCHE INTERNAZIONALI, PRESSO PARECCHIE CASA POUND, SPECIE DI ZONA VERBANIA: http://www.ilfattoquotidiano.it/2014/07/17/omicidio-fanella-la-rete-nera-di-ceniti-dal-trentino-al-kosovo/1060862/ http://roma.repubblica.it/cronaca/2014/07/04/news/mokbel_fanella_e_ceniti_ecco_il_giro_d_affari_dell_estrema_destra-90638562/ MEGLIO MORTI CHE ARRESI! CHE SIA 25 APRILE 1945 BIS! I NUOVI PARTIGIANI ( E NON CERTO, NAZIMAFIOSI KILLER "PAR-TEA"GIANI)! DA BRUXELLES, LONDON, RIO DE JANEIRO, MANAGUA (OVE TIFIAMO PER UN NUOVO VINCENTISSIMO CANALE OCEANO-PACIFICO "DI CENTRO-SINISTRA" PER SURCLUSSARE QUELLO MA-F-ASCISTA DI PANAMA DEI BASTARDI CRIMINALISSIMI VALTER LAVITOLA, RICARDO MARTINELLI, PAOLO BARRAI, SILVIO BERLUSCONI E NOTO AMBASCIATORE DI "COSA NOSTRA, CAMORRA E NDRANGHETA" GIANCARLO MARIA CURCIO http://www.globalist.it/Detail_News_Display?ID=2828), SAN JOSE DI COSTARICA, HABANA VIEJA, CARACAS ( OVE STIAMO PREPARANDO UN FORTISSIMO RECUPERO ECONOMICO E SOCIALE), ACCRA, JOHANNESBURG, PECHINO, TORONTO, NEW YORK ( QUELLA DEL GRANDISSIMO DEMOCRAT, PROSSIMAMENTE, US PRESIDENT: BILL DE BLASIO)! PS2 E CHE SIA CHIARO, IO NON SON PER NULLA GENIO, RE MIDA ED EROE CIVILE MICHELE NISTA. NON LO SONO, ANCHE SE LO VORREI DI CERTO ESSERE, VISTO IL SUO ECCEZIONALE GENIO E FIUTO. DA ASSOLUTI NUMERI UNO AL MONDO. E CHE VEDREI BENISSIMO SULLA SEGGIOLA DI STO CESSO NAZISTA E NDRANGHETISTA DI MATTEO RENZI, CORROTTISSIMO DA SILVIO BERLUSCONI, PER FARE LEGGI, E PRENDERE DECISIONI, PRO, QUEST'ULTIMA "FASCIOCAMORRISTAM ED PEDOFILAM PERSONAM". DA POSIZIONE DI FINTISSIMO CENTRO SINISTRA, CHE E' ORMAI, IN REALTA', ESTREMISSIMA DESTRA. CERCANDO COSI' DI FREGARE TUTTI ( DA APPOSTAZIONE INASPETTATA)! SGOZZANDO A MORTE, DEMOCRAZIA, GIUSTIZIA, E LIBERTA'. NON SONO GENIO, RE MIDA ED EROE CIVILE MICHELE NISTA, CHE, MAI DIMENTICHIAMOCI, PERO', OVUNQUE IN VITA SUA ABBIA MESSO LE MANI, HA SEMPRE, SEMPRE E STRA SEMPRE, RESO LE PIETRE, ORO. COME QUANDO CIRCA VENTENNE, PREVEDETTE E CON TRE MESI DI ANTICIPO IL MEGA CROLLO DEL DOW JONES DELL'OTTOBRE 1987. AVVENUTO POI PUNTUALISSIMAMENTE, FRA LO SHOCK DI TUTTI, IN BORSA, A MILANO, CHE LO INIZIARONO A CHIAMARE "IL PROFETA" ( ED INTANTO SI STRAPPAVANO DALLE MANI, MICHELE STESSO, DA UN POSTO DI LAVORO ALL'ALTRO, IN QUANTO RENDEVA SEMPRE, DESKS CHE FACEVANO ZERO PROFITTI, MILIARDARIE, PUR SE IN LIRE, UN ANNO DOPO.. DA QUI IL PASSAGGIO DEL SUO NICK, COL TEMPO, DA "PROFETA" A "RE MIDA".. E SENZA MAI CHE GIOCASSE SPORCO, SENZA MAI CHE CORROMPESSE O ELUDESSE UNA LIRA, CHE UNA, DI TASSE). A SEGUIRE, MICHELE PREVEDETTE ALLA PERFEZIONE IL MEGA RIALZO DEL DOW JONES DELL'ERA BILL CLINTON, IL CROLLO DEL NASDAQ CON L'ARRIVO ABUSIVISSIMO, FIGLIO DI MEGA FRODI ELETTORALI, DI "ADOLF HITLER - GEORGE [WC] BUSH". E SPECIALMENTE, QUI, ANTICIPANDO IL TUTTO VIA INTERNET, DAVANTI AGLI OCCHI DEL MONDO INTERO, MICHELE URLO' NEL SETTEMBRE 2007 CHE IL DOW JONES SAREBBE CROLLATO DA 13400 A 6900 ENTRO UN SOLO ANNO! TUTTI A DARGLI DEL MATTO, MA IL DOW JONES UN ANNO DOPO VALEVA ESATTAMENTE 6900! LI TUTTI A DARGLI DEL GENIO! 7 COME PREVEDETTE ALLA PERFEZIONE IL PIU' CHE RADDOPPIO DEL DOW JONES NELL'ERA DELL'AMMIRABILE OBAMA BARACK ( RIALZO DA LUI PREVISTO, SEMPRE DAVANTI AGLI OCCHI DEL MONDO INTERO, DI NUOVO, VIA INTERNET, BEN SEI MESI PRIMA DI QUANDO INIZIO' A VERIFICARSI: DA LUI ANTICIPATO NEL OTTOBRE 2008, VERIFICATOSI NEL MARZO 2009, ESATTAMENTE, NEL PERIODO DA LUI PREVISTO SEI MESI PRIMA). E DA APRILE 2014, RIPETO, DA APRILE 2014, MICHELE HA DETTO A TUTTI "NOI", CHE IL DOW JONES SAREBBE SALITO ANCORA, MA PER POI MINICROLLARE NELLA PARTE FINALE DEL LUGLIO 2014: ACCADUTO AL MILLESIMO. E "NOI" SAPPIAMO GIA' ANCHE DOVE SARA' IL DOW JONES ALLE PROSSIME ELEZIONI USA DEL 2016. E SIAMO CERTI CHE SARA' ESATTISSIMAMENTE LI, OVE CE LO HA DETTO LUI: GENIO, RE MIDA ED EROE CIVILE MICHELE NISTA. CON LUI SI VINCE SEMPRE E STRA SEMPRE, ALTRO CHE POR-C-ORROTTO BERLUSCONICCHIO SGOZZA DEMOCRAZIA, GIUSTIZIA E LIBERTA', PROVETTO DITTATORE PAZZO: MATTEO RENZI. IL VERME RISDOGANATORE DEL BASTARDAMENTE ASSASSINO, BERLUSCONISMO, OSSIA MAFIA, CAMORRA, NDRANGHETA, FASCISMO E PEDOFILIA, A PALAZZO CHIGI! PUAH!!!!!!!!!!! From torriem at gmail.com Sun Sep 28 14:09:17 2014 From: torriem at gmail.com (Michael Torrie) Date: Sun, 28 Sep 2014 12:09:17 -0600 Subject: Want to win a 500 tablet? In-Reply-To: References: Message-ID: <54284ECD.8000601@gmail.com> On 09/26/2014 05:03 PM, Seymore4Head wrote: > On Fri, 26 Sep 2014 18:55:54 -0400, Seymore4Head > wrote: > >> I am taking "An Introduction to Interactive Programming in Python" at >> coursera.org. From their announcments page: >> >> Week one of the video contest is open >> >> For those of you that are interested in helping your peers, the >> student video tutorial competition is an excellent opportunity. The >> week one submission thread is up in the "student video tutorial >> forum." Feel free to browse the current tutorials or make your own. >> The deadline for submission of this week's videos is 23:00 UTC on >> Thursday. The overall winner of this competition will receive a $500 >> tablet computer so give it a try if you are interested! > > BTW this was the most informative tutorial I found. > https://www.youtube.com/watch?v=LpTzLnryDq8 I personally find that video tutorials don't work for me at all. Give me a web page any day that I can read and re-read at my own pace (fast or slow). From torriem at gmail.com Sun Sep 28 14:11:57 2014 From: torriem at gmail.com (Michael Torrie) Date: Sun, 28 Sep 2014 12:11:57 -0600 Subject: tkinter and gtk problem In-Reply-To: References: Message-ID: <54284F6D.5050801@gmail.com> On 09/26/2014 12:15 PM, Paula Estrella wrote: > Hello, we are working on ubuntu 12.04 LTS; we use gtk to take screenshots > and we added a simple interface to select a file using tkFileDialog but it > doesn't work; is it possible that tkinter and gtk are incompatible? a test > script to open a file with tkFileDialog works fine but if we import gtk > even if we don't use it, the dialog box doesn't respond to mouse events > anymore; if we comment the import gtk it does work .... > > Anyone knows what might be going on or how to solve that? Just use the Gtk to show a file dialog box. As dieter says, you can't mix event loops easily across multiple platforms. You might be able to set up a gtk timer or idle event to pump the tkinter event loop manually, but that's probably overly complicated and prone to failure. PyGtk isn't that much harder to learn and work with than tkinter. From fabien.maussion at gmail.com Sun Sep 28 15:26:52 2014 From: fabien.maussion at gmail.com (Fabien) Date: Sun, 28 Sep 2014 21:26:52 +0200 Subject: Question about uninstallation. References: Message-ID: On 28.09.2014 03:07, Gregory Johannes-Kinsbourg wrote: > both Python 2 & 3 (I?m on OS X 10.10 btw) and first of all was curious to know if they will clash I am also quite new to the python business, and had the same kind of questions (how to install/uninstall a package, will different versions clash, should I use "pip install" or "pip3 install", etc). And then I discovered virtualenv and virtualenvwrapper and everything was much easier. Here is a resource that helped me: http://simononsoftware.com/virtualenv-tutorial-part-2/ I don't know about mac but on linux it works like a charm Fabien From duncan.booth at invalid.invalid Sun Sep 28 16:07:31 2014 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 28 Sep 2014 20:07:31 GMT Subject: Storage Cost Calculation References: <542760e9$0$13012$c3e8da3$5496439d@news.astraweb.com> <542776aa$0$13001$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > The Model B supported more graphics modes, had a six-pin DIN connector > for a monitor (both the A and B had UHF output for connecting to a > television, but only the B supported a dedicated monitor), had support > for an optional floppy disk controller and even an optional hard drive > controller. It also had RS-232 and Centronics parallel interfaces, a > 20-pin "user port" for I/O, and even support for a second CPU! The > Model A didn't support any of those. I won't disagree with most of those, but the graphics modes were simply a function of the available memory as RAM was shared between programs and graphics. The model A couldn't do the higher resolution graphics modes as they took too much out of the main memory (up to 20k which would have been tricky with 16k total RAM). > At the time, the BBC Micro memory was (I think) expandable: the Model > B could be upgraded to 128K of memory, double what Bill Gates > allegedly said was the most anyone would ever need. (He probably > didn't say that.) So what we need is to find out what an upgrade would > have cost. The memory expansion in the original BBC Micro was mostly ROM. The total addressable space was 64k, but 16k of that was the Acorn operating system and another 16k was paged ROM: by default you got BBC Basic but you could install up to 4 16k ROMs for languages such as BCPL or Logo or to drive external processor cards. That isn't to say of course that you couldn't expand the RAM: a company I worked for in the 80s that wrote the BCPL and Logo ROMs also manufactured a 1MB RAM card with battery backup. Later on the B+ had 64k of RAM and the B+128 had 128k of RAM and in each case the additional RAM was paged in as necessary but I don't think the RAM in the B was ever expandable. -- Duncan Booth From nad at acm.org Sun Sep 28 19:17:08 2014 From: nad at acm.org (Ned Deily) Date: Sun, 28 Sep 2014 16:17:08 -0700 Subject: Question about uninstallation. References: <22CC0B3F-BD80-475A-A452-7DC03DF75200@gmail.com> Message-ID: In article , Chris Angelico wrote: > On Sun, Sep 28, 2014 at 11:07 AM, Gregory Johannes-Kinsbourg > wrote: > > Anyway, I?ve basically ended up installing both Python 2 & 3 (I?m on OS X > > 10.10 btw) and first of all was curious to know if they will clash with > > each when being used in terminal and how do i safely remove 3 (figure i?ll > > learn 2 first, then re-install 3). According to the manual I should remove > > the files from the application folder (fair enough) but also the framework > > (surely I should leave that for python 2?) > They shouldn't clash. You'll invoke one as python2 and the other as > python3. However, as Yosemite hasn't been released yet, you may find > that you have problems that nobody's run into yet. To get a better > understanding of Python, separately from any OS X issues, you may want > to make yourself a Linux computer to test on - it's usually not hard > to install a virtualization system and create a Linux machine inside > your Mac (or just get an actual physical machine). There have been > some issues with OS X and Python, in various versions; not being a Mac > person myself, I can't say what the least problematic version is. That's odd advice. There's no need to install Linux to run Python on OS X; it works perfectly fine there and is fully supported there. Python 2 and Python 3 co-exist just fine on OS X, actually, with Python framework builds as is provided by python.org installers, even better than on Linux as scripts are installed to separate bin directories for Py2 and Py3. And, while OS X 10.10 Yosemite is still a few weeks away from its expected official release data, you can be sure that the current releases of Python have been tested with the public beta and with developer previews. The most recent release of Python 2 (2.7.8) and the upcoming release of Python 3.4.2 (3.4.2rc1 is now available for testing) should fully support Yosemite. There are some minor issues with older binary versions centering around building extension modules if you need full universal support; most people don't. There are somewhat more serious issues if you try to build older versions of Python from source. For more details, see http://bugs.python.org/issue21811. I know that MacPorts has backported these fixes to their older versions of Python, if you need them; no idea about other third-party distributors. -- Ned Deily, nad at acm.org From rosuav at gmail.com Sun Sep 28 19:34:55 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 29 Sep 2014 09:34:55 +1000 Subject: Question about uninstallation. In-Reply-To: References: <22CC0B3F-BD80-475A-A452-7DC03DF75200@gmail.com> Message-ID: On Mon, Sep 29, 2014 at 9:17 AM, Ned Deily wrote: > That's odd advice. > ... And, while OS X 10.10 Yosemite is still a few weeks away from its > expected official release data, you can be sure that the current > releases of Python have been tested with the public beta and with > developer previews. It's due to the issues there've been in the past. How can someone who doesn't know Python be sure of whether an issue is due to the mess that can happen when two Pythons are installed from different places (the system Python and homebrew, as is often the case), or is actually an attribute of Python? Also, I didn't know Yosemite was that close, so I thought it was still more in flux. So maybe my concerns were a little ... well, overcautious. If someone's willing to state with some degree of confidence that Python X.Y.Z will work perfectly on OS X 10.10, then there's no problem. ChrisA From nad at acm.org Sun Sep 28 20:01:47 2014 From: nad at acm.org (Ned Deily) Date: Sun, 28 Sep 2014 17:01:47 -0700 Subject: Question about uninstallation. References: <22CC0B3F-BD80-475A-A452-7DC03DF75200@gmail.com> Message-ID: In article , Chris Angelico wrote: > On Mon, Sep 29, 2014 at 9:17 AM, Ned Deily wrote: > > That's odd advice. > > ... And, while OS X 10.10 Yosemite is still a few weeks away from its > > expected official release data, you can be sure that the current > > releases of Python have been tested with the public beta and with > > developer previews. > It's due to the issues there've been in the past. How can someone who > doesn't know Python be sure of whether an issue is due to the mess > that can happen when two Pythons are installed from different places > (the system Python and homebrew, as is often the case), or is actually > an attribute of Python? It's pretty easy to avoid such issues: pick one Python instance of each version (2 and 3) and stick with it, be it one of the system-supplied Pythons, a python.org Python, or a third-party Python like from MacPorts, homebrew, Anaconda, et al. In that respect, OS X is no different than any Linux distribution. > Also, I didn't know Yosemite was that close, so I thought it was still > more in flux. So maybe my concerns were a little ... well, > overcautious. It's good to be cautious but better to be "informed cautious". Public betas have been available since July; developer previews before that. And, while Apple has not announced an official release date yet, they have said "Fall 2014" and, given the history of recent OS X releases and the current rumor mill, one would be advised to not bet against an October release date. > If someone's willing to state with some degree of confidence that > Python X.Y.Z will work perfectly on OS X 10.10, then there's no > problem. Let's just say that I will personally be *very* sad if 2.7.8 and 3.4.2 don't work as well or better on 10.10 as they do on 10.9.x and earlier supported OS X releases. -- Ned Deily, nad at acm.org From extasia at extasia.org Sun Sep 28 20:04:20 2014 From: extasia at extasia.org (David Alban) Date: Sun, 28 Sep 2014 17:04:20 -0700 Subject: trouble building data structure Message-ID: greetings, i'm writing a program to scan a data file. from each line of the data file i'd like to add something like below to a dictionary. my perl background makes me want python to autovivify, but when i do: file_data = {} [... as i loop through lines in the file ...] file_data[ md5sum ][ inode ] = { 'path' : path, 'size' : size, } i get: Traceback (most recent call last): File "foo.py", line 45, in file_data[ md5sum ][ inode ] = { 'path' : path, 'size' : size, } KeyError: '91b152ce64af8af91dfe275575a20489' what is the pythonic way to build my "file_data" data structure above that has the above structure? on http://en.wikipedia.org/wiki/Autovivification there is a section on how to do autovivification in python, but i want to learn how a python programmer would normally build a data structure like this. here is the code so far: #!/usr/bin/python import argparse import os ASCII_NUL = chr(0) HOSTNAME = 0 MD5SUM = 1 FSDEV = 2 INODE = 3 NLINKS = 4 SIZE = 5 PATH = 6 file_data = {} if __name__ == "__main__": parser = argparse.ArgumentParser(description='scan files in a tree and print a line of information about each regular file') parser.add_argument('--file', '-f', required=True, help='File from which to read data') parser.add_argument('--field-separator', '-s', default=ASCII_NUL, help='Specify the string to use as a field separator in output. The default is the ascii nul character.') args = parser.parse_args() file = args.file field_separator = args.field_separator with open( file, 'rb' ) as f: for line in f: line = line.rstrip('\n') if line == 'None': continue fields = line.split( ASCII_NUL ) hostname = fields[ HOSTNAME ] md5sum = fields[ MD5SUM ] fsdev = fields[ FSDEV ] inode = fields[ INODE ] nlinks = int( fields[ NLINKS ] ) size = int( fields[ SIZE ] ) path = fields[ PATH ] if size < ( 100 * 1024 * 1024 ): continue ### print "'%s' '%s' '%s' '%s' '%s' '%s' '%s'" % ( hostname, md5sum, fsdev, inode, nlinks, size, path, ) file_data[ md5sum ][ inode ] = { 'path' : path, 'size' : size, } thanks, david -- Our decisions are the most important things in our lives. *** Live in a world of your own, but always welcome visitors. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sun Sep 28 20:20:20 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 29 Sep 2014 10:20:20 +1000 Subject: trouble building data structure In-Reply-To: References: Message-ID: On Mon, Sep 29, 2014 at 10:04 AM, David Alban wrote: > file_data = {} > > [... as i loop through lines in the file ...] > > file_data[ md5sum ][ inode ] = { 'path' : path, 'size' : size, } > > what is the pythonic way to build my "file_data" data structure above that > has the above structure? The easiest way would be with a defaultdict. It's a subclass of dictionary that does what you're looking for. You'd use it something like this: from collections import defaultdict file_data = defaultdict(dict) # then continue with the program as normal # including the loop and assignments that you have above Any time it's asked to look up an MD5 that doesn't exist yet, it'll create a new dictionary by calling dict(), and that sets up the next level for you. Docs are here: https://docs.python.org/2/library/collections.html#collections.defaultdict https://docs.python.org/3/library/collections.html#collections.defaultdict You can also use the setdefault() method of the regular dictionary, which makes sense if you have just a few places where you need this behaviour. ChrisA From ned at nedbatchelder.com Sun Sep 28 20:21:30 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sun, 28 Sep 2014 20:21:30 -0400 Subject: trouble building data structure In-Reply-To: References: Message-ID: On 9/28/14 8:04 PM, David Alban wrote: > i'm writing a program to scan a data file. from each line of the data > file i'd like to add something like below to a dictionary. my perl > background makes me want python to autovivify, but when i do: > > file_data = {} > > [... as i loop through lines in the file ...] > > file_data[ md5sum ][ inode ] = { 'path' : path, 'size' : size, } > > i get: > > Traceback (most recent call last): > File "foo.py", line 45, in > file_data[ md5sum ][ inode ] = { 'path' : path, 'size' : size, } > KeyError: '91b152ce64af8af91dfe275575a20489' > > what is the pythonic way to build my "file_data" data structure above > that has the above structure? > If you want file_data to be a dictionary of dictionaries, use a defaultdict: file_data = collections.defaultdict(dict) This is Python's version of autovivification. When you access a key that doesn't exist, the defaultdict will use the callable you gave it (in this case, dict) to create the new value as needed. -- Ned Batchelder, http://nedbatchelder.com From rustompmody at gmail.com Mon Sep 29 02:58:42 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 28 Sep 2014 23:58:42 -0700 (PDT) Subject: Leap year In-Reply-To: References: Message-ID: <72778568-0205-47c5-8b60-163b09823170@googlegroups.com> On Saturday, September 27, 2014 9:21:15 AM UTC+5:30, Seymore4Head wrote: > Still practicing. Since this is listed as a Pseudocode, I assume this > is a good way to explain something. That means I can also assume my > logic is fading with age. > http://en.wikipedia.org/wiki/Leap_year#Algorithm > Me trying to look at the algorithm, it would lead me to try something > like: > if year % 4 !=0: > return False > elif year % 100 !=0: > return True > elif year % 400 !=0: > return False > **** Since it is a practice problem I have the answer: > def is_leap_year(year): > return ((year % 4) == 0 and ((year % 100) != 0 or (year % 400) == 0)) > I didn't have any problem when I did this: > if year % 400 == 0: > print ("Not leap year") > elif year % 100 == 0: > print ("Leap year") > elif year % 4 == 0: > print ("Leap year") > else: > print ("Not leap year") Python has an if-expression distinct from the if-statement. However its confusing because its order is 'upside down' So below I use C's if-expression a?b:c to state some 'laws' of programming and leave it as an exercise to pythonify them a?T:F ? a A a?F:T ? not a B a?T:b ? a or b C a?b:F ? a and b D if p: E return x else: return y ? return (p ? x : y) Likewise if p F print x else print y ? print (p ? x : y) ---------------------------- Now putting: a ? y%4==0 b ? y%100!=0 c ? y%400 == 0 the expression that is the (given) answer is a and (b or c) Lets use the above laws to open it up "by C" a and (b ? T: c) "by D" a?(b?T:c):F year%4==0 ? (y%100!=0 ? T: y%400==0) : F -------------------------- Now lets take your version: if year % 400 == 0: print ("Not leap year") elif year % 100 == 0: print ("Leap year") elif year % 4 == 0: print ("Leap year") else: print ("Not leap year") And now 'de-print' it [A good idea though I wont suggest it to you again!] print (!c ? F : (b? T : (a? T : F))) Forget about the print since its irrelevant and concentrate on (!c ? F : (b? T : (a? T : F))) "by A" = (!c ? F : (b? T : a)) "by B" = (c ? (b? T : a) : F) "by D" = (c and (b?T:a) "by C" = c and (b or a) Lets re-substitute a,b,c = y%400==0 and (y%100 !=0 or y%4 == 0) which interpreted says that ONLY years divisible by 400 are leap and not even all those!! From norman.ives at gmail.com Mon Sep 29 03:36:47 2014 From: norman.ives at gmail.com (norman.ives at gmail.com) Date: Mon, 29 Sep 2014 00:36:47 -0700 (PDT) Subject: Obscuring Python source from end users Message-ID: <89381545-5edc-4f85-a4b8-86eebfdf34ee@googlegroups.com> Hello list Python 3.4 applies. I have a project that involves distributing Python code to users in an organisation. Users do not interact directly with the Python code; they only know this project as an Excel add-in. Now, internal audit takes exception in some cases if users are able to see the source code. So I'm wondering if anyone has clever suggestions in this regard... My current plan is to modify the bdist_wheel setuptools extension so that it can produce distributions with only the .pyc files, laid out so that they will be importable in the normal way. This will be sufficient to satisfy internal audit, and will not negatively impact our users. However there are obvious downsides, including the overhead of maintaining separate wheels for different architectures and (in the future) Python versions. Not to mention that this plan seems to go against the grain of how Python wants to use byte code files... Is there a better solution? From rosuav at gmail.com Mon Sep 29 03:52:43 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 29 Sep 2014 17:52:43 +1000 Subject: Obscuring Python source from end users In-Reply-To: <89381545-5edc-4f85-a4b8-86eebfdf34ee@googlegroups.com> References: <89381545-5edc-4f85-a4b8-86eebfdf34ee@googlegroups.com> Message-ID: On Mon, Sep 29, 2014 at 5:36 PM, wrote: > I have a project that involves distributing Python code to users in an organisation. Users do not interact directly with the Python code; they only know this project as an Excel add-in. > > Now, internal audit takes exception in some cases if users are able to see the source code. The solution is to fix your internal audit. There's fundamentally no way to hide the source code, and it's going to add complexity. Demonstrate that it could take you a large number of man-hours and achieve little, and just declare that the source code IS what you want. Alternatively, you could do a source-level reformat that crunches everything down as much as possible, while still producing syntactically-identical source code. Remove all the comments, shorten local names to one letter, etc. That would result in something that, while still perfectly executable, won't be nearly as helpful. It wouldn't be nice readable source code, at least. Would your audit be satisfied with that? ChrisA From wxjmfauth at gmail.com Mon Sep 29 04:27:54 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Mon, 29 Sep 2014 01:27:54 -0700 (PDT) Subject: Leap year In-Reply-To: <72778568-0205-47c5-8b60-163b09823170@googlegroups.com> References: <72778568-0205-47c5-8b60-163b09823170@googlegroups.com> Message-ID: ------ >>> def z(y): ... if y <= 1582: # or < ... return 'not a leap year, Julian calendar' ... else: ... return 'process, Gregorian calendar' ... >>> z(1300) 'not a leap year, Julian calendar' >>> z(2014) 'process, Gregorian calendar' >>> From norman.ives at gmail.com Mon Sep 29 04:41:35 2014 From: norman.ives at gmail.com (norman.ives at gmail.com) Date: Mon, 29 Sep 2014 01:41:35 -0700 (PDT) Subject: Obscuring Python source from end users In-Reply-To: References: <89381545-5edc-4f85-a4b8-86eebfdf34ee@googlegroups.com> Message-ID: <9ad69bd8-ca77-438f-adfe-87d727ca170c@googlegroups.com> Thanks for the reply! I'm not concerned about hiding the source code in a fundamental way. The condition that needs to be satisfied is that independent validators (in the organisation) must not "have access" to the source code. Crunching the source is an interesting idea that could achieve that end, but it seems fraught with problems like maintaining consistency between renaming objects in a module and renaming where imports happen. From alister.nospam.ware at ntlworld.com Mon Sep 29 04:42:18 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Mon, 29 Sep 2014 08:42:18 GMT Subject: Obscuring Python source from end users References: <89381545-5edc-4f85-a4b8-86eebfdf34ee@googlegroups.com> Message-ID: On Mon, 29 Sep 2014 00:36:47 -0700, norman.ives wrote: > Hello list > > Python 3.4 applies. > > I have a project that involves distributing Python code to users in an > organisation. Users do not interact directly with the Python code; they > only know this project as an Excel add-in. > > Now, internal audit takes exception in some cases if users are able to > see the source code. > > So I'm wondering if anyone has clever suggestions in this regard... > > My current plan is to modify the bdist_wheel setuptools extension so > that it can produce distributions with only the .pyc files, laid out so > that they will be importable in the normal way. This will be sufficient > to satisfy internal audit, and will not negatively impact our users. > > However there are obvious downsides, including the overhead of > maintaining separate wheels for different architectures and (in the > future) Python versions. Not to mention that this plan seems to go > against the grain of how Python wants to use byte code files... > > Is there a better solution? For an internal app. I would suggest it is only necessary to protect user- names & passwords to back end services (databases etc.). storing these in a separate file in an encrypted format should be enough to discourage internal users from digging deeper. This will not stop a determined hacker but neither will any other forms of obfuscation. -- new, adj.: Different color from previous model. From rosuav at gmail.com Mon Sep 29 04:55:41 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 29 Sep 2014 18:55:41 +1000 Subject: Obscuring Python source from end users In-Reply-To: <9ad69bd8-ca77-438f-adfe-87d727ca170c@googlegroups.com> References: <89381545-5edc-4f85-a4b8-86eebfdf34ee@googlegroups.com> <9ad69bd8-ca77-438f-adfe-87d727ca170c@googlegroups.com> Message-ID: On Mon, Sep 29, 2014 at 6:41 PM, wrote: > Crunching the source is an interesting idea that could achieve that end, but it seems fraught with problems like maintaining consistency between renaming objects in a module and renaming where imports happen. > Here's a technique that you could use. Pick two prefixes, one for long names and one for short names, and maintain a translation table. So, for instance, you could have two source files like this: # file1.py # Do something with the length and the count def xx_some_func(length, cnt): # TODO: Implement me. pass # file2.py import file1 def xx_foo(lst, len, count): # Do something for every element in the list # where the something is blah blah blah for element in lst: file1.xx_some_func(len, count) And then your crunched files might be: # file1.py: def x_a(a,b): pass # file2.py import file1 def x_b(a,b,c): for d in a: file2.x_a(b,c) The translation is 100% mechanical: any place you find "xx_some_func", you replace it with "x_a". If you find a string that begins "xx_" and isn't in your translation table, you construct a new name (don't forget that you can use x_A as well as x_a) and add it to the table. It ought to be possible to do an AST reconstitution for at least part of this. I can hunt down some of my PEP 463 test code to help out with that. It should be possible to figure out what names are local, and then just use those. If this is of interest, I'll see what I can knock together. ChrisA From dieffedue at gmx.com Mon Sep 29 04:56:22 2014 From: dieffedue at gmx.com (Dieffe Due) Date: Mon, 29 Sep 2014 01:56:22 -0700 (PDT) Subject: AVVOCATO PEDOFILOMOSESSUALE ED ASSASSINO DANIELE MINOTTI (FACEBOOK). OLTRE CHE NAZI, MEGALAVA EURO MAFIOSI, E, COME DETTO, MANDANTE DI OMICIDI O "SUICIDATE"! STALKER DI EROE CIVILE MICHELE NISTA SU ORDINE DI TIRANNO FASCIOCAMORRISTA SILVIO In-Reply-To: References: Message-ID: <603309a8-28ed-40cf-9086-da16cee6447f@googlegroups.com> AVVOCATO NAZIPEDOFILO DANIELE MINOTTI DI RAPALLO E GENOVA MI STUPRO' CHE AVEVO 14 ANNI! FIGLIO DI PUTTANA DI GIRI FASCIOMAFIOSI DI SILVIO BERLUSCONI. DI SUE GANGS FAN ANCHE PARTE PEDERASTA GIULIANO FERRARA DE IL FOGLIO E NOTO CRIMINALE PAOLO BARRAI! 1 Ciao tuti e scusate di mio italiano. Io sono rumeno e non me nascondo: me chiamo Stefan Cumescu. Io ora tengo 19 anni. Quindi, 5 anni fa tenevo 14 anni). E bene, cinqua anni fa avvocato di giri nazifascisti misti a Cosa Nostra, Camorra, Ndrangheta Daniele Minotti di Rapallo e Ganova, mi diede tre grammi di cocaina, mi fece svenire e mentre ero mas di morto che vivo, me sodomizzo'. Vi era anche pancione pieno di merda Giuliano Ferrara a guardare. Me sodomizzo' lui insieme ad altri sei di suoi giri fascisti e mafiosi. Ho anche prove di questo. Io, ora, Stefan Cumescu di Genova, quartiere Caruggi, facio il muratore, basta droga, basta prostituirsi. Guadanio un decimo di quanto guadaniavo prima e lavoro il triplo di quanto prima. Ma preferisco di questo, sento la mia vita uno poco di maggiore securo. Ma avvocato di Hitler, Vallanzasca e Satana, avvocato figlio di puttana di Silvio Berlusconi e Giuliano Ferrara, nazista e mafioso Daniele Minotti con studio a Genova e Rapallo, davvero fa parte di setta di pedofili assassini molto pericolosi. Ciao. Stefan. Posti Scrito Io vedevo in giro uno belo testo che parlava di tuto questo... ma ora non vedo tanto di piu' in giro lo stesso testo. Alora sai cosa facio? Di mia iniciativa facio cut and copy e provo di riproporlo io. Ciao da Stefan Cumescu e ri scusa di mio italiano... ma presto volio di fare corsi di sera di miliorarlo. Ciao. 2 OCHO AD AVVOCATO "BERLUSCONIANISSIMAMENTE", MEGA RICICLA CASH MAFIOSO, NAZIFASCISTA, ASSASSINO E PEDOFILOMOSESSUALE: DANIELE MINOTTI ( PURE SU FACEBOOK) DI RAPALLO E GENOVA! TUTTI SANNO DI SUE "FESTE" SATANISTISSIME "ATTE A SODOMIZZARE ZINGARELLI DI 6-8 ANNI (A SANREMO, CON DON RICCARDO SEPPIA E COL TANTE VOLTE CONDANNATO A GALERA, PAOLO BARRAI DEL CRIMINALISSIMO BLOG MERCATO "MERDATO" LIBERO.. MA NON SOLO... E FRA POCO.. TUTTI I NOMI E COGNOMI)!!! OCCHIO, PLS, ALL'AVVOCATO PIU' INFIMAMENTE NAZISTA, MEGA LAVA CASH MAFIOSO, MANDANTE DI OMICIDI E "SUICIDATE", E COME SE NON BASTASSE, ACCLARATO PEDOFILOMOSESSUALE, CHE ESISTA ( IL VOMITO VA' SULLA PARTE "PEDOFILO", PIU' CHE OMOSESSUALE, ANCHE SE IL MEGA SODOMIZZATORE DI BAMBINI, DANIELE MINOTTI, LO E' ENTRAMBE LE COSE; OLTRE AD ESSERE UN VERMINOSO CODARDO: METTEVA DELLE SUE FOTO CON FACCE DA ASSOLUTO PERICOLOSISSIMO MANICACO SESSUALE, SU TUTTA INTERNET... ED OVVIAMENTE, ORA, DOPO CHE LE ABBIAM FATTE NOTARE SU MIGLIAIA DI SITI, DA TOPO DI FOGNA, DETTE FOTO LE HA FATTE SUBITO IMBOSCARE)! COME SE NON BASTASSE, PURE FREQUENTISSIMO MANDANTE DI "SUICIDATE" ED OMICIDI: DANIELE MINOTTI DI GENOVA E RAPALLO. Criminalissimo Studio Legale pro Mafia, Camorra, Ndrangheta e Neonazisti assassini, di noto pedofilomosessuale Daniele Minotti :: Genova - Rapallo Via della Libert?, 4/10 - 16035 - Rapallo (GE) (Tribunale di Chiavari) Via XX Settembre, 3/13 - 16121 - Genova RICICLANTE DA ANNI CASH KILLER DEGLI EMANUELLO DI COSA NOSTRA, BASATI A GENOVA. http://www.ilsecoloxix.it/p/genova/2011/05/19/AOJ0cAV-rischio_gronda_arresti.shtml O DEI FEROCI SICARI DELLA NDRANGHETA: I RAMPINO. SEMPRE BASATI A GENOVA. http://www.ilsecoloxix.it/p/genova/2013/06/05/APjJUSgF-ndrangheta_terra_liguria.shtml BASTARDO VERO, PEDERASTA PERVERTITO DANIELE MINOTTI DI GENOVA E RAPALLO: TUTTI SANNO DELLE ORGE PEDOFILE CHE FACEVA CON DON RICCARDO SEPPIA A SANREMO. FRA SIMBOLI DEMONIACI E TERRIFICANTI SODOMIZZAZIONI DI BAMBINI DI 6-8 ANNI ( E AHIME.. FATEMI SDRAMMATIZZARE, PLS... ANCHE 6-8 ANI). BAMBINI ZINGARELLI! D'ALTRONDE, TOPI DI FOGNA CODARDI E SPIETATI COME IL CRIMINALISSIMO AVVOCATO DANIELE MINOTTI DI GENOVA CHE ALTRO AVREBBERO POTUTO RACCATTARE? IL TUTTO FRA CHILI DI COCAINA, MEGA CASH MAFIOSO, E SCIOCCANTISSIMAMENTE, DOZZINE DI TESSERE FASCIOCAMORRISTE DI FORZA ITALIA, FRATELLI D'ITALIA, CASA POUND, FIAMMA TRICOLORE E LEGA NORD. IL DAVVERO "AVVOCATO DEL DIAVOLO", IL BASTARDO MASSONE NAZISTA, IL VERME MASSO-NAZISTA ( MERDA ASSASSINA P2ISTICA PER INTENDERCI), MEGA LAVA CASH MAFIOSO, MANDANTE DI "SUICIDATE" ED OMICIDI A RAFFICA, SEMPRE INC.LANTE BAMBINI O POCO PIU' CHE BAMBINI, DANIELE MINOTTI DI GENOVA E RAPALLO, D'ALTRONDE, I PEDOFILOMOSESSUALI O PEDOFILI IN GENERE LI AMA, SE NE SENTE STRA PARTE, LI DIFENDE. NON CI CREDETE??? VOLETE FARE GLI STRUZZI, CHE PER FRATELLANZA MASSO-N-AZIFASCISTA, PREFERISCONO METTERE LA TESTA DOVE GIRANO I VERMI, SOTTO TERRA??? GIVE A LOOK RIGHT NOW, THEN, PLS:http://www.ansa.it/liguria/notizie/2014/06/20/adescava-minori-sul-web-condannato_36c57304-90aa-4c7f-8463-c7d610ed10dd.html http://iltirreno.gelocal.it/massa/cronaca/2013/04/19/news/casolare-a-luci-rosse-il-pm-7-anni-e-mezzo-all-ex-dipendente-nca-1.6917147 3 E SE GOOGLATE " DANIELE MINOTTI PEDOPORNOGRAFIA" VEDRETE CHE IN TUTTI I SUOI ARTICOLI, SOTTILISSIMAMENTE ( E MANCO TANTO, SOTTILISSIMAMENTE) DIFENDE I PEDOFILI, MINIMIZZA O ELUDE LE LORO ABERRANTI, SPEZZA VITE, COLPE! LI SUPPORTA: OVVIO, E' UN VERME SODOMIZZA BAMBINI LUI IN PRIMO! DA RINCHIUDERE IN GALERA O MANICOMIO CRIMINALE SUBITO: AVRA' GIA' UCCISO E FATTO SCOMPARIRE QUALCHE BIMBO CHE HA INCULATO! O PRESTO LO FARA'! QUI SALVIAMO VITE DI PICCOLISSIME CREATURE CON QUESTI SCRITTI!!! SALVIAMO IL MONDO!!! MA TORNIAMO ORA A STO, PURE TERRORISTA NERO ( ED IN NERO), COME CITATO, FREQUENTE MANDANTE DI OMICIDI, "SUICIDATE" O TERRIFICANTI ISTIGAZIONI AL SUICIDIO: DANIELE MINOTTI DI RAPALLO E GENOVA. DA TANTISSIMI ANNI, VIA VARI CODARDI NICKS, MINACCIANTE MORTE E FACENTE KILLING STALKING A GENIO, SORT OF RE MIDA ED EROE CIVILE MICHELE NISTA, SU CERTISSIMO ORDINE DI AL CAPONE MISTO AD ADOLF HITLER: SILVIO BERLUSCONI ( VIA SUOI CA-N-AZISTI GIULIANO FERRARA, MAURIZIO BELPIETRO, DANIELA GARNERO "SANTANCHE'" E/O ALTRI TOPASTRI DI FOGNA CON SVASTICA AL BRACCIO, DEL CASO). IN QUANTO IL SEMPRE VINCENTISSIMO MICHELE NISTA DIEDE AL CANCRO DEL MONDO INTERO, SILVIO BERLUSCONI, GIUSTAMENTE, DEL DITTATORE, DURANTE UNA TELEFONATA I DUE EBBERO MOLTI ANNI FA. A SEGUITO DI QUESTO, IL COLLETTO LERCISSIMAMENTE INTRISO DI MAFIA, CAMORRA, NDRANGHETA, NAZIFASCISMO, PEDOFILIA, SUOI ORDINI DI OMICIDI E STRAGI, SILVIO BERLUSCONI, FECE DI TUTTO PER DISTRUGGERE LA POSIZIONE DI MICHELE NISTA DI QUASI NUMERO UNO DELLA BORSA DI MILANO, NEGLI ANNI 90. COI METODI PIU' CRIMINALI E VIGLIACCHI POSSIBILE! NON RIUSCENDOLO A DISTRUGGERE PROFESSIONALMENTE ( ESSENDO MICHELE NISTA IN FIUTO BORSISTICO, POLITICO ED INVESTIGATIVO, MOLTO PROBABILMENTE, IL NUMERO UNO DI TUTTO IL PIANETA TERRA), CI RIUSCI' "SOLO" AMMAZZANDOGLI IL PADRE ( CON BASTARDISSIMAMENTE ASSASSINO "METODO FERRULLI") E CERCANDO POI DI UCCIDERE MICHELE, "SOLO" ALTRE 4 VOLTE ( FACENDOGLI SPARIRE I FRENI ANDANDO IN AUTOSTRADA AD OLTRE 120 KM ALL'ORA, PER " SOLO" 3 VOLTE, STESSO MODO CON CUI SILVIO BERLUSCONI FECE AMMAZZARE I GENITORI DI CLEMENTINA FORLEO https://it.answers.yahoo.com/question/index?qid=20100118105650AAhOMTQ RIPETENDO LO STESSO, POI, CON CLEMENTINA FORLEO STESSA http://www.leiweb.it/celebrity/personaggi-news/10_a_clementina-forleo-strani-incidenti.shtml http://straker-61.blogspot.be/2009/12/il-giudice-forleo-coinvolto-in-un.html E IN UN QUARTO CASO, ATTRAVERSO UN AGGUATO FISICO, PREPARATO IN OGNI DETTAGLIO, DA POI FAR PASSARE PER MALORE, COME ACCADUTO COL GRANDE PAPA' DI MICHELE: NOTO " ASSASSINO BERLUSCONIANISSIMO "METODO FERRULLI" http://ricerca.repubblica.it/repubblica/archivio/repubblica/2014/07/06/da-aldrovandi-a-ferrulli-la-stessa-follia-degli-agenti16.html)! VIA VARIE OVRA E GESTAPO PUBBLICHE E PRIVATE DEL, NON SI DICE MAI ABBASTANZA, MEGA MANDANTE DI OMICIDI E STRAGI, BASTARDISSIMO, SPIETATO ASSASSINO SILVIO BERLUSCONI ( NON PER NIENTE LO STESSO VOLEVA " DISARTICOLARE CON TRAUMA", OSSIA U-C-C-I-D-E-N-D-O E FACENDO SEMBRARE IL TUTTO, FINTISSIMI INCIDENTI, INFARTI O SUICIDI, CHI NON SOTTO LE SUE SUOLE ALTE COME QUELLE DEI PAGLIACCI SU TRAMPOLI, A CUI ASSOMIGLIA IN TUTTO http://www.grnet.it/news/95-news/852-segreto-di-stato-sulle-schedature-illegali-berlusconi-salva-pollari-a-pompa.html ... MA TORNEREMO SU QUESTO CON MILIONI DI BLOGS, DOVESSIMO MORIRE DI INFARTO SU UNA TASTIERA, OGGI STESSO). PASSIAMO DI NUOVO, ORA, PLEASE, A UNO DEI SICARI KILLER DI SILVIO BERLUSCONI: L'AVVOCATO OMICIDA E PEDOFILOMOSESSUALE DANIELE MINOTTI (OLTRE CHE NAZI E MEGALAVA EURO MAFIOSI)! 4 INCITA I VERMI DI ESTREMISSIMA DESTRA COME LUI, DI TUTTO IL MONDO, I KAMERADEN KILLER DEI TEA PARTIES, AD UCCIDERE, PRIMA CIVILMENTE E PROFESSIONALMENTE, POI, SE NON "ABBASTANZA INTIMIDITI', DEL TUTTO, CHIUNQUE CRITICHI "TROPPO" I SUO LIDER MAXIMI (LIDER MAXIMI IN TUTTO, SPECIE IN PEDOFILIA, FASCIOCAMORRA ED ORDINI DI OMICIDI E STRAGI): SILVIO BERLUSCONI E LICIO GELLI (CITATI NAZIMAFIOSI DEI TEA PARTIES DI CUI E' STRA PARTE, L'INCULA BAMBINI DANIELE MINOTTI DI GENOVA E RAPALLO, INSIEME AD ALTRO VERME CRIMINALISSIMO: GIACOMO ZUCCO, OVVIAMENTE, PURE LUI, MEGA LAVA SOLDI DI COSA NOSTRA, CAMORRA E NDRANGHETA, SPECIE VIA BITCOINS, ED ESSENDO "BERLUSCONES CLASSIC E NON SPECIAL", PURE LUI NOTO PEDOFILOMOSESSUALE)! CON IL QUALE CONDIVIDE PURE, UNA, DA VOMITARE ANCHE LA BILE, TESSERA DEI PEDERASTA CHE "SON ORGOGLIOSI DI FAR SESSO CON BAMBINI", QUELLA DELL'ORGOGLIO PEDOFILO, OSSIA QUELLA DEI "North American Man-Boy Amore Association" http://www.today.it/rassegna/giornata-orgoglio-pedofilo.html STO PUTRIDISSIMO TOPO DI FOGNA DI DANIELE MINOTTI DEL FORO DI CHIAVARI ( ALTRA SDRAMMATIZZAZIONE, PLS: CHIAVARI, SI, E' DI CERTO LA COSA PIU' BELLA AL MONDO, MA ANCHE LA PIU' BRUTTA, QUANDO LO SI FA DEPRAVATISSIMAMENTE CON I BAMBINI, COME FA SEMPRE STO ESCREMENTOSO PEDERASTA DI DANIELE MINOTTI DI RAPALLO E GENOVA) E' OVVIAMENTE PURE UN BASTARDO RAZZISTA. AUSPICA LA MORTE SOCIALE, " MA ANCHE NON SOLO.. ANCHE TOTALISSIMA" ... DI CHIUNQUE NATO SOTTO LA VERMINOSAMENTE PIDUISTICA AREZZO (DA DOVE VENGONO, NON PER NIENTE, PURE LA BAGASCIONA PREFERITA DA LICIO GELLI, MARIA ELENA BOSCHI.. E SUO PADRE, PORCO SCHIFOSO BANCHIERE DI COSA NOSTRA, CAMORRA E NDRANGHETA, PIER LUIGI BOSCHI DI BANCA ETRURIA... CHE CON LE LORO "RIFORME IMPOSTE DA HITLERIANISSIMA WILLA WANDA", PORTERANNO IL PAESE A NUOVE SVASTICHE, A NUOVI REGIMI ASSASSINISSIMAMENTE DI ESTREMA DESTRA, UNITI AD OVVIA BANCAROTTA E GUERRA CIVILE). COLLABORA, NON PER NIENTE, CON IL VERME ASSASSINO DANIELE MINOTTI DI RAPALLO E GENOVA, IL NOTO AVANZO DI GALERA, CAPO DEL KU KLUK KLAN, ANZI, KAPO' DEL " KU KLUK KLAN PADANO", OVVIAMENTE, ACCLARATO PEDOFILOMOSESSUALE TANTO QUANTO: PAOLO BARRAI. DELL' IMMENSAMENTE CRIMINALE BLOG MERCATO LIBERO = MERDATO LIBERO ( CON CUI, NON PER NIENTE, NON FA ALTRO CHE RICICLARE, VIA MERDOSAMENTE CRIMINALI BITCOINS, SOLDI DI COSA NOSTRA, CAMORRA, NDRANGHETA, COME FRUTTO DI LADRATE E MEGA CORRUZIONE DI LL, LEGA LADRONA, ED EX PDL, POPOLO DI LADRONI, INSIEME AL PRIMA MENZIONATO NOTO SUPER RICICLA SOLDI MAFIOSI: GIACOMO ZUCCO DEI TEA PARTIES... IL TUTTO VIA NAZIMAFIOSA PANAMA O BITCOINS STESSI http://www.ticinonews.ch/ticino/159874/lugano-panama-tre-processi-per-riciclaggio http://www.corriere.it/esteri/14_gennaio_13/panama-polizia-scopre-7-milioni-dollari-doppiofondo-otto-valigie-b0196cb8-7c5a-11e3-bc95-3898e25f75f1.shtml http://www.liberainformazione.org/2013/04/16/panama-segreto-bancario-e-narcotraffico/ http://www.repubblica.it/economia/finanza/2014/01/28/news/bitcoin_arresti_traffico_droga-77128457/ http://www.repubblica.it/economia/2014/07/09/news/bitcoin_terrorismo_riciclaggio-91119086/ ECCO UN POST CHE DIMOSTRA LA LERCISSIMA ARROGANZA NAZINDRANGHETISTA, NAZIMAFIOSA, NAZICAMORRISTA DEI MEGA LAVA CASH ASSASSINO, NONCH? ACCLARATI SCHIFOSI PEDOFILI DI FORZA ITALIA: PAOLO BARRAI, GIACOMO ZUCCO E DANIELE MINOTTI! MA CHE MOSTRA ANCHE QUANTO SIA IDIOTA, CANE IN BORSA, BRUCIA RISPARMI A RAFFICA, L'AVANZO DI GALERA PAOLO BARRAI, CHE PREVEDEVA QUI, IL BIT COIN A ANDANTE DA 700 A 70.000, MENTRE VALE 500 CIRCA! OLE'! http://ilpunto-borsainvestimenti.blogspot.be/2014/03/bitcoin-con-giacomo-zucco-stiamo-ridendo.html). TRATTASI DI VERI E PROPRI AL CAPONE MISTI AD ADOLF HITLER DELLA POLITICA (NERA E SPECIALMENTE "IN NERO")! E FINANZA! 5 CHE IMBOSCANO MEGA VALIGIE PIENE DI CONTANTE KILLER ( http://ilpunto-borsainvestimenti.blogspot.be/2014/08/il-contante-come-strumento-di-marketing.html), PRESSO CRIMINALISSIMA FINTER BANK LUGANO DI COLLETTI MALAVITOSI TANTO QUANTO: FILIPPO CRIPPA E GIOVANNI DAI CAS! A VOI IL "BANCHIERE TOPO DI FOGNA" FILIPPO M CRIPPA DI FZB FINTER ZURICH BANK LUGANO http://www.linkedin.com/pub/filippo-m-crippa/a/a09/826 A VOI IL BANCHIERE AMATISSIMO DA TUTTI I SICARI MAFIOSI DI QUESTO PIANETA: GIOVANNI DEI CAS DI FZB FINTER ZURICH BANK LUGANOhttp://www.linkedin.com/pub/giovanni-dei-cas/2/262/654 MA QUESTI MEGA RICICLAGGI DI CASH SUPER ASSASSINO, AVVENGONO ANCHE PRESSO SCHIFOSISSIMAMENTE CRIMINALE FINECO DI ALTRO BANCHIERE, NOTORIAMENTE AMATISSIMO DA COSA NOSTRA, CAMORRA E NDRANGHETA: ALESSANDRO FOTI DI FINECO BANK, BEN APPUNTO https://www.unicreditgroup.eu/it/governance/management/alessandro-foti.html COMPLICI DI STO TOPO DI FOGNA ASSASSINO E PEDOFILOMOSESSUALE, AVVOCATO DANIELE MINOTTI DI RAPALLO E GENOVA, SONO TANTISSIMI. TUTTI OVVIAMENTE DEI GIRI MAFIOSI E FASCISTI DI SILVIO BERLUSCONI! COLLABORA CON LUI UN EX "BAMBINI DI SATANA", MEGA RICICLA SOLDI ASSASSINI PRESSO BANCA CARIM RIMINI: GABRIELE SILVAGNI. COME ANCHE UN EX "BESTIE DI SATANA", FACCENDIERE MALAVITOSO: MATTEO PARDU DI LA SPEZIA http://www.linkedin.com/pub/matteo-pardu/20/588/906 OLTRE CHE UNA VERME CHE MEGA TRUFFA VIA WEB E FA SEMPRE PERDERE TUTTI I RISPARMI DI OGNI BOCCALONE DA LUI ACCALAPPIATO, BASTARDISSIMO CRIMINALE FEDERICO IZZI DI ROMA. NOTO COME ZIO ROMOLO! VICINO AD ENRICO NICOLETTI, NOTO MALAVITOSO BANCHIERE DELLA BANCA DELLA MAGLIANA http://www.agoravox.it/Arrestato-Enrico-Nicoletti-il.html E AI CRUDELISSIMI ASSASSINI "CASALESI", VIA, NOTORIAMENTE, MEGA OMICIDA FAMIGLIA CAMORRISTA DEI BARDELLINO http://www.ilfattoquotidiano.it/2011/12/10/affari-politici-camorra-formia-avamposto-laziale-casalesi/176674/ PRESSO FORMIA E LATINA ( NON PER NIENTE, DI LATINA, SONO ANCHE I CRIMINALI SCARSI, "SCARSI" IN UMANITA' IN PRIMIS: I SCARSI SONO UNA FAMIGLIA DI DELINQUENTI MOSTRUOSI, SOCI DI QUESTO AL CAPONE DELLA FINANZA, BRUCIA RISPARMI A TONNELLATE, AVANZO DI GALERA FEDERICO IZZI "ZIO ROMOLO"... E PARLO DEL NOTO PEDOFILO, STRAPPA E VENDI ORGANI DI BAMBINI, GINECOLOGO ASSASSINO ALESSANDRO SCARSI, GIA' VARIE VOLTE FINITO IN GALERA http://archiviostorico.corriere.it/2003/febbraio/15/Ginecologo_sfruttatore_co_10_0302151733.shtml E SUO FIGLIO, MEGA RICICLA SOLDI DI CAMORRA, NDRANGHETA E MAFIA: ANDREA SCARSI DI BANCA IFIGEST http://it.linkedin.com/pub/andrea-scarsi/9/4a/67a). VI SONO COME COMPLICI ANCHE DUE LERCIE BALDRACCHE NAZIFASCISTE: ELISA COGNO E PIERA CLERICO DI FRUIMEX ALBA. TRATTASI DI BATTONE PIENE DI SIFILIDE (LA PRIMA FIGLIA DELLA SECONDA) CHE FACEVANO CENTINAIA DI ORGE AD (H)AR(D)CORE (INSIEME.. BAGASCIONE MADRE E FIGLIA... CHE SCHIFO... PUAH) E RICICLANO "BERLUSCONIANISSIMAMENTE" MONTAGNE DI CASH ASSASSINO, VIA LORO SUPER MALAVITOSA FRUIMEX DI ALBA http://it.linkedin.com/pub/elisa-alba-elisa-fruimex/1b/25b/212 COME SCHIFOSO COMPLICE E' ANCHE UN TERRORISTA DI ESTREMISSIMA DESTRA, UNA MERDACCIA DI SERVIZI SEGRETI DEVIATISSIMI, ANCHE LUI, NOTO PEDOFILO ASSASSINO: MAURIZIO BARBERO DI ALBA, PURE, E DI TECHNOSKY MONTESETTEPANI http://it.linkedin.com/pub/maurizio-barbero/8/197/a52 PER NON DIRE POI DEL VERME MEGA RICICLATORE DI SOLDI MAFIOSI GIANPIERO SAMORI', SUPER ATTIVO DA DECENNI A FAR CRIMINI ECONOMICI A PALLONE A CURACAO, PER FRANCESCO CORALLO E SILVIO BERLUSCONI: ALIAS COSA NOSTRA, CAMORRA E NDRANGHETA COME AL SOLITO! http://www.corriere.it/politica/12_novembre_19/affari-samori-tra-san-marino-curacao-gerevini_b46c36fc-3213-11e2-942f-a1cc3910a89d.shtml http://ronaldwederfoort.blogspot.fr/2014/01/curacao-italian-sicilian-mafia.html A FRA NON MOLTO PER OCEANI DI ALTRI DETTAGLI. 6 PS1 STO AVANZO DI GALERA, AVVOCATO NAZINDRANGHETISTA DANIELE MINOTTI DEL TRIBUNALE DI CHIAVARI, FACEVA ANCHE DA COLLANTE FRA IL SUO CAMERATA PAESANO, LADRO, MEGA CORROTTO, E SPIETAMENTE MANDANTE DI OMICIDI, CLAUDIO SCAJOLA, E LA NDRANGHETA. http://www.repubblica.it/politica/2014/05/10/news/il_patto_scajola-matacena_cos_la_ndrangheta_fece_crescere_forza_italia-85725761/ ERA L'ORGANIZZATORE, LA BASTARDISSIMA MENTE DI QUESTO CODARDO, OMICIDA, MA-F-ASCISTA ATTACCO NEI CONFRONTI DI POVERI SENZA TETTO A GENOVA https://www.youtube.com/watch?v=aZIwPGqUfvE ERA "AMICO INTIMO" DEL KILLER DI SILVIO FANELLA, OVVIAMENTE, "NAZIGENOVESE" COME LUI: GIOVANNI BATTISTA CENITI! CON CUI NON PER NIENTE CONDIVIDEVA TRAME MEGA KILLER, ANCHE INTERNAZIONALI, PRESSO PARECCHIE CASA POUND, SPECIE DI ZONA VERBANIA: http://www.ilfattoquotidiano.it/2014/07/17/omicidio-fanella-la-rete-nera-di-ceniti-dal-trentino-al-kosovo/1060862/ http://roma.repubblica.it/cronaca/2014/07/04/news/mokbel_fanella_e_ceniti_ecco_il_giro_d_affari_dell_estrema_destra-90638562/ MEGLIO MORTI CHE ARRESI! CHE SIA 25 APRILE 1945 BIS! I NUOVI PARTIGIANI ( E NON CERTO, NAZIMAFIOSI KILLER "PAR-TEA"GIANI)! DA BRUXELLES, LONDON, RIO DE JANEIRO, MANAGUA (OVE TIFIAMO PER UN NUOVO VINCENTISSIMO CANALE OCEANO-PACIFICO "DI CENTRO-SINISTRA" PER SURCLUSSARE QUELLO MA-F-ASCISTA DI PANAMA DEI BASTARDI CRIMINALISSIMI VALTER LAVITOLA, RICARDO MARTINELLI, PAOLO BARRAI, SILVIO BERLUSCONI E NOTO AMBASCIATORE DI "COSA NOSTRA, CAMORRA E NDRANGHETA" GIANCARLO MARIA CURCIO http://www.globalist.it/Detail_News_Display?ID=2828), SAN JOSE DI COSTARICA, HABANA VIEJA, CARACAS ( OVE STIAMO PREPARANDO UN FORTISSIMO RECUPERO ECONOMICO E SOCIALE), ACCRA, JOHANNESBURG, PECHINO, TORONTO, NEW YORK ( QUELLA DEL GRANDISSIMO DEMOCRAT, PROSSIMAMENTE, US PRESIDENT: BILL DE BLASIO)! PS2 E CHE SIA CHIARO, IO NON SON PER NULLA GENIO, RE MIDA ED EROE CIVILE MICHELE NISTA. NON LO SONO, ANCHE SE LO VORREI DI CERTO ESSERE, VISTO IL SUO ECCEZIONALE GENIO E FIUTO. DA ASSOLUTI NUMERI UNO AL MONDO. E CHE VEDREI BENISSIMO SULLA SEGGIOLA DI STO CESSO NAZISTA E NDRANGHETISTA DI MATTEO RENZI, CORROTTISSIMO DA SILVIO BERLUSCONI, PER FARE LEGGI, E PRENDERE DECISIONI, PRO, QUEST'ULTIMA "FASCIOCAMORRISTAM ED PEDOFILAM PERSONAM". DA POSIZIONE DI FINTISSIMO CENTRO SINISTRA, CHE E' ORMAI, IN REALTA', ESTREMISSIMA DESTRA. CERCANDO COSI' DI FREGARE TUTTI ( DA APPOSTAZIONE INASPETTATA)! SGOZZANDO A MORTE, DEMOCRAZIA, GIUSTIZIA, E LIBERTA'. NON SONO GENIO, RE MIDA ED EROE CIVILE MICHELE NISTA, CHE, MAI DIMENTICHIAMOCI, PERO', OVUNQUE IN VITA SUA ABBIA MESSO LE MANI, HA SEMPRE, SEMPRE E STRA SEMPRE, RESO LE PIETRE, ORO. COME QUANDO CIRCA VENTENNE, PREVEDETTE E CON TRE MESI DI ANTICIPO IL MEGA CROLLO DEL DOW JONES DELL'OTTOBRE 1987. AVVENUTO POI PUNTUALISSIMAMENTE, FRA LO SHOCK DI TUTTI, IN BORSA, A MILANO, CHE LO INIZIARONO A CHIAMARE "IL PROFETA" ( ED INTANTO SI STRAPPAVANO DALLE MANI, MICHELE STESSO, DA UN POSTO DI LAVORO ALL'ALTRO, IN QUANTO RENDEVA SEMPRE, DESKS CHE FACEVANO ZERO PROFITTI, MILIARDARIE, PUR SE IN LIRE, UN ANNO DOPO.. DA QUI IL PASSAGGIO DEL SUO NICK, COL TEMPO, DA "PROFETA" A "RE MIDA".. E SENZA MAI CHE GIOCASSE SPORCO, SENZA MAI CHE CORROMPESSE O ELUDESSE UNA LIRA, CHE UNA, DI TASSE). A SEGUIRE, MICHELE PREVEDETTE ALLA PERFEZIONE IL MEGA RIALZO DEL DOW JONES DELL'ERA BILL CLINTON, IL CROLLO DEL NASDAQ CON L'ARRIVO ABUSIVISSIMO, FIGLIO DI MEGA FRODI ELETTORALI, DI "ADOLF HITLER - GEORGE [WC] BUSH". E SPECIALMENTE, QUI, ANTICIPANDO IL TUTTO VIA INTERNET, DAVANTI AGLI OCCHI DEL MONDO INTERO, MICHELE URLO' NEL SETTEMBRE 2007 CHE IL DOW JONES SAREBBE CROLLATO DA 13400 A 6900 ENTRO UN SOLO ANNO! TUTTI A DARGLI DEL MATTO, MA IL DOW JONES UN ANNO DOPO VALEVA ESATTAMENTE 6900! LI TUTTI A DARGLI DEL GENIO! 7 COME PREVEDETTE ALLA PERFEZIONE IL PIU' CHE RADDOPPIO DEL DOW JONES NELL'ERA DELL'AMMIRABILE OBAMA BARACK ( RIALZO DA LUI PREVISTO, SEMPRE DAVANTI AGLI OCCHI DEL MONDO INTERO, DI NUOVO, VIA INTERNET, BEN SEI MESI PRIMA DI QUANDO INIZIO' A VERIFICARSI: DA LUI ANTICIPATO NEL OTTOBRE 2008, VERIFICATOSI NEL MARZO 2009, ESATTAMENTE, NEL PERIODO DA LUI PREVISTO SEI MESI PRIMA). E DA APRILE 2014, RIPETO, DA APRILE 2014, MICHELE HA DETTO A TUTTI "NOI", CHE IL DOW JONES SAREBBE SALITO ANCORA, MA PER POI MINICROLLARE NELLA PARTE FINALE DEL LUGLIO 2014: ACCADUTO AL MILLESIMO. E "NOI" SAPPIAMO GIA' ANCHE DOVE SARA' IL DOW JONES ALLE PROSSIME ELEZIONI USA DEL 2016. E SIAMO CERTI CHE SARA' ESATTISSIMAMENTE LI, OVE CE LO HA DETTO LUI: GENIO, RE MIDA ED EROE CIVILE MICHELE NISTA. CON LUI SI VINCE SEMPRE E STRA SEMPRE, ALTRO CHE POR-C-ORROTTO BERLUSCONICCHIO SGOZZA GIUSTIZIA E LIBERTA', PROVETTO DITTATORE PAZZO: MATTEO RENZI. IL VERME RISDOGANATORE DEL BASTARDAMENTE ASSASSINO, BERLUSCONISMO, OSSIA MAFIA, CAMORRA, NDRANGHETA, FASCISMO E PEDOFILIA, A PALAZZO CHIGI! PUAH!!! On Monday, August 18, 2014 3:37:14 PM UTC+2, Antony Whitehouse London wrote: > AVVOCATO PEDOFILOMOSESSUALE ED ASSASSINO DANIELE MINOTTI (FACEBOOK). OLTRE CHE NAZI, MEGALAVA EURO MAFIOSI, E, COME DETTO, MANDANTE DI OMICIDI O "SUICIDATE"! STALKER DI EROE CIVILE MICHELE NISTA SU ORDINE DI TIRANNO FASCIOCAMORRISTA SILVIO BERLUSCONI!! > > > > 1 > > OCHO AD AVVOCATO "BERLUSCONIANISSIMAMENTE", MEGA RICICLA CASH MAFIOSO, NAZIFASCISTA, ASSASSINO E PEDOFILOMOSESSUALE: DANIELE MINOTTI ( PURE SU FACEBOOK) DI RAPALLO E GENOVA! TUTTI SANNO DI SUE "FESTE" SATANISTISSIME "ATTE A SODOMIZZARE" ZINGARELLI DI 6-8 ANNI (A SANREMO, CON DON RICCARDO SEPPIA E COL TANTE VOLTE CONDANNATO A GALERA, PAOLO BARRAI DEL CRIMINALISSIMO BLOG MERCATO "MERDATO" LIBERO.. MA NON SOLO... E FRA POCO.. TUTTI I NOMI E COGNOMI)!!! > > > > OCCHIO, PLS, ALL'AVVOCATO PIU' INFIMAMENTE NAZISTA, MEGA LAVA CASH MAFIOSO, MANDANTE DI OMICIDI E "SUICIDATE", E COME SE NON BASTASSE, ACCLARATO PEDOFILMOSESSUALE, CHE ESISTA ( IL VOMITO VA' SULLA PARTE "PEDOFILO", PIU' CHE OMOSESSUALE, ANCHE SE IL MEGA SODMIZZATORE DI BAMBINI, DANIELE MINOTTI, LO E' ENTRAMBE LE COSE; OLTRE AD ESSERE UN VERMINOSO CODARDO: METTEVA DELLE SUE FOTO CON FACCE DA ASSOLUTO PERICOLOSISSIMO MANICACO SESSUALE, SU TUTTA INTERNET... ED OVVIAMENTE, ORA, DOPO CHE LE ABBIAM FATTE NOTARE SU MIGLIAIA DI SITI, DA TOPO DI FOGNA, DETTE FOTO LE HA FATTE SUBITO IMBOSCARE)! COME SE NON BASTASSE, PURE FREQUENTISSIMO MANDANTE DI "SUICIDATE" ED OMICIDI: DANIELE MINOTTI DI GENOVA E RAPALLO. > > > > Criminalissimo Studio Legale pro Mafia, Camorra, Ndrangheta e Neonazisti assassini, di noto pedofilomosessuale Daniele Minotti :: Genova - Rapallo > > Via della Libert?, 4/10 - 16035 - Rapallo (GE) (Tribunale di Chiavari) > > > > Tel. e fax +39 0185 57 880 > > > > Via XX Settembre, 3/13 - 16121 - Genova > > > > Fax +39 010 91 63 11 54 > > > > Fax to email +39 010 91 63 11 54 > > > > Cell. +39 335 5949904 - Skype daniele_minotti > > > > RICICLANTE DA ANNI CASH KILLER DEGLI EMANUELLO DI COSA NOSTRA, BASATI A GENOVA. http://www.ilsecoloxix.it/p/genova/2011/05/19/AOJ0cAV-rischio_gronda_arresti.shtml > > > > O DEI FEROCI SICARI DELLA NDRANGHETA: I RAMPINO. SEMPRE BASATI A GENOVA. http://www.ilsecoloxix.it/p/genova/2013/06/05/APjJUSgF-ndrangheta_terra_liguria.shtml > > > > BASTARDO VERO, PEDERASTA PERVERTITISSIMO DANIELE MINOTTI DI GENOVA E RAPALLO: TUTTI SANNO DELLE ORGE PEDOFILE CHE FACEVA CON DON RICCARDO SEPPIA A SANREMO. FRA SIMBOLI DEMONIACI E TERRIFICANTI SODOMIZZAZIONI DI BAMBINI DI 6-8 ANNI ( E AHIME.. FATEMI SDRAMMATIZZARE, PLS... ANCHE 6-8 ANI). BAMBINI ZINGARELLI! D'ALTRONDE, TOPI DI FOGNA CODARDI E SPIETATI COME IL CRIMINALISSIMO AVVOCATO DANIELE MINOTTI DI GENOVA CHE ALTRO AVREBBERO POTUTO RACCATTARE? IL TUTTO FRA CHILI DI COCAINA, MEGA CASH MAFIOSO, E SCIOCCANTISSIMAMENTE, DOZZINE DI TESSERE FASCIOCAMORRISTE DI FORZA ITALIA, FRATELLI D'ITALIA, CASA POUND, FIAMMA TRICOLORE E LEGA NORD. IL DAVVERO "AVVOCATO DEL DIAVOLO", IL BASTARDO MASSONE NAZISTA, IL VERME MASSO-NAZISTA ( MERDA ASSASSINA P2ISTICA PER INTENDERCI), MEGA LAVA CASH MAFIOSO, MANDANTE DI "SUICIDATE" ED OMICIDI A RAFFICA, SEMPRE SODOMIZZANTE POCO PIU' CHE BAMBINI, DANIELE MINOTTI DI GENOVA E RAPALLO, D'ALTRONDE, I PEDOFILOMOSESSUALI O PEDOFILI IN GENERE LI AMA, SE NE SENTE STRA PARTE, LI DIFENDE. NON CI CREDETE??? VOLETE FARE GLI STRUZZI, CHE PER FRATELLANZA MASSO-N-AZIFASCISTA, PREFERISCONO METTERE LA TESTA DOVE GIRANO I VERMI, SOTTO TERRA??? GIVE A LOOK RIGHT NOW, THEN, PLS: http://www.ansa.it/liguria/notizie/2014/06/20/adescava-minori-sul-web-condannato_36c57304-90aa-4c7f-8463-c7d610ed10dd.html > > http://iltirreno.gelocal.it/massa/cronaca/2013/04/19/news/casolare-a-luci-rosse-il-pm-7-anni-e-mezzo-all-ex-dipendente-nca-1.6917147 > > E SE GOOGLATE " DANIELE MINOTTI PEDOPORNOGRAFIA" VEDRETE CHE IN TUTTI I SUOI ARTICOLI, SOTTILISSIMAMENTE ( E MANCO TANTO, SOTTILISSIMAMENTE) DIFENDE I PEDOFILI, LI SUPPORTA: OVVIO, E' UN VERME SODOMIZZA BAMBINI LUI IN PRIMO! DA RINCHIUDERE IN GALERA O MANICOMIO SUBITO: AVRA' GIA' UCCISO E FATTO SCOMPARIRE QUALCHE BIMBO CHE HA INCULATO! O PRESTO LO FARA'! QUI SALVIAMO VITE DI PICCOLISSIME CREATURE CON QUESTI SCRITTI!!! SALVIAMO IL MONDO!!! > > > > 2 > > MA TORNIAMO ORA A STO, PURE TERRORISTA NERO ( ED IN NERO), COME CITATO, FREQUENTE MANDANTE DI OMICIDI, "SUICIDATE" O TERRIFICANTI ISTIGAZIONI AL SUICIDIO: DANIELE MINOTTI DI RAPALLO E GENOVA. INCITA I VERMI DI ESTREMISSIMA DESTRA COME LUI, DI TUTTO IL MONDO, I KAMERADEN KILLER DEI TEA PARTIES, AD AMMAZZARE, NELLA MERDA BASTARDAMENTE DITTATORIALE DI "RENZUSCONIA" ( O OVUNQUE SIANO NEL GLOBO), CHIUNQUE CRITICHI "TROPPO" I SUO LIDER MAXIMI, E LIDER MAXIMI IN TUTTO, SPECIE IN PEDOFILIA, FASCIOCAMORRA ED ORDINI DI UCCISIONI E STRAGI: SILVIO BERLUSCONI E LICIO GELLI (CITATI NAZIMAFIOSI DEI TEA PARTIES DI CUI E' STRA PARTE, INSIEME AD ALTRO VERME BERLUSCONAZISTA E CRIMINALISSIMO: GIACOMO ZUCCO, OVVIAMENTE, PURE LUI, MEGA LAVA SOLDI DI COSA NOSTRA, CAMORRA E NDRANGHETA, SPECIE VIA BITCOINS, E PURE LUI NOTO PEDOFILOMOSESSUALE TANTO QUANTO)! CON IL QUALE CONDIVIDE PURE, UNA, DA VOMITARE ANCHE LA BILE, TESSERA DEI PEDERASTA CHE "SON ORGOGLIOSI DI FAR SESSO CON BAMBINI", QUELLA DELL'ORGOGLIO PEDOFILO, OSSIA QUELLA DEI > > "North American Man-Boy Amore Association" > > http://www.today.it/rassegna/giornata-orgoglio-pedofilo.html > > STO PUTRIDISSIMO TOPO DI FOGNA DI DANIELE MINOTTI DEL FORO DI CHIAVARI ( ALTRA SDRAMMATIZZAZIONE, PLS.. CHIAVARI SI.. E' DI CERTO LA COSA PIU' BELLA AL MONDO, MA ANCHE LA PIU' BRUTTA, QUANDO LO SI FA DEPRAVATISSIMAMENTE CON I BAMBINI, COME FA SEMPRE STO ESCREMENTOSO PEDOFILOMOSESSUALE DI DANIELE MINOTTI DI RAPALLO E GENOVA) E' OVVIAMENTE PURE UN BASTARDO RAZZISTA. AUSPICA LA MORTE SOCIALE, " MA ANCHE NON SOLO.. ANCHE TOTALISSIMA" , DI CHIUNQUE NATO SOTTO LA VERMINOSAMENTE PIDUISTICA AREZZO (DA DOVE VENGONO, NON PER NIENTE, PURE LA PUTTANONA PREFERITA DA LICIO GELLI, MARIA ELENA BOSCHI, E IL BANCHIERE FRA I PI? USATI DAI KILLER DELLE MAFIE DI MEZZO GLOBO, PIER LUIGI BOSCHI DI BANCA ETRURIA, CHE CON LE LORO "RIFORME IMPOSTE DA HITLERIANISSIMA WILLA WANDA", PORTERANNO IL PAESE A NUOVE SVASTICHE, A NUOVI REGIMI ASSASSINISSIMAMENTE DI ESTREMA DESTRA, ANTICIPATI DA OVVIA BANCAROTTA E GUERRA CIVILE). COLLABORA, NON PER NIENTE, CON IL, COME LUI, AVANZO DI GALERA, CAPO DEL KU KLUK KLAN, ANZI, KAPO' DEL " KU KLUK KLAN PADANO", OVVIAMENTE, ACCLARATO PEDOFILOMOSESSUALE TANTO QUANTO: PAOLO BARRAI DELL' IMMENSAMENTE MALAVITOSO BLOG MERCATO LIBERO = MERDATO LIBERO ( CON CUI, NON PER NIENTE, NON FA ALTRO CHE RICICLARE, VIA MERDOSAMENTE CRIMINALI BITCOINS, SOLDI DI COSA NOSTRA, CAMORRA, NDRANGHETA, COME FRUTTO DI LADRATE E MEGA CORRUZIONE DI LL, LEGA LADRONA, ED EX PDL, POPOLO DI LADRONI, INSIEME AL PRIMA MENZIONATO NOTO SUPER RICICLA SOLDI DI MAFIOSISSIMI, GIACOMO ZUCCO DEI TEA PARTIES... IL TUTTO VIA NAZIMAFIOSA PANAMA O BITCOINS! > > http://www.repubblica.it/economia/finanza/2014/01/28/news/bitcoin_arresti_traffico_droga-77128457/ http://www.repubblica.it/economia/2014/07/09/news/bitcoin_terrorismo_riciclaggio-91119086/ > > ECCO UN POST CHE DIMOSTRA LA LERCISSIMA ARROGANZA NAZINDRANGHETISTA, NAZIMAFIOSA, NAZICAMORRISTA DEI MEGA LAVA CASH ASSASSINO, NONCH? ACCLARATI PEDOFILI BERLUSCONIANI: PAOLO BARRAI, GIACOMO ZUCCO E DANIELE MINOTTI! MA CHE MOSTRA ANCHE QUANTO SIA IDIOTA, CANE IN BORSA, BRUCIA RISPARMI A RAFFICA, L'AVANZO DI GALERA PAOLO BARRAI, CHE PREVEDEVA IL BIT COIN A ANDANTE DA 700 A 70.000, MENTRE VALE ( IN QUANTO "NOI", DA GRANDI "NUOVI PARTIGIANI" LO ABBIAMO SPACCATO IN GIU FINO A) 500 CIRCA! OLE'! http://ilpunto-borsainvestimenti.blogspot.be/2014/03/bitcoin-con-giacomo-zucco-stiamo-ridendo.html). TRATTASI DI VERI E PROPRI AL CAPONE MISTI AD ADOLF HITLER DELLA POLITICA (NERA E SPECIALMENTE "IN NERO")! E FINANZA! CHE IMBOSCANO MEGA VALIGIE PIENE DI CONTANTE KILLER ( http://ilpunto-borsainvestimenti.blogspot.be/2014/08/il-contante-come-strumento-di-marketing.html), PRESSO CRIMINALISSIMA FINTER BANK LUGANO DI COLLETTI MALAVITOSI TANTO QUANTO: FILIPPO CRIPPA E GIOVANNI DAI CAS! > > > > 3 > > A VOI IL "BANCHIERE TOPO DI FOGNA" FILIPPO M CRIPPA DI FZB FINTER ZURICH BANK LUGANO > > http://www.linkedin.com/pub/filippo-m-crippa/a/a09/826 A VOI IL BANCHIERE AMATISSIMO DA TUTTI I SICARI MAFIOSI DI QUESTO PIANETA: GIOVANNI DEI CAS DI FZB FINTER ZURICH BANK LUGANO http://www.linkedin.com/pub/giovanni-dei-cas/2/262/654 MA QUESTI MEGA RICICLAGGI DI CASH SUPER ASSASSINO, AVVENGONO ANCHE PRESSO SCHIFOSISSIMAMENTE CRIMINALE FINECO DI ALTRO BANCHIERE, NOTORIAMENTE AMATISSIMO DA COSA NOSTRA, NDRANGHETA E CAMORRA: ALESSANDRO FOTI DI FINECO BANK, BEN APPUNTO. > > https://www.unicreditgroup.eu/it/governance/management/alessandro-foti.html COME SE NON BASTASSE, IL PEDOFILOMOSESSUALE, NAZINDRANGHETISTA, ASSASSINO AVVOCATO DANIELE MINOTTI ? UN TUTT' UNO CON UN NOTO TERRORISTA DI ESTREMISSIMA DESTRA, MEGA OMICIDA, ED "OVVIAMENTE" PURE LUI NOTO PEDOFILO: ANGELO PEGLI. RIFUGIATOSI IN ECUADOR, A GUAYAQUIL, PER NON PASSARE ANNI IN GALERA A MARASSI. OVVIAMENTE, VIA REGIA DI SOLITO MEGA FIGLIO DI TROIA, BASTARDO "NERO" ( E QUASI SEMPRE "IN NERO"), AVVOCATO BASTARDISSIMAMENTE CRIMINALE: DANIELE MINOTTI DI GENOVA E RAPALLO. CHE COLLABORA ANCHE CON UN ALTRO NOTO DEPRAVATO SESSUALE E MEGA LAVA SOLDI MAFIOSI: GABRIELE SILVAGNI DI BANCA CARIM RIMINI. ED UN FACCENDIERE ESTREMISSIMAMENTE DELINQUENTE: MATTEO PARDU DI LA SPEZIA http://www.linkedin.com/pub/matteo-pardu/20/588/906 OLTRE CHE CON UNA BESTIA CHE MEGA TRUFFA VIA WEB E FA SEMPRE PERDERE TUTTI I RISPARMI DI TUTTI, BASTARDO CRIMINALISSIMO FEDERICO IZZI DI ROMA. NOTO COME ZIO ROMOLO! VICINISSIMO AD ENRICO NICOLETTI, NOTO BANCHIERE DELLA BANCA DELLA MAGLIANA http://www.agoravox.it/Arrestato-Enrico-Nicoletti-il.html E AI CRUDELISSIMI ASSASSINI "CASALESI", VIA, NOTORIAMENTE, MEGA OMICIDA FAMIGLIA CAMORRISTA DEI BARDELLINO http://www.ilfattoquotidiano.it/2011/12/10/affari-politici-camorra-formia-avamposto-laziale-casalesi/176674/ PRESSO FORMIA E LATINA ( NON PER NIENTE, DI LATINA, SONO ANCHE I CRIMINALISSIMI SCARSI, "SCARSI" IN UMANITA', SPECIALMENTE... NAZISTI.. A CAPO, ANZI, A KAPO' DI QUESTO SITO http://www.unionesatanistiitaliani.it/ I SCARSI SONO UNA FAMIGLIA DI CRIMINALI MOSTRUOSI, SOCI DI QUESTO AL CAPONE DELLA FINANZA, BRUCIA RISPARMI A TONNELLATE, VERME SUPER CRIMINALE FEDERICO IZZI "ZIO ROMOLO"... E PARLO DEL NOTO PEDOFILO, STRAPPA E VENDI ORGANI DI BAMBINI, GINECOLOGO ASSASSINO ALESSANDRO SCARSI, GIA' VARIE VOLTE FINITO IN GALERA http://archiviostorico.corriere.it/2003/febbraio/15/Ginecologo_sfruttatore_co_10_0302151733.shtml E DI SUO FIGLIO, MEGA RICICLA SOLDI DI MAFIA, CAMORRA E NDRANGHETA, VERME CRIMINALE TANTO QUANTO ANDREA SCARSI DI BANCA IFIGEST http://it.linkedin.com/pub/andrea-scarsi/9/4a/67a). A FRA NON MOLTO PER OCEANI DI ALTRI DETTAGLI. > > PS > > STO AVANZO DI GALERA, AVVOCATO NAZIMAFIOSO DANIELE MINOTTI DEL TRIBUNALE DI CHIAVARI, FACEVA ANCHE DA COLLANTE FRA IL SUO CAMERATA PAESANO, LADRO, MEGA CORROTTO, E SPIETAMENTE KILLER, CLAUDIO SCAJOLA E LA NDRANGHETA. http://www.repubblica.it/politica/2014/05/10/news/il_patto_scajola-matacena_cos_la_ndrangheta_fece_crescere_forza_italia-85725761/ > > ERA L'ORGANIZZATORE, LA BASTARDISSIMA MENTE DI QUESTO CODARDO, OMICIDA, MA-F-ASCISTA ATTACCO NEI CONFRONTI DI POVERI SENZA TETTO A GENOVA > > https://www.youtube.com/watch?v=aZIwPGqUfvE > > ERA "AMICO INTIMO" DEL KILLER DI ESTREMISSIMA DESTRA, OVVIAMENTE, "NAZIGENOVESE" COME LUI: GIOVANNI BATTISTA CENITI! CON CUI NON PER NIENTE CONDIVIDEVA TRAME MEGA KILLER, ANCHE INTERNAZIONALI, PRESSO TANTE CASA POUND: > > http://www.ilfattoquotidiano.it/2014/07/17/omicidio-fanella-la-rete-nera-di-ceniti-dal-trentino-al-kosovo/1060862/ http://roma.repubblica.it/cronaca/2014/07/04/news/mokbel_fanella_e_ceniti_ecco_il_giro_d_affari_dell_estrema_destra-90638562/ > > https://www.youtube.com/watch?v=QmxJVLqyQNI > > NEI PROSSIMI MESI TONNELLATE DI ALTRI FONDAMENTALI DETTAGLI! > > > > 4 > > MEGLIO MORTI CHE ARRESI! > > CHE SIA 25 APRILE 1945 BIS! > > I NUOVI PARTIGIANI ( E NON CERTO, NAZIMAFIOSI ASSASSINI "PAR-TEA"GIANI)! > > DA BRUXELLES, LONDON, RIO DE JANEIRO, HABANA VIEJA, MANAGUA, SAN JOSE DI COSTARICA, CARACAS ( OVE STIAMO PREPARANDO UN FORTISSIMO RECUPERO ECONOMICO E SOCIALE), ACCRA, JOHANNESBURG, PECHINO, TOKYO, TORONTO, NEW YORK ( QUELLA DEL GRANDISSIMO DEMOCRAT, PROSSIMAMENTE, US PRESIDENT: BILL DE BLASIO)! E CHE SIA CHIARO, IO NON SON PER NULLA GENIO, RE MIDA ED EROE CIVILE MICHELE NISTA. NON LO SONO, ANCHE SE LO VEDREI BENISSIMO SULLA SEGGIOLA DI STO CESSO NAZISTA E MAFIOSO DI MATTEO RENZI, CORROTTISSIMO DA SILVIO BERLUSCONI, PER FARE LEGGI, E PRENDERE DECISIONI, PRO, QUEST'ULTIMA "FASCIOCAMORRISTAM ED PEDOFILAM PERSONAM". DA POSIZIONE DI FINTISSIMO CENTRO SINISTRA, CHE E' ORMAI IN REALTA', ESTREMISSIMA DESTRA. CERCANDO COSI' DI FREGARE TUTTI! SGOZZANDO A MORTE, DEMOCRAZIA, GIUSTIZIA, E LIBERTA'. NON SONO GENIO, RE MIDA ED EROE CIVILE MICHELE NISTA, CHE, MAI DIMENTICHIAMOCI, OVUNQUE IN VITA SUA ABBIA MESSO LE MANI, HA SEMPRE, SEMPRE E STRA SEMPRE RESO LE PIETRE, ORO. COME QUANDO CIRCA VENTENNE, PREVEDETTE E CON TRE MESI DI ANTICIPO IL MEGA CROLLO DEL DOW JONES DELL'OTTOBRE 1987. AVVENUTO FRA LO SHOCK DI TUTTI, IN BORSA, A MILANO, CHE LO INIZIARONO A CHIAMARE " IL PROFETA" ( ED INTANTO SI STRAPPAVANO DALLE MANI, MICHELE,. DA UN POSTO DI LAVORO ALL'ALTRO, IN QUANTO RENDEVA SEMPRE, DESKS CHE FACEVANO ZERO PROFITTI, MILIARDARIE, PUR SE IN LIRE, SUBITO DOPO.. DA QUI IL PASSAGGIO DEL SUO NICK, COLE TEMPO, DA "PROFETA" A " RE MIDA".. E SENZA MAI CHE GIOCASSE SPORCO, SENZA MAI CHE CORROMPESSE O ELUDESSE UNA LIRA, CHE UNA, DI TASSE). A SEGUIRE, MICHELE PREVEDETTE ALLA PERFEZIONE IL MEGA RIALZO DELL'ERA CLINTON, IL CROLLO DEL NASDAQ CON L'ARRIVO ABUSIVISSIMO, FIGLIO DI MEGA FRODI ELETTORALI, DI " ADOLF HITLER - GEORGE [WC] BUSH ". E SPECIALMENTE, QUI, ANTICIPANDO IL TUTTO VIA INTERNET, DAVANTI AGLI OCCHI DEL MONDO INTERO, MICHELE URLO' NEL SETTEMBRE 2007 CHE IL DOW JONES SAREBBE CROLLATO DA 13400 A 6900 ENTRO UN SOLO ANNO! TUTTI A DARGLI DEL MATTO, MA IL DOW JONES UN ANNO DOPO VALEVA ESATTAMENTE 6900. LI TUTTI A DARGLI DEL GENIO! COME PREVEDETTE ALLA PERFEZIONE IL PIU' CHE RADDOPPIO DEL DOW JONES NELL'ERA DELL'AMMIRABILE OBAMA BARACK ( RIALZO DA LUI PREVISTO SEMPRE DAVANTI AGLI OCCHI DEL MONDO INTERO, DI NUOVO, VIA INTERNET, BEN SEI MESI PRIMA DI QUANDO INIZIO' A VERIFICARSI: NEL 3.2009). E DA APRILE 2014, RIPETO, DA APRILE 2014, MICHELE HA DETTO A TUTTI "NOI", CHE IL DOW JONES SAREBBE SALITO ANCORA, MA PER POI SEMICROLLARE NELLA PARTE FINALE DEL LUGLIO 2014: ACCADUTO AL MILLESIMO. E "NOI" SAPPIAMO GIA' ANCHE DOVE SARA' IL DOW JONES ALLE PROSSIME ELEZIONI USA DEL 2016. E SIAMO CERTI CHE SARA' ESATTISSIMAMENTE LI, OVE CE LO HA DETTO LUI: GENIO, RE MIDA ED EROE CIVILE MICHELE NISTA. CON LUI SI VINCE SEMPRE E STRA SEMPRE, ALTRO CHE POR-C-ORROTTO BERLUSCONICCHIO SGOZZA DEMOCRAZIA, GIUSTIZIA E LIBERTA', PROVETTO DITTATORE PAZZO: MATTEO RENZI ( CHE MICHELE CI DICE FINIRA' PEGGIO DI B-O-TTINO CRAXI, E QUINDI CI CREDIAMO, OLTRE CHE LO STRA AUSPICHIAMO... BASTA CHE ACCADA PRESTO, PRIMA CHE IMPONGA ALTRE RIFORME CON LA SVASTICA AL BRACCIO, CHE MANCO HITLER AVREBBE OSATO ANCHE SOLO PENSARE, NON FARE). IL VERME RI SDOGANATORE DI ASSASSINISSIME MAFIA, CAMORRA, NDRANGHETA, FASCISMO E PEDOFILIA, A PALAZZO CHIGI. PUAH. From roland.hedberg at adm.umu.se Mon Sep 29 05:12:15 2014 From: roland.hedberg at adm.umu.se (Roland Hedberg) Date: Mon, 29 Sep 2014 11:12:15 +0200 Subject: Weird SSL problem Message-ID: Hi! I?m trying to access https://stsadweb.one.microsoft.com/adfs/.well-known/openid-configuration Doing it the simplest way I get the following: >>> import urllib >>> f = urllib.urlopen("https://stsadweb.one.microsoft.com/adfs/.well-known/openid-configuration") Traceback (most recent call last): File "", line 1, in File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 87, in urlopen return opener.open(url) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 208, in open return getattr(self, name)(url) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 437, in open_https h.endheaders(data) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 969, in endheaders self._send_output(message_body) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 829, in _send_output self.send(msg) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 791, in send self.connect() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1176, in connect self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 387, in wrap_socket ciphers=ciphers) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 143, in __init__ self.do_handshake() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 305, in do_handshake self._sslobj.do_handshake() IOError: [Errno socket error] [Errno 54] Connection reset by peer >>> import ssl >>> ssl.OPENSSL_VERSION ?OpenSSL 0.9.8za 5 Jun 2014' Now, using Safari, or curl for that matter, from the same machine works without a hitch. The URL above is also the only URL I?ve encountered this problem with. Anyone got an idea ? ? Roland ?Being able to think like a child is an important attribute of being an adult? - Eddie Izzard From rosuav at gmail.com Mon Sep 29 06:14:08 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 29 Sep 2014 20:14:08 +1000 Subject: Obscuring Python source from end users In-Reply-To: References: <89381545-5edc-4f85-a4b8-86eebfdf34ee@googlegroups.com> <9ad69bd8-ca77-438f-adfe-87d727ca170c@googlegroups.com> Message-ID: On Mon, Sep 29, 2014 at 6:55 PM, Chris Angelico wrote: > It ought to be possible to do an AST reconstitution for at least part > of this. I can hunt down some of my PEP 463 test code to help out with > that. It should be possible to figure out what names are local, and > then just use those. > > If this is of interest, I'll see what I can knock together. Actually, why reconstitute? The AST can be compiled. Here's a Python cruncher/obscurer: import ast, sys, os # Note: If the file can't be parsed, this will raise SyntaxError # (from the ast.parse() line). def crunch(fn, outfn): with open(fn, "rb") as f: data = f.read() tree = ast.parse(data) os.makedirs(os.path.split(outfn)[0], exist_ok=True) with open(outfn, "w") as f: print("from ast import *", file=f) print("_code = "+ast.dump(tree), file=f) print("fix_missing_locations(_code)", file=f) print("[globals().__delitem__(_) for _ in dir() if _[0]!='_']", file=f) print("exec(compile(_code,__name__,'exec'))", file=f) if __name__ == "__main__": for fn in sys.argv[1:]: outfn = "crunched/" + fn crunch(fn, outfn) print("Crunched", fn, "to", outfn) The resulting files should work just the same as the original ones, but will be virtually unreadable. This is still only obscurity, though; the only information actually removed is formatting and comments, not even names. But you could easily add an ast.walk() in there, just after the ast.parse(), and do whatever transformations you want. Note that unlike with JavaScript crunching, this won't shrink the files - in fact, it's usually going to expand them. They'll probably also take longer to load. There is no benefit other than the obscurity. Run this over some of your files, then see if your auditors are happy. ChrisA From info at egenix.com Mon Sep 29 07:35:34 2014 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Mon, 29 Sep 2014 13:35:34 +0200 Subject: ANN: eGenix PyCon UK 2014 Talks & Videos Message-ID: <54294406.8000106@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix PyCon UK 2014 Talks & Videos This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/PyCon-UK-2014-Presentations.html ________________________________________________________________________ We have just published the talk slides and videos of our PyCon UK 2014 presentations. The PyCon UK Conference is the premier conference for Python users and developers in the UK. This year it was held from September 19-22 in Coventry, UK. ________________________________________________________________________ EGENIX TALKS AT PYCON UK 2014 At this year's PyCon UK, Marc-Andr? Lemburg, CEO of eGenix, gave the following talks at the conference. The presentations are available for viewing and download from our Presentations and Talks section: http://www.egenix.com/library/presentations/ When performance matters ... ---------------------------- Simple idioms you can use to make your Python code run faster and use less memory. Python applications sometimes need all the performance they can get. Think of e.g. web, REST or RPC servers. There are several ways to address this: scale up by using more processes, use Cython, use PyPy, rewrite parts in C, etc. However, there are also quite a few things that can be done directly in Python. This talk goes through a number of examples and show cases how sticking to a few idioms can easily enhance the performance of your existing applications without having to revert to more complex optimization strategies. The talk was complemented with a lightning talk titled "Pythons and Flies", which addresses a memory performance idiom and answers one of the audience questions raised in the above talk. Talk video and slides: http://www.egenix.com/library/presentations/PyCon-UK-2014-When-performance-matters/ Python Web Installer -------------------- Installing Python packages is usually done with one of the available package installation systems, e.g. pip, easy_install, zc.buildout, or manually by running "python setup.py install" in a package distribution directory. These systems work fine as long as you have Python-only packages. For packages that contain binaries, such as Python C extensions or other platform dependent code, the situation is a lot less bright. In this talk, we present a new web installer system that we're currently developing to overcome these limitations. The system combines the dynamic Python installation interface supported by all installers ("python setup.py install"), with a web installer which automatically selects, downloads, verifies and installs the binary package for your platform. Talk video and slides: http://www.egenix.com/library/presentations/PyCon-UK-2014-Python-Web-Installer/ If you are interested in learning more about these idioms and techniques, eGenix now offers Python project coaching and consulting services to give your project teams advice on how to achieve best performance and efficiency with Python: http://www.egenix.com/services/coaching/ Please contact our eGenix Sales Team for information: sales at egenix.com. ________________________________________________________________________ INFORMATION About Python (http://www.python.org/): Python is an object-oriented Open Source programming language which runs on all modern platforms. By integrating ease-of-use, clarity in coding, enterprise application connectivity and rapid application design, Python establishes an ideal programming platform for today's IT challenges. About eGenix (http://www.egenix.com/): eGenix is a software project, consulting and product company focusing on expert project services and professional quality products for companies, Python users and developers. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Sep 29 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/ ________________________________________________________________________ 2014-09-30: Python Meeting Duesseldorf ... tomorrow ::::: Try our mxODBC.Connect Python Database Interface for free ! :::::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From steve+comp.lang.python at pearwood.info Mon Sep 29 07:47:54 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 29 Sep 2014 21:47:54 +1000 Subject: Obscuring Python source from end users References: <89381545-5edc-4f85-a4b8-86eebfdf34ee@googlegroups.com> Message-ID: <542946ec$0$12998$c3e8da3$5496439d@news.astraweb.com> norman.ives at gmail.com wrote: > Hello list > > Python 3.4 applies. > > I have a project that involves distributing Python code to users in an > organisation. Users do not interact directly with the Python code; they > only know this project as an Excel add-in. > > Now, internal audit takes exception in some cases if users are able to see > the source code. You have my sympathy. > So I'm wondering if anyone has clever suggestions in this regard... Yes. Distribute the pyc files only. That is the canonical Python answer to the problem of not distributing source code. You may need a tiny "driver" script (or perhaps not), if you do it will be something as minor as: import module_where_all_the_work_is_really_done as module module.main() depending on how the Excel add-in system works. > My current plan is to modify the bdist_wheel setuptools extension so that > it can produce distributions with only the .pyc files, laid out so that > they will be importable in the normal way. This will be sufficient to > satisfy internal audit, and will not negatively impact our users. Sounds good to me. Do you know about the compileall.py script/module in the standard library? > However there are obvious downsides, including the overhead of maintaining > separate wheels for different architectures and (in the future) Python > versions. Not to mention that this plan seems to go against the grain of > how Python wants to use byte code files... Well, yes, it does go against the grain, but byte-code only distributions are officially supported. Occasionally people have made requests to simplify the import system by dropping support for .pyc only imports, but Python's creator Guido van Rossum has made it clear that as alien as such a thing is to the open source community, Python is going to allow it. Another possibility is to distribute your modules inside a zip file. See here: https://mail.python.org/pipermail/python-list/2014-July/675506.html Such zip files are not just runnable, but also importable. Depending on your Excel requirements, you might need a tiny driver script as above. -- Steven From urbangabo at gmail.com Mon Sep 29 09:18:31 2014 From: urbangabo at gmail.com (Gabor Urban) Date: Mon, 29 Sep 2014 15:18:31 +0200 Subject: Teaching Python Message-ID: Hi, my 11 years old son and his classmate told me, that they would like to learn Python. They did some programming in Logo and turtle graphics, bat not too much. Doesn anybody has an idea how to start? -- Urb?n G?bor Linux is like a wigwam: no Gates, no Windows and an Apache inside. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon Sep 29 09:28:47 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 29 Sep 2014 23:28:47 +1000 Subject: Teaching Python In-Reply-To: References: Message-ID: On Mon, Sep 29, 2014 at 11:18 PM, Gabor Urban wrote: > my 11 years old son and his classmate told me, that they would like to learn > Python. They did some programming in Logo and turtle graphics, bat not too > much. > > Doesn anybody has an idea how to start? Right here: https://docs.python.org/3/tutorial/ There are other tutorials on the web, too. I strongly recommend starting with Python 3. ChrisA From steve+comp.lang.python at pearwood.info Mon Sep 29 09:37:07 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 29 Sep 2014 23:37:07 +1000 Subject: Teaching Python References: Message-ID: <54296084$0$12979$c3e8da3$5496439d@news.astraweb.com> Gabor Urban wrote: > Hi, > > my 11 years old son and his classmate told me, that they would like to > learn Python. They did some programming in Logo and turtle graphics, bat > not too much. > > Doesn anybody has an idea how to start? The Internet is a big place, I always start by searching :-) https://duckduckgo.com/html/?q=python+tutorial+for+kids https://duckduckgo.com/html/?q=python+turtle+graphics https://startpage.com/do/search?q=python+programming+for+children Are you looking for instruction on how you can teach them, or for self-directed learning they can do on their own? -- Steven From rustompmody at gmail.com Mon Sep 29 09:38:34 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 29 Sep 2014 06:38:34 -0700 (PDT) Subject: Teaching Python In-Reply-To: References: Message-ID: <94667a8d-8e37-4f59-a850-2cbd3110562c@googlegroups.com> On Monday, September 29, 2014 6:59:10 PM UTC+5:30, Chris Angelico wrote: > On Mon, Sep 29, 2014 at 11:18 PM, Gabor Urban wrote: > > my 11 years old son and his classmate told me, that they would like to learn > > Python. They did some programming in Logo and turtle graphics, bat not too > > much. > > Doesn anybody has an idea how to start? > Right here: > https://docs.python.org/3/tutorial/ The official tutorial for an 11 year old?? I dont think so... > There are other tutorials on the web, too. I strongly recommend > starting with Python 3. There's the official turtle graphics Then there's this https://code.google.com/p/pynguin/ Though I guess just as the official tutorial is too adult for an 11 year old, turtle graphics may be too childish. You know your son better than we do: What excites him? Bores him? If you tell us then appropriate suggestions may follow From rosuav at gmail.com Mon Sep 29 09:46:20 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 29 Sep 2014 23:46:20 +1000 Subject: Teaching Python In-Reply-To: <94667a8d-8e37-4f59-a850-2cbd3110562c@googlegroups.com> References: <94667a8d-8e37-4f59-a850-2cbd3110562c@googlegroups.com> Message-ID: On Mon, Sep 29, 2014 at 11:38 PM, Rustom Mody wrote: >> https://docs.python.org/3/tutorial/ > > The official tutorial for an 11 year old?? I dont think so... I don't see why not, to be honest. Not a lot of difference between his 11yo son and my 12yo sister, and I just pointed her at the tutorial and Idle's interactive mode and set her going. But the father is the best one to judge that; if the boys have dabbled in programming already, he and/or they will know if the tutorial's aimed too high for them. ChrisA From steve+comp.lang.python at pearwood.info Mon Sep 29 09:52:01 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 29 Sep 2014 23:52:01 +1000 Subject: trouble building data structure References: Message-ID: <54296401$0$12999$c3e8da3$5496439d@news.astraweb.com> David Alban wrote: > greetings, > > i'm writing a program to scan a data file. from each line of the data > file > i'd like to add something like below to a dictionary. my perl background > makes me want python to autovivify, but when i do: > > file_data = {} > > [... as i loop through lines in the file ...] > > file_data[ md5sum ][ inode ] = { 'path' : path, 'size' : size, } > > i get: > > Traceback (most recent call last): > File "foo.py", line 45, in > file_data[ md5sum ][ inode ] = { 'path' : path, 'size' : size, } > KeyError: '91b152ce64af8af91dfe275575a20489' > > what is the pythonic way to build my "file_data" data structure above that > has the above structure? Others have suggested using a defaultdict, but here's an older solution: use the setdefault method on regular dicts. This fails: py> file_data = {} py> file_data[1234][23] = {'spam': 1, 'eggs': 2} Traceback (most recent call last): File "", line 1, in KeyError: 1234 But this succeeds: py> file_data.setdefault(1234, {})[23] = {'spam': 1, 'eggs': 2} py> file_data.setdefault(5678, {})[42] = {'spam': 3, 'cheese': 1} py> file_data {1234: {23: {'spam': 1, 'eggs': 2}}, 5678: {42: {'spam': 3, 'cheese': 1}}} Whether you prefer to use setdefault, or a defaultdict, is a matter of taste. -- Steven From mits39 at hotmail.com Mon Sep 29 10:03:15 2014 From: mits39 at hotmail.com (Skippy) Date: Mon, 29 Sep 2014 14:03:15 +0000 (UTC) Subject: Storage Cost Calculation References: Message-ID: Abohfu venant zinkeng gmail.com> writes: > > > > > Hard drives have been the secondary storage of choice on computers for many years. They have improved in speed, in capacity, and in cost for over 50 years. It's interesting to look at how the prices have dropped, or, conversely, how much storage your money will buy now as compared to many years ago. This improvement is an example of?Moore's Law > This site?was written by a person (in 2009) who had considered this amazing trend. He collected a lot of data about hard drive capacity and price. The formula he extrapolated by using the data he found iscost per gigabyte = 10-0.2502(year-1980) + 6.304where?year?is the year for which the extrapolated cost was desired. This formula is based on data from 1980 to 2010.Your program should develop a table of costs, based on the user's inputs of the starting and ending years and the formula. The table should produce columns as seen below, The column Year is the year, starting at the point the user says to start at, and going to the ending year, stopping there. The size of the step in the table is also specified by the user. The user inputs are all integers. Your program can assume that.?NOTE:?The "ending year, stopping there" phrase is a bit ambiguous. If you want to use the ending year as the stop value in a range function, that is fine. If you want to add one to the ending year and use that as the stop value, that is also ok.?In the tables below, ?end year plus one was used.?Tab characters can be used. > Sample Run:Big Blue Hard Drive Storage Cost > > Enter the starting year: 1992 > Enter the ending year: 2015 > What step size for the table? 4 > > Hard Drive Storage Costs Table > > Start Year = 1992 > End Year = 2015 > > Year Cost Per Gigabyte ($) > > 1992 2002.627 > 1996 199.894 > 2000 19.953 > 2004 1.992 > 2008 0.199 > 2012 0.02 > Another Run:Big Blue Hard Drive Storage Cost > > Enter the starting year: 1998 > Enter the ending year: 2010 > What step size for the table? 2 > > Hard Drive Storage Costs Table > > Start Year = 1998 > End Year = 2010 > > Year Cost Per Gigabyte ($) > > 1998 63.154 > 2000 19.953 > 2002 6.304 > 2004 1.992 > 2006 0.629 > 2008 0.199 > 2010 0.063 > QUESTION > Could someone help me with a design and a python program to implement that design to solve the above problem? > > > > >
>
    >
  • >

    Hard drives have been the secondary storage of choice on computers for many years. They have improved in speed, in capacity, and in cost for over 50 years. It's interesting to look at how the prices have dropped, or, conversely, how much storage your money will buy now as compared to many years ago. This improvement is an example of Moore's Law

    >

    This site was written by a person (in 2009) who had considered this amazing trend. He collected a lot of data about hard drive capacity and price. The formula he extrapolated by using the data he found is

    cost per gigabyte = 10-0.2502(year-1980) + 6.304
    where year is the year for which the extrapolated cost was desired. This formula is based on data from 1980 to 2010.

    Your program should develop a table of costs, based on the user's inputs of the starting and ending years and the formula. The table should produce columns as seen below, The column Year is the year, starting at the point the user says to start at, and going to the ending year, stopping there. The size of the step in the table is also specified by the user. The user inputs are all integers. Your program can assume that. NOTE: The "ending year, stopping there" phrase is a bit ambiguous. If you want to use the ending year as the stop value in a range function, that is fine. If you want to add one to the ending year and use that as the stop value, that is also ok. In the tables below,  end year plus one was used. Tab characters can be used.

    >

    Sample Run:

    Big Blue Hard Drive Storage Cost > > Enter the starting year: 1992 > Enter the ending year: 2015 > What step size for the table? 4 > > Hard Drive Storage Costs Table > > Start Year = 1992 > End Year = 2015 > > Year Cost Per Gigabyte ($) > > 1992 2002.627 > 1996 199.894 > 2000 19.953 > 2004 1.992 > 2008 0.199 > 2012 0.02 >

    Another Run:

    Big Blue Hard Drive Storage Cost > > Enter the starting year: 1998 > Enter the ending year: 2010 > What step size for the table? 2 > > Hard Drive Storage Costs Table > > Start Year = 1998 > End Year = 2010 > > Year Cost Per Gigabyte ($) > > 1998 63.154 > 2000 19.953 > 2002 6.304 > 2004 1.992 > 2006 0.629 > 2008 0.199 > 2010 0.063
  • >
  • QUESTION
  • >
  • Could someone help me with a design and a python program to implement that design to solve the above problem?
  • >
>

>
> I can help! This is the exactly the same problem that was assigned as the first project in CS115 at the University of Kentucky. If you happen to live anywhere near UK, you can stop by the TA office hours and give you all the help you need. I know the instructors and most of the TA's personally and I am sure any of them will be pleased to help you. To get you started the first thing you have to do is output the report heading to the screen. From denismfmcmahon at gmail.com Mon Sep 29 10:44:34 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Mon, 29 Sep 2014 14:44:34 +0000 (UTC) Subject: Storage Cost Calculation References: <542760e9$0$13012$c3e8da3$5496439d@news.astraweb.com> <542776aa$0$13001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, 28 Sep 2014 20:07:31 +0000, Duncan Booth wrote: > Later on the B+ had 64k of RAM and the B+128 had 128k of RAM and in each > case the additional RAM was paged in as necessary but I don't think the > RAM in the B was ever expandable. You could get various expansions to page multiple roms, I had a machine at one point with 15 multiple internally and a zif socket on top. I think there was a board that sat across the 4 paged ROM sockets which then had a cable to another board with 16 sockets on it, and one of the 16 sockets came through the case in a ZIF. Aries or Dabs or Watford Electronics I expect. I also remember soldering switches to TEAC drives from RS to make them 40 / 80 track switchable. Duncan, your name looks mighty familiar ..... Do you know a Judith? -- Denis McMahon, denismfmcmahon at gmail.com From sturla.molden at gmail.com Mon Sep 29 10:51:33 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Mon, 29 Sep 2014 14:51:33 +0000 (UTC) Subject: Obscuring Python source from end users References: <89381545-5edc-4f85-a4b8-86eebfdf34ee@googlegroups.com> <542946ec$0$12998$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1698645184433694524.059292sturla.molden-gmail.com@news.gmane.org> Steven D'Aprano wrote: > Another possibility is to distribute your modules inside a zip file. See > here: > > https://mail.python.org/pipermail/python-list/2014-July/675506.html > > Such zip files are not just runnable, but also importable. Depending on your > Excel requirements, you might need a tiny driver script as above. It should also be possible to temper with the zipimport module to allow a 'scrambled' zip file. That makes it harder for users to access the code by unpacking the zip file. py2exe will collect pyc files into a single zip file and import that. It does not need a driver script because it embeds the Python interpreter in an executable. Yet another option is to compile the Python code with Cython and distribute everything as compiled pyd files. Sturla From sturla.molden at gmail.com Mon Sep 29 10:53:16 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Mon, 29 Sep 2014 14:53:16 +0000 (UTC) Subject: Obscuring Python source from end users References: <89381545-5edc-4f85-a4b8-86eebfdf34ee@googlegroups.com> Message-ID: <1430110548433695114.937858sturla.molden-gmail.com@news.gmane.org> Chris Angelico wrote: >> I have a project that involves distributing Python code to users in an >> organisation. Users do not interact directly with the Python code; they >> only know this project as an Excel add-in. >> >> Now, internal audit takes exception in some cases if users are able to >> see the source code. > > The solution is to fix your internal audit. +1 From wxjmfauth at gmail.com Mon Sep 29 11:05:29 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Mon, 29 Sep 2014 08:05:29 -0700 (PDT) Subject: Leap year In-Reply-To: <72778568-0205-47c5-8b60-163b09823170@googlegroups.com> References: <72778568-0205-47c5-8b60-163b09823170@googlegroups.com> Message-ID: <975bd109-3a7e-4bbc-bd93-6f0940995775@googlegroups.com> Le lundi 29 septembre 2014 08:59:11 UTC+2, Rustom Mody a ?crit?: > > Python has an if-expression distinct from the if-statement. > However its confusing because its order is 'upside down' > Ditto for Unicode. Python is just doing the opposite of the implementation of the utf coding schemes endorsed by unicode. On the side of memory (very easy to check, performance (a little bit harder) and plenty of specific unicode tasks like normalization. ;-) From ian.g.kelly at gmail.com Mon Sep 29 11:36:25 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 29 Sep 2014 09:36:25 -0600 Subject: trouble building data structure In-Reply-To: <54296401$0$12999$c3e8da3$5496439d@news.astraweb.com> References: <54296401$0$12999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Sep 29, 2014 at 7:52 AM, Steven D'Aprano wrote: > Whether you prefer to use setdefault, or a defaultdict, is a matter of > taste. There is potentially a significant difference in performance -- with setdefault, the subordinate data structure is created on every call to be passed into setdefault, only to be discarded if the key already exists. With defaultdict, the subordinate data structure is only created when needed. Dicts are pretty cheap to construct though, and this is probably not worth fretting over until profiling shows it to be a problem. On the other hand, it's easier to nest setdefaults arbitrarily deep than it is for defaultdicts. This is because defaultdict suffers from a design flaw -- defaultdict should be a function that returns a class (like namedtuple), not a class itself. Fortunately that's easily fixable: _DEFAULT_DICT_CACHE = {} def defaultdict(callable): try: return _DEFAULT_DICT_CACHE[callable] except KeyError: class _defaultdict(dict): def __missing__(self, key): self[key] = value = self._callable() return value _DEFAULT_DICT_CACHE[callable] = _defaultdict return _defaultdict A downside is that it would take some extra work to make this picklable. From Seymore4Head at Hotmail.invalid Mon Sep 29 11:44:01 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Mon, 29 Sep 2014 11:44:01 -0400 Subject: Teaching Python References: Message-ID: <4vui2ahng4fr7dh66c084olrmp4fcnam1e@4ax.com> On Mon, 29 Sep 2014 15:18:31 +0200, Gabor Urban wrote: >Hi, > >my 11 years old son and his classmate told me, that they would like to >learn Python. They did some programming in Logo and turtle graphics, bat >not too much. > >Doesn anybody has an idea how to start? I ordered this book from the library a few weeks ago. It just came in yesterday. Python for kids. Jason R Briggs This was also a good page for starters. http://www.practicepython.org/ From simon+python at bleah.co.uk Mon Sep 29 13:27:48 2014 From: simon+python at bleah.co.uk (Simon Ward) Date: Mon, 29 Sep 2014 18:27:48 +0100 Subject: Teaching Python In-Reply-To: References: Message-ID: <9d5a8bc2-dbda-414f-8fdd-dee356f5fd1d@email.android.com> On 29 September 2014 14:18:31 BST, Gabor Urban wrote: >my 11 years old son and his classmate told me, that they would like to >learn Python. They did some programming in Logo and turtle graphics, >bat >not too much. > >Doesn anybody has an idea how to start? "How to Think Like a Computer Scientist - Learning with Python 3": http://openbookproject.net/thinkcs/python/english3e/ If you're after a printed book, the original (I believe) author's current version is here: http://www.greenteapress.com/thinkpython/thinkpython.html Simon From john_ladasky at sbcglobal.net Mon Sep 29 14:41:45 2014 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Mon, 29 Sep 2014 11:41:45 -0700 (PDT) Subject: Teaching Python In-Reply-To: References: Message-ID: I am actually teaching Python as a side job. My students have ranged from eighth graders, up to a Silicon Valley hardware engineer who had no coding experience, but who needed to do some test engineering. My wife is an elementary school teacher. We occasionally talk about age-appropriate learning, and pedagogical strategies. I once watched a research biologist try to explain restriction enzymes to my sixth-grade son. It was painful to watch. Sure, my son is a smart kid, but there was no way he was going to understand what she was talking about without some background. For my younger Python students, I interact with them directly, sitting by their side while they type. Initially, I do not ask them to read any computer documentation. It's too difficult for them, even the official Python tutorial. The tutorial is aimed at an adult reader who has at least a little computer experience -- and sometimes, quite a lot. Just read Chapter 1. Imagine that you're 14 years old, reading that. Even if you have already programmed in one of the languages aimed at children, like Scratch, you will be in way over your head. Now, even though I think that the Python tutorial is too hard for young students to read, I do cover much of the MATERIAL in that tutorial, and in approximately the same order. I sit the student down in front of the interpreter, explain what an interpreter is, and then have them type simple mathematical expressions. I introduce variable names, and then strings, and lists. This is, more or less, the material in Chapter 3 of the tutorial -- although lists are not discussed until Chapter 5. Next, I introduce the idea of a program file, and have them start working with an editor. That's not in the tutorial at all. I introduce the print() function (briefly mentioned in Chapter 3), and the for statement (Section 4.2). Once you introduce the for statement, you need to explain code blocks, the use of a colon at the end of a line, and the use of indentation. This is enough information to get the student to write short programs. I start with single loops. Then, I have the student write a multiplication table program. Getting the student to grasp the idea of a loop inside a loop can sometimes be challenging. The next three things that I teach are the if statement (Section 4.1), the input() function (which appears in Chapter 4 of the tutorial, without any introduction or explanation), and string concatenation using the + operator. This is enough to get the student to write a program which accepts an input string, and prints out an alphabetized version of that string. I do not show the student the sorted() function until after they write the program with what they know! Typically, I move on to the range() function and slicing operations next. But unless you are working with very bright kids, that should be enough to keep them busy for a while. :^) From tjreedy at udel.edu Mon Sep 29 15:02:38 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 29 Sep 2014 15:02:38 -0400 Subject: Teaching Python In-Reply-To: References: Message-ID: On 9/29/2014 9:18 AM, Gabor Urban wrote: > Hi, > > my 11 years old son and his classmate told me, that they would like to > learn Python. They did some programming in Logo and turtle graphics, bat > not too much. > > Doesn anybody has an idea how to start? Python has a turtle module, so they can continue where they left off. The turtledemo package has about 20 example programs and shows code in one pane beside a turtle canvas in another. The new 3.4.2 (release candidate now, final in a week or two) has several turtle and turtledemo fixes. -- Terry Jan Reedy From nad at acm.org Mon Sep 29 18:55:57 2014 From: nad at acm.org (Ned Deily) Date: Mon, 29 Sep 2014 15:55:57 -0700 Subject: Weird SSL problem References: Message-ID: In article , Roland Hedberg wrote: > Hi! > > I?m trying to access > https://stsadweb.one.microsoft.com/adfs/.well-known/openid-configuration > > Doing it the simplest way I get the following: > > >>> import urllib > >>> f = > >>> urllib.urlopen("https://stsadweb.one.microsoft.com/adfs/.well-known/openid > >>> -configuration") > Traceback (most recent call last): > File "", line 1, in > File > "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", > line 87, in urlopen > return opener.open(url) > File > "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", > line 208, in open > return getattr(self, name)(url) > File > "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", > line 437, in open_https > h.endheaders(data) > File > "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py" > , line 969, in endheaders > self._send_output(message_body) > File > "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py" > , line 829, in _send_output > self.send(msg) > File > "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py" > , line 791, in send > self.connect() > File > "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py" > , line 1176, in connect > self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file) > File > "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", > line 387, in wrap_socket > ciphers=ciphers) > File > "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", > line 143, in __init__ > self.do_handshake() > File > "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", > line 305, in do_handshake > self._sslobj.do_handshake() > IOError: [Errno socket error] [Errno 54] Connection reset by peer > >>> import ssl > >>> ssl.OPENSSL_VERSION > ?OpenSSL 0.9.8za 5 Jun 2014' > > Now, using Safari, or curl for that matter, from the same machine works > without a hitch. > > The URL above is also the only URL I?ve encountered this problem with. > > Anyone got an idea ? I believe the problem is that the connection is protected by a multi-hostname server certificate and Python 2's urllib (and underlying httplib and ssl modules) do not support SNI extensions to TLS. The request above works fine with Python 3 (which has supported client-side SNI since Python 3.2). See http://bugs.python.org/issue5639 for more discussion of the matter. If Python 3 is not an option for you, the requests package available via PyPI should help. -- Ned Deily, nad at acm.org From alfred at 54.org Mon Sep 29 21:19:53 2014 From: alfred at 54.org (alfred at 54.org) Date: Mon, 29 Sep 2014 18:19:53 -0700 (PDT) Subject: JSON-encoding very long iterators Message-ID: <4232c92a-101c-4a1b-89b2-e80d67ef7bc6@googlegroups.com> I would like to add the ability to JSONEncode large iterators. Right now there is no way to do this without modifying the code. The JSONEncoder.default() doc string suggests to do this: For example, to support arbitrary iterators, you could implement default like this:: def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o) but this method requires the whole serialized object to fit in memory and it's a good chance that your iterator is an iterator to save on memory in the first place. By changing the code to accept iterators it is then possible to stream json as I did here: http://stackoverflow.com/a/26094558/289240 This would ideal if it were included in the standard library. Is there any reason why it shouldn't be? From ian.g.kelly at gmail.com Mon Sep 29 21:58:47 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 29 Sep 2014 19:58:47 -0600 Subject: JSON-encoding very long iterators In-Reply-To: <4232c92a-101c-4a1b-89b2-e80d67ef7bc6@googlegroups.com> References: <4232c92a-101c-4a1b-89b2-e80d67ef7bc6@googlegroups.com> Message-ID: On Mon, Sep 29, 2014 at 7:19 PM, wrote: > I would like to add the ability to JSONEncode large iterators. Right now there is no way to do this without modifying the code. > > The JSONEncoder.default() doc string suggests to do this: > For example, to support arbitrary iterators, you could > implement default like this:: > def default(self, o): > try: > iterable = iter(o) > except TypeError: > pass > else: > return list(iterable) > # Let the base class default method raise the TypeError > return JSONEncoder.default(self, o) > > but this method requires the whole serialized object to fit in memory and it's a good chance that your iterator is an iterator to save on memory in the first place. > > By changing the code to accept iterators it is then possible to stream json as I did here: > http://stackoverflow.com/a/26094558/289240 > > This would ideal if it were included in the standard library. Is there any reason why it shouldn't be? This would cause things that aren't lists to be encoded as lists. Sometimes that may be desirable, but in general if e.g. a file object sneaks its way into your JSON encode call, it is more likely correct to raise an error than to silently encode the file as if it were a list of strings. So it should not be the default behavior. That said, it sounds like it could be made easier to enable streaming from iterators as an option for those cases where it's desired. From cl at isbd.net Tue Sep 30 07:35:01 2014 From: cl at isbd.net (cl at isbd.net) Date: Tue, 30 Sep 2014 12:35:01 +0100 Subject: Keepin constants, configuration values, etc. in Python - dedicated module or what? Message-ID: <54hqfb-nan.ln1@chris.zbmc.eu> I am developing some code which runs on a (remote from me most of the time) Beaglebone Black single board computer. It reads various items of data (voltages, currents, temperatures, etc.) using both a 1-wire bus system and the Beaglebone's ADC inputs. The values are stored at hourly intervals into a database which is regularly rsync'ed across to my home system where I use the values for monitoring etc. Associated with each value are various parameters, i.e. for each ADC input of the Beaglebone there is the ADC input number, a short name for the value, a conversion factor and a description. Similarly for the 1-wire inputs there is the 1-wire filesystem filename, a short name for the data and a longer description. I am puzzling where and how to keep these configuration values. My current design has them in dedicated tables in the database but this is rather clumsy in many ways as there's an overhead reading them every time the program needs them and changing them isn't particularly convenient at the Beaglebone doesn't have a GUI so it has to be done using SQL from the command line. Does it make sense to add them to the modules which handle the reading of the inputs? I already have modules defining classes called Adc and OneWire, is it a reasonable approach to add the configuration to these as, probably, dictionaries? Modifying it would be pretty simple - just edit the python source (one of the easiest things for me to do on the Beaglebone as my sole access is via ssh/command line). Thus I'd have something like (apologies for any syntax errors):- cfg = { "LeisureVolts": ["AIN0", 0.061256, "Leisure Battery Voltage"], "StarterVolts": ["AIN1", 0.060943, "Starter Battery Voltage"], "LeisureAmps1": ["AIN2", 0.423122, "Leisure Battery Current"} (It might be better to makes those lists dictionaries, but it shows the idea) Are there any better ways of doing this? E.g. some sort of standard configuration file format that Python knows about? I would actually quite like to keep the configuration data separate from the code as it would simplify using the data at the 'home' end of things as I'd just need to copy the configuration file across. This was why the database approach appealed at first as all I need to do is copy the database and everything is in there. I'm not really expecting quick/glib answers, just some ideas and comments on the various ways of doing this and their advantages and disadvantages. -- Chris Green ? From jeanmichel at sequans.com Tue Sep 30 07:50:08 2014 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 30 Sep 2014 13:50:08 +0200 (CEST) Subject: Python code in presentations In-Reply-To: <1617366671.8129227.1412075768865.JavaMail.root@sequans.com> Message-ID: <84647424.8133875.1412077808913.JavaMail.root@sequans.com> Hello list, I'm currently writing a presentation to help my co-workers ramp up on new features of our tool (written in python (2.7)). I have some difficulties presenting code in an efficient way (with some basic syntax highlights). I need to be catchy about the code I'm presenting otherwise the presentation will fail and I would be better saying to my co-workers "RTFM", cause there is a manual. So I really need to make them realize the code I'm presenting will benefit them (they're not software engineers, python is just a tool, their expertise and focus is aimed at something else, don't blame them :) ) Right now the method I'm using is write the code in notepad++, use a plugin (NppExport) to copy paste code into powerpoint. After using it a little bit, I'm really not satisfied with this method, it's expensive and all this copy paste stuff is driving me crazy. Not to mention that the syntax highlight from notepads renders like crap in powerpoint. I wonder if some people in this list who have successfully presented python code have some tips about doing the proper way. Ned's presentations for pycons are to me one example of successful code presentation: - the layout is simple - the code and code output are clearly identified - a line of code can be highlighted while presenting http://nedbatchelder.com/text/iter.html I have access to powerpoint, or any tool under linux (I don't have access to Mac's stuff). Right now I'm so not satisfied by my current method that I'm about to make the presentation showing the code from the file directly, alt-tabing between the slides and the code. At least it's cheap. JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From werotizy at freent.dd Tue Sep 30 08:46:24 2014 From: werotizy at freent.dd (Tom P) Date: Tue, 30 Sep 2014 14:46:24 +0200 Subject: Python code in presentations In-Reply-To: References: Message-ID: On 30.09.2014 13:50, Jean-Michel Pichavant wrote: > Hello list, > > I'm currently writing a presentation to help my co-workers ramp up on new features of our tool (written in python (2.7)). > > I have some difficulties presenting code in an efficient way (with some basic syntax highlights). I need to be catchy about the code I'm presenting otherwise the presentation will fail and I would be better saying to my co-workers "RTFM", cause there is a manual. > > So I really need to make them realize the code I'm presenting will benefit them (they're not software engineers, python is just a tool, their expertise and focus is aimed at something else, don't blame them :) ) > > Right now the method I'm using is write the code in notepad++, use a plugin (NppExport) to copy paste code into powerpoint. > After using it a little bit, I'm really not satisfied with this method, it's expensive and all this copy paste stuff is driving me crazy. Not to mention that the syntax highlight from notepads renders like crap in powerpoint. > > I wonder if some people in this list who have successfully presented python code have some tips about doing the proper way. Ned's presentations for pycons are to me one example of successful code presentation: > - the layout is simple > - the code and code output are clearly identified > - a line of code can be highlighted while presenting > > http://nedbatchelder.com/text/iter.html > > I have access to powerpoint, or any tool under linux (I don't have access to Mac's stuff). > > Right now I'm so not satisfied by my current method that I'm about to make the presentation showing the code from the file directly, alt-tabing between the slides and the code. At least it's cheap. > > JM > > > > > > -- IMPORTANT NOTICE: > > The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. > I can't answer your question, but thanks for the great presentation on iterables! From joel.goldstick at gmail.com Tue Sep 30 09:01:38 2014 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 30 Sep 2014 09:01:38 -0400 Subject: Python code in presentations In-Reply-To: References: Message-ID: On Tue, Sep 30, 2014 at 8:46 AM, Tom P wrote: > On 30.09.2014 13:50, Jean-Michel Pichavant wrote: >> >> Hello list, >> >> I'm currently writing a presentation to help my co-workers ramp up on new >> features of our tool (written in python (2.7)). >> >> I have some difficulties presenting code in an efficient way (with some >> basic syntax highlights). I need to be catchy about the code I'm presenting >> otherwise the presentation will fail and I would be better saying to my >> co-workers "RTFM", cause there is a manual. >> >> So I really need to make them realize the code I'm presenting will benefit >> them (they're not software engineers, python is just a tool, their expertise >> and focus is aimed at something else, don't blame them :) ) >> >> Right now the method I'm using is write the code in notepad++, use a >> plugin (NppExport) to copy paste code into powerpoint. >> After using it a little bit, I'm really not satisfied with this method, >> it's expensive and all this copy paste stuff is driving me crazy. Not to >> mention that the syntax highlight from notepads renders like crap in >> powerpoint. >> >> I wonder if some people in this list who have successfully presented >> python code have some tips about doing the proper way. Ned's presentations >> for pycons are to me one example of successful code presentation: >> - the layout is simple >> - the code and code output are clearly identified >> - a line of code can be highlighted while presenting >> >> http://nedbatchelder.com/text/iter.html >> >> I have access to powerpoint, or any tool under linux (I don't have access >> to Mac's stuff). >> >> Right now I'm so not satisfied by my current method that I'm about to make >> the presentation showing the code from the file directly, alt-tabing between >> the slides and the code. At least it's cheap. I like that idea. It offers everything you need I'm a little at a loss that you are concentrating on showing code to users. Are you also showing how your tool works to solve the problems that they will need to solve with it? >> >> JM >> >> >> >> >> >> -- IMPORTANT NOTICE: >> >> The contents of this email and any attachments are confidential and may >> also be privileged. If you are not the intended recipient, please notify the >> sender immediately and do not disclose the contents to any other person, use >> it for any purpose, or store or copy the information in any medium. Thank >> you. >> > > I can't answer your question, but thanks for the great presentation on > iterables! > > -- > https://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick http://joelgoldstick.com From davea at davea.name Tue Sep 30 09:14:57 2014 From: davea at davea.name (Dave Angel) Date: Tue, 30 Sep 2014 09:14:57 -0400 (EDT) Subject: Keepin constants, configuration values, etc. in Python - dedicated module or what? References: <54hqfb-nan.ln1@chris.zbmc.eu> Message-ID: cl at isbd.net Wrote in message: > I am developing some code which runs on a (remote from me most of the > time) Beaglebone Black single board computer. It reads various items > of data (voltages, currents, temperatures, etc.) using both a 1-wire > bus system and the Beaglebone's ADC inputs. The values are stored > at hourly intervals into a database which is regularly rsync'ed > across to my home system where I use the values for monitoring etc. > > Associated with each value are various parameters, i.e. for each ADC > input of the Beaglebone there is the ADC input number, a short name > for the value, a conversion factor and a description. Similarly for > the 1-wire inputs there is the 1-wire filesystem filename, a short > name for the data and a longer description. > > I am puzzling where and how to keep these configuration values. My > current design has them in dedicated tables in the database but this > is rather clumsy in many ways as there's an overhead reading them > every time the program needs them and changing them isn't particularly > convenient at the Beaglebone doesn't have a GUI so it has to be done > using SQL from the command line. It is very useful for the database to be self contained and self describing. Among other things it means that you can easily take a snapshot at any time, and that snapshot is not tied to any specific version of the code. As for changing with sql, you can always add a configuration utility when using sql becomes a nuisance, or introduces errors. The key thing is to manage change. You need to decide which things are conceivably going to change and how you'll manage both the change itself and the inevitable split between prechange data and post. One kind of change might be fixing the spelling of battery. No biggie, just let new accesses get the new one. Another kind might be the addition of a new instance of an adc converter. Not a problem, as long as you don't reuse an old name. And presumably you never remove an old name from the config. More troublesome is adding a new kind of data. You have to decide whether it's worth generalizing the code to anticipate the change, or just admit that the code will grow at that point and that old code won't deal with the new data. > > Does it make sense to add them to the modules which handle the reading > of the inputs? I already have modules defining classes called Adc and > OneWire, is it a reasonable approach to add the configuration to these > as, probably, dictionaries? Modifying it would be pretty simple - > just edit the python source (one of the easiest things for me to do on > the Beaglebone as my sole access is via ssh/command line). > Nope, read it from the db. You still might be loading it to a cfg variable, however. > Thus I'd have something like (apologies for any syntax errors):- > > cfg = { "LeisureVolts": ["AIN0", 0.061256, "Leisure Battery Voltage"], > "StarterVolts": ["AIN1", 0.060943, "Starter Battery Voltage"], > "LeisureAmps1": ["AIN2", 0.423122, "Leisure Battery Current"} > > (It might be better to makes those lists dictionaries, but it shows > the idea) Actually it's probably better to use named tuples. All those lists are apparently of identical length with identical meaning of a given element offset. But if named tuple isn't flexible,enough, you probably need a new class. > > Are there any better ways of doing this? E.g. some sort of standard > configuration file format that Python knows about? I would actually > quite like to keep the configuration data separate from the code as it > would simplify using the data at the 'home' end of things as I'd just > need to copy the configuration file across. This was why the database > approach appealed at first as all I need to do is copy the database > and everything is in there. > > I'm not really expecting quick/glib answers, just some ideas and > comments on the various ways of doing this and their advantages and > disadvantages. Main next question is whether you can restart each system when you add to the configuration. -- DaveA From rustompmody at gmail.com Tue Sep 30 09:15:39 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 30 Sep 2014 06:15:39 -0700 (PDT) Subject: Keepin constants, configuration values, etc. in Python - dedicated module or what? In-Reply-To: <54hqfb-nan.ln1@chris.zbmc.eu> References: <54hqfb-nan.ln1@chris.zbmc.eu> Message-ID: <36d7ddca-29f4-403c-a64d-611e187afc3a@googlegroups.com> On Tuesday, September 30, 2014 5:18:31 PM UTC+5:30, Chris wrote: > I would actually > quite like to keep the configuration data separate from the code as it > would simplify using the data at the 'home' end of things as I'd just > need to copy the configuration file across. This was why the database > approach appealed at first as all I need to do is copy the database > and everything is in there. Of course > Are there any better ways of doing this? E.g. some sort of standard > configuration file format that Python knows about? Umm this is getting to be a FAQ... Maybe it should go up somewhere? Yes there are dozens: - ini - csv - json - yml - xml - pickle - And any DBMS of your choice I guess Ive forgotten as many as Ive listed!! From rustompmody at gmail.com Tue Sep 30 09:23:06 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 30 Sep 2014 06:23:06 -0700 (PDT) Subject: Python code in presentations In-Reply-To: References: <1617366671.8129227.1412075768865.JavaMail.root@sequans.com> Message-ID: <0cdb659f-9d7f-4f1d-9952-7049170acac3@googlegroups.com> On Tuesday, September 30, 2014 5:21:00 PM UTC+5:30, Jean-Michel Pichavant wrote: > Hello list, > I'm currently writing a presentation to help my co-workers ramp up on new features of our tool (written in python (2.7)). > I have some difficulties presenting code in an efficient way (with some basic syntax highlights). I need to be catchy about the code I'm presenting otherwise the presentation will fail and I would be better saying to my co-workers "RTFM", cause there is a manual. > So I really need to make them realize the code I'm presenting will benefit them (they're not software engineers, python is just a tool, their expertise and focus is aimed at something else, don't blame them :) ) > Right now the method I'm using is write the code in notepad++, use a plugin (NppExport) to copy paste code into powerpoint. > After using it a little bit, I'm really not satisfied with this method, it's expensive and all this copy paste stuff is driving me crazy. Not to mention that the syntax highlight from notepads renders like crap in powerpoint. > I wonder if some people in this list who have successfully presented python code have some tips about doing the proper way. Ned's presentations for pycons are to me one example of successful code presentation: > - the layout is simple > - the code and code output are clearly identified > - a line of code can be highlighted while presenting > http://nedbatchelder.com/text/iter.html > I have access to powerpoint, or any tool under linux (I don't have access to Mac's stuff). > Right now I'm so not satisfied by my current method that I'm about to make the presentation showing the code from the file directly, alt-tabing between the slides and the code. At least it's cheap. Org mode's babel system is touted for exactly this: http://www.jstatsoft.org/v46/i03/paper [I must confess that Ive not quite got my teeth into it] From ned at nedbatchelder.com Tue Sep 30 09:26:19 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 30 Sep 2014 09:26:19 -0400 Subject: Python code in presentations In-Reply-To: <84647424.8133875.1412077808913.JavaMail.root@sequans.com> References: <1617366671.8129227.1412075768865.JavaMail.root@sequans.com> <84647424.8133875.1412077808913.JavaMail.root@sequans.com> Message-ID: On 9/30/14 7:50 AM, Jean-Michel Pichavant wrote: > I wonder if some people in this list who have successfully presented python code have some tips about doing the proper way. Ned's presentations for pycons are to me one example of successful code presentation: > - the layout is simple > - the code and code output are clearly identified > - a line of code can be highlighted while presenting > > http://nedbatchelder.com/text/iter.html Thanks for the hat-tip! The problem with my presentations is that the production tool-chain is only approachable by programmers, and probably not even all of them! I have a tendency toward custom-written purely text-based tools that give me lots of control at the expense of ease of use. The source of that presentation is here: https://github.com/nedbat/iter You'll notice there's a Makefile... > > I have access to powerpoint, or any tool under linux (I don't have access to Mac's stuff). I don't know how to get the highlighting (both static and dynamic) in a WYSIWYG presentation tool. :( -- Ned Batchelder, http://nedbatchelder.com From jeanmichel at sequans.com Tue Sep 30 09:55:16 2014 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 30 Sep 2014 15:55:16 +0200 (CEST) Subject: Python code in presentations In-Reply-To: Message-ID: <1606999336.8151188.1412085316706.JavaMail.root@sequans.com> ----- Original Message ----- > From: "Joel Goldstick" > Cc: python-list at python.org > Sent: Tuesday, 30 September, 2014 3:01:38 PM > Subject: Re: Python code in presentations > > I'm a little at a loss that you are concentrating on showing code to > users. Are you also showing how your tool works to solve the > problems > that they will need to solve with it? > >> > >> JM We write python code using the tools I've mentioned, these tools are nothing more than code snippets, custom classes, decorators and modules. Using them is all about writing python code. However we all have the kind of "quick and dirty" knowledge of python, writing python code is not our core expertise. That is why I thought showing how simple and elegant python can be could provoke some visual shock, making them think "I want to do that". Possibly the wrong approach, I'll tell you that after the presentation :) . JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From fomcl at yahoo.com Tue Sep 30 10:25:09 2014 From: fomcl at yahoo.com (Albert-Jan Roskam) Date: Tue, 30 Sep 2014 07:25:09 -0700 Subject: Python code in presentations Message-ID: <1412087109.81762.BPMail_high_noncarrier@web163802.mail.gq1.yahoo.com> ------------------------------ On Tue, Sep 30, 2014 1:50 PM CEST Jean-Michel Pichavant wrote: >Hello list, > >I'm currently writing a presentation to help my co-workers ramp up on new features of our tool (written in python (2.7)). > >I have some difficulties presenting code in an efficient way (with some basic syntax highlights). I need to be catchy about the code I'm presenting otherwise the presentation will fail and I would be better saying to my co-workers "RTFM", cause there is a manual. > >So I really need to make them realize the code I'm presenting will benefit them (they're not software engineers, python is just a tool, their expertise and focus is aimed at something else, don't blame them :) ) > >Right now the method I'm using is write the code in notepad++, use a plugin (NppExport) to copy paste code into powerpoint. >After using it a little bit, I'm really not satisfied with this method, it's expensive and all this copy paste stuff is driving me crazy. Not to mention that the syntax highlight from notepads renders like crap in powerpoint. > >I wonder if some people in this list who have successfully presented python code have some tips about doing the proper way. Ned's presentations for pycons are to me one example of successful code presentation: > - the layout is simple > - the code and code output are clearly identified > - a line of code can be highlighted while presenting > >http://nedbatchelder.com/text/iter.html > >I have access to powerpoint, or any tool under linux (I don't have access to Mac's stuff). > >Right now I'm so not satisfied by my current method that I'm about to make the presentation showing the code from the file directly, alt-tabing between the slides and the code. At least it's cheap. Have you considered using Ipython Notebook? Your browser would replace ppt. From cl at isbd.net Tue Sep 30 10:55:27 2014 From: cl at isbd.net (cl at isbd.net) Date: Tue, 30 Sep 2014 15:55:27 +0100 Subject: Keepin constants, configuration values, etc. in Python - dedicated module or what? References: <54hqfb-nan.ln1@chris.zbmc.eu> Message-ID: Dave Angel wrote: > cl at isbd.net Wrote in message: > > I am puzzling where and how to keep these configuration values. My > > current design has them in dedicated tables in the database but this > > is rather clumsy in many ways as there's an overhead reading them > > every time the program needs them and changing them isn't particularly > > convenient at the Beaglebone doesn't have a GUI so it has to be done > > using SQL from the command line. > > It is very useful for the database to be self contained and self > describing. Among other things it means that you can easily take > a snapshot at any time, and that snapshot is not tied to any > specific version of the code. As for changing with sql, you can > always add a configuration utility when using sql becomes a > nuisance, or introduces errors. > I guess I can write a script to do the change but it's more code to write and maintain as opposed to simply editing a configuration file with tools I know well. > The key thing is to manage change. You need to decide which > things are conceivably going to change and how you'll manage both > the change itself and the inevitable split between prechange data > and post. One kind of change might be fixing the spelling of > battery. No biggie, just let new accesses get the new one. > Another kind might be the addition of a new instance of an adc > converter. Not a problem, as long as you don't reuse an old > name. And presumably you never remove an old name from the > config. > The only things really likely to change (and may change regularly) are the conversion factors, drifting voltage references etc. will inevitably require these to be recalibrated every so often. Other than that it's just typos or me deciding to change the name of something. > More troublesome is adding a new kind of data. You have to decide > whether it's worth generalizing the code to anticipate the > change, or just admit that the code will grow at that point and > that old code won't deal with the new data. > There's a separate module for each input type (just ADC and 1-wire at the moment), I don't anticipate any more though I suppose there might be digital inputs one day. So a configuration [file] for each type seems to make sense, generalising it would be more trouble than it's worth I think. > > > > Does it make sense to add them to the modules which handle the reading > > of the inputs? I already have modules defining classes called Adc and > > OneWire, is it a reasonable approach to add the configuration to these > > as, probably, dictionaries? Modifying it would be pretty simple - > > just edit the python source (one of the easiest things for me to do on > > the Beaglebone as my sole access is via ssh/command line). > > > > Nope, read it from the db. You still might be loading it to a cfg > variable, however. > > > Thus I'd have something like (apologies for any syntax errors):- > > > > cfg = { "LeisureVolts": ["AIN0", 0.061256, "Leisure Battery Voltage"], > > "StarterVolts": ["AIN1", 0.060943, "Starter Battery Voltage"], > > "LeisureAmps1": ["AIN2", 0.423122, "Leisure Battery Current"} > > > > (It might be better to makes those lists dictionaries, but it shows > > the idea) > > Actually it's probably better to use named tuples. All those lists > are apparently of identical length with identical meaning of a > given element offset. But if named tuple isn't flexible,enough, > you probably need a new class. > > > > > Are there any better ways of doing this? E.g. some sort of standard > > configuration file format that Python knows about? I would actually > > quite like to keep the configuration data separate from the code as it > > would simplify using the data at the 'home' end of things as I'd just > > need to copy the configuration file across. This was why the database > > approach appealed at first as all I need to do is copy the database > > and everything is in there. > > > > I'm not really expecting quick/glib answers, just some ideas and > > comments on the various ways of doing this and their advantages and > > disadvantages. > > Main next question is whether you can restart each system when you > add to the configuration. > Yes, restarting isn't a problem, the Beaglebone is dedicated to this task and doesn't control anything so restarts are not an issue. -- Chris Green ? From reddy at poczta.fm Tue Sep 30 10:50:40 2014 From: reddy at poczta.fm (Reddy) Date: Tue, 30 Sep 2014 16:50:40 +0200 Subject: SNI support in python 2.7 for Locust load tests Message-ID: Hello, At the beginning - welcome everyone, as this is my first post here. I'm not an active Python developer now, but I have general knowledge of the language. I'm trying to use locust (http://locust.io/) to run load test of one site we're developing. Everything was running nice and smooth until we switch the servers to use SNI. SNI is not officially supported in python 2.7.5 but Locust doesn't work on python3 as it uses gevent which AFAIK are supported for python2 only. I finally managed to run our scripts on local Ubuntu after upgrading python to 2.7.8 from utopic repository but I can't replicate the same on target CentOS where the scripts are supposed to be executed. I tried compiling python from http://www.python.org/ftp/python/2.7.8/Python-2.7.8.tar.xz, I even tried unpacking sources of Ubuntu python2.7 package (from http://se.archive.ubuntu.com/ubuntu/pool/main/p/python2.7/python2.7_2.7.8.orig.tar.gz), patching them with TLS1_1 and TLS1_2 support from https://bugs.python.org/file30761/python-2.7.5-tls1.1-and-tls1.2.patch) and still no luck. I do monkey patch in Locust startup file according to http://stackoverflow.com/a/19477363 (otherwise it wouldn't work on Ubuntu as well) but still I get error stack as attached below. I also checked with pip list that all python packages have the same versions on both systems. Any idea what I'm missing on the target load test system which I have in Ubuntu? Regards, Reddy ... [2014-09-30 14:19:41,771] ip-x-x-x-x/ERROR/stderr: File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 503, in put [2014-09-30 14:19:41,771] ip-x-x-x-x/ERROR/stderr: return self.request('PUT', url, data=data, **kwargs) [2014-09-30 14:19:41,771] ip-x-x-x-x/ERROR/stderr: File "/usr/local/lib/python2.7/site-packages/locust/clients.py", line 111, in request [2014-09-30 14:19:41,772] ip-x-x-x-x/ERROR/stderr: response = self._send_request_safe_mode(method, url, **kwargs) [2014-09-30 14:19:41,772] ip-x-x-x-x/ERROR/stderr: File "/usr/local/lib/python2.7/site-packages/locust/clients.py", line 155, in _send_request_safe_mode [2014-09-30 14:19:41,772] ip-x-x-x-x/ERROR/stderr: return requests.Session.request(self, method, url, **kwargs) [2014-09-30 14:19:41,773] ip-x-x-x-x/ERROR/stderr: File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 451, in request [2014-09-30 14:19:41,773] ip-x-x-x-x/ERROR/stderr: resp = self.send(prep, **send_kwargs) [2014-09-30 14:19:41,773] ip-x-x-x-x/ERROR/stderr: File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 557, in send [2014-09-30 14:19:41,774] ip-x-x-x-x/ERROR/stderr: r = adapter.send(request, **kwargs) [2014-09-30 14:19:41,774] ip-x-x-x-x/ERROR/stderr: File "/usr/local/lib/python2.7/site-packages/requests/adapters.py", line 362, in send [2014-09-30 14:19:41,775] ip-x-x-x-x/ERROR/stderr: timeout=timeout [2014-09-30 14:19:41,775] ip-x-x-x-x/ERROR/stderr: File "/usr/local/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py", line 516, in urlopen [2014-09-30 14:19:41,775] ip-x-x-x-x/ERROR/stderr: body=body, headers=headers) [2014-09-30 14:19:41,776] ip-x-x-x-x/ERROR/stderr: File "/usr/local/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py", line 308, in _make_request [2014-09-30 14:19:41,776] ip-x-x-x-x/ERROR/stderr: conn.request(method, url, **httplib_request_kw) [2014-09-30 14:19:41,776] ip-x-x-x-x/ERROR/stderr: File "/usr/local/lib/python2.7/httplib.py", line 995, in request [2014-09-30 14:19:41,777] ip-x-x-x-x/ERROR/stderr: self._send_request(method, url, body, headers) [2014-09-30 14:19:41,777] ip-x-x-x-x/ERROR/stderr: File "/usr/local/lib/python2.7/httplib.py", line 1029, in _send_request [2014-09-30 14:19:41,778] ip-x-x-x-x/ERROR/stderr: self.endheaders(body) [2014-09-30 14:19:41,778] ip-x-x-x-x/ERROR/stderr: File "/usr/local/lib/python2.7/httplib.py", line 991, in endheaders [2014-09-30 14:19:41,778] ip-x-x-x-x/ERROR/stderr: self._send_output(message_body) [2014-09-30 14:19:41,779] ip-x-x-x-x/ERROR/stderr: File "/usr/local/lib/python2.7/httplib.py", line 848, in _send_output [2014-09-30 14:19:41,779] ip-x-x-x-x/ERROR/stderr: self.send(message_body) [2014-09-30 14:19:41,779] ip-x-x-x-x/ERROR/stderr: File "/usr/local/lib/python2.7/httplib.py", line 817, in send [2014-09-30 14:19:41,780] ip-x-x-x-x/ERROR/stderr: self.sock.sendall(datablock) [2014-09-30 14:19:41,792] ip-x-x-x-x/ERROR/stderr: File "/usr/local/lib/python2.7/site-packages/requests/packages/urllib3/contrib/pyopenssl.py", line 203, in sendall [2014-09-30 14:19:41,793] ip-x-x-x-x/ERROR/stderr: return self.connection.sendall(data) [2014-09-30 14:19:41,793] ip-x-x-x-x/ERROR/stderr: File "build/bdist.linux-x86_64/egg/OpenSSL/SSL.py", line 977, in sendall [2014-09-30 14:19:41,793] ip-x-x-x-x/ERROR/stderr: File "build/bdist.linux-x86_64/egg/OpenSSL/SSL.py", line 849, in _raise_ssl_error [2014-09-30 14:19:41,794] ip-x-x-x-x/ERROR/stderr: OpenSSL.SSL [2014-09-30 14:19:41,794] ip-x-x-x-x/ERROR/stderr: . [2014-09-30 14:19:41,794] ip-x-x-x-x/ERROR/stderr: WantWriteError From cl at isbd.net Tue Sep 30 11:06:19 2014 From: cl at isbd.net (cl at isbd.net) Date: Tue, 30 Sep 2014 16:06:19 +0100 Subject: Keepin constants, configuration values, etc. in Python - dedicated module or what? References: <54hqfb-nan.ln1@chris.zbmc.eu> <36d7ddca-29f4-403c-a64d-611e187afc3a@googlegroups.com> Message-ID: Rustom Mody wrote: > On Tuesday, September 30, 2014 5:18:31 PM UTC+5:30, Chris wrote: > > > I would actually > > quite like to keep the configuration data separate from the code as it > > would simplify using the data at the 'home' end of things as I'd just > > need to copy the configuration file across. This was why the database > > approach appealed at first as all I need to do is copy the database > > and everything is in there. > > Of course > > > Are there any better ways of doing this? E.g. some sort of standard > > configuration file format that Python knows about? > > Umm this is getting to be a FAQ... > Maybe it should go up somewhere? > > Yes there are dozens: > - ini > - csv > - json > - yml > - xml > - pickle > - And any DBMS of your choice > > I guess Ive forgotten as many as Ive listed!! Yes, I know, I've found most of those. I'm really asking for help in choosing which to use. I think I can reject some quite quickly:- ini - doesn't work so well with lists/dictionaries (though possible) csv - rather difficult to edit json - one of the most likely possibilities, but prefer yml yml - front runner if I go for configuration files xml - horrible, nasty to edit, etc. I don't like XML! :-) pickle - not user editable as I understand it dbms - current solution in sqlite3 as described What I'm really asking for is how to choose between:- DBMS - present solution, keeps config with data easily but more code and less easy to change yml - easy to edit config, keeps data separate from code but needs YAML installed and separate files to manage python - just keep config in the modules/classes, not easy to use at 'both ends' (home and remote), otherwise quite simple My requirements are:- Easy to change, i.e.human readable format which can be edited simply as I have to do this via a terminal/ssh. Easy to use at local end as well as remote end, the remote end is where it lives and is the 'driver' as it were but I need to know the configuration at the local end as well. -- Chris Green ? From jkn_gg at nicorp.f9.co.uk Tue Sep 30 11:59:58 2014 From: jkn_gg at nicorp.f9.co.uk (jkn) Date: Tue, 30 Sep 2014 08:59:58 -0700 (PDT) Subject: Keepin constants, configuration values, etc. in Python - dedicated module or what? In-Reply-To: References: <54hqfb-nan.ln1@chris.zbmc.eu> <36d7ddca-29f4-403c-a64d-611e187afc3a@googlegroups.com> Message-ID: <22666d61-990d-463c-8b83-d2263f132191@googlegroups.com> might this be of interest (though old)? https://wiki.python.org/moin/ConfigParserShootout Cheers Jon N From neilc at norwich.edu Tue Sep 30 12:16:47 2014 From: neilc at norwich.edu (Neil D. Cerutti) Date: Tue, 30 Sep 2014 12:16:47 -0400 Subject: Keepin constants, configuration values, etc. in Python - dedicated module or what? In-Reply-To: <54hqfb-nan.ln1@chris.zbmc.eu> References: <54hqfb-nan.ln1@chris.zbmc.eu> Message-ID: On 9/30/2014 7:35 AM, cl at isbd.net wrote: > Thus I'd have something like (apologies for any syntax errors):- > > cfg = { "LeisureVolts": ["AIN0", 0.061256, "Leisure Battery Voltage"], > "StarterVolts": ["AIN1", 0.060943, "Starter Battery Voltage"], > "LeisureAmps1": ["AIN2", 0.423122, "Leisure Battery Current"} > > (It might be better to makes those lists dictionaries, but it shows > the idea) Using configparser.ConfigParser to read an ini-format seems like a good idea. I use it for my own numerous fixed format data file definitions, and it's been convenient and even extensible. [LeisureVolts] Description=Leisure Battery Voltage Code=AIN0 Value=0.061256 [StarterVolts] Description=Starter Battery Voltage Code=AIN1 Value=0.060943 [LeisureAmps1] Description=Leisure Battery Current Code=AIN2 Value=0.423122 I've set it up so I can understand abbreviations for the field names, for when I want to be lazy. Some of my values are dictionaries, which looks like this in my files (an alternate spelling of one of the above entries): LeisureVolts=desc:Leisure Battery Voltage code:AIN2 value:0.061256 It's simple to hook into ConfigParser to get whatever meaning you'd like, and whatever verification you'd find necessary. -- Neil Cerutti From rustompmody at gmail.com Tue Sep 30 12:39:37 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 30 Sep 2014 09:39:37 -0700 (PDT) Subject: Keepin constants, configuration values, etc. in Python - dedicated module or what? In-Reply-To: References: <54hqfb-nan.ln1@chris.zbmc.eu> <36d7ddca-29f4-403c-a64d-611e187afc3a@googlegroups.com> Message-ID: On Tuesday, September 30, 2014 8:48:15 PM UTC+5:30, c... at isbd.net wrote: > Rustom Mody wrote: > > On Tuesday, September 30, 2014 5:18:31 PM UTC+5:30, Chris wrote: > > > I would actually > > > quite like to keep the configuration data separate from the code as it > > > would simplify using the data at the 'home' end of things as I'd just > > > need to copy the configuration file across. This was why the database > > > approach appealed at first as all I need to do is copy the database > > > and everything is in there. > > Of course > > > Are there any better ways of doing this? E.g. some sort of standard > > > configuration file format that Python knows about? > > Umm this is getting to be a FAQ... > > Maybe it should go up somewhere? > > Yes there are dozens: > > - ini > > - csv > > - json > > - yml > > - xml > > - pickle > > - And any DBMS of your choice > > I guess Ive forgotten as many as Ive listed!! > Yes, I know, I've found most of those. I'm really asking for help in > choosing which to use. I think I can reject some quite quickly:- > xml - horrible, nasty to edit, etc. I don't like XML! :-) Heh! Youve proved yourself a pythonista! > ini - doesn't work so well with lists/dictionaries (though possible) > csv - rather difficult to edit Have you tried with comma=tab? > yml - front runner if I go for configuration files Yeah my favorite as well > json - one of the most likely possibilities, but prefer yml Seems to be most popular nowadays -- maybe related to being almost yaml and in the standard lib > pickle - not user editable as I understand it Well not in any reasonably pleasant way! > What I'm really asking for is how to choose between:- > python - just keep config in the modules/classes, not easy to use > at 'both ends' (home and remote), otherwise quite simple Can work at a trivial level. As soon as things get a bit larger data and code mixed up is a recipe for mess up. From rosuav at gmail.com Tue Sep 30 12:51:27 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 1 Oct 2014 02:51:27 +1000 Subject: Keepin constants, configuration values, etc. in Python - dedicated module or what? In-Reply-To: References: <54hqfb-nan.ln1@chris.zbmc.eu> <36d7ddca-29f4-403c-a64d-611e187afc3a@googlegroups.com> Message-ID: On Wed, Oct 1, 2014 at 2:39 AM, Rustom Mody wrote: >> python - just keep config in the modules/classes, not easy to use >> at 'both ends' (home and remote), otherwise quite simple > > Can work at a trivial level. > > As soon as things get a bit larger data and code mixed up is a recipe for mess up. True, but it's certainly possible to break out the config data into an importable module that conceptually just provides constants. Technically it's code, yes, but it'll normally be code that looks like your standard "name = value" config file: # docs for first option # more docs # examples # etcetera first_option =123 # docs for second option second_option = 234 Is that Python code, or is it a sectionless INI file, or what? There's no difference. And you get expressions for free - simple stuff like "7*24*60*60" to represent the number of seconds in a week (for people who aren't intimately familiar with 604800), or calculations relative to previous data, or whatever. Sometimes it's helpful to have just a little code in your data. ChrisA From rustompmody at gmail.com Tue Sep 30 13:01:00 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 30 Sep 2014 10:01:00 -0700 (PDT) Subject: Keepin constants, configuration values, etc. in Python - dedicated module or what? In-Reply-To: References: <54hqfb-nan.ln1@chris.zbmc.eu> <36d7ddca-29f4-403c-a64d-611e187afc3a@googlegroups.com> Message-ID: <2ea96bcf-e905-4d77-a105-82b27715aa6e@googlegroups.com> On Tuesday, September 30, 2014 10:22:12 PM UTC+5:30, Chris Angelico wrote: > On Wed, Oct 1, 2014 at 2:39 AM, Rustom Mody wrote: > >> python - just keep config in the modules/classes, not easy to use > >> at 'both ends' (home and remote), otherwise quite simple > > Can work at a trivial level. > > As soon as things get a bit larger data and code mixed up is a recipe for mess up. > True, but it's certainly possible to break out the config data into an > importable module that conceptually just provides constants. > Technically it's code, yes, but it'll normally be code that looks like > your standard "name = value" config file: > # docs for first option > # more docs > # examples > # etcetera > first_option =123 > # docs for second option > second_option = 234 > Is that Python code, or is it a sectionless INI file, or what? Yeah I was going to say that this is possible > There's no difference. But there is! Its code that looks like data. > And you get expressions for free - simple stuff like > "7*24*60*60" to represent the number of seconds in a week (for people > who aren't intimately familiar with 604800), or calculations relative > to previous data, or whatever. Sometimes it's helpful to have just a > little code in your data. Not free at all. Power of code means cost of code See http://www.w3.org/2001/tag/doc/leastPower.html I'd reiterate though what I first said: In this case its probably ok if the code (=data) does not cross trivial limits From rosuav at gmail.com Tue Sep 30 13:15:30 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 1 Oct 2014 03:15:30 +1000 Subject: Keepin constants, configuration values, etc. in Python - dedicated module or what? In-Reply-To: <2ea96bcf-e905-4d77-a105-82b27715aa6e@googlegroups.com> References: <54hqfb-nan.ln1@chris.zbmc.eu> <36d7ddca-29f4-403c-a64d-611e187afc3a@googlegroups.com> <2ea96bcf-e905-4d77-a105-82b27715aa6e@googlegroups.com> Message-ID: On Wed, Oct 1, 2014 at 3:01 AM, Rustom Mody wrote: >> And you get expressions for free - simple stuff like >> "7*24*60*60" to represent the number of seconds in a week (for people >> who aren't intimately familiar with 604800), or calculations relative >> to previous data, or whatever. Sometimes it's helpful to have just a >> little code in your data. > > Not free at all. Power of code means cost of code > See http://www.w3.org/2001/tag/doc/leastPower.html It's free once you've already decided (for other reasons) to make your config file use Python syntax, at which point you've already paid the cost of code. But you're quite right, allowing code does have costs. Most notably, you have to quote your strings; although the direct benefits you get (line continuation, unambiguous handling of leading/trailing spaces, etc) may outweigh that on their own. > I'd reiterate though what I first said: In this case its probably > ok if the code (=data) does not cross trivial limits I'd agree, where "trivial limits" is defined by each individual item. Going with straight Python code is fine for huge projects with long config files, as long as each config entry is itself simple. You even get a form of #include: "from otherfile import *". ChrisA From rustompmody at gmail.com Tue Sep 30 13:31:01 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 30 Sep 2014 10:31:01 -0700 (PDT) Subject: Keepin constants, configuration values, etc. in Python - dedicated module or what? In-Reply-To: References: <54hqfb-nan.ln1@chris.zbmc.eu> <36d7ddca-29f4-403c-a64d-611e187afc3a@googlegroups.com> <2ea96bcf-e905-4d77-a105-82b27715aa6e@googlegroups.com> Message-ID: On Tuesday, September 30, 2014 10:46:21 PM UTC+5:30, Chris Angelico wrote: > On Wed, Oct 1, 2014 at 3:01 AM, Rustom Mody wrote: > >> And you get expressions for free - simple stuff like > >> "7*24*60*60" to represent the number of seconds in a week (for people > >> who aren't intimately familiar with 604800), or calculations relative > >> to previous data, or whatever. Sometimes it's helpful to have just a > >> little code in your data. > > Not free at all. Power of code means cost of code > > See http://www.w3.org/2001/tag/doc/leastPower.html > It's free once you've already decided (for other reasons) to make your > config file use Python syntax, at which point you've already paid the > cost of code. But you're quite right, allowing code does have costs. > Most notably, you have to quote your strings; although the direct > benefits you get (line continuation, unambiguous handling of > leading/trailing spaces, etc) may outweigh that on their own. > > I'd reiterate though what I first said: In this case its probably > > ok if the code (=data) does not cross trivial limits > I'd agree, where "trivial limits" is defined by each individual item. > Going with straight Python code is fine for huge projects with long > config files, as long as each config entry is itself simple. You even > get a form of #include: "from otherfile import *". Well in programming we sometimes use strict/formal methods and sometimes more informal. In this case using configparser or pyyaml or whatever means that the config file's syntax is rigorously fixed by that library On the other hand if you impose a convention: Constants file-module has NOTHING but constants, thats a non-formal convention and thats ok. If however you mix it up with other (real) code, you'll get a bloody mess. This kind of stuff "7*24*60*60" is borderline and in my experience its a slippery slope that ends up being more trouble than its worth. Experience being emacs where because in lisp code and data are the same, all kinds of design messes are perpetrated From cl at isbd.net Tue Sep 30 13:30:11 2014 From: cl at isbd.net (cl at isbd.net) Date: Tue, 30 Sep 2014 18:30:11 +0100 Subject: Keepin constants, configuration values, etc. in Python - dedicated module or what? References: <54hqfb-nan.ln1@chris.zbmc.eu> <36d7ddca-29f4-403c-a64d-611e187afc3a@googlegroups.com> <2ea96bcf-e905-4d77-a105-82b27715aa6e@googlegroups.com> Message-ID: <3u5rfb-mct.ln1@chris.zbmc.eu> Rustom Mody wrote: > > > # docs for first option > > # more docs > > # examples > > # etcetera > > first_option =123 > > > # docs for second option > > second_option = 234 > > > Is that Python code, or is it a sectionless INI file, or what? > > Yeah I was going to say that this is possible > > > There's no difference. > > But there is! Its code that looks like data. > The main trouble with this approach is that I need some way to have the python/config file available at the 'home' end of this as well as at the 'remote' end. I guess I could write a copy of the file into the database but then I have the editing issue again, changing it becomes messy. If it's not in the database then how do I 'tie' it to the data? -- Chris Green ? From christian at python.org Tue Sep 30 13:39:16 2014 From: christian at python.org (Christian Heimes) Date: Tue, 30 Sep 2014 19:39:16 +0200 Subject: SNI support in python 2.7 for Locust load tests In-Reply-To: References: Message-ID: On 30.09.2014 16:50, Reddy wrote: > Hello, > > At the beginning - welcome everyone, as this is my first post here. I'm not an active Python developer now, but I have general knowledge of the language. > > I'm trying to use locust (http://locust.io/) to run load test of one site we're developing. Everything was running nice and smooth until we switch the servers to use SNI. SNI is not officially supported in python 2.7.5 but Locust doesn't work on python3 as it uses gevent which AFAIK are supported for python2 only. I finally managed to run our scripts on local Ubuntu after upgrading python to 2.7.8 from utopic repository but I can't replicate the same on target CentOS where the scripts are supposed to be executed. I tried compiling python from http://www.python.org/ftp/python/2.7.8/Python-2.7.8.tar.xz, I even tried unpacking sources of Ubuntu python2.7 package (from http://se.archive.ubuntu.com/ubuntu/pool/main/p/python2.7/python2.7_2.7.8.orig.tar.gz), patching them with TLS1_1 and TLS1_2 s > upport from https://bugs.python.org/file30761/python-2.7.5-tls1.1-and-tls1.2.patch) and still no luck. I do monkey patch in Locust startup file according to http://stackoverflow.com/a/19477363 (oth > erwise it wouldn't work on Ubuntu as well) but still I get error stack as attached below. I also checked with pip list that all python packages have the same versions on both systems. Any idea what I'm missing on the target load test system which I have in Ubuntu? Hello, you have two options: Python 2.7.9 implements PEP 466 "Network Security Enhancements for Python 2.7.x" including TLS 1.1, 1.2 and SNI support. 2.7.9 will be released shortly. You could try the 2.7 branch from hg.python.org. Use PyOpenSSL instead of Python's ssl module. It supports SNI, too. Regards Christian From rosuav at gmail.com Tue Sep 30 13:46:25 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 1 Oct 2014 03:46:25 +1000 Subject: Keepin constants, configuration values, etc. in Python - dedicated module or what? In-Reply-To: References: <54hqfb-nan.ln1@chris.zbmc.eu> <36d7ddca-29f4-403c-a64d-611e187afc3a@googlegroups.com> <2ea96bcf-e905-4d77-a105-82b27715aa6e@googlegroups.com> Message-ID: On Wed, Oct 1, 2014 at 3:31 AM, Rustom Mody wrote: > On the other hand if you impose a convention: Constants file-module has > NOTHING but constants, thats a non-formal convention and thats ok. > > If however you mix it up with other (real) code, you'll get a bloody mess. > This kind of stuff "7*24*60*60" is borderline and in my experience > its a slippery slope that ends up being more trouble than its worth. Agreed, and which side of the border it's on is a matter of opinion. Suppose you were writing an INI-style parser - would you include this feature? I probably wouldn't include arithmetic, as it's usually more effort than it's worth, but it isn't a bad feature inherently. I'd definitely not include backreferencing (FOO = "bar", followed by FOO_LEN = len(FOO) or something), or the ability to chain assignments (FOO = BAR = 0), so those would be advised against in the convention docs. On the other hand, a quoted string requirement ("foo\nbar") makes a huge amount of sense in certain contexts, and I can imagine implementing quite a lot of a programming language's string literal syntax. ChrisA From rosuav at gmail.com Tue Sep 30 13:49:08 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 1 Oct 2014 03:49:08 +1000 Subject: Keepin constants, configuration values, etc. in Python - dedicated module or what? In-Reply-To: <3u5rfb-mct.ln1@chris.zbmc.eu> References: <54hqfb-nan.ln1@chris.zbmc.eu> <36d7ddca-29f4-403c-a64d-611e187afc3a@googlegroups.com> <2ea96bcf-e905-4d77-a105-82b27715aa6e@googlegroups.com> <3u5rfb-mct.ln1@chris.zbmc.eu> Message-ID: On Wed, Oct 1, 2014 at 3:30 AM, wrote: > The main trouble with this approach is that I need some way to have > the python/config file available at the 'home' end of this as well as > at the 'remote' end. I guess I could write a copy of the file into > the database but then I have the editing issue again, changing it > becomes messy. If it's not in the database then how do I 'tie' it to > the data? That's a design question. Maybe it's better for you to do your config in the database. I usually find that these config files include database credentials (server, port, user name, password), so they have to be (a) outside the database, (b) outside source control, and (c) separately configurable for test and production systems, even if they run on the exact same hardware. So for those situations, it makes more sense to have them in a script or INI file, rather than the database. Your situation may well be completely different. ChrisA From mihamina.rakotomandimby at rktmb.org Tue Sep 30 13:38:27 2014 From: mihamina.rakotomandimby at rktmb.org (Mihamina Rakotomandimby) Date: Tue, 30 Sep 2014 20:38:27 +0300 Subject: Python code in presentations In-Reply-To: <84647424.8133875.1412077808913.JavaMail.root@sequans.com> References: <84647424.8133875.1412077808913.JavaMail.root@sequans.com> Message-ID: <542AEA93.80003@rktmb.org> On 09/30/2014 02:50 PM, Jean-Michel Pichavant wrote: > I wonder if some people in this list who have successfully presented python code have some tips about doing the proper way. Ned's presentations for pycons are to me one example of successful code presentation: > - the layout is simple > - the code and code output are clearly identified > - a line of code can be highlighted while presenting I use to use Emacs + python-mode + htmlize to export snippets to HTML and then open the HTML with LibreOffice then copy-paste from Writer to Impress. -------------- next part -------------- An HTML attachment was scrubbed... URL: From cl at isbd.net Tue Sep 30 13:50:04 2014 From: cl at isbd.net (cl at isbd.net) Date: Tue, 30 Sep 2014 18:50:04 +0100 Subject: Keepin constants, configuration values, etc. in Python - dedicated module or what? References: <54hqfb-nan.ln1@chris.zbmc.eu> Message-ID: Neil D. Cerutti wrote: > On 9/30/2014 7:35 AM, cl at isbd.net wrote: > > Thus I'd have something like (apologies for any syntax errors):- > > > > cfg = { "LeisureVolts": ["AIN0", 0.061256, "Leisure Battery Voltage"], > > "StarterVolts": ["AIN1", 0.060943, "Starter Battery Voltage"], > > "LeisureAmps1": ["AIN2", 0.423122, "Leisure Battery Current"} > > > > (It might be better to makes those lists dictionaries, but it shows > > the idea) > > Using configparser.ConfigParser to read an ini-format seems like a good > idea. I use it for my own numerous fixed format data file definitions, > and it's been convenient and even extensible. > > [LeisureVolts] > Description=Leisure Battery Voltage > Code=AIN0 > Value=0.061256 > > [StarterVolts] > Description=Starter Battery Voltage > Code=AIN1 > Value=0.060943 > > [LeisureAmps1] > Description=Leisure Battery Current > Code=AIN2 > Value=0.423122 > That's OK except that it doesn't associate the different sections in any way, I need another level which includes these to indicate that these are values read from the ADC. There's another collection of config data for values read from the 1-wire bus. I guess I could have two config files, one for ADC and one for 1-wire. In fact I think that's the best approach so far. Ini format files are human readable (and more to the point editable), I can store them in the same directory as the database so they will get carried around with the data and the configparser module is built-in. -- Chris Green ? From grawburg at myglnc.com Tue Sep 30 16:25:21 2014 From: grawburg at myglnc.com (Grawburg) Date: Tue, 30 Sep 2014 16:25:21 -0400 Subject: Teaching Python In-Reply-To: References: Message-ID: I use Chris Roffey's "Coding Club - Python Basics (Level 1)" and "Coding Club - Python: Next Steps (Level 2)" I also use the Turtle material from "Python for Kids" These are 11+ year old kids in week long, 3 hour/day summer camps on the Raspberry Pi and Python. The Level 2 book is for the 2nd camp (for those who want to go further). Brian Grawburg Wilson, NC From mathematisch at gmail.com Tue Sep 30 16:53:00 2014 From: mathematisch at gmail.com (math math) Date: Tue, 30 Sep 2014 13:53:00 -0700 (PDT) Subject: how to parse standard algebraic notation Message-ID: <4a7f3e7a-ba4d-405e-a078-937bf861fcd8@googlegroups.com> Hi, I am trying to learn Python while solving exercises. I want to basically write a program that inputs a polynomial in standard algebraic notation and outputs its derivative. I know that I need to get the exponent somehow, but I am not sure how to accomplish this in python (3.3) Do you have any ideas or suggestions? I don't want to use existing modules as this is meant to be a didactic experience. Regards From gherron at digipen.edu Tue Sep 30 17:05:23 2014 From: gherron at digipen.edu (Gary Herron) Date: Tue, 30 Sep 2014 14:05:23 -0700 Subject: how to parse standard algebraic notation In-Reply-To: <4a7f3e7a-ba4d-405e-a078-937bf861fcd8@googlegroups.com> References: <4a7f3e7a-ba4d-405e-a078-937bf861fcd8@googlegroups.com> Message-ID: <542B1B13.20709@digipen.edu> On 09/30/2014 01:53 PM, math math wrote: > Hi, > > I am trying to learn Python while solving exercises. > > I want to basically write a program that inputs a polynomial in standard algebraic notation and outputs its derivative. > > I know that I need to get the exponent somehow, but I am not sure how to accomplish this in python (3.3) > > Do you have any ideas or suggestions? I don't want to use existing modules as this is meant to be a didactic experience. > > Regards This depends on things you have not yet told us. In particular -- what "standard algebraic notation"? For x-squared: x**2 ? or perhaps x^2 ? or something else like some Unicode characters or HTML to get a small superscript 2 above an x. Once you give an example of what your input looks like, we can start hashing out how to read it. Gary Herron -- Dr. Gary Herron Department of Computer Science DigiPen Institute of Technology (425) 895-4418 From Seymore4Head at Hotmail.invalid Tue Sep 30 17:15:35 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Tue, 30 Sep 2014 17:15:35 -0400 Subject: Restarting Python Message-ID: <447m2atpvha8jt21cpulq8qu5p92pmogk3@4ax.com> Since the developers of Python decided to make Python 3 non backward compatible, I can't help but wonder why they don't think a command to restart would be a useful addition? From invalid at invalid.invalid Tue Sep 30 17:27:04 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 30 Sep 2014 21:27:04 +0000 (UTC) Subject: Restarting Python References: <447m2atpvha8jt21cpulq8qu5p92pmogk3@4ax.com> Message-ID: On 2014-09-30, Seymore4Head wrote: > Since the developers of Python decided to make Python 3 non backward > compatible, I can't help but wonder why they don't think a command to > restart would be a useful addition? Uh... what? Does that make any sense to anybody else? -- Grant Edwards grant.b.edwards Yow! My nose feels like a at bad Ronald Reagan movie ... gmail.com From cl at isbd.net Tue Sep 30 17:32:07 2014 From: cl at isbd.net (cl at isbd.net) Date: Tue, 30 Sep 2014 22:32:07 +0100 Subject: Using namedtuple with sqlite, surely it can do better than the example Message-ID: In the namedtuple documentation there's an example:- EmployeeRecord = namedtuple('EmployeeRecord', 'name, age, title, department, paygrade') import sqlite3 conn = sqlite3.connect('/companydata') cursor = conn.cursor() cursor.execute('SELECT name, age, title, department, paygrade FROM employees') for emp in map(EmployeeRecord._make, cursor.fetchall()): print emp.name, emp.title (I've deleted the csv bit) Surely having to match up the "name, age, title, department, paygrade" between the tuple and the database can be automated, the example is rather pointless otherwise. At the very least one should use the same variable instance for both, but it should be possible to get the tuple names from the database. -- Chris Green ? From ned at nedbatchelder.com Tue Sep 30 18:05:20 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 30 Sep 2014 18:05:20 -0400 Subject: Restarting Python In-Reply-To: <447m2atpvha8jt21cpulq8qu5p92pmogk3@4ax.com> References: <447m2atpvha8jt21cpulq8qu5p92pmogk3@4ax.com> Message-ID: On 9/30/14 5:15 PM, Seymore4Head wrote: > Since the developers of Python decided to make Python 3 non backward > compatible, I can't help but wonder why they don't think a command to > restart would be a useful addition? > Starting a process over again in the same way is not something that is easy to do from within the process. How are you running Python? Is it difficult to start it again? -- Ned Batchelder, http://nedbatchelder.com From Seymore4Head at Hotmail.invalid Tue Sep 30 18:07:32 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Tue, 30 Sep 2014 18:07:32 -0400 Subject: Restarting Python References: <447m2atpvha8jt21cpulq8qu5p92pmogk3@4ax.com> Message-ID: On Tue, 30 Sep 2014 18:05:20 -0400, Ned Batchelder wrote: >On 9/30/14 5:15 PM, Seymore4Head wrote: >> Since the developers of Python decided to make Python 3 non backward >> compatible, I can't help but wonder why they don't think a command to >> restart would be a useful addition? >> > >Starting a process over again in the same way is not something that is >easy to do from within the process. How are you running Python? Is it >difficult to start it again? It is not difficult to start again. It just seems like restart is a missing command. I see many questions asking how to do it. From tjreedy at udel.edu Tue Sep 30 18:58:50 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 30 Sep 2014 18:58:50 -0400 Subject: Restarting Python In-Reply-To: <447m2atpvha8jt21cpulq8qu5p92pmogk3@4ax.com> References: <447m2atpvha8jt21cpulq8qu5p92pmogk3@4ax.com> Message-ID: On 9/30/2014 5:15 PM, Seymore4Head wrote: > Since the developers of Python decided to make Python 3 non backward > compatible, This is a trollish exaggeration. > I can't help but wonder why they don't think a command to > restart would be a useful addition? More trollishness. Python does not have 'commands'. Feature additions are independent of the changes make in 3.0. 2.7 got many new features, and even now is getting a few new security features. One cannot have opinions about something they do not think of. If you want to propose a new feature, just do that. Describe a use case and how the feature would look, using current Python syntax, and how it would operate. -- Terry Jan Reedy From __peter__ at web.de Tue Sep 30 19:06:51 2014 From: __peter__ at web.de (Peter Otten) Date: Wed, 01 Oct 2014 01:06:51 +0200 Subject: Using namedtuple with sqlite, surely it can do better than the example References: Message-ID: cl at isbd.net wrote: > In the namedtuple documentation there's an example:- > > EmployeeRecord = namedtuple('EmployeeRecord', 'name, age, title, > department, paygrade') > > import sqlite3 > conn = sqlite3.connect('/companydata') > cursor = conn.cursor() > cursor.execute('SELECT name, age, title, department, paygrade FROM > employees') for emp in map(EmployeeRecord._make, cursor.fetchall()): > print emp.name, emp.title > > (I've deleted the csv bit) > > Surely having to match up the "name, age, title, department, > paygrade" between the tuple and the database can be automated, the > example is rather pointless otherwise. At the very least one should > use the same variable instance for both, but it should be possible to > get the tuple names from the database. It's an example meant to convey the basic idea -- you can add bells and whistles in your actual code. Something like #!/usr/bin/env python3 import sqlite3 import functools from collections import namedtuple def make_namedtuple_row_factory(): last_pair = (None, None) # description, rowtype @functools.lru_cache(maxsize=500) def make_rowtype(description): return namedtuple("Row", [column[0] for column in description])._make def make_namedtuple_is_make(cursor, row): nonlocal last_pair this_description = cursor.description last_description, last_rowtype = last_pair if last_description is this_description: return last_rowtype(row) this_rowtype = make_rowtype(this_description) last_pair = this_description, this_rowtype return this_rowtype(row) return make_namedtuple_is_make db = sqlite3.connect("companydata") cursor = db.cursor() cursor.row_factory = make_namedtuple_row_factory() for employee in cursor.execute( 'SELECT name, age, title, department, paygrade FROM employees'): print(employee.name, employee.title) might be easy to use and have acceptable performance, but most of the code distracts from the namedtuple usage. From Seymore4Head at Hotmail.invalid Tue Sep 30 19:16:15 2014 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Tue, 30 Sep 2014 19:16:15 -0400 Subject: Restarting Python References: <447m2atpvha8jt21cpulq8qu5p92pmogk3@4ax.com> Message-ID: On Tue, 30 Sep 2014 18:58:50 -0400, Terry Reedy wrote: >On 9/30/2014 5:15 PM, Seymore4Head wrote: >> Since the developers of Python decided to make Python 3 non backward >> compatible, > >This is a trollish exaggeration. > > > I can't help but wonder why they don't think a command to >> restart would be a useful addition? > >More trollishness. Python does not have 'commands'. > >Feature additions are independent of the changes make in 3.0. 2.7 got >many new features, and even now is getting a few new security features. > >One cannot have opinions about something they do not think of. > >If you want to propose a new feature, just do that. Describe a use case >and how the feature would look, using current Python syntax, and how it >would operate. Bad day? From breamoreboy at yahoo.co.uk Tue Sep 30 19:23:36 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 01 Oct 2014 00:23:36 +0100 Subject: Using namedtuple with sqlite, surely it can do better than the example In-Reply-To: References: Message-ID: On 30/09/2014 22:32, cl at isbd.net wrote: > In the namedtuple documentation there's an example:- > > EmployeeRecord = namedtuple('EmployeeRecord', 'name, age, title, department, paygrade') > > import sqlite3 > conn = sqlite3.connect('/companydata') > cursor = conn.cursor() > cursor.execute('SELECT name, age, title, department, paygrade FROM employees') > for emp in map(EmployeeRecord._make, cursor.fetchall()): > print emp.name, emp.title > > (I've deleted the csv bit) > > Surely having to match up the "name, age, title, department, > paygrade" between the tuple and the database can be automated, the > example is rather pointless otherwise. At the very least one should > use the same variable instance for both, but it should be possible to > get the tuple names from the database. > I'm not sure what you're trying to achieve but I've found it easy to use the sqlite Row object see https://docs.python.org/3/library/sqlite3.html#row-objects -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Tue Sep 30 19:24:35 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 01 Oct 2014 00:24:35 +0100 Subject: Restarting Python In-Reply-To: References: <447m2atpvha8jt21cpulq8qu5p92pmogk3@4ax.com> Message-ID: On 30/09/2014 22:27, Grant Edwards wrote: > On 2014-09-30, Seymore4Head wrote: > >> Since the developers of Python decided to make Python 3 non backward >> compatible, I can't help but wonder why they don't think a command to >> restart would be a useful addition? > > Uh... what? > > Does that make any sense to anybody else? > Short answer no. Long answer definitely not. -- 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 Tue Sep 30 19:57:54 2014 From: roy at panix.com (Roy Smith) Date: Tue, 30 Sep 2014 19:57:54 -0400 Subject: Python code in presentations References: Message-ID: On Tue, Sep 30, 2014 1:50 PM CEST Jean-Michel Pichavant wrote: > >I'm currently writing a presentation to help my co-workers ramp up on new > >features of our tool (written in python (2.7)). > > > >I have some difficulties presenting code in an efficient way (with some > >basic syntax highlights). [...] In article , Albert-Jan Roskam wrote: > Have you considered using Ipython Notebook? Your browser would replace ppt. +1 on that suggestion. From rosuav at gmail.com Tue Sep 30 20:20:50 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 1 Oct 2014 10:20:50 +1000 Subject: how to parse standard algebraic notation In-Reply-To: <4a7f3e7a-ba4d-405e-a078-937bf861fcd8@googlegroups.com> References: <4a7f3e7a-ba4d-405e-a078-937bf861fcd8@googlegroups.com> Message-ID: On Wed, Oct 1, 2014 at 6:53 AM, math math wrote: > I want to basically write a program that inputs a polynomial in standard algebraic notation and outputs its derivative. > > I know that I need to get the exponent somehow, but I am not sure how to accomplish this in python (3.3) As Gary says, the form of input is really the critical part. How will users type these? One simple cheat you could do would be to prompt for each term separately - something like this: exponent = int(input("What is the highest exponent used? ")) terms = [] while exponent: terms.append(input("Enter coefficient of x^%d: " % exponent)) exponent -= 1 terms.append(input("Enter constant term: ")) You could do something similar with a GUI toolkit like tkinter or pygtk, too; provide input fields for the coefficients, and labels in between that say "x? + " etc. Otherwise, you're going to be primarily bound by the keyboard - your program is useless if it takes longer to key data into it than to do the work manually. Python 3.3 has excellent Unicode support, and Unicode has excellent support for mathematical notations, so you should be able to produce nice-looking output; but mathematical notation is much easier to write on a blackboard than on a computer's keyboard. (And even though some keyboards are black, like the one I'm using right now, it doesn't make it any easier. Sorry.) Gary's suggestions of the double asterisk and caret are two commonly-used notations for exponentiation in computers, so either would make some sense. Otherwise, you could come up with some other notation, but mainly, it has to be typeable. But hey! Once you have something you can type unambiguously, we can help you parse that into something you can make use of! That part's not too hard. ChrisA From rosuav at gmail.com Tue Sep 30 20:30:59 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 1 Oct 2014 10:30:59 +1000 Subject: Restarting Python In-Reply-To: References: <447m2atpvha8jt21cpulq8qu5p92pmogk3@4ax.com> Message-ID: On Wed, Oct 1, 2014 at 9:16 AM, Seymore4Head wrote: > On Tue, 30 Sep 2014 18:58:50 -0400, Terry Reedy > wrote: > >>On 9/30/2014 5:15 PM, Seymore4Head wrote: >>> Since the developers of Python decided to make Python 3 non backward >>> compatible, >> >>This is a trollish exaggeration. >> >> > I can't help but wonder why they don't think a command to >>> restart would be a useful addition? >> >>More trollishness. Python does not have 'commands'. >> >>Feature additions are independent of the changes make in 3.0. 2.7 got >>many new features, and even now is getting a few new security features. >> >>One cannot have opinions about something they do not think of. >> >>If you want to propose a new feature, just do that. Describe a use case >>and how the feature would look, using current Python syntax, and how it >>would operate. > > Bad day? No, that's not Terry having a bad day and taking it out on you. That's you making a vague proposal with dubious justification, and Terry coming back to you asking for clarification. As he says, you need to propose new features by saying what they'd do, how they'd do it, and why they should be implemented. Ignore Python's history here, just look at where the language currently is and where you're suggesting it go. ChrisA